warnings visual + intel (all warnings mode) completion module
[scilab.git] / scilab / modules / completion / sci_gateway / c / sci_completion.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2007 - INRIA - Allan CORNET
4  *
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12 #include "gw_completion.h"
13 #include "MALLOC.h"
14 #include "stack-c.h"
15 #include "localization.h"
16 #include "completion.h"
17 #include "Scierror.h"
18 #include "toolsdictionary.h"
19 #include "freeArrayOfString.h"
20 /*--------------------------------------------------------------------------*/
21 static int returnEmptyMatrix(int pos);
22 static int putResultOnStack(int pos,char **result,int sizeresult);
23 /*--------------------------------------------------------------------------*/
24 int sci_completion(char *fname,unsigned long fname_len)
25 {
26         int m1 = 0, n1 = 0;
27         char *partOfWord = NULL;
28         char ** Inputs1 = NULL;
29
30         CheckRhs(1,2);
31         CheckLhs(1,6);
32
33         if (GetType(1) == sci_strings)
34         {
35                 GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&m1,&n1,&Inputs1);
36                 if ( (m1 == n1) && (n1 == 1) )
37                 {
38                         partOfWord = Inputs1[0];
39                 }
40                 else
41                 {
42                         freeArrayOfString(Inputs1,m1 * n1);
43                         Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,1);
44                         return 0;
45                 }
46         }
47         else
48         {
49                 Scierror(999,_("%s: Wrong type for input argument #%d: String expected.\n"), fname,1);
50                 return 0;
51         }
52
53         if (Lhs == 1)
54         {
55                 if (Rhs == 1)
56                 {
57                         char **Results = NULL;
58                         int sizeResults = 0;
59
60                         Results = completion(partOfWord, &sizeResults);
61                         putResultOnStack(1,Results,sizeResults);
62                         freePointerDictionary(Results,sizeResults);
63                         PutLhsVar();
64                 }
65                 else /* Rhs == 2 */
66                 {
67                         if (GetType(2) == sci_strings)
68                         {
69                                 char **Inputs2 = NULL;
70                                 char *param2 = NULL;
71                                 char **Results = NULL;
72                                 int sizeResults = 0, m2 = 0, n2 = 0;
73
74                                 GetRhsVar(2,MATRIX_OF_STRING_DATATYPE,&m2,&n2,&Inputs2);
75                                 if ( (m2 == n2) && (n2 == 1) )
76                                 {
77                                         param2 = Inputs2[0];
78                                 }
79                                 else
80                                 {
81                                         freeArrayOfString(Inputs1,m1 * n1);
82                                         freeArrayOfString(Inputs2,m2 * n2);
83                                         Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,1);
84                                         return 0;
85                                 }
86
87                                 if ( strcmp(param2,"functions") == 0 )
88                                 {
89                                         Results = completionOnFunctions(partOfWord, &sizeResults);
90                                 }
91                                 else if ( strcmp(param2,"commands") == 0 )
92                                 {
93                                         Results = completionOnCommandWords(partOfWord, &sizeResults);
94                                 }
95                                 else if ( strcmp(param2,"variables") == 0 )
96                                 {
97                                         Results = completionOnVariablesWithoutMacros(partOfWord, &sizeResults);
98                                 }
99                                 else if( strcmp(param2,"macros") == 0 )
100                                 {
101                                         Results = completionOnMacros(partOfWord, &sizeResults);
102                                 }
103                                 else if( strcmp(param2,"graphic_properties") == 0 )
104                                 {
105                                         Results = completionOnHandleGraphicsProperties(partOfWord, &sizeResults);
106                                 }
107                                 else if( strcmp(param2,"files") == 0 )
108                                 {
109                                         Results = completionOnFiles(partOfWord, &sizeResults);
110                                 }
111                                 else
112                                 {
113                                         freeArrayOfString(Inputs1,m1 * n1);
114                                         freeArrayOfString(Inputs2,m2 * n2);
115                                         Scierror(999,_("%s: Wrong value for input argument: '%s', '%s', '%s', '%s', '%s' or '%s' expected.\n"),fname,"functions","commands","variables","macros","graphic_properties","files");
116                                         return 0;
117                                 }
118                                 putResultOnStack(1,Results,sizeResults);
119                                 freePointerDictionary(Results,sizeResults);
120                 freeArrayOfString(Inputs1,m1 * n1);
121                 Inputs1 = NULL;
122
123                                 freeArrayOfString(Inputs2,m2 * n2);
124                 Inputs2 = NULL;
125                                 PutLhsVar();
126
127                         }
128                         else
129                         {
130                                 freeArrayOfString(Inputs1,m1 * n1);
131                                 Scierror(999,_("%s: Wrong type for input argument #%d: String expected.\n"),fname,2);
132                                 return 0;
133                         }
134                 }
135         }
136         else
137         {
138                 char **FunctionsList = NULL;
139                 int sizeFunctionsList = 0;
140
141                 if (Rhs == 2)
142                 {
143                         freeArrayOfString(Inputs1,m1 * n1);
144                         Scierror(999,_("%s: Wrong number of output argument(s).\n"),fname);
145                         return 0;
146                 }
147
148                 FunctionsList = completionOnFunctions(partOfWord, &sizeFunctionsList);
149                 putResultOnStack(1,FunctionsList,sizeFunctionsList);
150                 freePointerDictionary(FunctionsList,sizeFunctionsList);
151
152                 if (Lhs > 1)
153                 {
154                         char **CommandsList = NULL;
155                         int sizeCommandsList = 0;
156
157                         CommandsList = completionOnCommandWords(partOfWord, &sizeCommandsList);
158                         putResultOnStack(2,CommandsList,sizeCommandsList);
159
160                         freePointerDictionary(CommandsList,sizeCommandsList);
161                 }
162
163                 if (Lhs > 2)
164                 {
165                         char **VariablesList = NULL;
166                         int sizeVariablesList = 0;
167
168                         VariablesList = completionOnVariablesWithoutMacros(partOfWord, &sizeVariablesList);
169                         putResultOnStack(3,VariablesList,sizeVariablesList);
170
171                         freePointerDictionary(VariablesList,sizeVariablesList);
172                 }
173
174                 if (Lhs > 3)
175                 {
176                         char **MacrosList = NULL;
177                         int sizeMacrosList = 0;
178
179                         MacrosList = completionOnMacros(partOfWord, &sizeMacrosList);
180                         putResultOnStack(4,MacrosList,sizeMacrosList);
181
182                         freePointerDictionary(MacrosList,sizeMacrosList);
183                 }
184
185                 if (Lhs > 4)
186                 {
187                         char **HandleGraphicsPropertiesList = NULL;
188                         int sizeHandleGraphicsPropertiesList = 0;
189
190                         HandleGraphicsPropertiesList = completionOnHandleGraphicsProperties(partOfWord, &sizeHandleGraphicsPropertiesList);
191                         putResultOnStack(5,HandleGraphicsPropertiesList,sizeHandleGraphicsPropertiesList);
192
193                         freePointerDictionary(HandleGraphicsPropertiesList,sizeHandleGraphicsPropertiesList);
194                 }
195
196                 if (Lhs > 5)
197                 {
198                         char **PathsList = NULL;
199                         int sizePathsList = 0;
200
201                         PathsList = completionOnFiles(partOfWord, &sizePathsList);
202                         putResultOnStack(6,PathsList,sizePathsList);
203
204                         freePointerDictionary(PathsList,sizePathsList);
205                 }
206
207                 PutLhsVar();
208         }
209         if (Inputs1) freeArrayOfString(Inputs1,m1 * n1);
210         return 0;
211 }
212 /*--------------------------------------------------------------------------*/
213 static int returnEmptyMatrix(int pos)
214 {
215         int l1 = 0, m1 = 0, n1 = 0;
216         CreateVarFromPtr(Rhs+ pos,MATRIX_OF_DOUBLE_DATATYPE,&n1,&m1,&l1);
217         return 0;
218 }
219 /*--------------------------------------------------------------------------*/
220 static int putResultOnStack(int pos,char **result,int sizeresult)
221 {
222         if (result)
223         {
224                 int m1 = 0, n1 = 0;
225                 m1 = sizeresult;
226                 n1 = 1;
227                 CreateVarFromPtr(Rhs+pos,MATRIX_OF_STRING_DATATYPE, &m1, &n1, result);
228         }
229         else
230         {
231                 returnEmptyMatrix(pos);
232         }
233         LhsVar(pos) = Rhs+pos;
234         return 0;
235 }
236 /*--------------------------------------------------------------------------*/