jpayne@68
|
1 /*
|
jpayne@68
|
2 * tclAppInit.c --
|
jpayne@68
|
3 *
|
jpayne@68
|
4 * Provides a default version of the main program and Tcl_AppInit
|
jpayne@68
|
5 * procedure for tclsh and other Tcl-based applications (without Tk).
|
jpayne@68
|
6 *
|
jpayne@68
|
7 * Copyright (c) 1993 The Regents of the University of California.
|
jpayne@68
|
8 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
|
jpayne@68
|
9 * Copyright (c) 1998-1999 Scriptics Corporation.
|
jpayne@68
|
10 *
|
jpayne@68
|
11 * See the file "license.terms" for information on usage and redistribution of
|
jpayne@68
|
12 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
jpayne@68
|
13 */
|
jpayne@68
|
14
|
jpayne@68
|
15 #undef BUILD_tcl
|
jpayne@68
|
16 #undef STATIC_BUILD
|
jpayne@68
|
17 #include "tcl.h"
|
jpayne@68
|
18 #if TCL_MAJOR_VERSION < 9 && TCL_MINOR_VERSION < 7
|
jpayne@68
|
19 # define Tcl_LibraryInitProc Tcl_PackageInitProc
|
jpayne@68
|
20 # define Tcl_StaticLibrary Tcl_StaticPackage
|
jpayne@68
|
21 #endif
|
jpayne@68
|
22
|
jpayne@68
|
23 #ifdef TCL_TEST
|
jpayne@68
|
24 extern Tcl_LibraryInitProc Tcltest_Init;
|
jpayne@68
|
25 extern Tcl_LibraryInitProc Tcltest_SafeInit;
|
jpayne@68
|
26 #endif /* TCL_TEST */
|
jpayne@68
|
27
|
jpayne@68
|
28 #ifdef TCL_XT_TEST
|
jpayne@68
|
29 extern void XtToolkitInitialize(void);
|
jpayne@68
|
30 extern Tcl_LibraryInitProc Tclxttest_Init;
|
jpayne@68
|
31 #endif /* TCL_XT_TEST */
|
jpayne@68
|
32
|
jpayne@68
|
33 /*
|
jpayne@68
|
34 * The following #if block allows you to change the AppInit function by using
|
jpayne@68
|
35 * a #define of TCL_LOCAL_APPINIT instead of rewriting this entire file. The
|
jpayne@68
|
36 * #if checks for that #define and uses Tcl_AppInit if it does not exist.
|
jpayne@68
|
37 */
|
jpayne@68
|
38
|
jpayne@68
|
39 #ifndef TCL_LOCAL_APPINIT
|
jpayne@68
|
40 #define TCL_LOCAL_APPINIT Tcl_AppInit
|
jpayne@68
|
41 #endif
|
jpayne@68
|
42 #ifndef MODULE_SCOPE
|
jpayne@68
|
43 # define MODULE_SCOPE extern
|
jpayne@68
|
44 #endif
|
jpayne@68
|
45 MODULE_SCOPE int TCL_LOCAL_APPINIT(Tcl_Interp *);
|
jpayne@68
|
46 MODULE_SCOPE int main(int, char **);
|
jpayne@68
|
47
|
jpayne@68
|
48 /*
|
jpayne@68
|
49 * The following #if block allows you to change how Tcl finds the startup
|
jpayne@68
|
50 * script, prime the library or encoding paths, fiddle with the argv, etc.,
|
jpayne@68
|
51 * without needing to rewrite Tcl_Main()
|
jpayne@68
|
52 */
|
jpayne@68
|
53
|
jpayne@68
|
54 #ifdef TCL_LOCAL_MAIN_HOOK
|
jpayne@68
|
55 MODULE_SCOPE int TCL_LOCAL_MAIN_HOOK(int *argc, char ***argv);
|
jpayne@68
|
56 #endif
|
jpayne@68
|
57
|
jpayne@68
|
58 /*
|
jpayne@68
|
59 *----------------------------------------------------------------------
|
jpayne@68
|
60 *
|
jpayne@68
|
61 * main --
|
jpayne@68
|
62 *
|
jpayne@68
|
63 * This is the main program for the application.
|
jpayne@68
|
64 *
|
jpayne@68
|
65 * Results:
|
jpayne@68
|
66 * None: Tcl_Main never returns here, so this procedure never returns
|
jpayne@68
|
67 * either.
|
jpayne@68
|
68 *
|
jpayne@68
|
69 * Side effects:
|
jpayne@68
|
70 * Just about anything, since from here we call arbitrary Tcl code.
|
jpayne@68
|
71 *
|
jpayne@68
|
72 *----------------------------------------------------------------------
|
jpayne@68
|
73 */
|
jpayne@68
|
74
|
jpayne@68
|
75 int
|
jpayne@68
|
76 main(
|
jpayne@68
|
77 int argc, /* Number of command-line arguments. */
|
jpayne@68
|
78 char *argv[]) /* Values of command-line arguments. */
|
jpayne@68
|
79 {
|
jpayne@68
|
80 #ifdef TCL_XT_TEST
|
jpayne@68
|
81 XtToolkitInitialize();
|
jpayne@68
|
82 #endif
|
jpayne@68
|
83
|
jpayne@68
|
84 #ifdef TCL_LOCAL_MAIN_HOOK
|
jpayne@68
|
85 TCL_LOCAL_MAIN_HOOK(&argc, &argv);
|
jpayne@68
|
86 #elif (TCL_MAJOR_VERSION > 8 || TCL_MINOR_VERSION > 6) && (!defined(_WIN32) || defined(UNICODE))
|
jpayne@68
|
87 /* New in Tcl 8.7. This doesn't work on Windows without UNICODE */
|
jpayne@68
|
88 TclZipfs_AppHook(&argc, &argv);
|
jpayne@68
|
89 #endif
|
jpayne@68
|
90
|
jpayne@68
|
91 Tcl_Main(argc, argv, TCL_LOCAL_APPINIT);
|
jpayne@68
|
92 return 0; /* Needed only to prevent compiler warning. */
|
jpayne@68
|
93 }
|
jpayne@68
|
94
|
jpayne@68
|
95 /*
|
jpayne@68
|
96 *----------------------------------------------------------------------
|
jpayne@68
|
97 *
|
jpayne@68
|
98 * Tcl_AppInit --
|
jpayne@68
|
99 *
|
jpayne@68
|
100 * This procedure performs application-specific initialization. Most
|
jpayne@68
|
101 * applications, especially those that incorporate additional packages,
|
jpayne@68
|
102 * will have their own version of this procedure.
|
jpayne@68
|
103 *
|
jpayne@68
|
104 * Results:
|
jpayne@68
|
105 * Returns a standard Tcl completion code, and leaves an error message in
|
jpayne@68
|
106 * the interp's result if an error occurs.
|
jpayne@68
|
107 *
|
jpayne@68
|
108 * Side effects:
|
jpayne@68
|
109 * Depends on the startup script.
|
jpayne@68
|
110 *
|
jpayne@68
|
111 *----------------------------------------------------------------------
|
jpayne@68
|
112 */
|
jpayne@68
|
113
|
jpayne@68
|
114 int
|
jpayne@68
|
115 Tcl_AppInit(
|
jpayne@68
|
116 Tcl_Interp *interp) /* Interpreter for application. */
|
jpayne@68
|
117 {
|
jpayne@68
|
118 if ((Tcl_Init)(interp) == TCL_ERROR) {
|
jpayne@68
|
119 return TCL_ERROR;
|
jpayne@68
|
120 }
|
jpayne@68
|
121
|
jpayne@68
|
122 #ifdef TCL_XT_TEST
|
jpayne@68
|
123 if (Tclxttest_Init(interp) == TCL_ERROR) {
|
jpayne@68
|
124 return TCL_ERROR;
|
jpayne@68
|
125 }
|
jpayne@68
|
126 #endif
|
jpayne@68
|
127
|
jpayne@68
|
128 #ifdef TCL_TEST
|
jpayne@68
|
129 if (Tcltest_Init(interp) == TCL_ERROR) {
|
jpayne@68
|
130 return TCL_ERROR;
|
jpayne@68
|
131 }
|
jpayne@68
|
132 Tcl_StaticLibrary(interp, "Tcltest", Tcltest_Init, Tcltest_SafeInit);
|
jpayne@68
|
133 #endif /* TCL_TEST */
|
jpayne@68
|
134
|
jpayne@68
|
135 /*
|
jpayne@68
|
136 * Call the init procedures for included packages. Each call should look
|
jpayne@68
|
137 * like this:
|
jpayne@68
|
138 *
|
jpayne@68
|
139 * if (Mod_Init(interp) == TCL_ERROR) {
|
jpayne@68
|
140 * return TCL_ERROR;
|
jpayne@68
|
141 * }
|
jpayne@68
|
142 *
|
jpayne@68
|
143 * where "Mod" is the name of the module. (Dynamically-loadable packages
|
jpayne@68
|
144 * should have the same entry-point name.)
|
jpayne@68
|
145 */
|
jpayne@68
|
146
|
jpayne@68
|
147 /*
|
jpayne@68
|
148 * Call Tcl_CreateCommand for application-specific commands, if they
|
jpayne@68
|
149 * weren't already created by the init procedures called above.
|
jpayne@68
|
150 */
|
jpayne@68
|
151
|
jpayne@68
|
152 /*
|
jpayne@68
|
153 * Specify a user-specific startup file to invoke if the application is
|
jpayne@68
|
154 * run interactively. Typically the startup file is "~/.apprc" where "app"
|
jpayne@68
|
155 * is the name of the application. If this line is deleted then no
|
jpayne@68
|
156 * user-specific startup file will be run under any conditions.
|
jpayne@68
|
157 */
|
jpayne@68
|
158
|
jpayne@68
|
159 #ifdef DJGPP
|
jpayne@68
|
160 (Tcl_ObjSetVar2)(interp, Tcl_NewStringObj("tcl_rcFileName", -1), NULL,
|
jpayne@68
|
161 Tcl_NewStringObj("~/tclsh.rc", -1), TCL_GLOBAL_ONLY);
|
jpayne@68
|
162 #else
|
jpayne@68
|
163 (Tcl_ObjSetVar2)(interp, Tcl_NewStringObj("tcl_rcFileName", -1), NULL,
|
jpayne@68
|
164 Tcl_NewStringObj("~/.tclshrc", -1), TCL_GLOBAL_ONLY);
|
jpayne@68
|
165 #endif
|
jpayne@68
|
166
|
jpayne@68
|
167 return TCL_OK;
|
jpayne@68
|
168 }
|
jpayne@68
|
169
|
jpayne@68
|
170 /*
|
jpayne@68
|
171 * Local Variables:
|
jpayne@68
|
172 * mode: c
|
jpayne@68
|
173 * c-basic-offset: 4
|
jpayne@68
|
174 * fill-column: 78
|
jpayne@68
|
175 * End:
|
jpayne@68
|
176 */
|