1 /*----------------------------------------------------------------------*/
2 /* netgenexec.c */
3 /* */
4 /* Written by R. Timothy Edwards for MultiGiG, Inc., November 2004 */
5 /* This file mainly lifted from the main application routine for */
6 /* "wish" from the Tk distribution. */
7 /* */
8 /* This is a compact re-write of the "wish" executable that calls */
9 /* Tk_MainEx with application-specific processing. Specifically, */
10 /* "wish" doesn't allow the startup script (~/.wishrc) to be renamed. */
11 /* However, for netgen running as an extension of Tcl, we want to */
12 /* source the netgen.tcl file instead of ~/.wishrc. So, all this file */
13 /* really does is to set the Tcl variable "tcl_rcFileName" to */
14 /* netgen.tcl, so that it will be processed as the startup script, */
15 /* followed by a drop back to the Tcl interpreter command-line main */
16 /* loop. */
17 /* */
18 /* This is a standalone executable. However, it is only called when */
19 /* "-noconsole" is specified on the UNIX command-line. When the */
20 /* console is used, the console is capable of sourcing the netgen.tcl */
21 /* script itself, and so it uses "wish" as the executable. However, */
22 /* the console redirects standard input, so it prevents netgen from */
23 /* being used in a batch processing mode. Thus, to batch-process with */
24 /* netgen, use "netgen -noc < script.tcl" or, interactively, */
25 /* "netgen -noc << EOF" followed by commands entered from stdin */
26 /* and ending with "EOF". */
27 /* */
28 /* The "netgenexec" method replaces the former use of "wish" with the */
29 /* "netgen" script setting HOME to point to the directory containing */
30 /* ".wishrc", a symbolic link to "netgen.tcl". That failed to work on */
31 /* remote systems because the $HOME environment variable is also used */
32 /* to find the user's .Xauthority file to authenticate the X11 */
33 /* connection. */
34 /* */
35 /* Update: Because "netgenexec" avoids the Tk console, no part of Tk */
36 /* is ever invoked. Making "netgenexec" run Tk_Init just causes it to */
37 /* require graphics accessibility that it does not need. All calls to */
38 /* Tk have been replaced with Tcl calls. */
39 /*----------------------------------------------------------------------*/
40
41 #include <stdio.h>
42
43 // #include <tk.h>
44 #include <tcl.h>
45
46 /*----------------------------------------------------------------------*/
47 /* Application initiation. This is exactly like the AppInit routine */
48 /* for "wish", minus the cruft, but with "tcl_rcFileName" set to */
49 /* "netgen.tcl" instead of "~/.wishrc". */
50 /*----------------------------------------------------------------------*/
51
52 int
netgen_AppInit(interp)53 netgen_AppInit(interp)
54 Tcl_Interp *interp;
55 {
56 if (Tcl_Init(interp) == TCL_ERROR) {
57 return TCL_ERROR;
58 }
59 // if (Tk_Init(interp) == TCL_ERROR) {
60 // return TCL_ERROR;
61 // }
62 // Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
63 Tcl_StaticPackage(interp, "Tcl", Tcl_Init, Tcl_Init);
64
65 /* This is where we replace the home ".wishrc" file with */
66 /* netgen's startup script. */
67
68 Tcl_SetVar(interp, "tcl_rcFileName", TCL_DIR "/netgen.tcl", TCL_GLOBAL_ONLY);
69 return TCL_OK;
70 }
71
72 /*----------------------------------------------------------------------*/
73 /* The main procedure; replacement for "wish". */
74 /*----------------------------------------------------------------------*/
75
76 int
main(argc,argv)77 main(argc, argv)
78 int argc;
79 char **argv;
80 {
81 // Tk_Main(argc, argv, netgen_AppInit);
82 Tcl_Main(argc, argv, netgen_AppInit);
83 return 0;
84 }
85
86 /*----------------------------------------------------------------------*/
87