update for [a,b] = getversion()
[scilab.git] / scilab / modules / core / src / c / inisci-c.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) INRIA
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
13 #ifdef _MSC_VER
14 #include <windows.h>
15 #else
16 #include <sys/utsname.h>
17 #endif
18 #include <stdio.h>
19 #include <string.h>
20 #include <stdlib.h> /* getenv ! */
21 #include "../../../io/includes/getenvc.h"
22 #include "../../../fileio/includes/FileExist.h"
23 #include "localization.h"
24 #include "machine.h" 
25 #include "Os_specific.h"
26 #include "core_math.h" 
27 #include "setgetSCIpath.h"
28 #include "MALLOC.h"
29 #include "inisci-c.h"
30 #include "SCIHOME.h"
31 #include "scilabmode.h"
32 #include "scilabDefaults.h"
33 /*--------------------------------------------------------------------------*/
34 int C2F(withmodelicac)(int *rep)
35 {
36         if (ExistModelicac())
37         {
38                 *rep =1;
39         }
40         else
41         {
42                 *rep =0; 
43         }
44   return 0;
45 }
46 /*--------------------------------------------------------------------------*/
47 int C2F(withmsdos)(int *rep)
48 {
49 #ifdef _MSC_VER
50         *rep =1;
51 #else
52         *rep =0; 
53 #endif
54         return 0;
55 }
56 /*--------------------------------------------------------------------------*/
57 int C2F(getcomp)(char *buf,int *nbuf,long int lbuf)
58 {
59   int ierr,iflag=0,l1buf=lbuf;
60   C2F(getenvc)(&ierr,"COMPILER",buf,&l1buf,&iflag);
61   if ( ierr== 1) strncpy(buf,"NO",lbuf);
62   *nbuf = (int)strlen(buf);
63   return 0;
64 }
65 /*--------------------------------------------------------------------------*/
66 /**
67  * Set the SCI path and initialize the scilab environement path
68  *
69  */
70 int SetSci()
71 {
72         int ierr,iflag=0;
73         int lbuf=PATH_MAX;
74         char *buf = MALLOC(PATH_MAX*sizeof(char));
75         if (buf)
76         {
77                 C2F(getenvc)(&ierr,"SCI",buf,&lbuf,&iflag);
78
79                 if ( ierr== 1) 
80                 {
81                 #ifdef  _MSC_VER
82                 MessageBox(NULL,_("SCI environment variable not defined.\n"),"Warning",MB_ICONWARNING);
83                 #else
84                 fprintf(stderr, _("SCI environment variable not defined.\n"));
85                 #endif
86                 exit(1);
87                 }
88                 setSCIpath(buf);
89                 FREE(buf);
90                 buf = NULL;
91         }
92         
93         return 0;
94 }
95 /*--------------------------------------------------------------------------*/
96 /**
97  * Get the SCI path and initialize the scilab environment path
98  *
99  */
100 int C2F(getsci)(char *buf,int *nbuf,long int lbuf)
101 {
102         char *pathtmp = NULL;
103
104         SetSci();
105
106         pathtmp = getSCIpath();
107         if (pathtmp)
108         {
109                 strcpy(buf,pathtmp);
110                 *nbuf = (int)strlen(buf);
111                 FREE(pathtmp);
112                 pathtmp = NULL;
113         }
114         else
115         {
116                 *buf = NULL;
117                 *nbuf = 0;
118         }
119         return 0;
120 }
121 /*--------------------------------------------------------------------------*/
122 /**
123 * Get the SCIHOME path and initialize the scilab environment path
124 *
125 */
126 int C2F(getscihome)(char *buf,int *nbuf,long int lbuf)
127 {
128         char *pathtmp=NULL;
129         char *SCIHOME = getSCIHOME();
130         if (strcmp(SCIHOME,"empty_SCIHOME")==0)
131         {
132                 if (!setSCIHOME())
133                 {
134                         #ifdef  _MSC_VER
135                                 MessageBox(NULL,_("SCIHOME not defined.\n"),_("Warning"),MB_ICONWARNING);
136                         #else
137                                 /* @TODO change that to the error output */
138                                 fprintf(stderr,_("SCIHOME not defined.\n"));
139                         #endif
140                         exit(1);
141                 }
142                 else
143                 {
144                         if (SCIHOME) {FREE(SCIHOME);SCIHOME=NULL;}
145                 }
146         }
147
148         pathtmp = getSCIHOME();
149         if (pathtmp)
150         {
151                 strcpy(buf,pathtmp);
152                 *nbuf = (int)strlen(buf);
153                 FREE(pathtmp);
154                 pathtmp = NULL;
155         }
156         return 0;
157 }
158 /*--------------------------------------------------------------------------*/
159 int C2F(gettmpdir)(char *buf,int *nbuf,long int lbuf)
160 {
161         int ierr,iflag=0,l1buf=lbuf;
162         C2F(getenvc)(&ierr,"TMPDIR",buf,&l1buf,&iflag);
163         if ( ierr== 1) 
164         {
165 #ifdef  _MSC_VER
166                 MessageBox(NULL,_("TMPDIR not defined.\n"),_("Warning"),MB_ICONWARNING);
167 #else
168                 fprintf(stderr,_("TMPDIR not defined.\n"));
169 #endif
170                 exit(1);
171         }
172         *nbuf = (int)strlen(buf);
173         return 0;
174 }
175 /*--------------------------------------------------------------------------*/
176 BOOL ExistModelicac(void)
177 {
178         char *fullpathModelicac = searchEnv( ModelicacName,"PATH");
179         if (fullpathModelicac)
180         {
181                 FREE(fullpathModelicac);
182                 fullpathModelicac = NULL;
183                 return TRUE;
184         }
185         return FALSE;
186 }
187 /*--------------------------------------------------------------------------*/
188 int C2F(withgui)(int *rep)
189
190         *rep = (getScilabMode() != SCILAB_NWNI); 
191         return 0;
192 }
193 /*--------------------------------------------------------------------------*/
194 int C2F(getdefaultgstacksize)(int *defaultsize)
195 {
196 #if defined(_MSC_VER) && defined(_WIN64)
197         *defaultsize = DEFAULTGSTACKSIZE;
198 #else
199         *defaultsize = DEFAULTGSTACKSIZE;
200 #endif
201         
202         return 0;
203 }
204 /*--------------------------------------------------------------------------*/
205 int C2F(getdefaultstacksize)(int *defaultsize)
206 {
207         *defaultsize = DEFAULTSTACKSIZE;
208         return 0;
209 }
210 /*--------------------------------------------------------------------------*/