replaces cluni0 by expandPathVariable
Allan CORNET [Mon, 14 Sep 2009 14:21:20 +0000 (16:21 +0200)]
27 files changed:
scilab/modules/completion/src/c/getfilesdictionary.c
scilab/modules/core/sci_gateway/c/sci_getmd5.c
scilab/modules/fileio/includes/cluni0.h
scilab/modules/fileio/sci_gateway/c/sci_chdir.c
scilab/modules/fileio/sci_gateway/c/sci_createdir.c
scilab/modules/fileio/sci_gateway/c/sci_findfiles.c
scilab/modules/fileio/sci_gateway/c/sci_fscanfMat.c
scilab/modules/fileio/sci_gateway/c/sci_isdir.c
scilab/modules/fileio/sci_gateway/c/sci_mopen.c
scilab/modules/fileio/sci_gateway/c/sci_newest.c
scilab/modules/fileio/sci_gateway/c/sci_removedir.c
scilab/modules/fileio/src/c/cluni0.c
scilab/modules/fileio/src/c/fileinfo.c
scilab/modules/fileio/src/c/splitpath.c
scilab/modules/functions/src/c/libraryinfo.c
scilab/modules/graphic_export/src/c/xs2file.c
scilab/modules/gui/sci_gateway/cpp/sci_uigetdir.cpp
scilab/modules/gui/sci_gateway/cpp/sci_uigetfile.cpp
scilab/modules/gui/sci_gateway/cpp/sci_uiputfile.cpp
scilab/modules/history_manager/sci_gateway/c/sci_loadhistory.c
scilab/modules/history_manager/sci_gateway/c/sci_savehistory.c
scilab/modules/history_manager/src/c/fileio_Import.def
scilab/modules/history_manager/src/cpp/HistoryFile.cpp
scilab/modules/history_manager/src/cpp/HistoryManager.cpp
scilab/modules/sound/sci_gateway/c/sci_PlaySound.c
scilab/modules/spreadsheet/sci_gateway/c/sci_xls_open.c
scilab/modules/windows_tools/src/c/winopen.c

index 3f41957..0da2c49 100644 (file)
@@ -18,7 +18,7 @@
 #include "scicurdir.h" /* scigetcwd */
 #include "findfiles.h" /* findfiles */
 #include "MALLOC.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "machine.h"
 #include "isdir.h"
 #include "stack-def.h"
@@ -46,7 +46,7 @@ char **getfilesdictionary(char *somechars,int *sizearray,BOOL fullpath)
                char pathname[PATH_MAX];
                char filename[PATH_MAX];
 
-               char pathextended[PATH_MAX];
+               char *pathextended = NULL;
                int out_n = 0;
 
                splitpath(somechars,pathname,filename);
@@ -82,8 +82,15 @@ char **getfilesdictionary(char *somechars,int *sizearray,BOOL fullpath)
                        sprintf(filespec,"%s*",filename);
                }
 
