to build scilab on Windows (temp.)
[scilab.git] / scilab / modules / tclsci / src / c / EnvTclTk.c
1 /*-----------------------------------------------------------------------------------*/
2 /* INRIA 2006 */
3 /* Allan CORNET */
4 /*-----------------------------------------------------------------------------------*/ 
5 #ifdef _MSC_VER
6 #include <windows.h>
7 #endif
8 #include "machine.h"
9
10 #include <stdio.h>
11 #include "tcl.h"
12 #include "tk.h"
13 #include "MALLOC.h"
14 //#include "../../localization/includes/QueryStringError.h"
15 #include "../../fileio/includes/ConvertPathUnixToWindows.h"
16 /*-----------------------------------------------------------------------------------*/
17 BOOL Set_TCL_LIBRARY_PATH(char *DefaultPath)
18 {
19         BOOL bOK=FALSE;
20         
21         int major=8;
22         int minor=4; /* Par defaut */
23         int patchLevel=0;
24         int type=0;
25         /* @TODO : WTF is 10 ? */
26         char env[PATH_MAX + 1 + 10];
27         
28         char ShortPath[PATH_MAX+1];
29         char *CopyOfDefaultPath=NULL;
30
31         CopyOfDefaultPath=MALLOC(((int)strlen(DefaultPath)+1)*sizeof(char));
32
33         
34         Tcl_GetVersion(&major, &minor, &patchLevel, &type);
35
36         /* to be sure that it's windows format */
37         /* c:\progra~1\scilab-5.0\modules\tclsci\tcl\tcl8.4 */
38         if (GetShortPathName(DefaultPath,ShortPath,PATH_MAX)==0)
39         {
40                 //char *msg1=QueryStringError("Incorrect TCL_LIBRARY environment variable");
41                 //char *msg2=QueryStringError("TCL_LIBRARY has been redefined to ");
42                 fprintf(stderr,"\n%s\n%s%s.\n","Incorrect TCL_LIBRARY environment variable","TCL_LIBRARY has been redefined to ",DefaultPath);
43                 if (CopyOfDefaultPath) {FREE(CopyOfDefaultPath);CopyOfDefaultPath=NULL;}
44 //              if (msg1) {FREE(msg1);msg1=NULL;}
45 //              if (msg2) {FREE(msg2);msg2=NULL;}
46
47                 ConvertPathUnixToWindowsFormat(ShortPath,CopyOfDefaultPath);
48                 wsprintf (env, "TCL_LIBRARY=%s\\modules\\tclsci\\tcl\\tcl%d.%d",CopyOfDefaultPath,major,minor);
49
50                 if (CopyOfDefaultPath) {FREE(CopyOfDefaultPath);CopyOfDefaultPath=NULL;}
51         }
52         else
53         {
54                 ConvertPathUnixToWindowsFormat(ShortPath,CopyOfDefaultPath);
55                 wsprintf (env, "TCL_LIBRARY=%s\\modules\\tclsci\\tcl\\tcl%d.%d",CopyOfDefaultPath,major,minor);
56                 
57                 if (CopyOfDefaultPath) {FREE(CopyOfDefaultPath);CopyOfDefaultPath=NULL;}
58         }
59
60         if (_putenv (env))
61         {
62                 bOK=FALSE;
63         }
64         else
65         {
66                 bOK=TRUE;
67         }
68
69         return bOK;
70 }
71 /*-----------------------------------------------------------------------------------*/
72 BOOL Set_TK_LIBRARY_PATH(char *DefaultPath)
73 {
74         BOOL bOK=FALSE;
75         char env[PATH_MAX + 1 + 10];
76         char ShortPath[PATH_MAX+1];
77         char *CopyOfDefaultPath=NULL;
78
79         int major=8;
80         int minor=4; /* Par defaut */
81         int patchLevel=0;
82         int type=0;
83
84         CopyOfDefaultPath=MALLOC(((int)strlen(DefaultPath)+1)*sizeof(char));
85
86         Tcl_GetVersion(&major, &minor, &patchLevel, &type);
87
88         /* to be sure that it's windows format */
89         /* c:\progra~1\scilab-3.1\modules\tclsci\tcl\tk8.4 */
90         if (GetShortPathName(DefaultPath,ShortPath,PATH_MAX)==0)
91         {
92                 //char *msg1=QueryStringError("Incorrect TK_LIBRARY environment variable");
93                 //char *msg2=QueryStringError("TK_LIBRARY has been redefined to ");
94                 fprintf(stderr,"\n%s\n%s%s.\n","Incorrect TK_LIBRARY environment variable","TK_LIBRARY has been redefined to ",DefaultPath);
95                 if (CopyOfDefaultPath) {FREE(CopyOfDefaultPath);CopyOfDefaultPath=NULL;}
96                 //if (msg1){FREE(msg1);msg1=NULL;}
97                 //if (msg2){FREE(msg2);msg2=NULL;}
98
99                 ConvertPathUnixToWindowsFormat(ShortPath,CopyOfDefaultPath);
100                 wsprintf (env, "TK_LIBRARY=%s\\modules\\tclsci\\tcl\\tk%d.%d",CopyOfDefaultPath,major,minor);
101
102                 if (CopyOfDefaultPath) {FREE(CopyOfDefaultPath);CopyOfDefaultPath=NULL;}
103                 
104         }
105         else
106         {
107                 ConvertPathUnixToWindowsFormat(ShortPath,CopyOfDefaultPath);
108                 wsprintf (env, "TK_LIBRARY=%s\\modules\\tclsci\\tcl\\tk%d.%d",CopyOfDefaultPath,major,minor);
109
110                 if (CopyOfDefaultPath) {FREE(CopyOfDefaultPath);CopyOfDefaultPath=NULL;}
111         }
112
113         if (_putenv (env))
114         {
115                 bOK=FALSE;
116         }
117         else
118         {
119                 bOK=TRUE;
120         }
121
122         return bOK;
123 }
124 /*-----------------------------------------------------------------------------------*/