One more check on valid display which is known to be in the startup
[xcircuit.git] / xcircexec.c
blob36678af58360e457f5136922382164068c7afe33
1 /*----------------------------------------------------------------------*/
2 /* xcircexec.c */
3 /* */
4 /* Written by R. Timothy Edwards for MultiGiG, Inc., September 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 xcircuit running as an extension of Tcl, we want to */
12 /* source the xcircuit.tcl file instead of ~/.wishrc. So, all this */
13 /* file really does is to set the Tcl variable "tcl_rcFileName" to */
14 /* xcircuit.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 magic.tcl */
21 /* script itself, and so it uses "wish" as the executable. However, */
22 /* the console redirects standard input, so it prevents magic from */
23 /* being used in a batch processing mode. Thus, to batch-process with */
24 /* xcircuit, use "xcircuit -noc < script.tcl" or, interactively, */
25 /* "xcircuit -noc << EOF" followed by commands entered from stdin */
26 /* and ending with "EOF". */
27 /* */
28 /* The "xcircexec" method replaces the former use of "wish" with the */
29 /* "xcircuit" script setting HOME to point to the directory containing */
30 /* ".wishrc", a symbolic link to "xcircuit.tcl". That failed to work */
31 /* on remote systems because the $HOME environment variable is also */
32 /* used to find the user's .Xauthority file to authenticate the X11 */
33 /* connection. */
34 /*----------------------------------------------------------------------*/
36 #include <stdio.h>
38 #include <tk.h>
39 #include <tcl.h>
41 /*----------------------------------------------------------------------*/
42 /* Application initiation. This is exactly like the AppInit routine */
43 /* for "wish", minus the cruft, but with "tcl_rcFileName" set to */
44 /* "xcircuit.tcl" instead of "~/.wishrc". */
45 /*----------------------------------------------------------------------*/
47 int
48 xcircuit_AppInit(interp)
49 Tcl_Interp *interp;
51 if (Tcl_Init(interp) == TCL_ERROR) {
52 return TCL_ERROR;
54 if (Tk_Init(interp) == TCL_ERROR) {
55 return TCL_ERROR;
57 Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
59 /* This is where we replace the home ".wishrc" file with */
60 /* xcircuit's startup script. */
62 Tcl_SetVar(interp, "tcl_rcFileName", SCRIPTS_DIR "/xcircuit.tcl",
63 TCL_GLOBAL_ONLY);
64 return TCL_OK;
67 /*----------------------------------------------------------------------*/
68 /* The main procedure; replacement for "wish". */
69 /*----------------------------------------------------------------------*/
71 int
72 main(argc, argv)
73 int argc;
74 char **argv;
76 Tk_Main(argc, argv, xcircuit_AppInit);
77 return 0;
80 /*----------------------------------------------------------------------*/