-               C2F(cluni0)(path,pathextended,&out_n,(long)strlen(path),PATH_MAX);
-               dictionary = findfiles(pathextended, filespec, &sizeListReturned);
+               pathextended = expandPathVariable(path);
+               
+               if (pathextended)
+               {
+                       dictionary = findfiles(pathextended, filespec, &sizeListReturned);
+                       FREE(pathextended);
+                       pathextended = NULL;
+               }
+
                if (fullpath)
                {
                        dictionary = addPath(dictionary, sizeListReturned, path);
@@ -162,15 +169,19 @@ static char **addDirSeparator(char **dictionary, int sizearray, char *path)
        int i = 0;
        for (i = 0;i < sizearray;i++)
        {
-               int out_n = 0;
-
-               char pathextended[PATH_MAX];
+               char *pathextended = NULL;
                char fullpath[PATH_MAX * 2];
 
-               C2F(cluni0)(path, pathextended, &out_n,( long)strlen(path), PATH_MAX);
-
-               strcpy(fullpath, pathextended);
-               strcat(fullpath, dictionary[i]);
+               pathextended = expandPathVariable(path);
+               if (pathextended)
+               {
+                       strcpy(fullpath, pathextended);
+                       strcat(fullpath, dictionary[i]);
+               }
+               else
+               {
+                       strcpy(fullpath, dictionary[i]);
+               }
 
                if ( isdir(fullpath) && (dictionary[i][strlen(dictionary[i])-1] != DIR_SEPARATOR[0]) )
                {
index 9b3872e..fefa83f 100644 (file)
@@ -18,7 +18,7 @@
 #include "Scierror.h"
 #include "stricmp.h"
 #include "freeArrayOfString.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "PATH_MAX.h"
 #include "charEncoding.h"
 #include "isdir.h"
@@ -61,14 +61,8 @@ int C2F(sci_getmd5) (char *fname,unsigned long fname_len)
                                char *MD5       = NULL;
                                char *real_path = NULL;
 
-                               long int lout;
-                               int out_n;
-
                                /* Replaces SCI, ~, HOME, TMPDIR by the real path */
-                               lout = PATH_MAX + FILENAME_MAX;
-                               real_path = (char*)MALLOC(sizeof(char*)*lout);
-
-                               C2F(cluni0)(Input_Matrix[i], real_path, &out_n, (long)strlen(Input_Matrix[i]), lout);
+                               real_path = expandPathVariable(Input_Matrix[i]);
 
                                /* bug 4469 */
                                if (isdir(real_path))
@@ -76,7 +70,7 @@ int C2F(sci_getmd5) (char *fname,unsigned long fname_len)
                                        Scierror(999,_("%s: The file %s does not exist.\n"),fname, Input_Matrix[i]);
                                        freeArrayOfString(Output_Matrix,mn);
                                        freeArrayOfString(Input_Matrix,mn);
-                                       FREE(real_path);real_path=NULL;
+                                       FREE(real_path); real_path = NULL;
                                        return 0;
                                }
 
index 181f825..6ab6324 100644 (file)
 #define __CLUNI0_H__
 #include "dynlib_fileio.h"
 #include "machine.h"
+
+/**
+* !!! DEPRECATED see expandPathVariable.h !!!
+*/
+
 /**
  * expand in_name to produce out_name 
  *
index 4d98886..1cbd858 100644 (file)
@@ -15,8 +15,9 @@
 #include "Scierror.h"
 #include "scicurdir.h"
 #include "localization.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "PATH_MAX.h"
+#include "MALLOC.h"
 /*--------------------------------------------------------------------------*/
 int sci_chdir(char *fname,unsigned long fname_len)
 {
@@ -26,15 +27,15 @@ int sci_chdir(char *fname,unsigned long fname_len)
 
        if ( (Rhs == 0) || (GetType(1) == sci_strings) )
        {
-               int ierr = 0;
-               static int l1,n1,m1;
+               int ierr = 1;
+               int l1 = 0, n1 = 0,m1 = 0;
                char shortpath[PATH_MAX];
-               char path[PATH_MAX];
+               char *path = NULL;
                int out_n = 0;
 
                if (Rhs == 0)
                {
-                       strcpy(shortpath,"home/");
+                       strcpy(shortpath, "home/");
                }
                else
                {
@@ -42,8 +43,13 @@ int sci_chdir(char *fname,unsigned long fname_len)
                        strcpy(shortpath,cstk(l1));
                }
 
-               C2F(cluni0)(shortpath,path,&out_n,(long)strlen(shortpath),PATH_MAX);
-               scichdir(path,&ierr);
+               path = expandPathVariable(shortpath);
+               if (path)
+               {
+                       scichdir(path, &ierr);
+                       FREE(path);
+                       path = NULL;
+               }
 
                n1=1;
                CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
index 6d06de0..34228fc 100644 (file)
@@ -17,7 +17,7 @@
 #include "MALLOC.h"
 #include "createdirectory.h"
 #include "isdir.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "warningmode.h"
 #include "sciprint.h"
 #include "Scierror.h"
@@ -33,13 +33,12 @@ int sci_createdir(char *fname,unsigned long l)
        {
                BOOL bOK = FALSE;
                int m1 = 0, n1 = 0, l1 = 0;
-               char expandedpath[PATH_MAX+1];
+               char *expandedpath = NULL;
                int out_n = 0;
 
                GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
 
-
-               C2F(cluni0)(cstk(l1),expandedpath, &out_n,(int)strlen(cstk(l1)),PATH_MAX);
+               expandedpath = expandPathVariable(cstk(l1));
 
                if (!isdir(expandedpath))
                {
@@ -51,6 +50,12 @@ int sci_createdir(char *fname,unsigned long l)
                        bOK = TRUE;
                }
 
+               if (expandedpath)
+               {
+                       FREE(expandedpath);
+                       expandedpath = NULL;
+               }
+
                m1 = 1; n1 = 1;
                CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &m1, &n1 ,&l1);
                *istk(l1) = bOK;
index 6e6518b..b3b8c20 100644 (file)
@@ -19,7 +19,7 @@
 #include "localization.h"
 #include "scicurdir.h" /* scigetcwd */
 #include "Scierror.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "PATH_MAX.h"
 #ifdef _MSC_VER
 #include "strdup_windows.h"
@@ -31,7 +31,7 @@
 int sci_findfiles(char *fname,unsigned long fname_len)
 {
        static int l1 = 0, n1 = 0, m1 = 0;
-       char pathextented[PATH_MAX];
+       char *pathextented = NULL;
        int out_n = 0;
        char *path = NULL;
        char *filespec = NULL;
@@ -102,8 +102,9 @@ int sci_findfiles(char *fname,unsigned long fname_len)
                break;
        }
 
-       C2F(cluni0)(path,pathextented,&out_n,(long)strlen(path),PATH_MAX); 
+       pathextented = expandPathVariable(path);
        FilesList = findfiles(pathextented, filespec, &sizeListReturned);
+       if (pathextented) {FREE(pathextented); pathextented = NULL;}
        if (needtofreefilespec) { if (filespec) FREE(filespec); filespec = NULL;}
 
        if (FilesList)
index 0e97907..3baffe8 100644 (file)
@@ -16,7 +16,7 @@
 #include "scanf_functions.h"
 #include "Scierror.h"
 #include "localization.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "freeArrayOfString.h"
 #include "PATH_MAX.h"
 #include "charEncoding.h"
@@ -79,11 +79,7 @@ int sci_fscanfMat(char *fname,unsigned long fname_len)
 
        /* BUG 3714 */
        shortcut_path = cstk(l1);
-
-       lout          = PATH_MAX + FILENAME_MAX;
-       real_path     = (char*)MALLOC(sizeof(char*)*lout);
-       
-       C2F(cluni0)( shortcut_path, real_path, &out_n, (long)strlen(shortcut_path), lout);
+       real_path     = expandPathVariable(shortcut_path);
 
        #if _MSC_VER
        #define MODEFD "rt"
@@ -91,7 +87,12 @@ int sci_fscanfMat(char *fname,unsigned long fname_len)
        #define MODEFD "r"
        #endif
 
-       wcfopen(f , real_path, MODEFD);
+       if (real_path)
+       {
+               wcfopen(f , real_path, MODEFD);
+               FREE(real_path);
+               real_path = NULL;
+       }
 
        if ( f  == (FILE *)0)
        {
index a101e54..e3f1b13 100644 (file)
@@ -22,7 +22,7 @@
 #include "isdir.h"
 #include "stack-c.h"
 #include "MALLOC.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "Scierror.h"
 #include "localization.h"
 #include "PATH_MAX.h"
@@ -45,9 +45,7 @@ int sci_isdir(char *fname,unsigned long fname_len)
        else
        {
                char *path = NULL, *myPath = NULL;
-               char filename[FILENAME_MAX];
-               long int lout;
-               int out_n;
+               char *filename = NULL;
                BOOL result = FALSE;
 
                GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
@@ -82,21 +80,25 @@ int sci_isdir(char *fname,unsigned long fname_len)
                }
                /* End of the crappy workaround */
 
-               lout = PATH_MAX + FILENAME_MAX;
                if(myPath == NULL)
                {
                        /* Replaces SCI, ~, HOME by the real path */
-                       C2F(cluni0)(path, filename, &out_n,m1*n1,lout);
+                       filename = expandPathVariable(path);
                }
                else
                {
                        /* Replaces SCI, ~, HOME by the real path */
-                       C2F(cluni0)(myPath, filename, &out_n,m1*n1,lout);
+                       filename = expandPathVariable(myPath);
                        FREE(myPath);
                        myPath = NULL;
                }
 
-               result = isdir(filename);
+               if (filename)
+               {
+                       result = isdir(filename);
+                       FREE(filename);
+                       filename = NULL;
+               }
                m1 = 1;
                n1 = 1;
                CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &m1, &n1 ,&l1); /* Create the space in the stack for result */
index 5953381..908813c 100644 (file)
@@ -19,7 +19,7 @@
 #include "localization.h"
 #include "Scierror.h"
 #include "PATH_MAX.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "mopen.h"
 #include "Scierror.h"
 #include "localization.h"
@@ -29,12 +29,10 @@ int sci_mopen(char *fname,unsigned long fname_len)
        int m1 = 0, n1 = 0, l1 = 0;
        int m2 = 0, n2 = 0, l2 = 0;
        int m3 = 0, n3 = 0, l3 = 0;
-       int l4 = 0, l5 = 0, err = 0;
+       int l4 = 0, l5 = 0, err = 3;
        int swap = 1, one = 1;
        char *status = NULL;
-       char filename[PATH_MAX + FILENAME_MAX];
-       int out_n = 0;
-       long int lout = 0;
+       char *filename = NULL;
 
        Nbvars = 0;
        CheckRhs(1,3);
@@ -90,10 +88,13 @@ int sci_mopen(char *fname,unsigned long fname_len)
        CreateVar(Rhs+1, MATRIX_OF_INTEGER_DATATYPE, &one,&one, &l4);
        CreateVar(Rhs+2, MATRIX_OF_DOUBLE_DATATYPE, &one,&one, &l5);
 
-       lout = PATH_MAX + FILENAME_MAX;
-       C2F(cluni0)(cstk(l1), filename, &out_n,m1*n1,lout);
-
-       C2F(mopen)(istk(l4),filename,status,&swap,stk(l5),&err);
+       filename = expandPathVariable(cstk(l1));
+       if (filename)
+       {
+               C2F(mopen)(istk(l4),filename,status,&swap,stk(l5),&err);
+               FREE(filename);
+               filename = NULL;
+       }
 
        if (err >  0)
        {
index 813087f..fcec39b 100644 (file)
@@ -19,7 +19,7 @@
 #include "MALLOC.h"
 #include "sciprint.h"
 #include "stack-c.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "Scierror.h"
 #include "localization.h"
 #include "freeArrayOfString.h"
@@ -156,14 +156,11 @@ static int GetIndexLastModifiedFileInList(char **ListFilename,int numberelemnts)
        for (i = 0; i<numberelemnts ;i++)
        {
 
-               int resultstat=0;
-               char *FileName=NULL;
-               int out_n;
-               long int lin=(long int)strlen(ListFilename[i]);
-               long int lout=(long int)strlen(ListFilename[i])+PATH_MAX;
+               int resultstat = 0;
+               char *FileName = NULL;
+
+               FileName = expandPathVariable(ListFilename[i]);
 
-               FileName=(char*)MALLOC(sizeof(char)*(lout+1));
-               C2F(cluni0)(ListFilename[i], FileName, &out_n,lin,lout);
 #ifdef _MSC_VER
                if (FileName)
                {
@@ -192,7 +189,7 @@ static int GetIndexLastModifiedFileInList(char **ListFilename,int numberelemnts)
                }
 
                FREE(FileName);
-               FileName=NULL;
+               FileName = NULL;
        }
 
        RetVal=RetIndex;
index 9060f35..a69c1bf 100644 (file)
@@ -18,7 +18,7 @@
 #include "removedir.h"
 #include "isdir.h"
 #include "Scierror.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "localization.h"
 #include "PATH_MAX.h"
 /*--------------------------------------------------------------------------*/
@@ -31,18 +31,22 @@ int sci_removedir(char *fname,unsigned long l)
        {
                BOOL bOK = FALSE;
                int m1 = 0, n1 = 0, l1 = 0;
-               char expandedpath[PATH_MAX+1];
-               int out_n = 0;
+               char *expandedpath = NULL;
                char *VarName = NULL;
 
                GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
                VarName = cstk(l1);
 
-               C2F(cluni0)(VarName,expandedpath, &out_n,(int)strlen(VarName),PATH_MAX);
-
-               if ( isdir(expandedpath) )
+               expandedpath = expandPathVariable(VarName);
+               if (expandedpath)
                {
-                       bOK = removedir(expandedpath);
+                       if ( isdir(expandedpath) )
+                       {
+                               bOK = removedir(expandedpath);
+                       }
+
+                       FREE(expandedpath);
+                       expandedpath = NULL;
                }
 
                m1 = 1; n1 = 1;
index 0c4c18d..3dac1fa 100644 (file)
@@ -2,6 +2,7 @@
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) INRIA
 * Copyright (C) ENPC
+* Copyright (C) DIGITEO - 2009 - Allan CORNET
 * 
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 *
 */
-#include <stdio.h>
-#include <string.h>
-
-#include "PATH_MAX.h"
-#include "core_math.h"
-#include "Os_specific.h"
-#include "../../../io/includes/setenvc.h"
+/*--------------------------------------------------------------------------*/ 
 #include "cluni0.h"
-#include "GetenvB.h"
-
-
-static char *SCI_a[]  = {  "SCI/"   , "sci/"   , "$SCI"   , "SCI\\"    , "sci\\"   , (char *) 0 };
-static char *HOME_a[] = {  "HOME/"  , "home/"  , "~/"     , "HOME\\"   , "home\\"  , "~\\" , "$HOME" , (char *) 0};
-static char *TMP_a[]  = {  "TMPDIR/", "tmpdir/","TMPDIR\\", "tmpdir\\" , "$TMPDIR" , (char *) 0};
-
-static int Cluni0(char *env,char **alias,char* in_name,char *out_name, long int lin);
-
-static int n=0;
-
-/************************************************
-* expand  in_name to produce out_name
-************************************************/
-
+#include "expandPathVariable.h"
+#include "MALLOC.h"
+/*--------------------------------------------------------------------------*/ 
 int C2F(cluni0)(char *in_name, char *out_name, int *out_n, long int lin, long int lout)
 {
-       int nc= PATH_MAX;
-       static char SCI[PATH_MAX],HOME[PATH_MAX],TMP[PATH_MAX];
-       static int k;
-       char *in_nameL = NULL;
-       long int linL;
-       char in_nameTmp[PATH_MAX];
-       strncpy(in_nameTmp,in_name,lin);
-       in_nameTmp[lin]='\0';
-       /* To convert to UTF-8 */
-       in_nameL = in_nameTmp;
-       /* Get the new size of the converted string */
-       linL=(long)strlen(in_nameL);
-       /* Copy it back into the in_nameTmp variable */
-       strncpy(in_nameTmp,in_nameL,linL);
-       in_nameL=in_nameTmp;
-       if ( ( n==0 ) || (getUpdateEnvVar() == 1) )
-       {
-               GetenvB("SCI"   , SCI ,nc);
-               GetenvB("HOME"  , HOME,nc);
-               GetenvB("TMPDIR", TMP ,nc);
-               n=n+1;
-               setUpdateEnvVar(0);
-       }
+       char *expandedVar = NULL;
+       in_name[lin] = 0;
 
-       /* in_name[lin]='\0';*/
-       if ( Cluni0(SCI,SCI_a,in_nameL,out_name,linL) == 0 )
-               if ( Cluni0(HOME,HOME_a,in_nameL,out_name,linL) == 0 )
-                       if ( Cluni0(TMP,TMP_a,in_nameL,out_name,linL) == 0 )
-                       {
-                               strncpy(out_name,in_nameL,(size_t)linL);
-                               out_name[linL]='\0';
-                       }
-
-                       *out_n = (int)strlen(out_name);
-#ifdef _MSC_VER
-                       for (k=0 ; k < *out_n ;k++) if ( out_name[k]=='/') out_name[k]='\\';
-#else
-                       for (k=0 ; k < *out_n ;k++) if ( out_name[k]=='\\') out_name[k]='/';
-#endif
-
-                       return(0);
-}
-
-/**
-* expand in_name to produce out_name
-*     try to find alias[i] at the begining of in_name
-*     and replaces it by env in out_name
-*     out_name must be large enough to get the result
-*
-* @param env
-* @param alias
-* @param in_name
-* @param out_name
-* @param lin
-* @return <ReturnValue>
-*/
-
-static int Cluni0(char *env, char **alias, char *in_name, char *out_name, long int lin)
-{
-       int i=0;
-       if ( env[0] == '\0' ) return(0);
-       while ( alias[i] != (char *) 0)
+       expandedVar = expandPathVariable(in_name);
+       if (expandedVar)
        {
-               if ( strncmp(alias[i],in_name,strlen(alias[i])) == 0)
-               {
-                       strcpy(out_name,env);
-                       strncat(out_name,in_name+strlen(alias[i])-1,
-                               (size_t)(lin-strlen(alias[i]+1)));
-                       /*sprintf(out_name,"%s/%s",env,in_name+strlen(alias[i]));*/
-                       return(1);
-               }
-               i++;
+               strcpy(out_name, expandedVar);
+               FREE(expandedVar);
+               expandedVar = NULL;
+               *out_n = (int) strlen(out_name);
        }
-       return(0);
+
+       return 0;
 }
+/*--------------------------------------------------------------------------*/ 
index 2262149..04d5495 100644 (file)
@@ -18,7 +18,7 @@
 #include "charEncoding.h"
 #include "MALLOC.h"
 #include "returnanan.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 /*--------------------------------------------------------------------------*/
 #define FILEINFO_ARRAY_SIZE 13
 
@@ -46,7 +46,7 @@ static double *fileinfo_Others(char *filepathname,int *ierr);
 /*--------------------------------------------------------------------------*/
 double * fileinfo(char *filename, int *ierr)
 {
-       char expandedpath[PATH_MAX + FILENAME_MAX + 1];
+       char *expandedpath = NULL;
        double *FILEINFO_ARRAY = NULL;
        int out_n = 0;
 
@@ -56,14 +56,18 @@ double * fileinfo(char *filename, int *ierr)
                return NULL;
        }
 
-       C2F(cluni0)(filename ,expandedpath, &out_n,(int)strlen(filename),PATH_MAX + FILENAME_MAX + 1);
-
-
+       expandedpath = expandPathVariable(filename);
+       if (expandedpath)
+       {
 #ifdef _MSC_VER
-       FILEINFO_ARRAY = fileinfo_Windows(expandedpath,ierr);
+               FILEINFO_ARRAY = fileinfo_Windows(expandedpath,ierr);
 #else
-       FILEINFO_ARRAY = fileinfo_Others(expandedpath,ierr);
+               FILEINFO_ARRAY = fileinfo_Others(expandedpath,ierr);
 #endif
+               FREE(expandedpath);
+               expandedpath = NULL;
+       }
+
        return FILEINFO_ARRAY;
 }
 /*--------------------------------------------------------------------------*/
index 3a9e9bd..c17ff02 100644 (file)
@@ -40,7 +40,7 @@ void splitpathW(const wchar_t* path, wchar_t* drv, wchar_t* dir, wchar_t* name,
                wcscpy(duplicate_path, path);
                begin_duplicate_path = duplicate_path;
                
-               for(i = 0; i < wcslen(duplicate_path); i++)
+               for(i = 0; i < (int)wcslen(duplicate_path); i++)
                {
 #ifdef _MSC_VER
                        if (duplicate_path[i] == L'/') duplicate_path[i] = L'\\';
index 3fdbbb9..cede1cb 100644 (file)
@@ -18,7 +18,7 @@
 #include "stackinfo.h"
 #include "MALLOC.h"
 #include "cvstr.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #ifdef _MSC_VER
 #include "strdup_windows.h"
 #endif
@@ -57,40 +57,42 @@ char **getlistmacrosfromlibrary(char *libraryname,int *sizearray)
        {
                /* in each library directory , we have a "names" file with list of macros */
                #define filenameNAMES "names"
-               char expandedpath[PATH_MAX+1];
-               char *fullfilename = NULL;
-               int out_n = 0;
+               char *expandedpath = expandPathVariable(pathlibrary);
 
-               C2F(cluni0)(pathlibrary,expandedpath, &out_n,(long)strlen(pathlibrary),PATH_MAX);
-
-               fullfilename = (char*)MALLOC(sizeof(char)*(strlen(expandedpath)+strlen(filenameNAMES)+1));
-               if (fullfilename)
+               if (expandedpath)
                {
-                       char  line[PATH_MAX+1];
-                       FILE * pFile = NULL;
-                       int nbElements = 0;
+                       char *fullfilename = (char*)MALLOC(sizeof(char)*(strlen(expandedpath)+strlen(filenameNAMES)+1));
+                       if (fullfilename)
+                       {
+                               char  line[PATH_MAX+1];
+                               FILE * pFile = NULL;
+                               int nbElements = 0;
 
-                       sprintf(fullfilename,"%s%s",expandedpath,filenameNAMES);
+                               sprintf(fullfilename,"%s%s",expandedpath,filenameNAMES);
 
-                       wcfopen (pFile,fullfilename,"rt");
-                       if (pFile)
-                       {
-                               while(fgets (line,sizeof(line),pFile) != NULL)
+                               wcfopen (pFile,fullfilename,"rt");
+                               if (pFile)
                                {
-                                       line[strlen(line)-1]='\0'; /* remove carriage return */
+                                       while(fgets (line,sizeof(line),pFile) != NULL)
+                                       {
+                                               line[strlen(line)-1]='\0'; /* remove carriage return */
                                        
-                                       if (macroslist) macroslist = (char**)REALLOC(macroslist,sizeof(char*)*(nbElements+1));
-                                       else macroslist =(char**)MALLOC(sizeof(char*)*(nbElements+1));
+                                               if (macroslist) macroslist = (char**)REALLOC(macroslist,sizeof(char*)*(nbElements+1));
+                                               else macroslist =(char**)MALLOC(sizeof(char*)*(nbElements+1));
 
-                                       macroslist[nbElements] = strdup(line);
-                                       nbElements++;
+                                               macroslist[nbElements] = strdup(line);
+                                               nbElements++;
+                                       }
+                                       fclose(pFile);
+                                       *sizearray = nbElements;
                                }
-                               fclose(pFile);
-                               *sizearray = nbElements;
+                               FREE(fullfilename);
+                               fullfilename = NULL;
                        }
-                       FREE(fullfilename);
-                       fullfilename = NULL;
+                       FREE(expandedpath);
+                       expandedpath = NULL;
                }
+
                FREE(pathlibrary);
                pathlibrary = NULL;
        }
index 593badb..007773f 100644 (file)
@@ -25,7 +25,7 @@
 #include "localization.h"
 #include "SetJavaProperty.h"
 #include "Scierror.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "PATH_MAX.h"
 #include "MALLOC.h"
 #include "freeArrayOfString.h"
@@ -129,9 +129,7 @@ int xs2file(char * fname, ExportFileType fileType )
                        }
 
                        /* Replaces SCI, ~, HOME, TMPDIR by the real path */
-                       lout = PATH_MAX + FILENAME_MAX;
-                       real_filename = (char*)MALLOC(sizeof(char)*lout);
-                       C2F(cluni0)(fileName[0], real_filename, &out_n, (long)strlen(fileName[0]), lout);
+                       real_filename = expandPathVariable(fileName[0]);
 
                        /* Call the function for exporting file */
                        status = exportToFile(getFigureFromIndex(figurenum), real_filename, fileType, orientation);
index 8f89351..a028e3c 100644 (file)
@@ -22,7 +22,7 @@ extern "C"
 #include "MALLOC.h"
 #include "localization.h"
 #include "Scierror.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "freeArrayOfString.h"
 }
 
@@ -44,12 +44,6 @@ int sci_uigetdir(char *fname,unsigned long l)
   CheckRhs(0,2);
   CheckLhs(1,1);
 
-  if ((expandedpath = (char*)MALLOC(sizeof(char*)*(PATH_MAX + FILENAME_MAX + 1))) == NULL)
-    {
-      Scierror(999, _("%s: No more memory.\n"),fname);
-      return FALSE;
-    }
-
   if (Rhs >= 1)
     {
       /* First argument is initial directory */
@@ -64,14 +58,12 @@ int sci_uigetdir(char *fname,unsigned long l)
             }
           initialDirectory = cstk(initialDirectoryAdr);
 
-          int out_n = 0;
-          C2F(cluni0)(initialDirectory ,expandedpath, &out_n,(int)strlen(initialDirectory),PATH_MAX + FILENAME_MAX);
-
+                 expandedpath = expandPathVariable(initialDirectory);
        }
       else
         {
           Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
-          FREE(expandedpath);
+                 if (expandedpath) {FREE(expandedpath); expandedpath = NULL;}
           return FALSE;
         }
 
@@ -86,7 +78,7 @@ int sci_uigetdir(char *fname,unsigned long l)
            if (nbCol !=1)
              {
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
-               FREE(expandedpath);
+               if (expandedpath) {FREE(expandedpath); expandedpath = NULL;}
                return FALSE;
              }
            title = cstk(titleAdr);
@@ -94,7 +86,7 @@ int sci_uigetdir(char *fname,unsigned long l)
        else
          {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
-           FREE(expandedpath);
+           if (expandedpath) {FREE(expandedpath); expandedpath = NULL;}
            return FALSE;
          }
      }
@@ -140,7 +132,7 @@ int sci_uigetdir(char *fname,unsigned long l)
   LhsVar(1)=Rhs+1;
   PutLhsVar();
 
-  FREE(expandedpath);
+  if (expandedpath) {FREE(expandedpath); expandedpath = NULL;}
   
   return TRUE;
 }
index 283e0a7..2a83d36 100644 (file)
@@ -28,7 +28,7 @@ extern "C"
 #include "MALLOC.h"
 #include "localization.h"
 #include "Scierror.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "freeArrayOfString.h"
 #ifdef _MSC_VER
 #include "strdup_windows.h"
@@ -117,7 +117,7 @@ int sci_uigetfile(char *fname, unsigned long fname_len)
        if (Rhs >= 2)
        {
                int out_n = 0;
-               char path[PATH_MAX + FILENAME_MAX];
+               char *path = NULL;
 
                if (VarType(2) != sci_strings) 
                { 
@@ -135,9 +135,9 @@ int sci_uigetfile(char *fname, unsigned long fname_len)
                        return 0;
                }
 
-               C2F(cluni0)(initialDirectory[0],path,&out_n,(long)strlen(initialDirectory[0]),PATH_MAX + FILENAME_MAX);
+               path = expandPathVariable(initialDirectory[0]);
                FREE(initialDirectory[0]);
-               initialDirectory[0] = strdup(path);
+               initialDirectory[0] = path;
        }
 
        /* call uigetfile with 3 arg */
index 8a5bc65..414c77a 100644 (file)
@@ -26,7 +26,7 @@ extern "C"
 #include "MALLOC.h"
 #include "localization.h"
 #include "Scierror.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "freeArrayOfString.h"
 #ifdef _MSC_VER
 #include "strdup_windows.h"
@@ -115,7 +115,7 @@ int sci_uiputfile(char *fname, unsigned long fname_len)
        if (Rhs >= 2)
        {
                int out_n = 0;
-               char path[PATH_MAX + FILENAME_MAX];
+               char *path = NULL;
 
                if (VarType(2) != sci_strings) 
                { 
@@ -133,9 +133,9 @@ int sci_uiputfile(char *fname, unsigned long fname_len)
                        return 0;
                }
 
-               C2F(cluni0)(initialDirectory[0],path,&out_n,(long)strlen(initialDirectory[0]),PATH_MAX + FILENAME_MAX);
+               path = expandPathVariable(initialDirectory[0]);
                FREE(initialDirectory[0]);
-               initialDirectory[0] = strdup(path);
+               initialDirectory[0] = path;
        }
 
        /* call uiputfile with 3 arg */
index 20078c6..1d7fb5e 100644 (file)
@@ -18,7 +18,7 @@
 #include "stack-c.h"
 #include "HistoryManager.h"
 #include "MALLOC.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 /*--------------------------------------------------------------------------*/
 int sci_loadhistory(char *fname,unsigned long fname_len)
 {
@@ -37,18 +37,22 @@ int sci_loadhistory(char *fname,unsigned long fname_len)
        }
        else
        {
-               #define MAXBUF  1024
-               char line[MAXBUF];
-               int l1 = 0, m1 = 0, n1 = 0, out_n = 0;
+               char *line = NULL;
+               int l1 = 0, m1 = 0, n1 = 0;
                char *Path = NULL;
 
                GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-               Path=cstk(l1);
-               C2F(cluni0)(Path, line, &out_n,(long)strlen(Path),MAXBUF);
-               loadScilabHistoryFromFile(line);
+               Path = cstk(l1);
+               line = expandPathVariable(Path);
+               if (line)
+               {
+                       loadScilabHistoryFromFile(line);
+                       FREE(line);
+                       line = NULL;
+               }
        }
 
-       LhsVar(1)=0;
+       LhsVar(1) = 0;
        C2F(putlhsvar)();
        return 0;
 }
index 52b0ca1..fc7fccf 100644 (file)
@@ -15,7 +15,7 @@
 #include "stack-c.h"
 #include "HistoryManager.h"
 #include "MALLOC.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 /*--------------------------------------------------------------------------*/
 int sci_savehistory(char *fname,unsigned long fname_len)
 {
@@ -34,22 +34,25 @@ int sci_savehistory(char *fname,unsigned long fname_len)
        }
        else
        {
-               #define MAXBUF  1024
-               char  line[MAXBUF];
-               char *Path;
-               int l1, m1, n1, out_n;
+               char  *line = NULL;
+               char *Path = NULL;
+               int l1 = 0, m1 = 0, n1 = 0;
 
                if ( GetType(1) == sci_strings )
                {
                        GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-                       Path=cstk(l1);
+                       Path = cstk(l1);
 
-                       C2F(cluni0)(Path, line, &out_n,(long)strlen(Path),MAXBUF);
-                       writeScilabHistoryToFile(line);
+                       line = expandPathVariable(Path);
+                       if (line)
+                       {
+                               writeScilabHistoryToFile(line);
+                               FREE(line);
+                               line = NULL;
+                       }
                }
        }
-
-       LhsVar(1)=0;
+       LhsVar(1) = 0;
        C2F(putlhsvar)();
        return 0;
 }
