move files
Allan Cornet [Thu, 30 Aug 2007 13:58:39 +0000 (13:58 +0000)]
need to do primitives with removedir et createdirectory (UAC management)

27 files changed:
scilab/modules/core/sci_gateway/c/sci_getcwd.c
scilab/modules/core/src/c/SCIHOME.c
scilab/modules/core/src/c/tmpdir.c
scilab/modules/fileio/Makefile.am
scilab/modules/fileio/fileio.vcproj
scilab/modules/fileio/includes/createdirectory.h [new file with mode: 0644]
scilab/modules/fileio/includes/gw_fileio.h
scilab/modules/fileio/includes/isdir.h [new file with mode: 0644]
scilab/modules/fileio/includes/removedir.h [new file with mode: 0644]
scilab/modules/fileio/sci_gateway/c/gw_fileio.c
scilab/modules/fileio/sci_gateway/c/sci_isdir.c [moved from scilab/modules/io/sci_gateway/c/sci_isdir.c with 98% similarity]
scilab/modules/fileio/sci_gateway/fileio_gateway.xml
scilab/modules/fileio/src/c/createdirectory.c [new file with mode: 0644]
scilab/modules/fileio/src/c/isDrive.c [new file with mode: 0644]
scilab/modules/fileio/src/c/isDrive.h [new file with mode: 0644]
scilab/modules/fileio/src/c/isdir.c [new file with mode: 0644]
scilab/modules/fileio/src/c/removedir.c [moved from scilab/modules/io/src/c/directories.c with 60% similarity]
scilab/modules/io/Makefile.am
scilab/modules/io/includes/directories.h [deleted file]
scilab/modules/io/includes/gw_io.h
scilab/modules/io/sci_gateway/c/gw_io.c
scilab/modules/io/sci_gateway/c/sci_get_absolute_file_path.c
scilab/modules/io/sci_gateway/c/sci_getrelativefilename.c
scilab/modules/io/sci_gateway/io_gateway.xml
scilab/modules/io/src/c/io.vcproj
scilab/modules/jvm/src/c/addToClasspath.c
scilab/modules/jvm/src/c/addToLibrarypath.c

index 239b1ad..eb7a29d 100644 (file)
@@ -6,7 +6,6 @@
 #include "machine.h"
 #include "stack-c.h"
 #include "scicurdir.h"
-#include "../../../io/includes/directories.h"
 #include "MALLOC.h"
 #include "error_scilab.h"
 /*-----------------------------------------------------------------------------------*/
index cb34a63..fea74bd 100644 (file)
@@ -10,7 +10,8 @@
 #include "version.h"
 #include "machine.h"
 
-#include "../../../io/includes/directories.h"
+#include "../../../fileio/includes/createdirectory.h"
+#include "../../../fileio/includes/isdir.h"
 #include "../../../io/includes/getenvc.h"
 #include "scilabDefaults.h"
 /*-----------------------------------------------------------------------------------*/
