add javalibrarypath function
[scilab.git] / scilab / modules / jvm / sci_gateway / c / sci_javalibrarypath.c
1 /*-----------------------------------------------------------------------------------*/\r
2 /**\r
3  * @author Allan CORNET INRIA 2007\r
4  */\r
5 /*-----------------------------------------------------------------------------------*/\r
6 #include "gw_jvm.h"\r
7 #include "MALLOC.h"\r
8 #include "machine.h"\r
9 #include "stack-c.h"\r
10 #include "sciprint.h"\r
11 #include "Scierror.h"\r
12 #include "addToLibrarypath.h"\r
13 #include "getLibrarypath.h"\r
14 /*-----------------------------------------------------------------------------------*/\r
15 int C2F(sci_javalibrarypath) _PARAMS((char *fname,unsigned long fname_len))\r
16 {\r
17         Rhs = Max(Rhs,0);\r
18         CheckRhs(0,1);\r
19         CheckLhs(0,1);\r
20 \r
21         if (Rhs == 0)\r
22         {\r
23                 int nbRow=0;\r
24                 int nbCol=1;\r
25                 int i=0;\r
26                 char **Strings=NULL;\r
27 \r
28                 Strings=getLibrarypath(&nbRow);\r
29                 CreateVarFromPtr( Rhs+1, "S", &nbRow, &nbCol,Strings ) ;\r
30 \r
31                 LhsVar(1)=Rhs+1;\r
32                 C2F(putlhsvar)();\r
33                 if (Strings)\r
34                 {\r
35                         for (i=0;i<nbRow;i++)\r
36                         {\r
37                                 if (Strings[i])\r
38                                 {\r
39                                         FREE(Strings[i]);\r
40                                         Strings[i]=NULL;\r
41                                 }\r
42                         }\r
43                         FREE(Strings);\r
44                         Strings=NULL;\r
45                 }\r
46 \r
47         }\r
48         else\r
49         {\r
50                 if ( GetType(1) == sci_strings )\r
51                 {\r
52                         static int n1=0,m1=0;\r
53                         int i=0;\r
54                         BOOL bOK=FALSE;\r
55                         char **LIBRARYPATHS=NULL;\r
56 \r
57                         GetRhsVar(1,"S",&m1,&n1,&LIBRARYPATHS);\r
58 \r
59                         for (i = 0; i<m1*n1 ;i++)\r
60                         {\r
61                                 bOK=addToLibrarypath(LIBRARYPATHS[i]);\r
62                                 if (!bOK)\r
63                                 {\r
64                                         Scierror(999,"could not add path to java.library.path : %s.\r\n",LIBRARYPATHS[i]);\r
65                                         return 0;\r
66                                 }\r
67                         }\r
68                         LhsVar(1) = 0;\r
69                         C2F(putlhsvar)();       \r
70                 }\r
71                 else\r
72                 {\r
73                         Scierror(999,"invalid parameter(s).\r\n");\r
74                 }\r
75         }\r
76         return 0;\r
77 }\r
78 /*-----------------------------------------------------------------------------------*/\r