update fileio
Allan Cornet [Sat, 21 Apr 2007 09:49:03 +0000 (09:49 +0000)]
dynamic allocation of files (remove limit of 20 files max)

54 files changed:
scilab/modules/core/Makefile.am
scilab/modules/core/includes/filesmanagement.h [new file with mode: 0644]
scilab/modules/core/src/c/InitializeCore.c
scilab/modules/core/src/c/TerminateCore.c
scilab/modules/core/src/c/core.vcproj
scilab/modules/core/src/c/diary.c
scilab/modules/core/src/c/filesmanagement.c [new file with mode: 0644]
scilab/modules/core/src/c/readline.c
scilab/modules/core/src/c/returnanan.c
scilab/modules/fileio/Makefile.am
scilab/modules/fileio/fileio.vcproj
scilab/modules/fileio/includes/addfile.h [new file with mode: 0644]
scilab/modules/fileio/includes/delfile.h [new file with mode: 0644]
scilab/modules/fileio/includes/getfiledesc.h [new file with mode: 0644]
scilab/modules/fileio/includes/getfileinfo.h [new file with mode: 0644]
scilab/modules/fileio/includes/getfiletype.h [new file with mode: 0644]
scilab/modules/fileio/includes/mclose.h [new file with mode: 0644]
scilab/modules/fileio/includes/mget.h [new file with mode: 0644]
scilab/modules/fileio/includes/mput.h [new file with mode: 0644]
scilab/modules/fileio/includes/mseek.h [new file with mode: 0644]
scilab/modules/fileio/sci_gateway/c/intreadxls.c
scilab/modules/fileio/sci_gateway/c/sci_fileio.c
scilab/modules/fileio/sci_gateway/c/sci_mfprintf.c
scilab/modules/fileio/sci_gateway/c/sci_mfscanf.c
scilab/modules/fileio/src/c/addfile.c [new file with mode: 0644]
scilab/modules/fileio/src/c/delfile.c [new file with mode: 0644]
scilab/modules/fileio/src/c/files.c [deleted file]
scilab/modules/fileio/src/c/files.h [deleted file]
scilab/modules/fileio/src/c/getfiledesc.c [new file with mode: 0644]
scilab/modules/fileio/src/c/getfileinfo.c [new file with mode: 0644]
scilab/modules/fileio/src/c/getfiletype.c [new file with mode: 0644]
scilab/modules/fileio/src/c/mclearerr.c [new file with mode: 0644]
scilab/modules/fileio/src/c/mclearerr.h [new file with mode: 0644]
scilab/modules/fileio/src/c/mclose.c [new file with mode: 0644]
scilab/modules/fileio/src/c/meof.c [new file with mode: 0644]
scilab/modules/fileio/src/c/meof.h [new file with mode: 0644]
scilab/modules/fileio/src/c/merror.c [new file with mode: 0644]
scilab/modules/fileio/src/c/merror.h [new file with mode: 0644]
scilab/modules/fileio/src/c/mget.c [new file with mode: 0644]
scilab/modules/fileio/src/c/mgetstr.c [new file with mode: 0644]
scilab/modules/fileio/src/c/mgetstr.h [new file with mode: 0644]
scilab/modules/fileio/src/c/mopen.c [new file with mode: 0644]
scilab/modules/fileio/src/c/mopen.h [new file with mode: 0644]
scilab/modules/fileio/src/c/mput.c [new file with mode: 0644]
scilab/modules/fileio/src/c/mputstr.c [new file with mode: 0644]
scilab/modules/fileio/src/c/mputstr.h [new file with mode: 0644]
scilab/modules/fileio/src/c/mseek.c [new file with mode: 0644]
scilab/modules/fileio/src/c/mtell.c [new file with mode: 0644]
scilab/modules/fileio/src/c/mtell.h [new file with mode: 0644]
scilab/modules/fileio/src/c/xls.c
scilab/modules/gui/src/c/men_getfile.c
scilab/modules/integer/src/c/mgeti.c
scilab/modules/integer/src/c/mputi.c
scilab/modules/io/sci_gateway/c/sci_get_absolute_file_path.c

index 55ad901..90e2c23 100644 (file)
@@ -80,7 +80,8 @@ src/c/diary.c \
 src/c/GetXmlFileEncoding.c \
 src/c/msgs.c \
 src/c/GetenvB.c \
-src/c/islittleendian.c
+src/c/islittleendian.c \
+src/c/filesmanagement.c
 
 CORE_FORTRAN_SOURCES = src/fortran/algebre.f \
 src/fortran/clunit.f \
diff --git a/scilab/modules/core/includes/filesmanagement.h b/scilab/modules/core/includes/filesmanagement.h
new file mode 100644 (file)
index 0000000..5b92992
--- /dev/null
@@ -0,0 +1,128 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* Allan CORNET */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __FILESMANAGEMENT_H__\r
+#define __FILESMANAGEMENT_H__\r
+\r
+#include <stdio.h>\r
+#include "machine.h"\r
+\r
+/**\r
+* Get max of files opened in scilab\r
+* @return max of files opened in scilab\r
+*/\r
+int GetMaximumFileOpenedInScilab(void);\r
+\r
+/**\r
+* Get the file associated to int Id\r
+* @param Id\r
+* @return FILE ptr\r
+*/\r
+FILE *GetFileOpenedInScilab(int Id);\r
+\r
+/**\r
+* Set the file associated to int Id\r
+* @param FILE ptr\r
+* @param Id\r
+*/\r
+void SetFileOpenedInScilab(int Id,FILE *fptr);\r
+\r
+/**\r
+* Get the current Id (current file)\r
+* @return Id\r
+*/\r
+int GetCurrentFileId(void);\r
+\r
+/**\r
+* Set the current Id (current file)\r
+* @param Id\r
+*/\r
+void SetCurrentFileId(int Id);\r
+\r
+/**\r
+* Get the swap status of file Id\r
+* @param Id\r
+* @return swap status\r
+*/\r
+int GetSwapStatus(integer Id);\r
+\r
+/**\r
+* Set the swap status of file Id\r
+* @param Id\r
+* @param new swap\r
+*/\r
+void SetSwapStatus(int Id,int newswap);\r
+\r
+/**\r
+* Get the mode of file Id\r
+* @param Id\r
+* @return mode\r
+*/\r
+int GetFileModeOpenedInScilab(int Id);\r
+\r
+/**\r
+* Set the mode of file Id\r
+* @param Id\r
+* @param new mode\r
+*/\r
+void SetFileModeOpenedInScilab(int Id,int mode);\r
+\r
+/**\r
+* Get the type of file Id\r
+* @param Id\r
+* @return Type (Fortran,C)\r
+*/\r
+int GetFileTypeOpenedInScilab(int Id);\r
+\r
+/**\r
+* Set the mode of file Id\r
+* @param Id\r
+* @param new Type (Fortran,C)\r
+*/\r
+void SetFileTypeOpenedInScilab(int Id,int Type);\r
+\r
+/**\r
+* Get the name of file Id\r
+* @param Id\r
+* @return name\r
+*/\r
+char* GetFileNameOpenedInScilab(int Id);\r
+\r
+/**\r
+* Set the name of file Id\r
+* @param Id\r
+* @param new name\r
+* @return TRUE or FALSE\r
+*/\r
+BOOL SetFileNameOpenedInScilab(int Id,char *name);\r
+\r
+/**\r
+* Free filename of file Id\r
+* @param Id\r
+* @return TRUE or FALSE\r
+*/\r
+BOOL FreeFileNameOpenedInScilab(int Id);\r
+\r
+/**\r
+* Initialize Scilab's file list\r
+* @return TRUE or FALSE\r
+*/\r
+BOOL InitializeScilabFilesList(void);\r
+\r
+/**\r
+* Terminate Scilab's file list\r
+* @return TRUE or FALSE\r
+*/\r
+BOOL TerminateScilabFilesList(void);\r
+\r
+/**\r
+* Extend Scilab's file list\r
+* @return TRUE or FALSE\r
+*/\r
+BOOL ExtendScilabFilesList(int NewSize);\r
+\r
+#endif /* __FILESMANAGEMENT_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
+\r
index 53222aa..4db7587 100644 (file)
 #include "LoadFunctionsTab.h"
 #include "prompt.h"
 #include "message_scilab.h"