index f8f54fe..57a6330 100644 (file)
@@ -22,7 +22,6 @@ extern "C"
 #include <stdlib.h>
 #include "sciprint.h"
 #include "PATH_MAX.h"
-#include "cluni0.h"
 #include "SCIHOME.h"
 #include "inffic.h"
 #include "getCommentDateSession.h"
index 7c21ede..69ed647 100644 (file)
@@ -22,7 +22,6 @@ extern "C"
        #include <string.h>
        #include <stdlib.h>
        #include "sciprint.h"
-       #include "cluni0.h"
        #include "SCIHOME.h"
        #include "inffic.h"
        #include "InitializeHistoryManager.h"
index d7b4ef3..4e25290 100644 (file)
@@ -19,7 +19,7 @@
 #include "gw_sound.h"
 #include "PATH_MAX.h"
 #include "stack-c.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "Scierror.h"
 #include "localization.h"
 #include "charEncoding.h"
@@ -31,11 +31,9 @@ static int playsound(char *filename,char *command);
 /*--------------------------------------------------------------------------*/
 int sci_Playsound (char *fname,unsigned long fname_len)
 {
-       char filename[PATH_MAX];
-       int out_n;
-       long int lout;
-       char *command=NULL;
-       int m1,n1,l1,un=1,rep,m2,n2,l2;
+       char *filename = NULL;
+       char *command = NULL;
+       int m1,n1,l1,un=1,rep = -1 ,m2,n2,l2;
        CheckRhs(1,2);
        CheckLhs(0,1);
        /*  checking variable file */
@@ -45,11 +43,15 @@ int sci_Playsound (char *fname,unsigned long fname_len)
                GetRhsVar(2,STRING_DATATYPE,&m2,&n2,&l2);
                command = cstk(l2);
        }
