1 /****************************************************************************
2 Copyright (C) 1987-2015 by Jeffery P. Hansen
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 Last edit by hansen on Tue Jan 27 23:21:37 2009
19 ****************************************************************************/
20 #include <stdlib.h>
21 #include "tcl.h"
22 #include "tk.h"
23
24 #define STRMAX 1024
25
26 void findTkGateHome(char *homeDir);
27 int Tkgate_Init(Tcl_Interp *tcl);
28
29 /*****************************************************************************
30 *
31 * This contains the inital setup for tcl/tk.
32 *
33 *****************************************************************************/
Tcl_AppInit(Tcl_Interp * tcl)34 int Tcl_AppInit(Tcl_Interp *tcl)
35 {
36 int r;
37
38 r = Tcl_Init(tcl);
39 if (r == TCL_ERROR) {
40 fprintf(stderr,"Tcl_Init Error in tkgate:\n%s\n",Tcl_GetStringResult(tcl));
41 fprintf(stderr,"Perhaps you could try setting the environment variable TCL_LIBRARY\n");
42 fprintf(stderr,"to the directory in which init.tcl can be found. You can also\n");
43 fprintf(stderr,"set TCL_LIBRARY in options.h.\n");
44 exit(1);
45 }
46
47 Tkgate_Init(tcl);
48
49 return TCL_OK;
50 }
51
52 /*****************************************************************************
53 *
54 * This is the main() for tkgate. We do some basic setup, parsing of command-
55 * line options, then call Tk_Main() to start the application. Tk_Main() will
56 * call Tcl_AppInit to do tcl-related initialization then start the tcl script
57 * interpreter to start the tkgate application script.
58 *
59 *****************************************************************************/
main(int argc,char * argv[])60 int main(int argc,char *argv[])
61 {
62 char tkgate_startup_script[STRMAX];
63 char homeDir[STRMAX];
64 char **tk_argv;
65 int i,tk_argc;
66
67 /*
68 * Figure out which directory we should use as the tkgate home.
69 */
70 findTkGateHome(homeDir);
71
72 /*
73 * If the tcl/tk library file path environment variables are not set, use
74 * the ones that we found when tkgate was compiled.
75 */
76 #ifdef TCL_LIBRARY
77 if (!getenv("TCL_LIBRARY")) putenv("TCL_LIBRARY=" TCL_LIBRARY);
78 #endif
79 #ifdef TK_LIBRARY
80 if (!getenv("TK_LIBRARY")) putenv("TK_LIBRARY=" TK_LIBRARY);
81 #endif
82
83 /*
84 * Build a mock command line with the main tcl script for tkgate and start up the tcl/tk
85 * interpeter with that script. All of the rest of the initialization will be controlled
86 * by the tcl script.
87 */
88 tk_argc = 0;
89 tk_argv = (char**) malloc(sizeof(char*)*(argc+4));
90 tk_argv[tk_argc++] = argv[0];
91 sprintf(tkgate_startup_script,"%s/scripts/tkgate.tcl",homeDir);
92 tk_argv[tk_argc++] = tkgate_startup_script;
93 tk_argv[tk_argc++] = "--";
94 tk_argv[tk_argc++] = "-H";
95 tk_argv[tk_argc++] = homeDir;
96 for (i = 1;i < argc;i++)
97 tk_argv[tk_argc++] = argv[i];
98
99 /*
100 * Here we go, off to tcl/tk land.
101 */
102 Tk_Main(tk_argc,tk_argv,Tcl_AppInit);
103
104 return 0;
105 }
106