add javalibrarypath function
[scilab.git] / scilab / modules / jvm / src / c / InitializeJVM.c
1 /*-----------------------------------------------------------------------------------*/
2 /* INRIA 2007 */
3 /* Allan CORNET */
4 /*-----------------------------------------------------------------------------------*/ 
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include "InitializeJVM.h"
9 #include "loadClasspath.h"
10 #include "loadLibrarypath.h"
11 #include "setgetSCIpath.h"
12 #include "MALLOC.h"
13 #include "JVM.h"
14 #include "createMainScilabObject.h"
15 /*-----------------------------------------------------------------------------------*/ 
16 static void DoLoadClasspathInEtc(char *SCIPATH);
17 static void DoLoadLibrarypathInEtc(char *SCIPATH);
18 /*-----------------------------------------------------------------------------------*/ 
19 BOOL InitializeJVM(void)
20 {
21         BOOL bOK=FALSE;
22         char *SCIPATH=NULL;
23
24         SCIPATH=getSCIpath();
25
26         bOK=startJVM(SCIPATH);
27
28         if (!bOK)
29         {
30 #ifdef _MSC_VER
31                 MessageBox(NULL,"Scilab cannot open JVM library.","Error",MB_ICONEXCLAMATION|MB_OK);
32 #else
33                 printf("\nError : Scilab cannot open JVM library.\n");
34 #endif
35         }
36         else
37         {
38                 DoLoadLibrarypathInEtc(SCIPATH);
39                 DoLoadClasspathInEtc(SCIPATH);
40
41                 bOK = createMainScilabObject();
42
43                 if (!bOK)
44                 {
45 #ifdef _MSC_VER
46                         MessageBox(NULL,"Scilab cannot create Scilab Java Main-Class. (we have not been able to find the main Scilab class. Check if the Scilab and thirdparty packages are available).","Error",MB_ICONEXCLAMATION|MB_OK);
47 #else
48                         printf("\nError : Scilab cannot create Scilab Java Main-Class. (we have not been able to find the main Scilab class. Check if the Scilab and thirdparty packages are available).\n");
49 #endif
50                 }
51         }
52
53         if (SCIPATH) {FREE(SCIPATH);SCIPATH=NULL;}
54
55         if (!bOK) exit(1);
56
57         return bOK;
58 }
59 /*-----------------------------------------------------------------------------------*/ 
60 static void DoLoadClasspathInEtc(char *SCIPATH)
61 {
62         #define XMLCLASSPATH "%s/etc/classpath.xml"
63         char *classpathfile = NULL;
64         classpathfile = (char*)MALLOC(sizeof(char)*(strlen(SCIPATH)+strlen(XMLCLASSPATH)+1));
65         sprintf(classpathfile,XMLCLASSPATH,SCIPATH);
66         LoadClasspath(classpathfile);
67         if (classpathfile) {FREE(classpathfile); classpathfile = NULL;}
68 }
69 /*-----------------------------------------------------------------------------------*/ 
70 static void DoLoadLibrarypathInEtc(char *SCIPATH)
71 {
72         #define XMLLIBRARYPATH "%s/etc/librarypath.xml"
73         char *librarypathfile = NULL;
74         librarypathfile = (char*)MALLOC(sizeof(char)*(strlen(SCIPATH)+strlen(XMLLIBRARYPATH)+1));
75         sprintf(librarypathfile,XMLLIBRARYPATH,SCIPATH);
76         LoadLibrarypath(librarypathfile);
77         if (librarypathfile) {FREE(librarypathfile); librarypathfile = NULL;}
78 }
79 /*-----------------------------------------------------------------------------------*/ 
80
81