bug 2848
Allan Cornet [Fri, 4 Apr 2008 12:44:45 +0000 (12:44 +0000)]
scilab/modules/completion/includes/completion.h
scilab/modules/completion/sci_gateway/c/sci_completion.c
scilab/modules/completion/src/c/completion.c
scilab/modules/completion/src/c/completion_wrap_java.c
scilab/modules/completion/src/c/getfilesdictionary.c
scilab/modules/completion/tests/nonreg_tests/bug_2848.dia.ref [new file with mode: 0644]
scilab/modules/completion/tests/nonreg_tests/bug_2848.tst

index 4391b9b..d7eb435 100644 (file)
@@ -54,6 +54,15 @@ char **completionOnMacros(char *somechars, int *sizeArrayReturned);
 char **completionOnVariables(char *somechars, int *sizeArrayReturned);
 
 /**
+* completion function on Variables for scilab
+* Macros already defined as variables are removed
+* @param[in] somechars first characters of a word
+* @param[out] sizeArrayReturned
+* @return a array of chars 
+*/
+char **completionOnVariablesWithoutMacros(char *somechars, int *sizeArrayReturned);
+
+/**
 * completion function on files for scilab
 * @param[in] somechars first characters of a word
 * @param[out] sizeArrayReturned
index f61200f..82e35e2 100644 (file)
@@ -73,7 +73,7 @@ int C2F(sci_completion) _PARAMS((char *fname,unsigned long fname_len))
                                }
                                else if ( strcmp(param2,"variables") == 0 )
                                {
-                                       Results = completionOnVariables(partOfWord, &sizeResults);
+                                       Results = completionOnVariablesWithoutMacros(partOfWord, &sizeResults);
                                }
                                else if( strcmp(param2,"macros") == 0 )
                                {
@@ -136,7 +136,7 @@ int C2F(sci_completion) _PARAMS((char *fname,unsigned long fname_len))
                        char **VariablesList = NULL;
                        int sizeVariablesList = 0;
 
-                       VariablesList = completionOnVariables(partOfWord, &sizeVariablesList);
+                       VariablesList = completionOnVariablesWithoutMacros(partOfWord, &sizeVariablesList);
                        putResultOnStack(3,VariablesList,sizeVariablesList);
 
                        freePointerDictionary(VariablesList,sizeVariablesList);
index ce1721c..ffef183 100644 (file)
@@ -167,6 +167,122 @@ char **completionOnVariables(char *somechars, int *sizeArrayReturned)
        return ListWords;
 }
 /*--------------------------------------------------------------------------*/