-       /*** first call to get the size **/
-       lout = PATH_MAX + FILENAME_MAX;
-       C2F(cluni0)(cstk(l1), filename, &out_n,m1*n1,lout);
 
-       rep = playsound(filename,command);
+       filename = expandPathVariable(filename);
+       if (filename)
+       {
+               rep = playsound(filename,command);
+               FREE(filename);
+               filename = NULL;
+       }
+
 
        if ( Lhs == 1 )
        {
index 179279e..6f2efc2 100644 (file)
@@ -21,7 +21,7 @@
 #include "xls.h"
 #include "ole.h"
 #include "ripole.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "MALLOC.h"
 #include "../../../fileio/includes/mopen.h"
 #include "Scierror.h"
@@ -44,7 +44,9 @@ int sci_xls_open(char *fname,unsigned long fname_len)
        char **Sheetnames = NULL;
        int *Abspos = NULL;
        int nsheets = 0;
-       char IN[max_char_xls_open],TMP[max_char_xls_open];
+       char *filename_IN = NULL;
+       char TMP[max_char_xls_open];
+
        char sep[2];
        char *TMPDIR = NULL;
 #ifdef _MSC_VER
@@ -65,20 +67,21 @@ int sci_xls_open(char *fname,unsigned long fname_len)
 
        /*  checking variable file */
        GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-       C2F(cluni0)(cstk(l1), IN, &ns,(long int) (m1*n1),256L);
+
+       filename_IN = expandPathVariable(cstk(l1));
 
        TMPDIR = getTMPDIR();
-       strcpy(TMP,TMPDIR);
+       strcpy(TMP, TMPDIR);
        if (TMPDIR){FREE(TMPDIR);TMPDIR=NULL;}
 
        strcat(TMP,sep);
-       strcat(TMP,xls_basename(IN));
-       result=ripole(IN, TMP, 0, 0);
+       strcat(TMP,xls_basename(filename_IN));
+       result = ripole(filename_IN, TMP, 0, 0);
        if (result != OLE_OK) 
        {
                if (result == OLEER_NO_INPUT_FILE) 
                {
-                       Scierror(999,_("The file %s does not exist.\n"),IN);
+                       Scierror(999,_("The file %s does not exist.\n"), filename_IN);
                }
                else if(result == OLEER_NOT_OLE_FILE || 
                        result == OLEER_INSANE_OLE_FILE || 
@@ -86,11 +89,13 @@ int sci_xls_open(char *fname,unsigned long fname_len)
                        result == OLEER_MINIFAT_READ_FAIL || 
                        result == OLEER_PROPERTIES_READ_FAIL)
                {
-                       Scierror(999,_("%s: File %s is not an ole2 file.\n"),fname,IN);
+                       Scierror(999,_("%s: File %s is not an ole2 file.\n"),fname, filename_IN);
+                       if (filename_IN) {FREE(filename_IN); filename_IN = NULL;}
                }
                else if(result == -1)
                {
-                       Scierror(999,_("%s: Cannot open file %s.\n"),fname,IN);
+                       Scierror(999,_("%s: Cannot open file %s.\n"),fname, filename_IN);
+                       if (filename_IN) {FREE(filename_IN); filename_IN = NULL;}
                }
                return 0;
        }
@@ -99,9 +104,13 @@ int sci_xls_open(char *fname,unsigned long fname_len)
        C2F(mopen)(&fd, TMP,"rb", &f_swap, &res, &ierr);
        if (ierr != 0)
        {
-               Scierror(999,_("%s: There is no xls stream in the ole2 file %s.\n"),fname,IN);
+               Scierror(999,_("%s: There is no xls stream in the ole2 file %s.\n"),fname, filename_IN);
+               if (filename_IN) {FREE(filename_IN); filename_IN = NULL;}
                return 0;
        }
+
+       if (filename_IN) {FREE(filename_IN); filename_IN = NULL;}
+
        CreateVar(Rhs+1,MATRIX_OF_INTEGER_DATATYPE,&one,&one,&l2);
        *istk(l2)=fd; /* logical unit */
 
index aa2015b..79d084d 100644 (file)
@@ -14,7 +14,7 @@
 #include <stdio.h>
 #include <Windows.h>
 #include "winopen.h"
-#include "cluni0.h"
+#include "expandPathVariable.h"
 #include "Scierror.h"
 #include "PATH_MAX.h"
 #include "charEncoding.h"
 BOOL winopen(char *scilabfilename)
 {
        BOOL bOK = FALSE;
-       char filename[PATH_MAX + FILENAME_MAX];
+       char *filename = NULL;
        wchar_t *wcfilename = NULL;
        int out_n = 0;
        long int lout = 0;
        HINSTANCE error = NULL;
 
-       lout = PATH_MAX + FILENAME_MAX;
-       C2F(cluni0)(scilabfilename, filename, &out_n,(int)strlen(scilabfilename),lout);
-       wcfilename = to_wide_string(filename);
-       if (wcfilename)
+       filename = expandPathVariable(scilabfilename);
+       if (filename)
        {
-               error = ShellExecuteW(NULL, L"open", wcfilename, NULL, NULL, SW_SHOWNORMAL);
-               if ( error <= (HINSTANCE)32) bOK = FALSE;
-               else bOK = TRUE;
-       }
-       else
-       {
-               return FALSE;
+               wcfilename = to_wide_string(filename);
+               FREE(filename); filename = NULL;
+               if (wcfilename)
+               {
+                       error = ShellExecuteW(NULL, L"open", wcfilename, NULL, NULL, SW_SHOWNORMAL);
+                       if ( error <= (HINSTANCE)32) bOK = FALSE;
+                       else bOK = TRUE;
+               }
        }
        return bOK;
 }