inisci-c.c

Go to the documentation of this file.
00001 /*************************************************************************************************/
00002 /* Scilab */
00003 /* INRIA */
00004 /*************************************************************************************************/
00005 #ifdef _MSC_VER
00006 #include <windows.h>
00007 #else
00008 #include <sys/utsname.h>
00009 #endif
00010 #include <stdio.h>
00011 #include <string.h>
00012 #include <stdlib.h> /* getenv ! */
00013 #include "machine.h" 
00014 #include "Os_specific.h"
00015 #include "core_math.h" 
00016 #include "setgetSCIpath.h"
00017 #include "MALLOC.h"
00018 #include "inisci-c.h"
00019 #include "SCIHOME.h"
00020 /*************************************************************************************************/
00021 static BOOL WITH_GUI=TRUE;
00022 /*************************************************************************************************/
00023 extern int C2F(withtk)(int *rep);
00024 extern BOOL FileExist(char *filename);
00025 /*************************************************************************************************/
00026 int C2F(withpvm)(int *rep)
00027 { 
00028 #ifdef WITH_PVM
00029   *rep =1; 
00030 #else 
00031   *rep =0; 
00032 #endif 
00033   return 0;
00034 }
00035 /*************************************************************************************************/
00036 int C2F(withgtk)(int *rep)
00037 { 
00038   *rep =0; 
00039   return 0;
00040 }
00041 /*************************************************************************************************/
00042 int C2F(withscicos)(int *rep)
00043 { 
00044         *rep = ExistScicos(); 
00045         return 0;
00046 }
00047 /*************************************************************************************************/
00048 int C2F(withmodelicac)(int *rep)
00049 {
00050         if (ExistModelicac())
00051         {
00052                 *rep =1;
00053         }
00054         else
00055         {
00056                 *rep =0; 
00057         }
00058   return 0;
00059 }
00060 /*************************************************************************************************/
00061 int C2F(withjavasci)(int *rep)
00062 {
00063 #ifdef _MSC_VER
00064         if (ExistJavaSciWin())
00065         {
00066                 *rep =1;
00067         }
00068         else
00069         {
00070                 *rep =0; 
00071         }
00072 #else
00073         if (ExistJavaSciUnix())
00074         {
00075                 *rep =1;
00076         }
00077         else
00078         {
00079                 *rep =0; 
00080         }
00081 #endif
00082   return 0;
00083 }
00084 /*************************************************************************************************/
00085 int C2F(withmsdos)(int *rep)
00086 {
00087 #ifdef _MSC_VER
00088         *rep =1;
00089 #else
00090         *rep =0; 
00091 #endif
00092         return 0;
00093 }
00094 /*************************************************************************************************/
00095 int C2F(getcomp)(char *buf,int *nbuf,long int lbuf)
00096 {
00097   int ierr,iflag=0,l1buf=lbuf;
00098   C2F(getenvc)(&ierr,"COMPILER",buf,&l1buf,&iflag);
00099   if ( ierr== 1) strncpy(buf,"NO",lbuf);
00100   *nbuf = strlen(buf);
00101   return 0;
00102 }
00103 
00104 
00105 /*************************************************************************************************/
00110 int SetSci()
00111 {
00112 #ifdef _MSC_VER
00113 #define PATH_MAX 1024
00114 #endif
00115 
00116         int ierr,iflag=0;
00117         int lbuf=PATH_MAX;
00118         char *buf=MALLOC(PATH_MAX*sizeof(char));
00119         C2F(getenvc)(&ierr,"SCI",buf,&lbuf,&iflag);
00120 
00121         if ( ierr== 1) 
00122         {
00123                 #ifdef  _MSC_VER
00124                 MessageBox(NULL,"SCI not defined.","Warning",MB_ICONWARNING);
00125                 #else
00126                 printf("SCI not defined.\n");
00127                 #endif
00128                 exit(1);
00129         }
00130         setSCIpath(buf);
00131         if (buf) {FREE(buf);buf=NULL;}
00132         return 0;
00133 }
00134 
00135 /*************************************************************************************************/
00140 int C2F(getsci)(char *buf,int *nbuf,long int lbuf)
00141 {
00142         char *pathtmp=NULL;
00143         SetSci();
00144         pathtmp=getSCIpath();
00145         strcpy(buf,pathtmp);
00146         *nbuf = strlen(buf);
00147         if (pathtmp) {FREE(pathtmp);pathtmp=NULL;}
00148         return 0;
00149 }
00150 /*************************************************************************************************/
00155 int C2F(getscihome)(char *buf,int *nbuf,long int lbuf)
00156 {
00157         char *pathtmp=NULL;
00158         char *SCIHOME=getSCIHOME();
00159         if (strcmp(SCIHOME,"empty_SCIHOME")==0)
00160         {
00161                 if (!setSCIHOME())
00162                 {
00163                         #ifdef  _MSC_VER
00164                                 MessageBox(NULL,"SCIHOME not defined.","Warning",MB_ICONWARNING);
00165                         #else
00166                                 printf("SCIHOME not defined.\n");
00167                         #endif
00168                         exit(1);
00169                 }
00170                 else
00171                 {
00172                         if (SCIHOME) {FREE(SCIHOME);SCIHOME=NULL;}
00173                 }
00174         }
00175 
00176         pathtmp=getSCIHOME();
00177         strcpy(buf,pathtmp);
00178         *nbuf = strlen(buf);
00179         if (pathtmp) {FREE(pathtmp);pathtmp=NULL;}
00180 
00181         return 0;
00182 }
00183 /*************************************************************************************************/
00184 int C2F(gettmpdir)(char *buf,int *nbuf,long int lbuf)
00185 {
00186         int ierr,iflag=0,l1buf=lbuf;
00187         C2F(getenvc)(&ierr,"TMPDIR",buf,&l1buf,&iflag);
00188         if ( ierr== 1) 
00189         {
00190 #ifdef  _MSC_VER
00191                 MessageBox(NULL,"TMPDIR not defined.","Warning",MB_ICONWARNING);
00192 #else
00193                 printf("TMPDIR not defined.\n");
00194 #endif
00195                 exit(1);
00196         }
00197         *nbuf = strlen(buf);
00198         return 0;
00199 }
00200 /*************************************************************************************************/
00201 BOOL ExistModelicac(void)
00202 {
00203         #define ModelicacNameWindows "/modules/scicos/bin/modelicac.exe"
00204         #define ModelicacNameLinux "/modules/scicos/bin/modelicac"
00205 
00206         BOOL bOK=FALSE;
00207         char *SCIPATH = (char*)getSCIpath();
00208         char *fullpathModelicac=NULL;
00209         
00210         #ifdef _MSC_VER
00211                 fullpathModelicac=(char*)MALLOC((strlen(SCIPATH)+strlen(ModelicacNameWindows)+1)*sizeof(char));
00212                 sprintf(fullpathModelicac,"%s%s",SCIPATH,ModelicacNameWindows);
00213         #else
00214                 fullpathModelicac=(char*)MALLOC((strlen(SCIPATH)+strlen(ModelicacNameLinux)+1)*sizeof(char));
00215                 sprintf(fullpathModelicac,"%s%s",SCIPATH,ModelicacNameLinux);
00216         #endif
00217         bOK=FileExist(fullpathModelicac);
00218         if (fullpathModelicac) FREE(fullpathModelicac);
00219         if (SCIPATH) FREE(SCIPATH);
00220         return bOK;
00221 }
00222 /*************************************************************************************************/
00223 #ifdef _MSC_VER
00224 BOOL ExistJavaSciWin(void)
00225 {
00226         #define JavaSCIName "/bin/javasci.dll"
00227 
00228         BOOL bOK=FALSE;
00229         char *SCIPATH = (char*)getSCIpath();
00230         char *fullpathJavaSci=NULL;
00231         
00232         fullpathJavaSci=(char*)MALLOC((strlen(SCIPATH)+strlen(JavaSCIName)+1)*sizeof(char));
00233         wsprintf(fullpathJavaSci,"%s%s",SCIPATH,JavaSCIName);
00234         bOK=FileExist(fullpathJavaSci);
00235         if (fullpathJavaSci) FREE(fullpathJavaSci);
00236         if (SCIPATH) {FREE(SCIPATH);SCIPATH=NULL;}
00237         return bOK;
00238 }
00239 #endif
00240 /*************************************************************************************************/
00241 int ExistJavaSciUnix(void)
00242 {
00243         int bOK=0;
00244 #ifndef _MSC_VER
00245         char *SCIPATH = (char*)getSCIpath();
00246         char *fullpathJavaSci=NULL;
00247 
00248         #define JavaSciName "libjavasci"
00249 
00250         struct utsname uname_pointer;
00251         FILE *fp;
00252 
00253         char OperatinSystem[256];
00254         char Release[256];
00255         char extension[5];
00256 
00257         uname(&uname_pointer);
00258         sprintf(OperatinSystem,"%s",uname_pointer.sysname);
00259         sprintf(Release,"%s",uname_pointer.release);
00260 
00261         if ( strcmp(OperatinSystem,"HP-UX") == 0 )
00262         {
00263                 strcpy(extension,".sl");
00264         }
00265         else
00266         {
00267                 strcpy(extension,".so");
00268         }
00269         fullpathJavaSci=(char*)MALLOC((strlen(SCIPATH)+strlen("/bin/")+strlen(JavaSciName)+strlen(extension)+1)*sizeof(char));
00270         sprintf(fullpathJavaSci,"%s/bin/%s%s",SCIPATH,JavaSciName,extension);
00271         fp=fopen(fullpathJavaSci,"r");
00272         if (fp)
00273         {
00274                 fclose(fp);
00275                 bOK=1;
00276         }
00277         else
00278         {
00279                 bOK=0;
00280         }
00281         if (fullpathJavaSci) FREE(fullpathJavaSci);
00282 #endif
00283         return bOK;
00284 }
00285 /*************************************************************************************************/
00286 int C2F(withgui)(int *rep)
00287 { 
00288         *rep = WITH_GUI; 
00289         return 0;
00290 }
00291 /*************************************************************************************************/
00292 void SetWITH_GUI(BOOL ON)
00293 {
00294         if ( (ON == FALSE) || (ON == TRUE) ) WITH_GUI=ON;
00295 }
00296 /*************************************************************************************************/
00297 BOOL  GetWITH_GUI(void)
00298 {
00299         return WITH_GUI;
00300 }
00301 /*************************************************************************************************/

Generated on Sun Mar 4 15:03:46 2007 for Scilab [trunk] by  doxygen 1.5.1