332d6a413819c521426eaa44474e1c44c533fa5d
[scilab.git] / scilab / modules / core / sci_gateway / c / sci_getvariablesonstack.c
1 /*--------------------------------------------------------------------------*/
2 /* INRIA 2006 */
3 /* Allan CORNET */
4 /*--------------------------------------------------------------------------*/
5 #include "machine.h"
6 #include "stack-c.h"
7 #include "gw_core.h"
8 #include "getvariablesname.h"
9 #include "MALLOC.h"
10 #include "Scierror.h"
11 #include "localization.h"
12 /*--------------------------------------------------------------------------*/
13 int C2F(sci_getvariablesonstack) _PARAMS((char *fname,unsigned long fname_len))
14 {
15         int l1,n1,m1;
16         char **Variables = NULL;
17         int sizeVariables = 0;
18
19         CheckRhs(0,1);
20         CheckLhs(0,1);
21
22         if (Rhs == 0)
23         {
24                 Variables = getVariablesName(&sizeVariables,TRUE);
25         }
26         else
27         {
28                 if (GetType(1) == sci_strings)
29                 {
30                         char *parameter = NULL;
31                         GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
32                         parameter = cstk(l1);
33
34                         if ( ( strcmp(parameter,"local") == 0 ) || ( strcmp(parameter,"global") == 0) )
35                         {
36                                 if (strcmp(parameter,"local") == 0)
37                                 {
38                                         Variables = getLocalVariablesName(&sizeVariables,TRUE);
39                                 }
40                                 else /* global */
41                                 {
42                                         Variables = getGlobalVariablesName(&sizeVariables,TRUE);
43                                 }
44                         }
45                         else
46                         {
47                                 Scierror(999,_("%s: Wrong first input argument: '%s' or '%s' expected.\n"),'global','locale');
48                                 return 0;
49                         }
50                 }
51                 else
52                 {
53                         Scierror(999,_("%s: Wrong type for input argument: String expected.\n"));
54                         return 0;
55                 }
56         }
57
58         m1 = sizeVariables;
59         n1 = 1;
60         CreateVarFromPtr(Rhs+1,MATRIX_OF_STRING_DATATYPE, &m1, &n1, Variables);
61
62         LhsVar(1) = Rhs + 1;
63         C2F(putlhsvar)();
64
65         if (Variables)
66         {
67                 int i = 0;
68                 for( i = 0; i < sizeVariables; i++)
69                 {
70                         if (Variables[i])
71                         {
72                                 FREE(Variables[i]);
73                                 Variables[i] = NULL;
74                         }
75                 }
76                 FREE(Variables);
77                 Variables = NULL;
78         }
79
80         return 0;
81 }
82 /*--------------------------------------------------------------------------*/