+#include "filesmanagement.h"
 /*-----------------------------------------------------------------------------------*/ 
 BOOL InitializeCore(void)
 {
        BOOL bOK=FALSE;
        int pause=0;
 
+       InitializeScilabFilesList();
+
        SciEnv();
 
        getmodules();
index 23d04dd..5890241 100644 (file)
@@ -11,6 +11,7 @@
 #include "scimem.h" /* freegmem */
 #include "tmpdir.h" /* tmpdirc */
 #include "hashtable_core.h" /* destroy_hashtable_scilab_functions */
+#include "filesmanagement.h"
 /*-----------------------------------------------------------------------------------*/ 
 BOOL TerminateCorePart1(void)
 {
@@ -33,6 +34,9 @@ BOOL TerminateCorePart2(void)
 
        destroy_hashtable_scilab_functions();
 
+       /* Close all scilab's files */
+       TerminateScilabFilesList();
+
        /** clean tmpfiles **/
        C2F(tmpdirc)();
 
index b0f2bf6..3dc0986 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\filesmanagement.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\flags.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath="..\..\includes\filesmanagement.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\flags.h"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath=".\fromjava.h"
+                               RelativePath="..\..\includes\fromjava.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\includes\fromjava.h"
+                               RelativePath=".\fromjava.h"
                                >
                        </File>
                        <File
                                >
                        </File>
                        <File
-                               RelativePath=".\InitScilab.h"
+                               RelativePath="..\..\includes\InitScilab.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\includes\InitScilab.h"
+                               RelativePath=".\InitScilab.h"
                                >
                        </File>
                        <File
index 1704bcf..a2425cb 100644 (file)
@@ -3,7 +3,7 @@
 /*-----------------------------------------------------------------------------------*/
 #include "diary.h"
 #include "stack-c.h"
-#include "../../fileio/src/c/files.h" /* GetFile */
+#include "filesmanagement.h"
 /*-----------------------------------------------------------------------------------*/
 int getdiary(void)
 {
@@ -24,7 +24,7 @@ void C2F(diary)(char *str,int *n)
        u=getdiary();
        if ( u != 0 ) 
        {
-               FILE *fd= GetFile(&u);
+               FILE *fd= GetFileOpenedInScilab(u);
                fwrite(str,sizeof(unsigned char),*n,fd);
                fwrite(newline,sizeof(unsigned char),nn,fd);
        }
@@ -38,7 +38,7 @@ void diary_nnl(char *str,int *n)
 
        if (u) 
        {
-               FILE *fd= GetFile(&u);
+               FILE *fd= GetFileOpenedInScilab(u);
                fwrite(str,sizeof(unsigned char),*n,fd);
        }
 }
diff --git a/scilab/modules/core/src/c/filesmanagement.c b/scilab/modules/core/src/c/filesmanagement.c
new file mode 100644 (file)
index 0000000..9cac6fd
--- /dev/null
@@ -0,0 +1,185 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* Allan CORNET */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include "machine.h"\r
+#include "filesmanagement.h"\r
+#include "core_math.h" /* Min Max */\r
+#include "MALLOC.h" \r
+/*-----------------------------------------------------------------------------------*/\r
+#define DEFAULT_MAX_FILES 20 \r
+/*-----------------------------------------------------------------------------------*/\r
+typedef struct {\r
+       FILE *ftformat;\r
+       int ftswap; /* swap status for each file */\r
+       int ftmode; /* mode for each file */\r
+       int fttype; /* type (Fortran,C) for each file must be zero initialized */\r
+       char *ftname; /* name for each file */\r
+       \r
+} scilabfile;\r
+/*-----------------------------------------------------------------------------------*/\r
+static scilabfile *ScilabFileList = NULL;\r
+static int CurFile =-1;\r
+static int CurrentMaxFiles=DEFAULT_MAX_FILES;\r
+/*-----------------------------------------------------------------------------------*/\r
+FILE *GetFileOpenedInScilab(int Id)\r
+{\r
+       int fd1=0;\r
+\r
+       fd1 = (Id != -1) ?  Min(Max(Id,0),GetMaximumFileOpenedInScilab()-1) : CurFile ;\r
+\r
+       if ( fd1 != -1 ) return(ScilabFileList[fd1].ftformat);\r
+       return((FILE *) 0);\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+int GetCurrentFileId(void)\r
+{\r
+       return CurFile;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void SetCurrentFileId(int Id)\r
+{\r
+       CurFile=Id;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void SetFileOpenedInScilab(int Id,FILE *fptr)\r
+{\r
+       ScilabFileList[Id].ftformat=fptr;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+int GetSwapStatus(integer Id)\r
+{\r
+       int fd1;\r
+       fd1 = (Id != -1) ?  Min(Max(Id,0),GetMaximumFileOpenedInScilab()-1) : GetCurrentFileId() ;\r
+       if ( fd1 != -1 ) return(ScilabFileList[fd1].ftswap);\r
+       return(0);\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void SetSwapStatus(int Id,int newswap)\r
+{\r
+       ScilabFileList[Id].ftswap =  newswap;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+int GetMaximumFileOpenedInScilab(void)\r
+{\r
+       return CurrentMaxFiles;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+int GetFileModeOpenedInScilab(int Id)\r
+{\r
+       return ScilabFileList[Id].ftmode;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void SetFileModeOpenedInScilab(int Id,int mode)\r
+{\r
+       ScilabFileList[Id].ftmode = mode;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+int GetFileTypeOpenedInScilab(int Id)\r
+{\r
+       return ScilabFileList[Id].fttype;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void SetFileTypeOpenedInScilab(int Id,int Type)\r
+{\r
+       ScilabFileList[Id].fttype = Type;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+char* GetFileNameOpenedInScilab(int Id)\r
+{\r
+       return ScilabFileList[Id].ftname;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+BOOL SetFileNameOpenedInScilab(int Id,char *name)\r
+{\r
+       BOOL bOK=FALSE;\r
+       char *ptrName=NULL;\r
+\r
+       ptrName=(char*)MALLOC(sizeof(char)*(strlen(name)+1));\r
+       if (ptrName)\r
+       {\r
+               ScilabFileList[Id].ftname = ptrName;\r
+               strcpy(ptrName,name);\r
+               bOK=TRUE;\r
+       }\r
+\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+BOOL FreeFileNameOpenedInScilab(int Id)\r
+{\r
+       BOOL bOK=FALSE;\r
+       char *ptr = ScilabFileList[Id].ftname;\r
+       if (ptr) { FREE(ptr);  ptr = NULL; bOK=TRUE;}\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+BOOL InitializeScilabFilesList(void)\r
+{\r
+       BOOL bOK=FALSE;\r
+       if (!ScilabFileList)\r
+       {\r
+               CurrentMaxFiles=DEFAULT_MAX_FILES;\r
+               ScilabFileList=(scilabfile *)MALLOC(sizeof(scilabfile)*CurrentMaxFiles);\r
+\r
+               if (ScilabFileList)\r
+               {\r
+                       int i=0;\r
+                       for (i=0;i<CurrentMaxFiles;i++)\r
+                       {\r
+                               ScilabFileList[i].ftformat=NULL;\r
+                               ScilabFileList[i].ftmode=0;\r
+                               ScilabFileList[i].ftname=NULL;\r
+                               ScilabFileList[i].ftswap=0;\r
+                               ScilabFileList[i].fttype=0;\r
+                       }\r
+                       bOK=TRUE;\r
+               }\r
+       }\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+BOOL TerminateScilabFilesList(void)\r
+{\r
+       BOOL bOK=FALSE;\r
+\r
+       if (ScilabFileList)\r
+       {\r
+               FREE(ScilabFileList);\r
+               ScilabFileList=NULL;\r
+               bOK=TRUE;\r
+       }\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+BOOL ExtendScilabFilesList(int NewSize)\r
+{\r
+       BOOL bOK=FALSE;\r
+       if (ScilabFileList)\r
+       {\r
+               if (NewSize > CurrentMaxFiles)\r
+               {\r
+                       \r
+                       scilabfile *ScilabFileListTmp=NULL;\r
+                       ScilabFileListTmp=(scilabfile *)REALLOC(ScilabFileList,NewSize*sizeof(scilabfile));\r
+                       if (ScilabFileListTmp)\r
+                       {\r
+                               int i=0;\r
+                               ScilabFileList=ScilabFileListTmp;\r
+                               for (i=CurrentMaxFiles;i<NewSize;i++)\r
+                               {\r
+                                       ScilabFileList[i].ftformat=NULL;\r
+                                       ScilabFileList[i].ftmode=0;\r
+                                       ScilabFileList[i].ftname=NULL;\r
+                                       ScilabFileList[i].ftswap=0;\r
+                                       ScilabFileList[i].fttype=0;\r
+                               }\r
+                               CurrentMaxFiles=NewSize;\r
+                               bOK=TRUE;\r
+                       }\r
+               }\r
+       }\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
index 71cf43b..1e1f139 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include "machine.h"
 #include "readline.h"
+#include "filesmanagement.h"
 
 #if (defined(sun) && !defined(SYSV)) || defined(sgi)
 #define SEEK_SET 0
@@ -13,7 +14,7 @@
 
 #define CR 13
 #define LF 10
-FILE *GetFile();
+
 
  /* 
   * @params cnt : number of charaters returned in buf 
@@ -81,10 +82,7 @@ int LineRead(FILE *fd,char buf[],int n,int *cnt,int *nr)
  
 void C2F(readnextline)(integer *fd,char buf[],integer *n,integer *count,integer *nr,integer *ierr)
 {
-
-FILE *fa= GetFile(fd);
-
-*ierr=LineRead(fa,buf,*n,count,nr);
-
+       FILE *fa= GetFileOpenedInScilab(*fd);
+       *ierr=LineRead(fa,buf,*n,count,nr);
 }
 
index b4226eb..46cb5dd 100644 (file)
@@ -1,5 +1,4 @@
 /*-----------------------------------------------------------------------------------*/
-#include "machine.h"
 #include "returnanan.h"
 /*-----------------------------------------------------------------------------------*/
 double C2F(returnanan)(void)
index 5d77d83..d1f8333 100644 (file)
@@ -17,7 +17,24 @@ src/c/bt-int.c \
 src/c/do_xxprintf.c \
 src/c/do_xxscanf.c \
 src/c/findfiles.c \
-src/c/Status2Mode.c
+src/c/Status2Mode.c \
+src/c/addfile.c \
+src/c/delfile.c \
+src/c/getfiledesc.c \
+src/c/getfileinfo.c \
+src/c/getfiletype.c \
+src/c/mclearerr.c \
+src/c/mclose.c \
+src/c/meof.c \
+src/c/merror.c \
+src/c/mget.c \
+src/c/mgetstr.c \
+src/c/mopen.c \
+src/c/mput.c \
+src/c/mputstr.c \
+src/c/mseek.c \
+src/c/mtell.c
+
 
 GATEWAY_SOURCES = \
 sci_gateway/c/sci_xls_read.c \
index 2abd2ac..68ec485 100644 (file)
                        Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
                        >
                        <File
+                               RelativePath=".\src\c\addfile.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\bt-int.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\delfile.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\do_xxprintf.c"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath=".\src\c\files.c"
+                               RelativePath=".\src\c\findfiles.c"
                                >
                        </File>
                        <File
-                               RelativePath=".\src\c\findfiles.c"
+                               RelativePath=".\src\c\getfiledesc.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\getfileinfo.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\getfiletype.c"
                                >
                        </File>
                        <File
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\mclearerr.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mclose.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\meof.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\merror.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mget.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mgetstr.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mopen.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mput.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mputstr.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mseek.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mtell.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\ole.c"
                                >
                        </File>
                        Filter="h;hpp;hxx;hm;inl"
                        >
                        <File
+                               RelativePath=".\includes\addfile.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\bt-int.h"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\includes\delfile.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\do_xxprintf.h"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath=".\src\c\files.h"
+                               RelativePath=".\src\c\findfiles.h"
                                >
                        </File>
                        <File
-                               RelativePath=".\src\c\findfiles.h"
+                               RelativePath=".\includes\getfiledesc.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\includes\getfileinfo.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\includes\getfiletype.h"
                                >
                        </File>
                        <File
                                >
                        </File>
                        <File
+                               RelativePath=".\src\c\mclearerr.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\includes\mclose.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\meof.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\merror.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\includes\mget.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mgetstr.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mopen.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\includes\mput.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mputstr.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\includes\mseek.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\src\c\mtell.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\c\ole.h"
                                >
                        </File>
diff --git a/scilab/modules/fileio/includes/addfile.h b/scilab/modules/fileio/includes/addfile.h
new file mode 100644 (file)
index 0000000..25a76cf
--- /dev/null
@@ -0,0 +1,18 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __ADDFILE_H__\r
+#define __ADDFILE_H__\r
+\r
+#include <stdio.h>\r
+#include "machine.h"\r
+\r
+/**\r
+* add a file in the files table\r
+*/\r
+\r
+void C2F(addfile)(integer *fd, FILE *fa, integer *swap2, integer *type, integer *mode, char *filename, integer *ierr);\r
+\r
+#endif /*  __ADDFILE_H__ */\r
+/*-----------------------------------------------------------------------------------*/
\ No newline at end of file
diff --git a/scilab/modules/fileio/includes/delfile.h b/scilab/modules/fileio/includes/delfile.h
new file mode 100644 (file)
index 0000000..24a6559
--- /dev/null
@@ -0,0 +1,16 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __DELFILE_H__\r
+#define __DELFILE_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* delete a file in the files table\r
+*/\r
+void C2F(delfile)(integer *fd);\r
+\r
+#endif /* __DELFILE_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/includes/getfiledesc.h b/scilab/modules/fileio/includes/getfiledesc.h
new file mode 100644 (file)
index 0000000..6104bc9
--- /dev/null
@@ -0,0 +1,18 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __GETFILEDESC_H__\r
+#define __GETFILEDESC_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* returns the first available position in Files descriptor Table\r
+* @param fd (id)\r
+* @param[out] fd (-1 error)\r
+*/\r
+void C2F(getfiledesc)(integer *fd); \r
+\r
+#endif /* __GETFILEDESC_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/includes/getfileinfo.h b/scilab/modules/fileio/includes/getfileinfo.h
new file mode 100644 (file)
index 0000000..850c408
--- /dev/null
@@ -0,0 +1,17 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __GETFILEINFO_H__\r
+#define __GETFILEINFO_H__\r
+\r
+#include <stdio.h>\r
+#include "machine.h"\r
+\r
+/**\r
+* get file info in the files table\r
+*/\r
+void C2F(getfileinfo)(integer *fd, FILE *fa, integer *swap, integer *type, integer *mode, char *filename, integer *lf, integer *ierr);\r
+\r
+#endif /* __GETFILEINFO_H__ */\r
+\r
diff --git a/scilab/modules/fileio/includes/getfiletype.h b/scilab/modules/fileio/includes/getfiletype.h
new file mode 100644 (file)
index 0000000..a8ed015
--- /dev/null
@@ -0,0 +1,16 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __GETFILETYPE_H__\r
+#define __GETFILETYPE_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* get file type (Fortran or C)\r
+*/\r
+void C2F(getfiletype)(integer *fd, integer *type, integer *ierr);\r
+\r
+#endif /* __GETFILETYPE_H__ */\r
+/*-----------------------------------------------------------------------------------*/
\ No newline at end of file
diff --git a/scilab/modules/fileio/includes/mclose.h b/scilab/modules/fileio/includes/mclose.h
new file mode 100644 (file)
index 0000000..7db035d
--- /dev/null
@@ -0,0 +1,19 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MCLOSE_H__\r
+#define __MCLOSE_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* close the file with id *fd \r
+* if *id != -1 and *id != -2\r
+* the current file if *id = -1 \r
+* all opened file if *id = -2 \r
+*/\r
+void C2F(mclose) (integer *fd, double *res);\r
+\r
+#endif /* __MCLOSE_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/includes/mget.h b/scilab/modules/fileio/includes/mget.h
new file mode 100644 (file)
index 0000000..aebdcd2
--- /dev/null
@@ -0,0 +1,24 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MGET_H__\r
+#define __MGET_H__\r
+\r
+#include <stdio.h>\r
+#include "machine.h"\r
+\r
+/**\r
+* mget functions  read data in a machine \r
+* independant way (i.e write in little-endian) \r
+* or can be used to read in little or big endian \r
+* if read fails *ierr contains the number of properly read items \r
+*/\r
+void C2F(mget) (integer *fd, double *res, integer *n, char *type, integer *ierr);\r
+\r
+void C2F(mgetnc)(integer *fd, void * res, integer *n1, char *type, integer *ierr);\r
+\r
+void mget2(FILE *fa, integer swap, double *res, integer n, char *type, integer *ierr);\r
+\r
+#endif /* __MGET_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/includes/mput.h b/scilab/modules/fileio/includes/mput.h
new file mode 100644 (file)
index 0000000..115da1b
--- /dev/null
@@ -0,0 +1,23 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MPUT_H__\r
+#define __MPUT_H__\r
+\r
+#include <stdio.h>\r
+#include "machine.h"\r
+\r
+/**\r
+* mput functions  write data in a machine \r
+* independant way (i.e write in little-endian) \r
+* or can be used to write in little or big endian \r
+*/\r
+void C2F(mput) (integer *fd, double *res, integer *n, char *type, integer *ierr);\r
+\r
+void C2F(mputnc) (integer *fd, void * res, integer *n1, char *type, integer *ierr);\r
+\r
+void mput2 (FILE *fa, integer swap2, double *res, integer n, char *type, integer *ierr);\r
+\r
+#endif /* __MPUT_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/includes/mseek.h b/scilab/modules/fileio/includes/mseek.h
new file mode 100644 (file)
index 0000000..9ef3a03
--- /dev/null
@@ -0,0 +1,16 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MSEEK_H__\r
+#define __MSEEK_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* seek function \r
+*/\r
+void C2F(mseek) (integer *fd, integer *offset, char *flag, integer *err);\r
+\r
+#endif /* __MSEEK_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
index 7824925..da0fa42 100644 (file)
@@ -6,7 +6,6 @@
 #include "stack-c.h"
 #include "ole.h"
 #include "ripole.h"
-#include "files.h"
 #include "gw_fileio.h"
 #include "intreadxls.h"
 #include "tmpdir.h"
index 908fd15..b862974 100644 (file)
@@ -7,7 +7,6 @@
 #include "MALLOC.h" /* MALLOC */
 #include "sci_fileio.h"
 #include "gw_fileio.h"
-#include "files.h"
 #include "cluni0.h"
 /*-----------------------------------------------------------------------------------*/ 
 #ifdef hppa 
index 89a30c4..7e999c5 100644 (file)
@@ -5,8 +5,8 @@
 #include "machine.h"
 #include "stack-c.h"
 #include "do_xxprintf.h"
-#include "files.h"
 #include "gw_fileio.h"
+#include "filesmanagement.h"
 /*-----------------------------------------------------------------------------------*/ 
 int int_objfprintf __PARAMS((char *fname,unsigned long fname_len))
 {
@@ -15,6 +15,7 @@ int int_objfprintf __PARAMS((char *fname,unsigned long fname_len))
        char *ptrFormat=NULL;
        int i=0;
        int NumberPercent=0;
+       int param1=0;
 
        Nbvars = 0;
        CheckRhs(1,1000);
@@ -32,7 +33,9 @@ int int_objfprintf __PARAMS((char *fname,unsigned long fname_len))
        GetRhsVar(2,"c",&m2,&n2,&l2); /* format */
        ptrFormat=cstk(l2);
 
-       if ((f= GetFile(istk(l1))) == (FILE *)0)
+       param1=*istk(l1);
+
+       if ((f= GetFileOpenedInScilab(param1)) == (FILE *)0)
        {
                Scierror(999,"mfprintf:\t wrong file descriptor %d\r\n",*istk(l1));
                return 0;
index 9a56efa..db73f08 100644 (file)
@@ -7,8 +7,8 @@
 #include "do_xxprintf.h"
 #include "do_xxscanf.h"
 #include "fileio.h"
-#include "files.h"
 #include "gw_fileio.h"
+#include "filesmanagement.h"
 /*-----------------------------------------------------------------------------------*/ 
 int int_objfscanf(char *fname,unsigned long fname_len)
 {
@@ -18,6 +18,7 @@ int int_objfscanf(char *fname,unsigned long fname_len)
        int retval_s=0;
        entry *data=NULL;
        long int pos;
+       int param1=0;
 
        rec_entry buf[MAXSCAN];
        sfdir  type[MAXSCAN],type_s[MAXSCAN];
@@ -45,8 +46,9 @@ int int_objfscanf(char *fname,unsigned long fname_len)
        GetRhsVar(iarg,"i",&m1,&n1,&l1);
        GetRhsVar(iarg+1,"c",&m2,&n2,&l2);/* format */
 
+       param1=*istk(l1);
        StringConvert(cstk(l2));  /* conversion */
-       if ((f= GetFile(istk(l1))) == (FILE *)0)
+       if ((f= GetFileOpenedInScilab(param1)) == (FILE *)0)
        {
                Scierror(999,"fprintf:\t wrong file descriptor %d\r\n",*istk(l1));
                return 0;
diff --git a/scilab/modules/fileio/src/c/addfile.c b/scilab/modules/fileio/src/c/addfile.c
new file mode 100644 (file)
index 0000000..2640ca2
--- /dev/null
@@ -0,0 +1,32 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include "addfile.h"\r
+#include "filesmanagement.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(addfile)(integer *fd, FILE *fa, integer *swap2, integer *type, integer *mode, char *filename, integer *ierr)\r
+{\r
+       if (SetFileNameOpenedInScilab(*fd,filename) == FALSE ) \r
+       {\r
+               *ierr=1;\r
+               return;\r
+       }\r
+       if (*type==2) SetFileOpenedInScilab(*fd,fa);\r
+       else if (*type==-1) \r
+               SetFileOpenedInScilab(*fd,stdin);\r
+       else if (*type==-2) \r
+               SetFileOpenedInScilab(*fd,stdout);\r
+       else if (*type==-3) \r
+               SetFileOpenedInScilab(*fd,stderr);\r
+       else\r
+               SetFileOpenedInScilab(*fd,(FILE *) 0);\r
+\r
+       SetSwapStatus(*fd,*swap2);\r
+       SetFileTypeOpenedInScilab(*fd,*type);\r
+       SetFileModeOpenedInScilab(*fd,*mode);\r
+\r
+       *ierr=0;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+\r
diff --git a/scilab/modules/fileio/src/c/delfile.c b/scilab/modules/fileio/src/c/delfile.c
new file mode 100644 (file)
index 0000000..af04f13
--- /dev/null
@@ -0,0 +1,20 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <stdio.h>\r
+#include "delfile.h"\r
+#include "filesmanagement.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(delfile)(integer *fd)\r
+{\r
+       if (*fd>=0 && *fd<GetMaximumFileOpenedInScilab() ) \r
+       {\r
+               SetFileOpenedInScilab(*fd,(FILE*) NULL);\r
+               SetSwapStatus(*fd,0);\r
+               SetFileTypeOpenedInScilab(*fd,0);\r
+               SetFileModeOpenedInScilab(*fd,0);\r
+               FreeFileNameOpenedInScilab(*fd);\r
+       }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/files.c b/scilab/modules/fileio/src/c/files.c
deleted file mode 100644 (file)
index 6e3094a..0000000
+++ /dev/null
@@ -1,803 +0,0 @@
-/*********************************************
- * A set of functions for reading and writing binary 
- * datas in a machine independant way 
- * using functions from a sound library 
- * Copyright ENPC/ Chancelier 
- *********************************************/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <float.h>
-
-#include <limits.h>
-#include <ctype.h>
-
-
-#include "files.h"
-#include "core_math.h"
-
-#include "MALLOC.h"
-
-#include "stack-c.h" 
-#include "../../../libs/libst/misc.h"
-#include "sciprint.h"
-#include "Status2Mode.h"
-#include "islittleendian.h"
-
-
-#if (defined(sun) && !defined(SYSV)) 
-char *strerror __PARAMS((int errcode));
-#endif
-
-
-static int swap = 0;
-
-#define MAXF 20
-static int CurFile =-1;
-static struct soundstream ftf;
-
-static FILE *ftformat[MAXF]={(FILE*) 0}; 
-static int ftswap[MAXF]={0}; /** swap status for each file **/
-static int ftmode[MAXF]={0}; /** mode for each file **/
-static int fttype[MAXF]={0}; /** type (Fortran,C) for each file must
-                                 be zero initialized **/
-static char * ftname[MAXF]={0};/** name for each file **/
-
-
-
-/**************************************
- * returns the first available position
- * in File array (ftformat) or -1 
- * if no more position is available
- **************************************/
-
-void C2F(getfiledesc)( integer *fd) 
-{
-  int i ;
-  for ( i = 1 ; i < MAXF ; i++) {
-    if ( fttype[i] == 0 ) {
-      *fd = i;
-      return ;
-    }
-  }
-  *fd = -1;
-}
-
-/**************************************
- * add a file in the files table
- **************************************/
-
-void C2F(addfile)(integer *fd, FILE *fa, integer *swap2, integer *type, integer *mode, char *filename, integer *ierr)
-{
-  char* name;
-  name= (char *) MALLOC((strlen(filename)+1)*sizeof(char));
-  if ( name == (char *) 0) {
-    *ierr=1;
-    return;
-  }
-  if (*type==2) 
-    ftformat[*fd] = fa;
-  else if (*type==-1) 
-    ftformat[*fd] = stdin;
-  else if (*type==-2) 
-    ftformat[*fd] = stdout;
-  else if (*type==-3) 
-    ftformat[*fd] = stderr;
-  else
-    ftformat[*fd] = (FILE *) 0;
-  ftswap[*fd] = *swap2;
-  fttype[*fd] = *type;
-  ftmode[*fd] = *mode;
-  ftname[*fd] = name;
-  strcpy(name,filename);
-  *ierr=0;
-}
-
-/**************************************
- * get file info in the files table
- **************************************/
-
-void C2F(getfileinfo)(integer *fd, FILE *fa, integer *swap2, integer *type, integer *mode, char *filename, integer *lf, integer *ierr)
-{
-  if (*fd<0 || *fd>=MAXF ) {
-    *ierr=1;
-    return;
-  }
-  if ( fttype[*fd] == 0 ) {
-    *ierr=2;
-    return;
-  }
-  fa = ftformat[*fd];
-  *swap2 = ftswap[*fd];
-  *type = fttype[*fd];
-  *mode = ftmode[*fd];
-  strcpy(filename,ftname[*fd]);
-  *lf=strlen(filename);
-  *ierr=0;
-}
-/**************************************
- * get file type (C or Fortran)
- **************************************/
-
-void C2F(getfiletype)(integer *fd, integer *type, integer *ierr)
-{
-  if (*fd<0 || *fd>=MAXF ) {
-    *ierr=1;
-    return;
-  }
-  if ( fttype[*fd] == 0 ) {
-    *ierr=2;
-    return;
-  }
-  *type = fttype[*fd];
-  *ierr=0;
-}
-
-
-/**************************************
- * delete a file in the files table
- **************************************/
-
-void C2F(delfile)(integer *fd)
-{
-  if (*fd>=0 && *fd<MAXF ) 
-    {
-      ftformat[*fd] = (FILE*) NULL;
-      ftswap[*fd] = 0;
-      fttype[*fd] = 0;
-      ftmode[*fd] = 0;
-      if (ftname[*fd]) { FREE(ftname[*fd]);  ftname[*fd] = NULL; }
-    }
-}
-/**************************************
- * returns the file associated to int fd 
- * or NULL if no such file. 
- **************************************/
-
-FILE *GetFile(integer *fd)
-{
-  int fd1;
-  fd1 = (*fd != -1) ?  Min(Max(*fd,0),MAXF-1) : CurFile ;
-  if ( fd1 != -1 ) 
-    return(ftformat[fd1]);
-  else
-    return((FILE *) 0);
-}
-
-/**************************************
- * returns the swap status of file fd 
- **************************************/
-
-int GetSwap(integer *fd)
-{
-  int fd1;
-  fd1 = (*fd != -1) ?  Min(Max(*fd,0),MAXF-1) : CurFile ;
-  if ( fd1 != -1 ) 
-    return(ftswap[fd1]);
-  else
-    return(0);
-}
-
-/*********************************************
- * Opens file given by file and return it's id 
- * in fd. 
- * status can be "r","w","a" or "rb","wb","ab"
- *********************************************/
-
-void C2F(mopen)(int *fd, char *file, char *status, int *f_swap, double *res, int *error)
-{   
-  int  littlendian = 1,type = 2,ierr,mode;
-  char *endptr;
-  FILE * fa;
-  /* next line added by ss 16/10/98 */
-  swap =0;
-  *error=0;
-  endptr = (char *) &littlendian;
-  if ( (!*endptr) )
-    {
-      if( *f_swap == 1 ) 
-       swap = 1;
-      else 
-       swap =0;
-    }
-  /*  sciprint("    Byte Swap status %d \r\n",swap);*/
-
-  C2F(getfiledesc)(fd);
-  if ( *fd == -1 )
-    {
-      *error=1; /* Too many opened files */
-      return;
-    }
-  fa=fopen(file,status);
-  if (! fa )
-    {     
-      *error=2; /* Could not open the file*/
-      return;
-    }
-  mode=Status2Mode(status);
-  C2F(addfile)(fd,fa,&swap,&type,&mode,file,&ierr);
-  if (ierr)
-    {
-      *error=3; /* Not enough memory;*/
-      return;
-    }
-  CurFile = *fd;
-  *res = (double)ferror(fa);
-}
-
-/**************************************
- * close the file with id *fd if *id != -1 and *id != -2
- * the current file if *id = -1 
- * all opened file if *id = -2 
- **************************************/
-
-void C2F(mclose) (integer *fd, double *res)
-{     
-  int fd1;
-  int res1 = 1;
-  *res = 0.0;
-  switch ( *fd )
-    {
-    case -2 :
-      /* closing all opened files */
-      for ( fd1=0; fd1< MAXF; fd1++) {
-       if ( ftformat[fd1] )
-         {
-           fclose( ftformat[fd1] );
-           res1 = ferror( ftformat[fd1]);
-           if (res1 != 0) *res =1;
-           C2F(delfile)(&fd1);
-         }
-      }
-      break;
-    default :
-      fd1 = (*fd == -1 ) ? CurFile : Min(Max(*fd,0),MAXF-1);
-      if ( fd1 != -1 ) 
-       {
-         if ( ftformat[fd1] )
-           {
-             if (fclose(ftformat[fd1])) {
-               *res = (double)ferror(ftformat[fd1]);
-             }
-             C2F(delfile)(&fd1);
-           }
-         else
-           {
-             *res = 0.0;
-             sciprint("File %d not active \r\n",fd1);
-           }
-       }
-      else 
-       {
-         *res = -1.0;
-         sciprint("No file to close \r\n",fd1);
-       }
-    }
-}
-
-/*********************************************
- * check eof 
- *********************************************/
-
-
-void C2F(meof) (integer *fd, double *res)
-{       
-  FILE *fa= GetFile(fd);
-  *res = fa ? feof(fa) : 1;
-}
-/*********************************************
- * check error
- *********************************************/
-
-
-void C2F(merror) (integer *fd, double *res)
-{       
-  FILE *fa= GetFile(fd);
-  *res = fa ? ferror(fa) : 1;
-}
-
-/*********************************************
- * clear errors 
- *********************************************/
-
-
-void C2F(mclearerr) (integer *fd)
-{       
-  FILE *fa= GetFile(fd);
-  clearerr(fa);
-}
-
-/*********************************************
- * seek function 
- *********************************************/
-
-#if (defined(sun) && !defined(SYSV)) || defined(sgi)
-#define SEEK_SET 0
-#define SEEK_CUR 1
-#define SEEK_END 2
-#endif 
-
-void C2F(mseek) (integer *fd, integer *offset, char *flag, integer *err)
-{     
-  int iflag;
-#if (defined(sun) && !defined(SYSV)) || defined(sgi)
-  int irep;
-#endif
-  FILE *fa= GetFile(fd);
-  *err=0;
-  if ( fa == (FILE *) 0 ) 
-    {
-      sciprint("mseek: wrong file logical unit \r\n");
-      *err=1;
-      return;
-    }
-  if ( strncmp(flag,"set",3)==0 ) 
-    iflag = SEEK_SET;
-  else if ( strncmp(flag,"cur",3)==0 ) 
-    iflag = SEEK_CUR;
-  else if ( strncmp(flag,"end",3)==0 ) 
-    iflag = SEEK_END;
-  else 
-    {
-      sciprint("mseek : flag = %s not recognized \r\n");
-      *err=1;
-      return;
-    }
-#if (defined(sun) && !defined(SYSV)) || defined(sgi)
-  irep = fseek(fa,(long) *offset,iflag) ;
-  if ( irep != 0 ) 
-    {
-      sciprint(strerror(irep));
-      *err=1;
-    }
-  else
-    *err=0;
-#else
-  if (fseek(fa,(long) *offset,iflag) == -1 ) 
-    {
-      sciprint("mseek: error\r\n");
-      *err=1;
-    }
-  else 
-    *err=0;
-#endif
-}
-
-/*********************************************
- * tell function 
- *********************************************/
-
-void C2F(mtell) (integer *fd, double *offset, integer *err)
-{     
-  FILE *fa= GetFile(fd);
-  if ( fa == (FILE *) 0 ) 
-    {
-      sciprint("mtell: wrong file logical unit \r\b");
-      *err=1;
-      return;
-    }
-  *err=0;
-  *offset = (double) ftell(fa) ;
-}
-
-
-
-/*********************************************
- * mput functions  write data in a machine 
- * independant way (i.e write in little-endian) 
- * or can be used to write in little or big endian 
- *********************************************/
-
-
-/*===============================================
- * function to write data without type conversion
- *===============================================*/
-#define MPUT_CHAR_NC(Type) \
-{\
-   Type *val = (Type *) res ; \
-   fwrite(val,sizeof(Type),n,fa); \
-}
-               
-#define MPUT_NC(Type,Fswap) \
-{ \
-   Type *val = (Type *) res ; \
-   Type vali; \
-   for ( i=0; i< n; i++)  \
-           { \
-             vali = *val++; \
-             if ( swap) vali = Fswap(vali); \
-             fwrite(&vali,sizeof(Type),1,fa); \
-           } \
-}
-#define MPUT_GEN_NC(Type,Fswap,cf) \
-      switch ( cf )  \
-       { \
-               case ' ': MPUT_NC(Type,Fswap); break; \
-               case 'b': \
-                 swap = (islittleendian()==1) ? 1 : 0; \
-                 MPUT_NC(Type,Fswap); break; \
-               case 'l': \
-                 swap = (islittleendian()==1) ? 0 : 1; \
-                 MPUT_NC(Type,Fswap); break; \
-               default: \
-                 sciprint("mput : %s format not recognized \r\n",type); \
-                 *ierr=1;return; \
-                                   }
-void C2F(mputnc) (integer *fd, void * res, integer *n1, char *type, integer *ierr)
-{  
-  char c1,c2;
-  int i,swap2,n;
-  FILE *fa;
-  n=*n1;
-  *ierr=0;
-  if ((fa = GetFile(fd)) ==NULL) {
-    sciprint("No input file associated to logical unit %d\r\n",*fd);
-    *ierr=3;
-    return;
-  }
-  swap2 = GetSwap(fd);
-
-  c1 = ( strlen(type) > 1) ? type[1] : ' '; 
-  c2 = ( strlen(type) > 2) ? type[2] : ' '; 
-  switch ( type[0] )
-    {
-    case 'i' : MPUT_GEN_NC(int,swapi,c1);       break;
-    case 'l' : MPUT_GEN_NC(long,swapl,c1);      break;
-    case 's' : MPUT_GEN_NC(short,swapw,c1);     break;
-    case 'c' : MPUT_CHAR_NC(char) ;          break;
-    case 'd' : MPUT_GEN_NC(double,swapd,c1);    break;
-    case 'f' : MPUT_GEN_NC(float,swapf,c1);     break;
-    case 'u' :
-      switch ( c1 )
-       {
-       case 'i' :  MPUT_GEN_NC(unsigned int,swapi,c2); break;
-       case 'l' :  MPUT_GEN_NC(unsigned long,swapl,c2); break;
-       case 's' :  MPUT_GEN_NC(unsigned short,swapw,c2); break;
-       case ' ' :  MPUT_GEN_NC(unsigned int,swapi,' '); break;
-       case 'c' :  MPUT_CHAR_NC(unsigned char); break;
-       default :  *ierr=1;return ;
-       }
-      break;
-    default : *ierr=1; break;
-    }
-}
-/*================================================
- * function to write data stored in double
- *================================================*/
-/** used for char **/
-#define MPUT_CHAR(Type) \
-      for ( i=0; i< n; i++)  \
-       { \
-           Type  val = (char) *res++; \
-           fwrite(&val,sizeof(Type),1,fa); \
-        }
-
-/** write in a machine independant way : i.e data 
-    is swaped if necessary to output little-endian 
-    data **/
-               
-#define MPUT(Type,Fswap) for ( i=0; i< n; i++)  \
-           { \
-             Type val; \
-             val =(Type) *res++; \
-             if ( swap) val = Fswap(val); \
-             fwrite(&val,sizeof(Type),1,fa); \
-           }
-
-/** The output mode is controlled by type[1] **/
-#define MPUT_GEN(Type,Fswap,cf) \
-      switch ( cf )  \
-       { \
-               case ' ': MPUT(Type,Fswap); break; \
-               case 'b': \
-                 swap = (islittleendian()==1) ? 1 : 0; \
-                 MPUT(Type,Fswap); break; \
-               case 'l': \
-                 swap = (islittleendian()==1) ? 0 : 1; \
-                 MPUT(Type,Fswap); break; \
-               default: \
-                 sciprint("mput : %s format not recognized \r\n",type); \
-                 *ierr=1;return; \
-                                   }
-
-void mput2 (FILE *fa, integer swap2, double *res, integer n, char *type, integer *ierr)
-{  
-  char c1,c2;
-  int i;
-  ft_t ft = &ftf;
-  *ierr=0;
-  ft->fp = fa;
-  c1 = ( strlen(type) > 1) ? type[1] : ' '; 
-  c2 = ( strlen(type) > 2) ? type[2] : ' '; 
-  switch ( type[0] )
-    {
-    case 'i' : MPUT_GEN(int,swapi,c1);       break;
-    case 'l' : MPUT_GEN(long,swapl,c1);      break;
-    case 's' : MPUT_GEN(short,swapw,c1);     break;
-    case 'c' : MPUT_CHAR(char) ;          break;
-    case 'd' : MPUT_GEN(double,swapd,c1);    break;
-    case 'f' : MPUT_GEN(float,swapf,c1);     break;
-    case 'u' :
-      switch ( c1 )
-       {
-       case 'i' :  MPUT_GEN(unsigned int,swapi,c2); break;
-       case 'l' :  MPUT_GEN(unsigned long,swapl,c2); break;
-       case 's' :  MPUT_GEN(unsigned short,swapw,c2); break;
-       case ' ' :  MPUT_GEN(unsigned int,swapi,' '); break;
-       case 'c' :  MPUT_CHAR(unsigned char); break;
-       default :  *ierr=1;return ;
-       }
-      break;
-    default : *ierr=1; break;
-    }
-}
-
-void C2F(mput) (integer *fd, double *res, integer *n, char *type, integer *ierr)
-{
-  int nc,swap2;
-  FILE *fa;
-  *ierr=0;
-  if ((nc = strlen(type)) == 0) 
-    {
-      sciprint("mput : format is of length 0\r\n",type);
-      *ierr=2;
-      return;
-    }
-  if ((fa = GetFile(fd)) !=NULL)
-    {
-      swap2 = GetSwap(fd);
-      mput2(fa,swap2,res,*n,type,ierr);
-      if (*ierr > 0)
-       sciprint("mput : %s format not recognized \r\n",type);
-    }
-  else {
-    sciprint("No input file associated to logical unit %d\r\n",*fd);
-    *ierr=3;
-  }
-}
-
-
-
-/*****************************************************************
- * mget functions  read data in a machine 
- * independant way (i.e write in little-endian) 
- * or can be used to read in little or big endian 
- * if read fails *ierr contains the number of properly read items 
- *****************************************************************/
-
-
-/* =================================================
- * reads data and store them without type conversion 
- * =================================================*/
-#define MGET_CHAR_NC(Type) \
-{\
-   Type *val = (Type *) res ;\
-   items=fread(val,sizeof(Type),n,fa);\
-}
-
-#define MGET_NC(Type,Fswap) \
-{\
-   Type *val = (Type *) res ;\
-   items=fread(val,sizeof(Type),n,fa);\
-   if (swap) \
-      for (i=0;i<items;i++) \
-         val[i]=Fswap(val[i]);\
-}
-
-
-#define MGET_GEN_NC(NumType,Fswap,cf)\
-{ \
-    switch (cf) { \
-          case ' ': MGET_NC(NumType,Fswap);break; \
-         case 'b': swap = (islittleendian()==1)? 1:0; \
-                           MGET_NC(NumType,Fswap); break; \
-         case 'l': swap = (islittleendian()==1) ? 0:1; \
-                 MGET_NC(NumType,Fswap);  break; \
-         default: sciprint("mget : %s format not recognized \r\n",type); \
-            *ierr=1; return; \
-                } \
-}
-void C2F(mgetnc)(integer *fd, void * res, integer *n1, char *type, integer *ierr)
-{  
-  char c1,c2;
-  int i,items=*n1,n=*n1;
-  FILE *fa;
-
-
-  *ierr=0;
-  if ((fa = GetFile(fd)) ==NULL) {
-    sciprint("No input file associated to logical unit %d\r\n",*fd);
-    *ierr=3;
-    return;
-  }
-  swap = GetSwap(fd);
-  c1 = ( strlen(type) > 1) ? type[1] : ' '; 
-  c2 = ( strlen(type) > 2) ? type[2] : ' '; 
-  switch ( type[0] )
-    {
-    case 'i' : MGET_GEN_NC(int,swapi,c1);break;
-    case 'l' : MGET_GEN_NC(long,swapl,c1);break;
-    case 's' : MGET_GEN_NC(short,swapw,c1);break;
-    case 'c' : MGET_CHAR_NC(char) ; break;
-    case 'd' : MGET_GEN_NC(double,swapd,c1);break;
-    case 'f' : MGET_GEN_NC(float,swapf,c1);break;
-    case 'u' :
-      switch ( c1 )
-       {
-       case 'i' :  MGET_GEN_NC(unsigned int,swapi,c2); break;
-       case 'l' :  MGET_GEN_NC(unsigned long,swapl,c2); break;
-       case 's' :  MGET_GEN_NC(unsigned short,swapw,c2); break;
-       case ' ' :  MGET_GEN_NC(unsigned int,swapi,' '); break;
-       case 'c' :  MGET_CHAR_NC(unsigned char); break;
-       default : *ierr=1; return; break;
-       }
-      break;
-    default :
-      *ierr=1;
-      return ;
-    }
-  if ( items != n ) 
-    {
-      *ierr = -(items) -1 ;
-      /** sciprint("Read %d out of \r\n",items,n); **/
-    }
-  return;
-}
-
-/* =================================================
- * reads data and store them in double
- * =================================================*/
-
-/* conversion macro  */
-#define CONVGD(Type) \
-{\
-   Type *val = (Type *) res ;\
-   for ( i = items-1 ; i >=0 ; i--)  \
-     res[i] = val[i]; \
-}
-
-#define MGET_GEN(NumType,Fswap,cf)  MGET_GEN_NC(NumType,Fswap,cf); CONVGD(NumType);
-#define MGET_CHAR(NumType)  MGET_CHAR_NC(NumType); CONVGD(NumType); 
-
-/* reads data and store them in double  */
-void mget2(FILE *fa, integer swap2, double *res, integer n, char *type, integer *ierr)
-{  
-  char c1,c2;
-  int i,items=n;
-  ft_t ft = &ftf; 
-  *ierr=0;
-  ft->fp = fa;
-  c1 = ( strlen(type) > 1) ? type[1] : ' '; 
-  c2 = ( strlen(type) > 2) ? type[2] : ' '; 
-  switch ( type[0] )
-    {
-    case 'i' : MGET_GEN(int,swapi,c1);break;
-    case 'l' : MGET_GEN(long,swapl,c1);break;
-    case 's' : MGET_GEN(short,swapw,c1);break;
-    case 'c' : MGET_CHAR(char) ; break;
-    case 'd' : MGET_GEN(double,swapd,c1);break;
-    case 'f' : MGET_GEN(float,swapf,c1);break;
-    case 'u' :
-      switch ( c1 )
-       {
-       case 'i' :  MGET_GEN(unsigned int,swapi,c2); break;
-       case 'l' :  MGET_GEN(unsigned long,swapl,c2); break;
-       case 's' :  MGET_GEN(unsigned short,swapw,c2); break;
-       case ' ' :  MGET_GEN(unsigned int,swapi,' '); break;
-       case 'c' :  MGET_CHAR(unsigned char); break;
-       default : *ierr=1; return; break;
-       }
-      break;
-    default :
-      *ierr=1;
-      return ;
-    }
-  if ( items != n ) 
-    {
-      *ierr = -(items) -1 ;
-      /** sciprint("Read %d out of \r\n",items,n); **/
-    }
-  return;
-}
-
-void C2F(mget) (integer *fd, double *res, integer *n, char *type, integer *ierr)
-{  
-  int nc,swap2;
-  FILE *fa;
-  nc=strlen(type);
-  *ierr=0;
-  if ( nc == 0) 
-    {
-      sciprint("mget : format is of length 0\r\n",type);
-      *ierr=2;
-      return;
-    }
-  fa = GetFile(fd);
-  if (fa ) 
-    {
-      swap2 = GetSwap(fd);
-      mget2(fa,swap2,res,*n,type,ierr);
-      if (*ierr > 0)
-       sciprint("mget : %s format not recognized \r\n",type);
-    }
-  else {
-    sciprint("No input file associated to logical unit %d\r\n",*fd);
-    *ierr=3;
-  }
-}
-
-
-
-/*********************************************
- * read a string 
- *********************************************/
-
-void C2F(mgetstr) (integer *fd, char **start, integer *n, integer *ierr)
-{ 
-  int count;
-  FILE *fa;
-  fa = GetFile(fd);
-  *ierr=0;
-  if (fa)
-    { 
-      *start= (char *) MALLOC((*n+1)*sizeof(char));
-      if ( *start == (char *) 0)
-       {       
-         sciprint("No more memory \r\n");
-         *ierr=1;
-         return;
-       }
-      count=fread(*start,sizeof(char),*n,fa);
-      (*start)[*n]='\0';
-      if ( count != *n ) 
-       {
-         *ierr = - count -1;
-       }
-      return;
-    }
-  sciprint("No input file \r\n");
-  *ierr=1;
-}
-
-void C2F(mgetstr1) (integer *fd, char *start, integer *n, integer *ierr)
-{ 
-  int count;
-  FILE *fa;
-  fa = GetFile(fd);
-  *ierr=0;
-  if (fa)
-    { 
-      count=fread(start,sizeof(char),*n,fa);
-      start[*n]='\0';
-      if ( count != *n ) 
-       {
-         *ierr = - count -1;
-       }
-      return;
-    }
-  sciprint("No input file \r\n");
-  *ierr=1;
-}
-
-/*********************************************
- * write a string 
- *********************************************/
-
-void C2F(mputstr) (int *fd, char *str, double *res, int *ierr)
-{   
-  FILE *fa;
-  fa = GetFile(fd);
-  if (!fa) 
-    {
-      sciprint("No input file \r\n");
-      *ierr=1;
-    }
-  else 
-    {
-      fprintf(fa,"%s",str);
-      (*res) = (*ierr) =ferror(fa);
-    }
-}
-
-
diff --git a/scilab/modules/fileio/src/c/files.h b/scilab/modules/fileio/src/c/files.h
deleted file mode 100644 (file)
index 0f7d47f..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*------------------------------------------------------------------------*/
-/* Copyright INRIA 2006                                                   */
-/* Authors : Sylvestre ledru                                              */
-/*------------------------------------------------------------------------*/
-#ifndef __FILES_H__
-#define __FILES_H__
-
-#include <stdio.h> /* FILE */
-#include "machine.h" /* C2F() */
-
-void C2F(getfiledesc)(integer *fd);
-
-void C2F(addfile)(integer *fd, FILE *fa, integer *swap, integer *type, integer *mode, char *filename, integer *ierr);
-
-void C2F(getfileinfo)(integer *fd, FILE *fa, integer *swap, integer *type, integer *mode, char *filename, integer *lf, integer *ierr);
-
-void C2F(getfiletype)(integer *fd, integer *type, integer *ierr);
-
-void C2F(delfile)(integer *fd);
-
-FILE *GetFile(integer *fd);
-
-int GetSwap(integer *fd);
-
-void C2F(mopen)(int *fd, char *file, char *status, int *f_swap, double *res, int *error);
-
-void C2F(mclose) (integer *fd, double *res);
-
-void C2F(meof) (integer *fd, double *res);
-
-void C2F(merror) (integer *fd, double *res);
-
-void C2F(mclearerr) (integer *fd);
-
-void C2F(mseek) (integer *fd, integer *offset, char *flag, integer *err);
-
-void C2F(mtell) (integer *fd, double *offset, integer *err);
-
-void C2F(mputnc) (integer *fd, void * res, integer *n1, char *type, integer *ierr);
-
-void mput2 (FILE *fa, integer swap2, double *res, integer n, char *type, integer *ierr);
-
-void C2F(mput) (integer *fd, double *res, integer *n, char *type, integer *ierr);
-
-void C2F(mgetnc)(integer *fd, void * res, integer *n1, char *type, integer *ierr);
-
-void mget2(FILE *fa, integer swap, double *res, integer n, char *type, integer *ierr);
-
-void C2F(mget) (integer *fd, double *res, integer *n, char *type, integer *ierr);
-
-void C2F(mgetstr) (integer *fd, char **start, integer *n, integer *ierr);
-
-void C2F(mgetstr1) (integer *fd, char *start, integer *n, integer *ierr);
-
-void C2F(mputstr) (int *fd, char *str, double *res, int *ierr);
-
-#endif /* __FILES_H__ */
diff --git a/scilab/modules/fileio/src/c/getfiledesc.c b/scilab/modules/fileio/src/c/getfiledesc.c
new file mode 100644 (file)
index 0000000..a3f1201
--- /dev/null
@@ -0,0 +1,21 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include "getfiledesc.h"\r
+#include "filesmanagement.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(getfiledesc)(integer *fd) \r
+{\r
+       int i ;\r
+       for ( i = 1 ; i < GetMaximumFileOpenedInScilab() ; i++) \r
+       {\r
+               if ( GetFileTypeOpenedInScilab(i) == 0 ) \r
+               {\r
+                       *fd = i;\r
+                       return ;\r
+               }\r
+       }\r
+       *fd = -1;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/getfileinfo.c b/scilab/modules/fileio/src/c/getfileinfo.c
new file mode 100644 (file)
index 0000000..3960712
--- /dev/null
@@ -0,0 +1,30 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <string.h> /* strlen */\r
+#include "getfileinfo.h"\r
+#include "filesmanagement.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(getfileinfo)(integer *fd, FILE *fa, integer *swap2, integer *type, integer *mode, char *filename, integer *lf, integer *ierr)\r
+{\r
+       if (*fd<0 || *fd>=GetMaximumFileOpenedInScilab() ) \r
+       {\r
+               *ierr=1;\r
+               return;\r
+       }\r
+       if ( GetFileTypeOpenedInScilab(*fd) == 0 ) \r
+       {\r
+               *ierr=2;\r
+               return;\r
+       }\r
+       fa = GetFileOpenedInScilab(*fd);\r
+\r
+       *swap2 = GetSwapStatus(*fd);\r
+       *type = GetFileTypeOpenedInScilab(*fd);\r
+       *mode = GetFileModeOpenedInScilab(*fd);\r
+       strcpy(filename,GetFileNameOpenedInScilab(*fd));\r
+       *lf=strlen(filename);\r
+       *ierr=0;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/getfiletype.c b/scilab/modules/fileio/src/c/getfiletype.c
new file mode 100644 (file)
index 0000000..ea1a6bf
--- /dev/null
@@ -0,0 +1,23 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include "getfiletype.h"\r
+#include "filesmanagement.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(getfiletype)(integer *fd, integer *type, integer *ierr)\r
+{\r
+       if (*fd<0 || *fd>=GetMaximumFileOpenedInScilab() ) \r
+       {\r
+               *ierr=1;\r
+               return;\r
+       }\r
+       if ( GetFileTypeOpenedInScilab(*fd) == 0 ) \r
+       {\r
+               *ierr=2;\r
+               return;\r
+       }\r
+       *type = GetFileTypeOpenedInScilab(*fd);\r
+       *ierr=0;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mclearerr.c b/scilab/modules/fileio/src/c/mclearerr.c
new file mode 100644 (file)
index 0000000..ebffa5a
--- /dev/null
@@ -0,0 +1,14 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <stdio.h>\r
+#include "mclearerr.h"\r
+#include "filesmanagement.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mclearerr) (integer *fd)\r
+{       \r
+       FILE *fa= GetFileOpenedInScilab(*fd);\r
+       clearerr(fa);\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mclearerr.h b/scilab/modules/fileio/src/c/mclearerr.h
new file mode 100644 (file)
index 0000000..26b9316
--- /dev/null
@@ -0,0 +1,16 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MCLEARERR_H__\r
+#define __MCLEARERR_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* clear errors \r
+*/\r
+void C2F(mclearerr) (integer *fd);\r
+\r
+#endif /* __MCLEARERR_H__ */\r
+/*-----------------------------------------------------------------------------------*/
\ No newline at end of file
diff --git a/scilab/modules/fileio/src/c/mclose.c b/scilab/modules/fileio/src/c/mclose.c
new file mode 100644 (file)
index 0000000..5314fb9
--- /dev/null
@@ -0,0 +1,55 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include "mclose.h"\r
+#include "filesmanagement.h"\r
+#include "delfile.h"\r
+#include "core_math.h" /* Min Max */\r
+#include "sciprint.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mclose) (integer *fd, double *res)\r
+{     \r
+       int fd1;\r
+       int res1 = 1;\r
+       *res = 0.0;\r
+       switch ( *fd )\r
+       {\r
+       case -2 :\r
+               /* closing all opened files */\r
+               for ( fd1=0; fd1< GetMaximumFileOpenedInScilab(); fd1++) {\r
+                       if ( GetFileOpenedInScilab(fd1) )\r
+                       {\r
+                               fclose( GetFileOpenedInScilab(fd1) );\r
+                               res1 = ferror( GetFileOpenedInScilab(fd1));\r
+                               if (res1 != 0) *res =1;\r
+                               C2F(delfile)(&fd1);\r
+                       }\r
+               }\r
+               break;\r
+       default :\r
+               fd1 = (*fd == -1 ) ? GetCurrentFileId() : Min(Max(*fd,0),GetMaximumFileOpenedInScilab()-1);\r
+               if ( fd1 != -1 ) \r
+               {\r
+                       if ( GetFileOpenedInScilab(fd1) )\r
+                       {\r
+                               if (fclose(GetFileOpenedInScilab(fd1)))\r
+                               {\r
+                                       *res = (double)ferror(GetFileOpenedInScilab(fd1));\r
+                               }\r
+                               C2F(delfile)(&fd1);\r
+                       }\r
+                       else\r
+                       {\r
+                               *res = 0.0;\r
+                               sciprint("File %d not active \r\n",fd1);\r
+                       }\r
+               }\r
+               else \r
+               {\r
+                       *res = -1.0;\r
+                       sciprint("No file to close \r\n",fd1);\r
+               }\r
+       }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/meof.c b/scilab/modules/fileio/src/c/meof.c
new file mode 100644 (file)
index 0000000..8d48f34
--- /dev/null
@@ -0,0 +1,14 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <stdio.h>\r
+#include "meof.h"\r
+#include "filesmanagement.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(meof) (integer *fd, double *res)\r
+{       \r
+       FILE *fa= GetFileOpenedInScilab(*fd);\r
+       *res = fa ? feof(fa) : 1;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/meof.h b/scilab/modules/fileio/src/c/meof.h
new file mode 100644 (file)
index 0000000..f54bf39
--- /dev/null
@@ -0,0 +1,16 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MEOF_H__\r
+#define __MEOF_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* check eof \r
+*/\r
+void C2F(meof) (integer *fd, double *res);\r
+\r
+#endif /* __MEOF_H__ */\r
+/*-----------------------------------------------------------------------------------*/
\ No newline at end of file
diff --git a/scilab/modules/fileio/src/c/merror.c b/scilab/modules/fileio/src/c/merror.c
new file mode 100644 (file)
index 0000000..9cc8934
--- /dev/null
@@ -0,0 +1,15 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <stdio.h>\r
+#include "merror.h"\r
+#include "filesmanagement.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(merror) (integer *fd, double *res)\r
+{       \r
+       FILE *fa= GetFileOpenedInScilab(*fd);\r
+       *res = fa ? ferror(fa) : 1;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+\r
diff --git a/scilab/modules/fileio/src/c/merror.h b/scilab/modules/fileio/src/c/merror.h
new file mode 100644 (file)
index 0000000..c7992a2
--- /dev/null
@@ -0,0 +1,16 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MERROR_H__\r
+#define __MERROR_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* check error\r
+*/\r
+void C2F(merror) (integer *fd, double *res);\r
+\r
+#endif /* __MERROR_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mget.c b/scilab/modules/fileio/src/c/mget.c
new file mode 100644 (file)
index 0000000..bd4295c
--- /dev/null
@@ -0,0 +1,174 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <string.h>\r
+#include "mget.h"\r
+#include "filesmanagement.h"\r
+#include "../../../libs/libst/misc.h"\r
+#include "sciprint.h"\r
+#include "islittleendian.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+struct soundstream ftf;\r
+int swap = 0;\r
+/*-----------------------------------------------------------------------------------*/\r
+/* =================================================\r
+* reads data and store them without type conversion \r
+* =================================================*/\r
+#define MGET_CHAR_NC(Type) \\r
+{\\r
+       Type *val = (Type *) res ;\\r
+       items=fread(val,sizeof(Type),n,fa);\\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+#define MGET_NC(Type,Fswap) \\r
+{\\r
+       Type *val = (Type *) res ;\\r
+       items=fread(val,sizeof(Type),n,fa);\\r
+       if (swap) \\r
+       for (i=0;i<items;i++) \\r
+       val[i]=Fswap(val[i]);\\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+#define MGET_GEN_NC(NumType,Fswap,cf)\\r
+{ \\r
+       switch (cf) { \\r
+                 case ' ': MGET_NC(NumType,Fswap);break; \\r
+                 case 'b': swap = (islittleendian()==1)? 1:0; \\r
+                 MGET_NC(NumType,Fswap); break; \\r
+         case 'l': swap = (islittleendian()==1) ? 0:1; \\r
+         MGET_NC(NumType,Fswap);  break; \\r
+         default: sciprint("mget : %s format not recognized \r\n",type); \\r
+         *ierr=1; return; \\r
+                               } \\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mgetnc)(integer *fd, void * res, integer *n1, char *type, integer *ierr)\r
+{  \r
+       char c1,c2;\r
+       int i,items=*n1,n=*n1;\r
+       FILE *fa;\r
+\r
+\r
+       *ierr=0;\r
+       if ((fa = GetFileOpenedInScilab(*fd)) ==NULL) {\r
+               sciprint("No input file associated to logical unit %d\r\n",*fd);\r
+               *ierr=3;\r
+               return;\r
+       }\r
+       swap = GetSwapStatus(*fd);\r
+       c1 = ( strlen(type) > 1) ? type[1] : ' '; \r
+       c2 = ( strlen(type) > 2) ? type[2] : ' '; \r
+       switch ( type[0] )\r
+       {\r
+       case 'i' : MGET_GEN_NC(int,swapi,c1);break;\r
+       case 'l' : MGET_GEN_NC(long,swapl,c1);break;\r
+       case 's' : MGET_GEN_NC(short,swapw,c1);break;\r
+       case 'c' : MGET_CHAR_NC(char) ; break;\r
+       case 'd' : MGET_GEN_NC(double,swapd,c1);break;\r
+       case 'f' : MGET_GEN_NC(float,swapf,c1);break;\r
+       case 'u' :\r
+               switch ( c1 )\r
+               {\r
+               case 'i' :  MGET_GEN_NC(unsigned int,swapi,c2); break;\r
+               case 'l' :  MGET_GEN_NC(unsigned long,swapl,c2); break;\r
+               case 's' :  MGET_GEN_NC(unsigned short,swapw,c2); break;\r
+               case ' ' :  MGET_GEN_NC(unsigned int,swapi,' '); break;\r
+               case 'c' :  MGET_CHAR_NC(unsigned char); break;\r
+               default : *ierr=1; return; break;\r
+               }\r
+               break;\r
+       default :\r
+               *ierr=1;\r
+               return ;\r
+       }\r
+       if ( items != n ) \r
+       {\r
+               *ierr = -(items) -1 ;\r
+               /** sciprint("Read %d out of \r\n",items,n); **/\r
+       }\r
+       return;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/* =================================================\r
+* reads data and store them in double\r
+* =================================================*/\r
+\r
+/* conversion macro  */\r
+#define CONVGD(Type) \\r
+{\\r
+       Type *val = (Type *) res ;\\r
+       for ( i = items-1 ; i >=0 ; i--)  \\r
+       res[i] = val[i]; \\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+#define MGET_GEN(NumType,Fswap,cf)  MGET_GEN_NC(NumType,Fswap,cf); CONVGD(NumType);\r
+#define MGET_CHAR(NumType)  MGET_CHAR_NC(NumType); CONVGD(NumType); \r
+/*-----------------------------------------------------------------------------------*/\r
+/* reads data and store them in double  */\r
+void mget2(FILE *fa, integer swap2, double *res, integer n, char *type, integer *ierr)\r
+{  \r
+       char c1,c2;\r
+       int i,items=n;\r
+       ft_t ft = &ftf; \r
+       *ierr=0;\r
+       ft->fp = fa;\r
+       c1 = ( strlen(type) > 1) ? type[1] : ' '; \r
+       c2 = ( strlen(type) > 2) ? type[2] : ' '; \r
+       switch ( type[0] )\r
+       {\r
+       case 'i' : MGET_GEN(int,swapi,c1);break;\r
+       case 'l' : MGET_GEN(long,swapl,c1);break;\r
+       case 's' : MGET_GEN(short,swapw,c1);break;\r
+       case 'c' : MGET_CHAR(char) ; break;\r
+       case 'd' : MGET_GEN(double,swapd,c1);break;\r
+       case 'f' : MGET_GEN(float,swapf,c1);break;\r
+       case 'u' :\r
+               switch ( c1 )\r
+               {\r
+               case 'i' :  MGET_GEN(unsigned int,swapi,c2); break;\r
+               case 'l' :  MGET_GEN(unsigned long,swapl,c2); break;\r
+               case 's' :  MGET_GEN(unsigned short,swapw,c2); break;\r
+               case ' ' :  MGET_GEN(unsigned int,swapi,' '); break;\r
+               case 'c' :  MGET_CHAR(unsigned char); break;\r
+               default : *ierr=1; return; break;\r
+               }\r
+               break;\r
+       default :\r
+               *ierr=1;\r
+               return ;\r
+       }\r
+       if ( items != n ) \r
+       {\r
+               *ierr = -(items) -1 ;\r
+               /** sciprint("Read %d out of \r\n",items,n); **/\r
+       }\r
+       return;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mget) (integer *fd, double *res, integer *n, char *type, integer *ierr)\r
+{  \r
+       int nc,swap2;\r
+       FILE *fa;\r
+       nc=strlen(type);\r
+       *ierr=0;\r
+       if ( nc == 0) \r
+       {\r
+               sciprint("mget : format is of length 0\r\n",type);\r
+               *ierr=2;\r
+               return;\r
+       }\r
+       fa = GetFileOpenedInScilab(*fd);\r
+       if (fa ) \r
+       {\r
+               swap2 = GetSwapStatus(*fd);\r
+               mget2(fa,swap2,res,*n,type,ierr);\r
+               if (*ierr > 0) sciprint("mget : %s format not recognized \r\n",type);\r
+       }\r
+       else \r
+       {\r
+               sciprint("No input file associated to logical unit %d\r\n",*fd);\r
+               *ierr=3;\r
+       }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mgetstr.c b/scilab/modules/fileio/src/c/mgetstr.c
new file mode 100644 (file)
index 0000000..3e00b25
--- /dev/null
@@ -0,0 +1,57 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <stdio.h>\r
+#include "mgetstr.h"\r
+#include "filesmanagement.h"\r
+#include "MALLOC.h"\r
+#include "sciprint.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mgetstr) (integer *fd, char **start, integer *n, integer *ierr)\r
+{ \r
+       int count=0;\r
+       FILE *fa=NULL;\r
+       fa = GetFileOpenedInScilab(*fd);\r
+       *ierr=0;\r
+       if (fa)\r
+       { \r
+               *start= (char *) MALLOC((*n+1)*sizeof(char));\r
+               if ( *start == (char *) 0)\r
+               {       \r
+                       sciprint("No more memory \r\n");\r
+                       *ierr=1;\r
+                       return;\r
+               }\r
+               count=fread(*start,sizeof(char),*n,fa);\r
+               (*start)[*n]='\0';\r
+               if ( count != *n ) \r
+               {\r
+                       *ierr = - count -1;\r
+               }\r
+               return;\r
+       }\r
+       sciprint("No input file \r\n");\r
+       *ierr=1;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mgetstr1) (integer *fd, char *start, integer *n, integer *ierr)\r
+{ \r
+       int count=0;\r
+       FILE *fa=NULL;\r
+       fa = GetFileOpenedInScilab(*fd);\r
+       *ierr=0;\r
+       if (fa)\r
+       { \r
+               count=fread(start,sizeof(char),*n,fa);\r
+               start[*n]='\0';\r
+               if ( count != *n ) \r
+               {\r
+                       *ierr = - count -1;\r
+               }\r
+               return;\r
+       }\r
+       sciprint("No input file \r\n");\r
+       *ierr=1;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mgetstr.h b/scilab/modules/fileio/src/c/mgetstr.h
new file mode 100644 (file)
index 0000000..decf8da
--- /dev/null
@@ -0,0 +1,17 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MGETSTR_H__\r
+#define __MGETSTR_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* read a string \r
+*/\r
+void C2F(mgetstr) (integer *fd, char **start, integer *n, integer *ierr);\r
+void C2F(mgetstr1) (integer *fd, char *start, integer *n, integer *ierr);\r
+\r
+#endif /* __MGETSTR_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mopen.c b/scilab/modules/fileio/src/c/mopen.c
new file mode 100644 (file)
index 0000000..9dab998
--- /dev/null
@@ -0,0 +1,53 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <stdio.h>\r
+#include "mopen.h"\r
+#include "Status2Mode.h"\r
+#include "filesmanagement.h"\r
+#include "getfiledesc.h"\r
+#include "addfile.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+extern int swap;\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mopen)(int *fd, char *file, char *status, int *f_swap, double *res, int *error)\r
+{   \r
+       int     littlendian = 1,type = 2,ierr,mode;\r
+       char    *endptr;\r
+       FILE * fa;\r
+       /* next line added by ss 16/10/98 */\r
+       swap =0;\r
+       *error=0;\r
+       endptr = (char *) &littlendian;\r
+       if ( (!*endptr) )\r
+       {\r
+               if( *f_swap == 1 ) swap = 1;\r
+               else swap =0;\r
+       }\r
+\r
+       C2F(getfiledesc)(fd);\r
+\r
+       if ( *fd == -1 )\r
+       {\r
+               *error=1; /* Too many opened files */\r
+               return;\r
+       }\r
+       fa=fopen(file,status);\r
+       if (! fa )\r
+       {     \r
+               *error=2; /* Could not open the file*/\r
+               return;\r
+       }\r
+       mode=Status2Mode(status);\r
+       C2F(addfile)(fd,fa,&swap,&type,&mode,file,&ierr);\r
+       if (ierr)\r
+       {\r
+               *error=3; /* Not enough memory;*/\r
+               return;\r
+       }\r
+       SetCurrentFileId(*fd);\r
+       *res = (double)ferror(fa);\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+\r
diff --git a/scilab/modules/fileio/src/c/mopen.h b/scilab/modules/fileio/src/c/mopen.h
new file mode 100644 (file)
index 0000000..cd8875e
--- /dev/null
@@ -0,0 +1,23 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MOPEN_H__\r
+#define __MOPEN_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* Opens file given by file and return it's id \r
+* @param[out] fd (id)\r
+* @param filename\r
+* @param status "r","w","a" or "rb","wb","ab"\r
+* @param swap\r
+* @param[out] res\r
+* @param[out] error\r
+*/\r
+\r
+void C2F(mopen)(int *fd, char *file, char *status, int *f_swap, double *res, int *error);\r
+\r
+#endif  /* __MOPEN_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mput.c b/scilab/modules/fileio/src/c/mput.c
new file mode 100644 (file)
index 0000000..847f8f5
--- /dev/null
@@ -0,0 +1,186 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <string.h>\r
+#include "mput.h"\r
+#include "filesmanagement.h"\r
+#include "sciprint.h"\r
+#include "islittleendian.h"\r
+#include "../../../libs/libst/misc.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+extern struct soundstream ftf; /* defined in mget.c */\r
+extern int swap; /* defined in mget.c */\r
+/*-----------------------------------------------------------------------------------*/\r
+/*===============================================\r
+* function to write data without type conversion\r
+*===============================================*/\r
+#define MPUT_CHAR_NC(Type) \\r
+{\\r
+       Type *val = (Type *) res ; \\r
+       fwrite(val,sizeof(Type),n,fa); \\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+#define MPUT_NC(Type,Fswap) \\r
+{ \\r
+       Type *val = (Type *) res ; \\r
+       Type vali; \\r
+       for ( i=0; i< n; i++)  \\r
+                  { \\r
+                  vali = *val++; \\r
+                  if ( swap) vali = Fswap(vali); \\r
+                  fwrite(&vali,sizeof(Type),1,fa); \\r
+               } \\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+#define MPUT_GEN_NC(Type,Fswap,cf) \\r
+       switch ( cf )  \\r
+       { \\r
+       case ' ': MPUT_NC(Type,Fswap); break; \\r
+       case 'b': \\r
+       swap = (islittleendian()==1) ? 1 : 0; \\r
+       MPUT_NC(Type,Fswap); break; \\r
+               case 'l': \\r
+               swap = (islittleendian()==1) ? 0 : 1; \\r
+               MPUT_NC(Type,Fswap); break; \\r
+               default: \\r
+               sciprint("mput : %s format not recognized \r\n",type); \\r
+               *ierr=1;return; \\r
+       }\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mputnc) (integer *fd, void * res, integer *n1, char *type, integer *ierr)\r
+{  \r
+       char c1,c2;\r
+       int i,swap2,n;\r
+       FILE *fa;\r
+       n=*n1;\r
+       *ierr=0;\r
+       if ((fa = GetFileOpenedInScilab(*fd)) ==NULL) {\r
+               sciprint("No input file associated to logical unit %d\r\n",*fd);\r
+               *ierr=3;\r
+               return;\r
+       }\r
+       swap2 = GetSwapStatus(*fd);\r
+\r
+       c1 = ( strlen(type) > 1) ? type[1] : ' '; \r
+       c2 = ( strlen(type) > 2) ? type[2] : ' '; \r
+       switch ( type[0] )\r
+       {\r
+       case 'i' : MPUT_GEN_NC(int,swapi,c1);       break;\r
+       case 'l' : MPUT_GEN_NC(long,swapl,c1);      break;\r
+       case 's' : MPUT_GEN_NC(short,swapw,c1);     break;\r
+       case 'c' : MPUT_CHAR_NC(char) ;          break;\r
+       case 'd' : MPUT_GEN_NC(double,swapd,c1);    break;\r
+       case 'f' : MPUT_GEN_NC(float,swapf,c1);     break;\r
+       case 'u' :\r
+               switch ( c1 )\r
+               {\r
+               case 'i' :  MPUT_GEN_NC(unsigned int,swapi,c2); break;\r
+               case 'l' :  MPUT_GEN_NC(unsigned long,swapl,c2); break;\r
+               case 's' :  MPUT_GEN_NC(unsigned short,swapw,c2); break;\r
+               case ' ' :  MPUT_GEN_NC(unsigned int,swapi,' '); break;\r
+               case 'c' :  MPUT_CHAR_NC(unsigned char); break;\r
+               default :  *ierr=1;return ;\r
+               }\r
+               break;\r
+       default : *ierr=1; break;\r
+       }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/*================================================\r
+* function to write data stored in double\r
+*================================================*/\r
+/** used for char **/\r
+#define MPUT_CHAR(Type) \\r
+       for ( i=0; i< n; i++)  \\r
+{ \\r
+       Type  val = (char) *res++; \\r
+       fwrite(&val,sizeof(Type),1,fa); \\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/** write in a machine independant way : i.e data \r
+is swaped if necessary to output little-endian \r
+data **/\r
+\r
+#define MPUT(Type,Fswap) for ( i=0; i< n; i++)  \\r
+{ \\r
+       Type val; \\r
+       val =(Type) *res++; \\r
+       if ( swap) val = Fswap(val); \\r
+       fwrite(&val,sizeof(Type),1,fa); \\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/** The output mode is controlled by type[1] **/\r
+#define MPUT_GEN(Type,Fswap,cf) \\r
+       switch ( cf )  \\r
+{ \\r
+       case ' ': MPUT(Type,Fswap); break; \\r
+       case 'b': \\r
+       swap = (islittleendian()==1) ? 1 : 0; \\r
+       MPUT(Type,Fswap); break; \\r
+               case 'l': \\r
+               swap = (islittleendian()==1) ? 0 : 1; \\r
+               MPUT(Type,Fswap); break; \\r
+               default: \\r
+               sciprint("mput : %s format not recognized \r\n",type); \\r
+               *ierr=1;return; \\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void mput2 (FILE *fa, integer swap2, double *res, integer n, char *type, integer *ierr)\r
+{  \r
+       char c1,c2;\r
+       int i;\r
+       ft_t ft = &ftf;\r
+       *ierr=0;\r
+       ft->fp = fa;\r
+       c1 = ( strlen(type) > 1) ? type[1] : ' '; \r
+       c2 = ( strlen(type) > 2) ? type[2] : ' '; \r
+       switch ( type[0] )\r
+       {\r
+       case 'i' : MPUT_GEN(int,swapi,c1);       break;\r
+       case 'l' : MPUT_GEN(long,swapl,c1);      break;\r
+       case 's' : MPUT_GEN(short,swapw,c1);     break;\r
+       case 'c' : MPUT_CHAR(char) ;          break;\r
+       case 'd' : MPUT_GEN(double,swapd,c1);    break;\r
+       case 'f' : MPUT_GEN(float,swapf,c1);     break;\r
+       case 'u' :\r
+               switch ( c1 )\r
+               {\r
+               case 'i' :  MPUT_GEN(unsigned int,swapi,c2); break;\r
+               case 'l' :  MPUT_GEN(unsigned long,swapl,c2); break;\r
+               case 's' :  MPUT_GEN(unsigned short,swapw,c2); break;\r
+               case ' ' :  MPUT_GEN(unsigned int,swapi,' '); break;\r
+               case 'c' :  MPUT_CHAR(unsigned char); break;\r
+               default :  *ierr=1;return ;\r
+               }\r
+               break;\r
+       default : *ierr=1; break;\r
+       }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mput) (integer *fd, double *res, integer *n, char *type, integer *ierr)\r
+{\r
+       int nc,swap2;\r
+       FILE *fa;\r
+       *ierr=0;\r
+       if ((nc = strlen(type)) == 0) \r
+       {\r
+               sciprint("mput : format is of length 0\r\n",type);\r
+               *ierr=2;\r
+               return;\r
+       }\r
+       if ((fa = GetFileOpenedInScilab(*fd)) !=NULL)\r
+       {\r
+               swap2 = GetSwapStatus(*fd);\r
+               mput2(fa,swap2,res,*n,type,ierr);\r
+               if (*ierr > 0) sciprint("mput : %s format not recognized \r\n",type);\r
+       }\r
+       else \r
+       {\r
+               sciprint("No input file associated to logical unit %d\r\n",*fd);\r
+               *ierr=3;\r
+       }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+\r
+\r
diff --git a/scilab/modules/fileio/src/c/mputstr.c b/scilab/modules/fileio/src/c/mputstr.c
new file mode 100644 (file)
index 0000000..85b472b
--- /dev/null
@@ -0,0 +1,25 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <stdio.h> /* FILE */\r
+#include "mputstr.h"\r
+#include "filesmanagement.h"\r
+#include "sciprint.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mputstr) (int *fd, char *str, double *res, int *ierr)\r
+{   \r
+       FILE *fa=NULL;\r
+       fa = GetFileOpenedInScilab(*fd);\r
+       if (!fa) \r
+       {\r
+               sciprint("No input file \r\n");\r
+               *ierr=1;\r
+       }\r
+       else \r
+       {\r
+               fprintf(fa,"%s",str);\r
+               (*res) = (*ierr) =ferror(fa);\r
+       }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mputstr.h b/scilab/modules/fileio/src/c/mputstr.h
new file mode 100644 (file)
index 0000000..43c103f
--- /dev/null
@@ -0,0 +1,16 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MPUTSTR_H__\r
+#define __MPUTSTR_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* write a string \r
+*/\r
+void C2F(mputstr) (int *fd, char *str, double *res, int *ierr);\r
+\r
+#endif /* __MPUTSTR_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mseek.c b/scilab/modules/fileio/src/c/mseek.c
new file mode 100644 (file)
index 0000000..2f937c5
--- /dev/null
@@ -0,0 +1,66 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include "mseek.h"\r
+#include "filesmanagement.h"\r
+#include "sciprint.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+#if (defined(sun) && !defined(SYSV)) \r
+char *strerror __PARAMS((int errcode));\r
+#endif\r
+/*-----------------------------------------------------------------------------------*/\r
+#if (defined(sun) && !defined(SYSV)) || defined(sgi)\r
+#define SEEK_SET 0\r
+#define SEEK_CUR 1\r
+#define SEEK_END 2\r
+#endif \r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mseek) (integer *fd, integer *offset, char *flag, integer *err)\r
+{     \r
+       int iflag;\r
+#if (defined(sun) && !defined(SYSV)) || defined(sgi)\r
+       int irep;\r
+#endif\r
+       FILE *fa= GetFileOpenedInScilab(*fd);\r
+       *err=0;\r
+       if ( fa == (FILE *) 0 ) \r
+       {\r
+               sciprint("mseek: wrong file logical unit \r\n");\r
+               *err=1;\r
+               return;\r
+       }\r
+       if ( strncmp(flag,"set",3)==0 ) \r
+               iflag = SEEK_SET;\r
+       else if ( strncmp(flag,"cur",3)==0 ) \r
+               iflag = SEEK_CUR;\r
+       else if ( strncmp(flag,"end",3)==0 ) \r
+               iflag = SEEK_END;\r
+       else \r
+       {\r
+               sciprint("mseek : flag = %s not recognized \r\n");\r
+               *err=1;\r
+               return;\r
+       }\r
+#if (defined(sun) && !defined(SYSV)) || defined(sgi)\r
+       irep = fseek(fa,(long) *offset,iflag) ;\r
+       if ( irep != 0 ) \r
+       {\r
+               sciprint(strerror(irep));\r
+               *err=1;\r
+       }\r
+       else\r
+               *err=0;\r
+#else\r
+       if (fseek(fa,(long) *offset,iflag) == -1 ) \r
+       {\r
+               sciprint("mseek: error\r\n");\r
+               *err=1;\r
+       }\r
+       else \r
+               *err=0;\r
+#endif\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mtell.c b/scilab/modules/fileio/src/c/mtell.c
new file mode 100644 (file)
index 0000000..0f8439b
--- /dev/null
@@ -0,0 +1,22 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include <stdio.h>\r
+#include "mtell.h"\r
+#include "filesmanagement.h"\r
+#include "sciprint.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+void C2F(mtell) (integer *fd, double *offset, integer *err)\r
+{     \r
+       FILE *fa= GetFileOpenedInScilab(*fd);\r
+       if ( fa == (FILE *) 0 ) \r
+       {\r
+               sciprint("mtell: wrong file logical unit \r\b");\r
+               *err=1;\r
+               return;\r
+       }\r
+       *err=0;\r
+       *offset = (double) ftell(fa) ;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/fileio/src/c/mtell.h b/scilab/modules/fileio/src/c/mtell.h
new file mode 100644 (file)
index 0000000..8ede710
--- /dev/null
@@ -0,0 +1,17 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* Scilab */\r
+/* INRIA 2007 */\r
+/*-----------------------------------------------------------------------------------*/\r
+#ifndef __MTELL_H__\r
+#define __MTELL_H__\r
+\r
+#include "machine.h"\r
+\r
+/**\r
+* tell function \r
+*/\r
+void C2F(mtell) (integer *fd, double *offset, integer *err);\r
+\r
+#endif /* __MTELL_H__ */\r
+/*-----------------------------------------------------------------------------------*/\r
+\r
index 1b98bff..6b02a08 100644 (file)
@@ -7,7 +7,11 @@
 #include "machine.h"
 #include "MALLOC.h" /* MALLOC */
 #include "sciprint.h"
-
+#include "returnanan.h"
+#include "mseek.h"
+#include "mtell.h"
+#include "mget.h"
+/*------------------------------------------------------------------*/
 #define  typ_short "s"
 #define  typ_ushort "us"
 #define  typ_char "c"
 #define  typ_double "d"
 #define  typ_int "i"
 #define Min(x,y)  ((x) < (y) ? (x) : (y))
-
-extern int ripole(char *inputfile, char *outputfile, int debug, int verbose);
-extern void C2F(mgetnc) (integer *fd, void *res, integer *n, char *type, integer *ierr);
-extern void C2F(mtell) (integer *fd, double *offset, integer *err);
-extern void C2F(mseek) (integer *fd, integer *offset, char *flag, integer *err);
-extern FILE *GetFile(integer *fd);
-extern int GetSwap(integer *fd);
-
 /*------------------------------------------------------------------*/
+extern int ripole(char *inputfile, char *outputfile, int debug, int verbose);
 /*------------------------------------------------------------------*/
 /*Prototype*/
 void xls_read(int *fd, int *cur_pos,double **data, int **chainesind, int *N, int *M, int *err);
@@ -35,22 +32,6 @@ static void getBOF(int *fd ,int* Data, int *err);
 static void getString(int *fd,short *count, short *Len, int flag,char **str,int *err);
 static int get_oleheader(int *fd);
 /*------------------------------------------------------------------*/
-/*------------------------------------------------------------------*/
-static double return_a_nan()
-{
-  static int first = 1;
-  static double nan = 1.0;
-
-  if ( first )
-    {
-      nan = (nan - (double) first)/(nan - (double) first);
-      first = 0;
-    }
-  return (nan);
-}
-
-
-
 void xls_read(int *fd, int *cur_pos,double **data, int **chainesind, int *N, int *M, int *err)
 {
   /*---------------D├ęclaration Des Variables*--------------------*/
@@ -81,7 +62,7 @@ void xls_read(int *fd, int *cur_pos,double **data, int **chainesind, int *N, int
   double resultat;/*Result of the formula*/
   short optionflag;/*Option flags*/
   int formula_notused; /*Not used*/
-  double NaN=return_a_nan();
+  double NaN=C2F(returnanan)();
 
   int BOFData[7]; /*[BIFF  Version DataType Identifier Year HistoryFlags LowestXlsVersion]*/
   /* initialization of pointers corresponding to malloc's */
index 749b295..f2fea20 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "Os_specific.h" /* isanan */ 
 #include "MALLOC.h"
-
+#include "cluni0.h"
 
 /****************************************************
  * Scilab xgetfile command used to get a file name 
index 710c0b8..6652ed5 100644 (file)
@@ -8,10 +8,9 @@
 #include "sciprint.h"
 #include "../../../../libs/libst/misc.h"
 #include "islittleendian.h"
+#include "filesmanagement.h"
 
 struct soundstream ftf;
-extern FILE *GetFile();
-extern int GetSwap();
 
 
 #define MGETI(Type,Fswap) {\
@@ -47,8 +46,8 @@ void C2F(mgeti) (integer *fd,integer *res,integer *n,char type[],integer *ierr)
   RES_ul=(unsigned long *)res;
   RES_us=(unsigned short *)res;
 
-  fa = GetFile(fd);
-  swap = GetSwap(fd);
+  fa = GetFileOpenedInScilab(*fd);
+  swap = GetSwapStatus(*fd);
   ft = &ftf; 
   ft->fp = fa;
   nc=strlen(type);
@@ -186,7 +185,7 @@ int SWAP(char type[],integer *fd)
 {
 int nc,swap;
   nc=strlen(type);
-  swap = GetSwap(fd);
+  swap = GetSwapStatus(*fd);
   if ( nc > 1) {
     switch (type[1])  {
     case 'b': 
index 1d7ee5e..f23f5ce 100644 (file)
@@ -8,10 +8,11 @@
 
 #include "../../../../libs/libst/misc.h"
 #include "sciprint.h"
+#include "filesmanagement.h"
 
 struct soundstream ftf;
-extern FILE *GetFile();
-extern int GetSwap();
+
+
 
 extern int SWAP(char type[],integer *fd); /* Defined in mgeti.c */
 
@@ -42,8 +43,8 @@ void C2F(mputi) (integer *fd,integer *res,integer *n,char type[],integer *ierr)
   RES_ul=(unsigned long *)res;
   RES_us=(unsigned short *)res;
 
-  fa = GetFile(fd);
-  swap = GetSwap(fd);
+  fa = GetFileOpenedInScilab(*fd);
+  swap = GetSwapStatus(*fd);
   ft = &ftf; 
   ft->fp = fa;
   nc=strlen(type);
index 3727bf6..282a981 100644 (file)
 
 #include "gw_io.h"
 #include "../../../fileio/includes/FileExist.h"
-#include "../../../fileio/src/c/files.h"
 #include "../../../core/src/c/scicurdir.h"
 #include "directories.h"
 #include "stack-c.h"
 #include "MALLOC.h"
 #include "Scierror.h"
+#include "../../../fileio/includes/getfiledesc.h"
+#include "../../../fileio/includes/getfileinfo.h"
 /*-----------------------------------------------------------------------------------*/
 #ifdef _MSC_VER
        #define DIR_SEPARATOR "\\"