+char **completionOnVariablesWithoutMacros(char *somechars, int *sizeArrayReturned)
+{
+       int i = 0;
+       int j = 0;
+       int nbWordsAlreadyInMacros = 0;
+
+       char **ListWords = NULL;
+       int sizeListWords = 0;
+
+       char **dictionaryVariables = NULL;
+       int sizedictionaryVariables = 0;
+       
+
+       dictionaryVariables = completionOnVariables(somechars,&sizedictionaryVariables);
+
+       if (sizedictionaryVariables)
+       {
+               char **dictionaryMacros = NULL;
+               int sizedictionaryMacros = 0;
+
+               dictionaryMacros = getmacrosdictionary(&sizedictionaryMacros);
+               dictionaryMacros = SortDictionary(dictionaryMacros,sizedictionaryMacros);       
+       
+               /* Search if we have more than one definition */
+               for ( i = 0; i < sizedictionaryVariables; i++)
+               {
+                       for ( j = 0; j < sizedictionaryMacros; j++)
+                       {
+                               if ( strcmp(dictionaryVariables[i],dictionaryMacros[j]) == 0 )
+                               {
+                                       nbWordsAlreadyInMacros++;
+                               }
+                       }
+               }
+
+               if (nbWordsAlreadyInMacros)
+               {
+                       sizeListWords = sizedictionaryVariables - nbWordsAlreadyInMacros;
+                       if (sizeListWords)
+                       {
+                               char **ListWordsTmp = (char**)MALLOC(sizeof(char*)*sizedictionaryVariables);
+                               if (ListWordsTmp)
+                               {
+                                       int k = 0;
+
+                                       /* do a copy of dictionnary of Variables */
+                                       for ( i = 0; i < sizedictionaryVariables; i++)
+                                       {
+                                               ListWordsTmp[i] = (char*)MALLOC(sizeof(char)*(strlen(dictionaryVariables[i])+1));
+                                               if (ListWordsTmp[i]) strcpy(ListWordsTmp[i],dictionaryVariables[i]);
+                                       }
+
+                                       for ( i = 0; i < sizedictionaryVariables; i++)
+                                       {
+                                               for ( j = 0; j < sizedictionaryMacros; j++)
+                                               {
+                                                       if ( strcmp(dictionaryVariables[i],dictionaryMacros[j]) == 0 )
+                                                       {
+                                                               FREE(ListWordsTmp[i]);
+                                                               ListWordsTmp[i] = NULL;
+                                                       }
+                                               }
+                                       }
+
+                                       ListWords = (char**)MALLOC(sizeof(char*)*(sizeListWords+1));
+                                       if (ListWords)
+                                       {
+                                               for ( i = 0; i < sizedictionaryVariables; i++)
+                                               {
+                                                       if (ListWordsTmp[i])
+                                                       {
+                                                               ListWords[k] = (char*)MALLOC(sizeof(char)*(strlen(ListWordsTmp[i])+1));
+                                                               if (ListWords[k]) strcpy(ListWords[k],ListWordsTmp[i]);
+                                                               if (k <= sizeListWords) k++;
+                                                       }
+                                               }
+                                               /* Add a NULL element at the end (to get number of items from JNI) */
+                                               ListWords[sizeListWords] = NULL;
+
+                                               *sizeArrayReturned = sizeListWords;
+                                       }
+                                       else
+                                       {
+                                               ListWords = NULL;
+                                               *sizeArrayReturned = 0;
+                                       }
+                               }
+                               else
+                               {
+                                       ListWords = NULL;
+                                       *sizeArrayReturned = 0;
+                               }
+                       }
+                       else
+                       {
+                               ListWords = NULL;
+                               *sizeArrayReturned = 0;
+                       }
+               }
+               else
+               {
+                       ListWords = dictionaryVariables;
+                       *sizeArrayReturned = sizedictionaryVariables;
+               }
+
+               freePointerDictionary(dictionaryMacros,sizedictionaryMacros);
+       }
+       else
+       {
+               ListWords = NULL;
+               *sizeArrayReturned = 0;
+       }
+
+       return ListWords;
+}
+/*--------------------------------------------------------------------------*/
 char **completionOnFiles(char *somechars, int *sizeArrayReturned)
 {
        char **ListWords = NULL;
index 9c2fbbe..2cc9534 100644 (file)
@@ -39,7 +39,7 @@ char **searchMacrosDictionary(char *somechars)
 char **searchVariablesDictionary(char *somechars)
 {
        int nbrElements = 0;
-       return completionOnVariables(somechars,&nbrElements);
+       return completionOnVariablesWithoutMacros(somechars,&nbrElements);
 }
 /*--------------------------------------------------------------------------*/
 char **searchFilesDictionary(char *somechars)
index f50a49e..7beace5 100644 (file)
@@ -63,12 +63,12 @@ char **getfilesdictionary(char *somechars,int *sizearray)
                dictionary = findfiles(path,filespec,&sizeListReturned);
                *sizearray = sizeListReturned;
 
-                /* Add a NULL element at the end (to get number of items from JNI) */
-                if (dictionary != NULL)
-                  {
-                    dictionary = (char**)REALLOC(dictionary,sizeof(char*)*(sizeListReturned+1));
-                    dictionary[sizeListReturned] = NULL;
-                  }
+        /* Add a NULL element at the end (to get number of items from JNI) */
+        if (dictionary != NULL)
+        {
+                       dictionary = (char**)REALLOC(dictionary,sizeof(char*)*(sizeListReturned+1));
+                       dictionary[sizeListReturned] = NULL;
+               }
        }
        else
        {
diff --git a/scilab/modules/completion/tests/nonreg_tests/bug_2848.dia.ref b/scilab/modules/completion/tests/nonreg_tests/bug_2848.dia.ref
new file mode 100644 (file)
index 0000000..8d3d36b
--- /dev/null
@@ -0,0 +1,34 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - INRIA - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- Non-regression test for bug 2848 -->
+//
+// <-- Bugzilla URL -->
+// http://www.scilab.org/cgi-bin/bugzilla_bug_II/show_bug.cgi?id=2848
+//
+// <-- Short Description -->
+//    When using the TAB key for completion in the console, after using once a Scilab
+//    macro, its name appears twice in the completion list: as a macro and as a variable.
+with_atlas();
+[a,b,c,d]=completion('with');
+if c <> [] then bugmes();quit;end
+with_tk();
+[a,b,c,d]=completion('with');
+if c <> [] then bugmes();quit;end
+clear with_atlas
+clear with_tk
+[a,b,c,d]=completion('with');
+if c <> [] then bugmes();quit;end
+with_atlas();
+with_tk();
+deff('[x]=with_foo(y,z)','x=y+z');
+[a,b,c,d]=completion('with');
+if or(c <> 'with_foo') then bugmes();quit;end
+clear with_atlas
+clear with_tk
+clear with_foo
+[a,b,c,d]=completion('with');
+if c <> [] then bugmes();quit;end
index ece96e1..b0648ba 100644 (file)
 //    macro, its name appears twice in the completion list: as a macro and as a variable.\r
 \r
 \r
-with_atlas\r
-[a,b,c,d]=completion('with')\r
+with_atlas();\r
+[a,b,c,d]=completion('with');\r
 if c <> [] then pause,end\r
 \r
-with_tk\r
-[a,b,c,d]=completion('with')\r
+with_tk();\r
+[a,b,c,d]=completion('with');\r
 if c <> [] then pause,end\r
 \r
 clear with_atlas\r
 clear with_tk\r
-[a,b,c,d]=completion('with')\r
+[a,b,c,d]=completion('with');\r
 if c <> [] then pause,end\r
 \r
-with_atlas\r
-with_tk\r
-deff('[x]=with_foo(y,z)','x=y+z')\r
-[a,b,c,d]=completion('with')\r
-if c <> 'with_foo' then pause,end\r
+with_atlas();\r
+with_tk();\r
+deff('[x]=with_foo(y,z)','x=y+z');\r
+[a,b,c,d]=completion('with');\r
+if or(c <> 'with_foo') then pause,end\r
+\r
+clear with_atlas\r
+clear with_tk\r
+clear with_foo\r
+\r
+[a,b,c,d]=completion('with');\r
+if c <> [] then pause,end\r