2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2005-2008 - INRIA - Allan CORNET
4 * Copyright (C) 2012 - DIGITEO - Allan CORNET
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
14 /*--------------------------------------------------------------------------*/
18 #include "dropFiles.h"
19 #include "sci_malloc.h"
20 #include "storeCommand.h" /* storecommand */
21 #include "FindFileExtension.h"
22 #include "URIFileToFilename.h"
23 #include "with_module.h"
24 #include "os_string.h"
25 #include "charEncoding.h"
26 /*--------------------------------------------------------------------------*/
27 #define BIN_EXTENSION_FILE ".bin"
28 #define SAV_EXTENSION_FILE ".sav"
29 #define COS_EXTENSION_FILE ".cos"
30 #define XCOS_EXTENSION_FILE ".xcos"
31 #define COSF_EXTENSION_FILE ".cosf"
32 #define SCI_EXTENSION_FILE ".sci"
33 #define SCE_EXTENSION_FILE ".sce"
34 #define TST_EXTENSION_FILE ".tst"
35 #define DEM_EXTENSION_FILE ".dem"
36 #define SCG_EXTENSION_FILE ".scg"
37 #define ZCOS_EXTENSION_FILE ".zcos"
38 #define SOD_EXTENSION_FILE ".sod"
39 /*--------------------------------------------------------------------------*/
40 #define FORMAT_BIN_SCE_EXTENSION_FILES "load('%s');"
41 #define FORMAT_COS_COSF_XCOS_EXTENSION_FILES "xcos('%s');"
42 #define FORMAT_SCI_EXTENSION_FILES "exec('%s');"
43 #define FORMAT_SCE_TST_EXTENSION_FILES "exec('%s');"
44 #define FORMAT_SCG_EXTENSION_FILES "load('%s');"
45 #define FORMAT_UNKNOW_EXTENSION_FILES "disp(gettext('Unknown file type : %s'));"
46 #define XCOS_NOT_INSTALLED "disp(gettext('Please install xcos module.'))"
47 /*--------------------------------------------------------------------------*/
48 static char *getCommandByFileExtension(char *File, char *FileExtension);
49 static char *buildCommand(char *format, char *filename);
50 static BOOL LaunchFilebyExtension(char *File);
51 /*--------------------------------------------------------------------------*/
52 BOOL dropFiles(char **files)
58 char *convertfile = URIFileToFilename(files[len]);
62 BOOL bCheck = LaunchFilebyExtension(convertfile);
77 /*--------------------------------------------------------------------------*/
78 BOOL LaunchFilebyExtension(char *File)
82 char *CommandLine = NULL;
83 char *FileExtension = NULL;
85 FileExtension = FindFileExtension(File);
86 CommandLine = getCommandByFileExtension(File, FileExtension);
90 StoreCommand(CommandLine);
105 /*--------------------------------------------------------------------------*/
106 static char *getCommandByFileExtension(char *File, char *FileExtension)
108 char *command = NULL;
112 if ( (stricmp(FileExtension, BIN_EXTENSION_FILE) == 0) ||
113 (stricmp(FileExtension, SAV_EXTENSION_FILE) == 0) ||
114 (stricmp(FileExtension, SOD_EXTENSION_FILE) == 0))
116 command = buildCommand(FORMAT_BIN_SCE_EXTENSION_FILES, File);
118 else if ( (stricmp(FileExtension, COS_EXTENSION_FILE) == 0) ||
119 (stricmp(FileExtension, COSF_EXTENSION_FILE) == 0) ||
120 (stricmp(FileExtension, ZCOS_EXTENSION_FILE) == 0) ||
121 (stricmp(FileExtension, XCOS_EXTENSION_FILE) == 0))
123 if (with_module("xcos"))
125 command = buildCommand(FORMAT_COS_COSF_XCOS_EXTENSION_FILES, File);
129 command = os_strdup(XCOS_NOT_INSTALLED);
132 else if (stricmp(FileExtension, SCI_EXTENSION_FILE) == 0)
134 command = buildCommand(FORMAT_SCI_EXTENSION_FILES, File);
136 else if ( (stricmp(FileExtension, SCE_EXTENSION_FILE) == 0) || (stricmp(FileExtension, TST_EXTENSION_FILE) == 0) || (stricmp(FileExtension, DEM_EXTENSION_FILE) == 0) )
138 command = buildCommand(FORMAT_SCE_TST_EXTENSION_FILES, File);
140 else if (stricmp(FileExtension, SCG_EXTENSION_FILE) == 0)
142 command = buildCommand(FORMAT_SCG_EXTENSION_FILES, File);
146 command = buildCommand(FORMAT_UNKNOW_EXTENSION_FILES, File);
151 /*--------------------------------------------------------------------------*/
152 static char *buildCommand(char *format, char *filename)
154 char *command = NULL;
156 if (format && filename)
158 command = (char*)MALLOC( (strlen(filename) + strlen(format) + 1) * sizeof(char) );
161 sprintf(command, format, filename);
167 /*--------------------------------------------------------------------------*/