1 /*
2 * tclAppInit.c --
3 *
4 * Provides a default version of the main program and Tcl_AppInit
5 * procedure for Tcl applications (without Tk).
6 *
7 * Copyright (c) 1993 The Regents of the University of California.
8 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
9 * Copyright (c) 1998-1999 by Scriptics Corporation.
10 *
11 * Changes:
12 * Added tclgeomap headers and initializing functions.
13 * Gordon D. Carrie, 2003.
14 *
15 * See the file "license.terms" for information on usage and redistribution
16 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
17 *
18 * RCS: @(#) $Id: tclAppInit.c,v 1.1 2004/02/18 20:26:20 tkgeomap Exp $
19 */
20
21 #include "tcl.h"
22 #include "tclgeomap.h"
23
24 /*
25 * The following variable is a special hack that is needed in order for
26 * Sun shared libraries to be used for Tcl.
27 */
28
29 extern int matherr();
30 int *tclDummyMathPtr = (int *) matherr;
31
32
33 #ifdef TCL_TEST
34
35 #include "tclInt.h"
36
37 extern int Procbodytest_Init _ANSI_ARGS_((Tcl_Interp *interp));
38 extern int Procbodytest_SafeInit _ANSI_ARGS_((Tcl_Interp *interp));
39 extern int TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
40 extern int Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
41 #ifdef TCL_THREADS
42 extern int TclThread_Init _ANSI_ARGS_((Tcl_Interp *interp));
43 #endif
44
45 #endif /* TCL_TEST */
46
47 #ifdef TCL_XT_TEST
48 extern void XtToolkitInitialize _ANSI_ARGS_((void));
49 extern int Tclxttest_Init _ANSI_ARGS_((Tcl_Interp *interp));
50 #endif
51
52 /*
53 *----------------------------------------------------------------------
54 *
55 * main --
56 *
57 * This is the main program for the application.
58 *
59 * Results:
60 * None: Tcl_Main never returns here, so this procedure never
61 * returns either.
62 *
63 * Side effects:
64 * Whatever the application does.
65 *
66 *----------------------------------------------------------------------
67 */
68
69 int
main(argc,argv)70 main(argc, argv)
71 int argc; /* Number of command-line arguments. */
72 char **argv; /* Values of command-line arguments. */
73 {
74 /*
75 * The following #if block allows you to change the AppInit
76 * function by using a #define of TCL_LOCAL_APPINIT instead
77 * of rewriting this entire file. The #if checks for that
78 * #define and uses Tcl_AppInit if it doesn't exist.
79 */
80
81 #ifndef TCL_LOCAL_APPINIT
82 #define TCL_LOCAL_APPINIT Tcl_AppInit
83 #endif
84 extern int TCL_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp));
85
86 /*
87 * The following #if block allows you to change how Tcl finds the startup
88 * script, prime the library or encoding paths, fiddle with the argv,
89 * etc., without needing to rewrite Tcl_Main()
90 */
91
92 #ifdef TCL_LOCAL_MAIN_HOOK
93 extern int TCL_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv));
94 #endif
95
96 #ifdef TCL_TEST
97 /*
98 * Pass the build time location of the tcl library (to find init.tcl)
99 *
100 * This causes a 2400b "potential" mem leak, according to purify
101 * (the obj allocation that never seems to gets deallocated)
102 */
103 Tcl_Obj *path;
104 path = Tcl_NewStringObj(TCL_BUILDTIME_LIBRARY, -1);
105 TclSetLibraryPath(Tcl_NewListObj(1,&path));
106
107 #endif
108
109 #ifdef TCL_XT_TEST
110 XtToolkitInitialize();
111 #endif
112
113 #ifdef TCL_LOCAL_MAIN_HOOK
114 TCL_LOCAL_MAIN_HOOK(&argc, &argv);
115 #endif
116
117 Tcl_Main(argc, argv, TCL_LOCAL_APPINIT);
118
119 return 0; /* Needed only to prevent compiler warning. */
120 }
121
122 /*
123 *----------------------------------------------------------------------
124 *
125 * Tcl_AppInit --
126 *
127 * This procedure performs application-specific initialization.
128 * Most applications, especially those that incorporate additional
129 * packages, will have their own version of this procedure.
130 *
131 * Results:
132 * Returns a standard Tcl completion code, and leaves an error
133 * message in the interp's result if an error occurs.
134 *
135 * Side effects:
136 * Depends on the startup script.
137 *
138 *----------------------------------------------------------------------
139 */
140
141 int
Tcl_AppInit(interp)142 Tcl_AppInit(interp)
143 Tcl_Interp *interp; /* Interpreter for application. */
144 {
145 if (Tcl_Init(interp) == TCL_ERROR) {
146 return TCL_ERROR;
147 }
148
149 #ifdef TCL_TEST
150 #ifdef TCL_XT_TEST
151 if (Tclxttest_Init(interp) == TCL_ERROR) {
152 return TCL_ERROR;
153 }
154 #endif
155 if (Tcltest_Init(interp) == TCL_ERROR) {
156 return TCL_ERROR;
157 }
158 Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
159 (Tcl_PackageInitProc *) NULL);
160 if (TclObjTest_Init(interp) == TCL_ERROR) {
161 return TCL_ERROR;
162 }
163 #ifdef TCL_THREADS
164 if (TclThread_Init(interp) == TCL_ERROR) {
165 return TCL_ERROR;
166 }
167 #endif
168 if (Procbodytest_Init(interp) == TCL_ERROR) {
169 return TCL_ERROR;
170 }
171 Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init,
172 Procbodytest_SafeInit);
173 #endif /* TCL_TEST */
174
175 /*
176 * Call the init procedures for included packages. Each call should
177 * look like this:
178 *
179 * if (Mod_Init(interp) == TCL_ERROR) {
180 * return TCL_ERROR;
181 * }
182 *
183 * where "Mod" is the name of the module.
184 */
185
186 if (Tclgeomap_Init(interp) == TCL_ERROR) {
187 return TCL_ERROR;
188 }
189
190 /*
191 * Call Tcl_CreateCommand for application-specific commands, if
192 * they weren't already created by the init procedures called above.
193 */
194
195 /*
196 * Specify a user-specific startup file to invoke if the application
197 * is run interactively. Typically the startup file is "~/.apprc"
198 * where "app" is the name of the application. If this line is deleted
199 * then no user-specific startup file will be run under any conditions.
200 */
201
202 Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);
203 return TCL_OK;
204 }
205