@@ -69,8 +70,8 @@ BOOL setSCIHOME(void)
 
        if (!isdir(SCIHOMEPATH))
        {
-               if(!isdir(USERPATHSCILAB)) CreateDir(USERPATHSCILAB);
-               if (CreateDir(SCIHOMEPATH))
+               if(!isdir(USERPATHSCILAB)) createdirectory(USERPATHSCILAB);
+               if (createdirectory(SCIHOMEPATH))
                {
                        bOK=TRUE;
                        return bOK;
index 2786e71..4483da0 100644 (file)
@@ -3,7 +3,8 @@
 /*-----------------------------------------------------------------------------------*/
 #include <stdio.h>
 #include "machine.h"
-#include "../../../io/includes/directories.h"
+#include "../../../fileio/includes/removedir.h"
+#include "../../../fileio/includes/createdirectory.h"
 #include <string.h>
 #include "MALLOC.h" /* MALLOC */
 
@@ -80,7 +81,7 @@ void C2F(settmpdir)(void)
   }
 #else 
   sprintf(tmp_dir,"/tmp/SD_%d_",(int) getpid());
-  CreateDir(tmp_dir) ;
+  createdirectory(tmp_dir) ;
 #endif 
   sprintf(buf,"TMPDIR=%s",tmp_dir);
   putenv(buf);
@@ -104,7 +105,7 @@ char *get_sci_tmp_dir(void)
 void C2F(tmpdirc)(void)
 {
   char *tmp_dir2 = get_sci_tmp_dir(); 
-  RemoveDir(tmp_dir2);
+  removedir(tmp_dir2);
 }
 /*-----------------------------------------------------------------------------------*/
 char *getTMPDIR(void)
index 5b596ec..5dd6ab3 100644 (file)
@@ -41,7 +41,11 @@ src/c/getshortpathname.c \
 src/c/getlongpathname.c \
 src/c/FindFileExtension.c \
 src/c/URIFileToFilename.c \
-src/c/ConvertPathUnixToWindows.c
+src/c/ConvertPathUnixToWindows.c \
+src/c/createdirectory.c \
+src/c/isdir.c \
+src/c/isDrive.c \
+src/c/removedir.c
 
 
 GATEWAY_SOURCES = \
@@ -68,8 +72,8 @@ sci_gateway/c/sci_pathsep.c \
 sci_gateway/c/sci_filesep.c \
 sci_gateway/c/sci_getshortpathname.c \
 sci_gateway/c/sci_getlongpathname.c \
-sci_gateway/c/sci_fileext.c
-
+sci_gateway/c/sci_fileext.c \
+sci_gateway/c/sci_isdir.c
 
 libscifileio_la_CFLAGS=-Iincludes/ -Isrc/c/ -I$(top_srcdir)/libs/MALLOC/includes/ 
 
@@ -112,9 +116,10 @@ includes/sci_fileio.h \
 includes/findfiles.h \
 includes/FindFileExtension.h \
 includes/URIFileToFilename.h \
-includes/ConvertPathUnixToWindows.h
-
-
+includes/ConvertPathUnixToWindows.h \
+includes/createdirectory.h \
+includes/isdir.h \
+includes/removedir.h
 
 ####¬†fileio : demos files ####
 libscifileio_la_demosdir=$(mydatadir)
index 6c5c751..4d4afc9 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\createdirectory.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\deleteafile.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\isdir.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\isDrive.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\logger.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\removedir.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\ripole.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\sci_gateway\c\sci_isdir.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\sci_gateway\c\sci_maxfiles.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\includes\createdirectory.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\deleteafile.h"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\includes\isdir.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\isDrive.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\logger.h"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\includes\removedir.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\resource.h"
                                >
                        </File>
diff --git a/scilab/modules/fileio/includes/createdirectory.h b/scilab/modules/fileio/includes/createdirectory.h
new file mode 100644 (file)
index 0000000..f6acf75
--- /dev/null
@@ -0,0 +1,18 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifndef __CREATEDIRECTORY_H__\r
+#define __CREATEDIRECTORY_H__\r
+\r
+#include "machine.h" /* BOOL */\r
+\r
+/**\r
+* Create a directory\r
+* @param path the path of the futur directory\r
+* @return the result of the operation TRUE or FALSE\r
+*/\r
+BOOL createdirectory(const char *path);\r
+\r
+#endif /* __CREATEDIRECTORY_H__ */\r
+/*-----------------------------------------------------------------------------------*/ \r
index 3e67225..e875515 100644 (file)
@@ -44,6 +44,7 @@ int C2F(sci_filesep) _PARAMS((char *fname,unsigned long fname_len));
 int C2F(sci_getlongpathname) _PARAMS((char *fname,unsigned long fname_len));
 int C2F(sci_getshortpathname) _PARAMS((char *fname,unsigned long fname_len));
 int C2F(sci_fileext) _PARAMS((char *fname,unsigned long fname_len));
+int C2F(sci_isdir) _PARAMS((char *fname,unsigned long fname_len));
 /*-----------------------------------------------------------------------------------*/ 
 #endif /* __GW_FILEIO_H__ */
 /*-----------------------------------------------------------------------------------*/
diff --git a/scilab/modules/fileio/includes/isdir.h b/scilab/modules/fileio/includes/isdir.h
new file mode 100644 (file)
index 0000000..6390620
--- /dev/null
@@ -0,0 +1,18 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifndef __ISDIR_H__\r
+#define __ISDIR_H__\r
+\r
+#include "machine.h" /* BOOL */\r
+\r
+/**\r
+* Check if a directory exists or not\r
+* @param path the directory\r
+* @return if the directory exists (TRUE) or not (FALSE)\r
+*/\r
+BOOL isdir(const char *path);\r
+\r
+#endif /* __ISDIR_H__ */\r
+/*-----------------------------------------------------------------------------------*/ \r
diff --git a/scilab/modules/fileio/includes/removedir.h b/scilab/modules/fileio/includes/removedir.h
new file mode 100644 (file)
index 0000000..daf240e
--- /dev/null
@@ -0,0 +1,18 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifndef __REMOVEDIR_H__\r
+#define __REMOVEDIR_H__\r
+\r
+#include "machine.h" /* BOOL */\r
+\r
+/**\r
+* Remove a directory\r
+* @param path the directory\r
+* @return the result of the operation\r
+*/\r
+BOOL removedir(char *path);\r
+\r
+#endif /* __REMOVEDIR_H__ */\r
+/*-----------------------------------------------------------------------------------*/ \r
index d243249..2f1d385 100644 (file)
@@ -40,7 +40,8 @@ static gw_generic_table Tab[]={
        {C2F(sci_filesep),"filesep"},
        {C2F(sci_getlongpathname),"getlongpathname"},
        {C2F(sci_getshortpathname),"getshortpathname"},
-       {C2F(sci_fileext),"fileext"}
+       {C2F(sci_fileext),"fileext"},
+       {C2F(sci_isdir),"isdir"}
        };
 /*-----------------------------------------------------------------------------------*/ 
 int C2F(gw_fileio)(void)
@@ -3,8 +3,8 @@
  * @author Sylvestre LEDRU - INRIA 2007
  */
 /*-----------------------------------------------------------------------------------*/ 
-#include "gw_io.h"
-#include "directories.h"
+#include "gw_fileio.h"
+#include "isdir.h"
 #include "stack-c.h"
 #include "MALLOC.h"
 #include "cluni0.h"
index 1ade630..a34bae2 100644 (file)
@@ -56,4 +56,5 @@
 <PRIMITIVE gatewayId="34" primitiveId="30" primitiveName="getlongpathname"/>
 <PRIMITIVE gatewayId="34" primitiveId="31" primitiveName="getshortpathname"/>
 <PRIMITIVE gatewayId="34" primitiveId="32" primitiveName="fileext"/>
+<PRIMITIVE gatewayId="34" primitiveId="33" primitiveName="isdir"/>
 </GATEWAY>
diff --git a/scilab/modules/fileio/src/c/createdirectory.c b/scilab/modules/fileio/src/c/createdirectory.c
new file mode 100644 (file)
index 0000000..1449633
--- /dev/null
@@ -0,0 +1,32 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifndef _MSC_VER\r
+#include <sys/stat.h>\r
+#include <sys/types.h>\r
+#include <fcntl.h>\r
+#include <unistd.h>\r
+#include <dirent.h>\r
+#else\r
+#include <Windows.h>\r
+#endif\r
+#include "createdirectory.h"\r
+#include "isdir.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+#define DIRMODE 0777\r
+/*-----------------------------------------------------------------------------------*/\r
+BOOL createdirectory(const char *path)\r
+{\r
+       BOOL bOK=FALSE;\r
+#ifndef _MSC_VER\r
+       if  (!isdir(path)) \r
+       {\r
+               if (mkdir(path, DIRMODE) == 0) bOK=TRUE;\r
+       }\r
+#else\r
+       if (CreateDirectory(path,NULL)) bOK=TRUE;\r
+#endif\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/isDrive.c b/scilab/modules/fileio/src/c/isDrive.c
new file mode 100644 (file)
index 0000000..f557acd
--- /dev/null
@@ -0,0 +1,36 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#include <string.h>\r
+#ifdef _MSC_VER\r
+#include <Windows.h>\r
+#endif\r
+#include "isDrive.h"\r
+/*-----------------------------------------------------------------------------------*/ \r
+BOOL isDrive(const char *strname)\r
+{\r
+       BOOL bOK=FALSE;\r
+       #ifdef _MSC_VER\r
+       if (strname)\r
+       {\r
+               if ( (strlen(strname) == 2) || (strlen(strname) == 3) && (strname[1]== ':') )\r
+               {\r
+                       if (strlen(strname) == 3)\r
+                       {\r
+                               if ( (strname[2]!= '\\') && (strname[2]!= '/') )\r
+                               {\r
+                                       return FALSE;\r
+                               }\r
+                       }\r
+\r
+                       if ( ( strname[0] >= 'A' && strname[0] <= 'Z' ) || ( strname[0] >= 'a' && strname[0] <= 'z' ) )\r
+                       {\r
+                               bOK =TRUE;\r
+                       }\r
+               }\r
+       }\r
+       #endif\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/ \r
diff --git a/scilab/modules/fileio/src/c/isDrive.h b/scilab/modules/fileio/src/c/isDrive.h
new file mode 100644 (file)
index 0000000..79be926
--- /dev/null
@@ -0,0 +1,19 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifndef __ISDRIVE_H__\r
+#define __ISDRIVE_H__\r
+\r
+#include "machine.h" /* BOOL */\r
+\r
+/**\r
+* check if strname is a drive (only for windows)\r
+* @param[in] a string \r
+* @return TRUE or FALSE\r
+* returns always false on linux\r
+*/\r
+BOOL isDrive(const char *strname);\r
+\r
+#endif\r
+/*-----------------------------------------------------------------------------------*/ \r
diff --git a/scilab/modules/fileio/src/c/isdir.c b/scilab/modules/fileio/src/c/isdir.c
new file mode 100644 (file)
index 0000000..08763ad
--- /dev/null
@@ -0,0 +1,51 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifdef _MSC_VER\r
+       #include <Windows.h>\r
+#else\r
+       #include <sys/stat.h>\r
+       #include <sys/types.h>\r
+       #include <fcntl.h>\r
+       #include <unistd.h>\r
+       #include <dirent.h>\r
+#endif\r
+#include "isDrive.h"\r
+#include "isdir.h"\r
+#include "MALLOC.h"\r
+/*-----------------------------------------------------------------------------------*/ \r
+BOOL isdir(const char * path)\r
+{\r
+       BOOL bOK=FALSE;\r
+#ifndef _MSC_VER\r
+       struct stat buf;\r
+       if (path == NULL) return FALSE;\r
+       if (stat(path, &buf) == 0 && S_ISDIR(buf.st_mode)) bOK=TRUE;\r
+#else\r
+       if (isDrive(path)) return TRUE;\r
+       else\r
+       {\r
+               char *pathTmp=NULL;\r
+\r
+               pathTmp=MALLOC(sizeof(char)*((int)strlen(path)+1));\r
+               if (pathTmp)\r
+               {\r
+                       WIN32_FIND_DATA ffd;\r
+                       HANDLE sh=NULL;\r
+                       strcpy(pathTmp,path);\r
+                       if ( (pathTmp[strlen(pathTmp)-1]=='\\') || (pathTmp[strlen(pathTmp)-1]=='/') )\r
+                       {\r
+                               pathTmp[strlen(pathTmp)-1]='\0';\r
+                       }\r
+\r
+                       sh = FindFirstFile(pathTmp, &ffd);\r
+                       FREE(pathTmp);pathTmp=NULL;\r
+                       if(INVALID_HANDLE_VALUE == sh) return FALSE;\r
+                       if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) bOK=TRUE;\r
+               }\r
+       }\r
+#endif\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/ 
\ No newline at end of file
similarity index 60%
rename from scilab/modules/io/src/c/directories.c
rename to scilab/modules/fileio/src/c/removedir.c
index a1d17e4..fefade8 100644 (file)
-/*-----------------------------------------------------------------------------------*/
-/* INRIA 2007 */
-/* Allan CORNET */
-/*-----------------------------------------------------------------------------------*/ 
-#ifndef _MSC_VER
-       #include <sys/stat.h>
-       #include <sys/types.h>
-       #include <fcntl.h>
-       #include <unistd.h>
-       #include <dirent.h>
-#else
-       #include <Windows.h>
-#endif
-#include <stdlib.h>
-#include <stdio.h>
-#include "directories.h"
-#include "MALLOC.h"
-/*-----------------------------------------------------------------------------------*/ 
-#define DIRMODE 0777
-/*-----------------------------------------------------------------------------------*/ 
-int DeleteDirectory(char *refcstrRootDirectory);
-#ifndef _MSC_VER
-static void removefile(char *filename);
-#else
-static BOOL isDrive(const char *strname);
-#endif
-/*-----------------------------------------------------------------------------------*/ 
-BOOL isdir(const char * path)
-{
-       BOOL bOK=FALSE;
-       #ifndef _MSC_VER
-               struct stat buf;
-               if (path == NULL) return FALSE;
-               if (stat(path, &buf) == 0 && S_ISDIR(buf.st_mode)) bOK=TRUE;
-       #else
-               if (isDrive(path)) return TRUE;
-               else
-               {
-                       char *pathTmp=NULL;
-
-                       pathTmp=MALLOC(sizeof(char)*((int)strlen(path)+1));
-                       if (pathTmp)
-                       {
-                               WIN32_FIND_DATA ffd;
-                               HANDLE sh=NULL;
-                               strcpy(pathTmp,path);
-                               if ( (pathTmp[strlen(pathTmp)-1]=='\\') || (pathTmp[strlen(pathTmp)-1]=='/') )
-                               {
-                                       pathTmp[strlen(pathTmp)-1]='\0';
-                               }
-
-                               sh = FindFirstFile(pathTmp, &ffd);
-                               FREE(pathTmp);pathTmp=NULL;
-                               if(INVALID_HANDLE_VALUE == sh) return FALSE;
-                               if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) bOK=TRUE;
-                       }
-               }
-       #endif
-
-       return bOK;
-}
-/*-----------------------------------------------------------------------------------*/ 
-BOOL CreateDir(const char* path) 
-{
-       BOOL bOK=FALSE;
-       #ifndef _MSC_VER
-               if  (!isdir(path)) 
-               {
-                       if (mkdir(path, DIRMODE) == 0) 
-                       {
-                               bOK=TRUE;
-                       }
-               }
-       #else
-               if (CreateDirectory(path,NULL)) bOK=TRUE;
-       #endif
-       return bOK;
-}
-/*-----------------------------------------------------------------------------------*/ 
-BOOL RemoveDir(char *path)
-{
-       BOOL bOK=FALSE;
-       if (isdir(path))
-       {
-               DeleteDirectory(path);
-               if (!isdir(path)) bOK=TRUE; 
-       }
-       return bOK;
-}
-/*-----------------------------------------------------------------------------------*/ 
-#ifdef _MSC_VER
-int DeleteDirectory(char *refcstrRootDirectory)
-{
-       BOOL bDeleteSubdirectories=TRUE;
-       BOOL bSubdirectory = FALSE;
-       HANDLE hFile;
-       char *strFilePath=NULL;
-       char *strPattern=NULL;
-       WIN32_FIND_DATA FileInformation;
-       DWORD dwError;
-
-       strPattern = MALLOC(sizeof(char)*(strlen(refcstrRootDirectory)+5));
-       sprintf(strPattern,"%s\\*.*",refcstrRootDirectory);
-
-       hFile = FindFirstFile(strPattern, &FileInformation);
-       if (strPattern) { FREE(strPattern);strPattern=NULL;}
-
-       if(hFile != INVALID_HANDLE_VALUE)
-       {
-               do
-               {
-                       if(FileInformation.cFileName[0] != '.')
-                       {
-                               if (strFilePath) {FREE(strFilePath);strFilePath=NULL;}
-                               strFilePath = MALLOC(sizeof(char)*(strlen(refcstrRootDirectory)+5+strlen(FileInformation.cFileName)));
-                               sprintf(strFilePath,"%s\\%s",refcstrRootDirectory,FileInformation.cFileName);
-
-                               if(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
-                               {
-                                       if(bDeleteSubdirectories)
-                                       {
-                                               int iRC = DeleteDirectory(strFilePath);
-                                               if(iRC) return iRC;
-                                       }
-                                       else bSubdirectory = TRUE;
-                               }
-                               else
-                               {
-                                       if(SetFileAttributes(strFilePath,FILE_ATTRIBUTE_NORMAL) == FALSE) return GetLastError();
-                                       if(DeleteFile(strFilePath) == FALSE) return GetLastError();
-                               }
-                       }
-               } while(FindNextFile(hFile, &FileInformation) == TRUE);
-
-               FindClose(hFile);
-
-               dwError = GetLastError();
-               if(dwError != ERROR_NO_MORE_FILES) return dwError;
-               else
-               {
-                       if(!bSubdirectory)
-                       {
-                               if(SetFileAttributes(refcstrRootDirectory,FILE_ATTRIBUTE_NORMAL) == FALSE) return GetLastError();
-                               if(RemoveDirectory(refcstrRootDirectory) == FALSE)      return GetLastError();
-                       }
-               }
-       }
-
-       if (strFilePath) {FREE(strFilePath);strFilePath=NULL;}
-       if (strFilePath) {FREE(strFilePath);strFilePath=NULL;}
-
-       return 0;
-}
-#endif
-/*-----------------------------------------------------------------------------------*/
-#ifndef _MSC_VER
-static void removefile(char *filename)
-{
-       FILE *f = fopen(filename, "r") ;
-       if (! f) return ;
-       fclose(f) ;
-       chmod(filename, S_IWRITE) ;
-       remove(filename) ;
-}
-#endif 
-/*-----------------------------------------------------------------------------------*/
-#ifndef _MSC_VER
-int DeleteDirectory(char *refcstrRootDirectory)
-{
-       DIR *dir;
-       struct dirent *ent;
-
-       dir = opendir(refcstrRootDirectory) ;
-
-       if (!dir)
-       {
-               removefile(refcstrRootDirectory) ;
-       } 
-       else
-       {
-               while((ent = readdir(dir)) != NULL)
-               {
-                       char *filename = NULL;
-                       if (ent->d_name[0] == '.') continue ;
-
-                       filename = MALLOC(strlen(refcstrRootDirectory) + 1 + strlen(ent->d_name) + 1 + 1) ;
-                       sprintf(filename,"%s/%s",refcstrRootDirectory,ent->d_name);
-                       removefile(filename);
-                       if (filename) {FREE(filename);filename=NULL;}
-               }
-               rmdir(refcstrRootDirectory);
-       }
-       return 0;
-}
-#endif
-/*-----------------------------------------------------------------------------------*/
-#if _MSC_VER
-BOOL isDrive(const char *strname)
-{
-       BOOL bOK=FALSE;
-       if (strname)
-       {
-               if ( (strlen(strname) == 2) || (strlen(strname) == 3) && (strname[1]== ':') )
-               {
-                       if (strlen(strname) == 3)
-                       {
-                               if ( (strname[2]!= '\\') && (strname[2]!= '/') )
-                               {
-                                       return FALSE;
-                               }
-                       }
-
-                       if ( ( strname[0] >= 'A' && strname[0] <= 'Z' ) || ( strname[0] >= 'a' && strname[0] <= 'z' ) )
-                       {
-                               bOK =TRUE;
-                       }
-               }
-       }
-       return bOK;
-}
-#endif
-/*-----------------------------------------------------------------------------------*/
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifdef _MSC_VER\r
+#include <Windows.h>\r
+#else\r
+#include <sys/stat.h>\r
+#include <sys/types.h>\r
+#include <fcntl.h>\r
+#include <unistd.h>\r
+#include <dirent.h>\r
+#endif\r
+#include <stdio.h>\r
+#include "removedir.h"\r
+#include "isdir.h"\r
+#include "MALLOC.h"\r
+/*-----------------------------------------------------------------------------------*/ \r
+static int DeleteDirectory(char *refcstrRootDirectory);\r
+#ifndef _MSC_VER\r
+static void removefile(char *filename);\r
+#endif\r
+/*-----------------------------------------------------------------------------------*/ \r
+BOOL removedir(char *path)\r
+{\r
+       BOOL bOK=FALSE;\r
+       if (isdir(path))\r
+       {\r
+               DeleteDirectory(path);\r
+               if (!isdir(path)) bOK=TRUE; \r
+       }\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifdef _MSC_VER\r
+static int DeleteDirectory(char *refcstrRootDirectory)\r
+{\r
+       BOOL bDeleteSubdirectories=TRUE;\r
+       BOOL bSubdirectory = FALSE;\r
+       HANDLE hFile;\r
+       char *strFilePath=NULL;\r
+       char *strPattern=NULL;\r
+       WIN32_FIND_DATA FileInformation;\r
+       DWORD dwError;\r
+\r
+       strPattern = MALLOC(sizeof(char)*(strlen(refcstrRootDirectory)+5));\r
+       sprintf(strPattern,"%s\\*.*",refcstrRootDirectory);\r
+\r
+       hFile = FindFirstFile(strPattern, &FileInformation);\r
+       if (strPattern) { FREE(strPattern);strPattern=NULL;}\r
+\r
+       if(hFile != INVALID_HANDLE_VALUE)\r
+       {\r
+               do\r
+               {\r
+                       if(FileInformation.cFileName[0] != '.')\r
+                       {\r
+                               if (strFilePath) {FREE(strFilePath);strFilePath=NULL;}\r
+                               strFilePath = MALLOC(sizeof(char)*(strlen(refcstrRootDirectory)+5+strlen(FileInformation.cFileName)));\r
+                               sprintf(strFilePath,"%s\\%s",refcstrRootDirectory,FileInformation.cFileName);\r
+\r
+                               if(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)\r
+                               {\r
+                                       if(bDeleteSubdirectories)\r
+                                       {\r
+                                               int iRC = DeleteDirectory(strFilePath);\r
+                                               if(iRC) return iRC;\r
+                                       }\r
+                                       else bSubdirectory = TRUE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       if(SetFileAttributes(strFilePath,FILE_ATTRIBUTE_NORMAL) == FALSE) return GetLastError();\r
+                                       if(DeleteFile(strFilePath) == FALSE) return GetLastError();\r
+                               }\r
+                       }\r
+               } while(FindNextFile(hFile, &FileInformation) == TRUE);\r
+\r
+               FindClose(hFile);\r
+\r
+               dwError = GetLastError();\r
+               if(dwError != ERROR_NO_MORE_FILES) return dwError;\r
+               else\r
+               {\r
+                       if(!bSubdirectory)\r
+                       {\r
+                               if(SetFileAttributes(refcstrRootDirectory,FILE_ATTRIBUTE_NORMAL) == FALSE) return GetLastError();\r
+                               if(RemoveDirectory(refcstrRootDirectory) == FALSE)      return GetLastError();\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (strFilePath) {FREE(strFilePath);strFilePath=NULL;}\r
+       if (strFilePath) {FREE(strFilePath);strFilePath=NULL;}\r
+\r
+       return 0;\r
+}\r
+#endif\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifndef _MSC_VER\r
+static void removefile(char *filename)\r
+{\r
+       FILE *f = fopen(filename, "r") ;\r
+       if (! f) return ;\r
+       fclose(f) ;\r
+       chmod(filename, S_IWRITE) ;\r
+       remove(filename) ;\r
+}\r
+#endif \r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef _MSC_VER\r
+static int DeleteDirectory(char *refcstrRootDirectory)\r
+{\r
+       DIR *dir;\r
+       struct dirent *ent;\r
+\r
+       dir = opendir(refcstrRootDirectory) ;\r
+\r
+       if (!dir)\r
+       {\r
+               removefile(refcstrRootDirectory) ;\r
+       } \r
+       else\r
+       {\r
+               while((ent = readdir(dir)) != NULL)\r
+               {\r
+                       char *filename = NULL;\r
+                       if (ent->d_name[0] == '.') continue ;\r
+\r
+                       filename = MALLOC(strlen(refcstrRootDirectory) + 1 + strlen(ent->d_name) + 1 + 1) ;\r
+                       sprintf(filename,"%s/%s",refcstrRootDirectory,ent->d_name);\r
+                       removefile(filename);\r
+                       if (filename) {FREE(filename);filename=NULL;}\r
+               }\r
+               rmdir(refcstrRootDirectory);\r
+       }\r
+       return 0;\r
+}\r
+#endif\r
+/*-----------------------------------------------------------------------------------*/\r
index eef6d2c..000b4ee 100644 (file)
@@ -6,9 +6,7 @@
 IO_C_SOURCES = src/c/getpidc.c \
 src/c/setenvc.c \
 src/c/systemc.c \
-src/c/getenvc.c \
-src/c/directories.c
-
+src/c/getenvc.c 
 
 IO_FORTRAN_SOURCES = src/fortran/v2unit.f \
 src/fortran/newsave.f \
diff --git a/scilab/modules/io/includes/directories.h b/scilab/modules/io/includes/directories.h
deleted file mode 100644 (file)
index 399732b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-----------------------------------------------------------------------------------*/
-/* INRIA 2007 */
-/* Allan CORNET */
-/*-----------------------------------------------------------------------------------*/ 
-#ifndef __CREATEDIR_H__
-#define __CREATEDIR_H__
-/*-----------------------------------------------------------------------------------*/ 
-#include "machine.h"
-#include "string.h"
-/*-----------------------------------------------------------------------------------*/ 
-
-/**
- * Create a directory
- *
- * @param path the path of the futur directory
- * @return the result of the operation
- */
-BOOL CreateDir(const char *path);
-
-/**
- * Check if a directory exists or not
- *
- * @param path the directory
- * @return if the directory exists (true) or not (false)
- */
-BOOL isdir(const char *path);
-
-/**
- * Remove a directory
- *
- * @param path the directory
- * @return the result of the operation
- */
-BOOL RemoveDir(char *path);
-/*-----------------------------------------------------------------------------------*/ 
-#define MAX_FILENAME_LEN 512
-
-#endif /* __CREATEDIR_H__ */
-/*-----------------------------------------------------------------------------------*/ 
index 0c1375d..10cb8fa 100644 (file)
@@ -45,7 +45,6 @@ int C2F(intdisp)();
 int C2F(intexec)();
 int C2F(sci_getrelativefilename) _PARAMS((char *fname,unsigned long l));
 int C2F(sci_newest) _PARAMS((char *fname,unsigned long l));
-int C2F(sci_isdir) _PARAMS((char *fname,unsigned long l));
 int C2F(sci_get_absolute_file_path) _PARAMS((char *fname,unsigned long l));
 int C2F(sci_setenv) _PARAMS((char *fname,unsigned long fname_len));
 
index e66998e..7762d3d 100644 (file)
@@ -38,7 +38,6 @@ static gw_generic_table Tab[]=
 {C2F(sci_setenv),"setenv"},
 {C2F(sci_getrelativefilename),"getrelativefilename"},
 {C2F(sci_newest),"newest"},
-{C2F(sci_isdir),"isdir"},
 {C2F(sci_get_absolute_file_path),"get_absolute_file_path"}
 };
 /*-----------------------------------------------------------------------------------*/
index bc4db60..359416b 100644 (file)
@@ -15,7 +15,6 @@
 #include "gw_io.h"
 #include "FileExist.h"
 #include "../../../core/src/c/scicurdir.h"
-#include "directories.h"
 #include "stack-c.h"
 #include "MALLOC.h"
 #include "Scierror.h"
index 1d2ab7d..4f28846 100644 (file)
@@ -7,14 +7,15 @@
 #include "gw_io.h"
 #include "MALLOC.h"
 #include "sci_getrelativefilename.h"
-#include "directories.h"
 #include "machine.h"
+ /*-----------------------------------------------------------------------------------*/
+#define MAX_FILENAME_LEN 512
+ /*-----------------------------------------------------------------------------------*/
 /* ================================================================================== */
 // sci_getrelativefilename
 // 
 // scilab interface to getrelativefilename
 /* ================================================================================== */
-
 int C2F(sci_getrelativefilename) _PARAMS((char *fname, unsigned long l))
 {
        static int l1,n1,m1,l2,n2,m2;
index fdc35d4..7570fa7 100644 (file)
@@ -54,6 +54,5 @@
 <PRIMITIVE gatewayId="5" primitiveId="28" primitiveName="setenv" />
 <PRIMITIVE gatewayId="5" primitiveId="29" primitiveName="getrelativefilename" />
 <PRIMITIVE gatewayId="5" primitiveId="30" primitiveName="newest" />
-<PRIMITIVE gatewayId="5" primitiveId="31" primitiveName="isdir" />
-<PRIMITIVE gatewayId="5" primitiveId="32" primitiveName="get_absolute_file_path" />
+<PRIMITIVE gatewayId="5" primitiveId="31" primitiveName="get_absolute_file_path" />
 </GATEWAY>
\ No newline at end of file
index cf70f09..fc0f3cd 100644 (file)
                        Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
                        >
                        <File
-                               RelativePath=".\directories.c"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\getenvc.c"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath="..\..\sci_gateway\c\sci_isdir.c"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\..\sci_gateway\c\sci_lib.c"
                                >
                        </File>
                        Filter="h;hpp;hxx;hm;inl"
                        >
                        <File
-                               RelativePath="..\..\includes\directories.h"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\..\includes\getenvc.h"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath="..\..\includes\setenvc.h"
+                               RelativePath=".\setenvc.h"
                                >
                        </File>
                        <File
-                               RelativePath=".\setenvc.h"
+                               RelativePath="..\..\includes\setenvc.h"
                                >
                        </File>
                        <File
index 2fe2df9..9d0f147 100644 (file)
@@ -5,7 +5,7 @@
 #include <jni.h>
 #include "addToClasspath.h"
 #include "getScilabJNIEnv.h"
-#include "../../io/includes/directories.h"
+#include "../../fileio/includes/isdir.h"
 #include "../../fileio/includes/FileExist.h"
 #include "fromjava.h"
 /*-----------------------------------------------------------------------------------*/ 
index 0f6597b..c9dcc64 100644 (file)
@@ -5,7 +5,7 @@
 #include <jni.h>
 #include "addToLibrarypath.h"
 #include "getScilabJNIEnv.h"
-#include "../../io/includes/directories.h"
+#include "../../fileio/includes/isdir.h"
 #include "fromjava.h"
 /*-----------------------------------------------------------------------------------*/ 
 BOOL addToLibrarypath(char *librarypathstring)