request 564
Allan CORNET [Wed, 3 Dec 2008 09:44:15 +0000 (10:44 +0100)]
scilab/CHANGES_5.1
scilab/modules/completion/src/c/getfilesdictionary.c

index ac2a33c..c15fffa 100644 (file)
@@ -34,6 +34,8 @@ Enhancement:
 This function is providing the same features as dassl with ode (ordinary differential equations) profile.
 For more information, see SEP #2.
 
+* Request 564 : completion add '\' or '/' at the end of a directory
+
 Bug fixes:
 ==========
 
index 828b0b5..d52734e 100644 (file)
 #include "MALLOC.h"
 #include "cluni0.h"
 #include "machine.h"
+#include "isdir.h"
 /*--------------------------------------------------------------------------*/ 
 static void splitpath(char *composite,  char *path,  char *fname);
 static char **addPath(char **dictionary, int sizearray, char *path);
+static char **addDirSeparator(char **dictionary, int sizearray, char *path);
 /*--------------------------------------------------------------------------*/ 
 char **getfilesdictionary(char *somechars,int *sizearray,BOOL fullpath)
 {
@@ -78,7 +80,9 @@ char **getfilesdictionary(char *somechars,int *sizearray,BOOL fullpath)
                {
                        dictionary = addPath(dictionary, sizeListReturned, path);
                }
-               
+
+               dictionary = addDirSeparator(dictionary, sizeListReturned, path);
+
                *sizearray = sizeListReturned;
 
         /* Add a NULL element at the end (to get number of items from JNI) */
@@ -140,8 +144,35 @@ static char **addPath(char **dictionary, int sizearray, char *path)
                sprintf(newPath,"%s%s",path,dictionary[i]);
                FREE(dictionary[i]);
                dictionary[i] = newPath;
-               
        }
        return dictionary;
 }
-/*--------------------------------------------------------------------------*/
\ No newline at end of file
+/*--------------------------------------------------------------------------*/
+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 fullpath[PATH_MAX * 2];
+
+               C2F(cluni0)(path, pathextended, &out_n,( long)strlen(path), PATH_MAX);
+
+               strcpy(fullpath, pathextended);
+               strcat(fullpath, dictionary[i]);
+
+               if ( isdir(fullpath) && (dictionary[i][strlen(dictionary[i])-1] != DIR_SEPARATOR[0]) )
+               {
+                       char *newPath = NULL;
+                       int newlength = (int)(strlen(dictionary[i]) + strlen(DIR_SEPARATOR) + 1);
+                       newPath = (char *)MALLOC(sizeof(char)*(newlength));
+                       sprintf(newPath,"%s%s",dictionary[i],DIR_SEPARATOR);
+                       FREE(dictionary[i]);
+                       dictionary[i] = newPath;
+               }
+       }
+       return dictionary;
+}
+/*--------------------------------------------------------------------------*/