sl@0
|
1 |
/*
|
sl@0
|
2 |
* tclMacAppInit.c --
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* Provides a version of the Tcl_AppInit procedure for the example shell.
|
sl@0
|
5 |
*
|
sl@0
|
6 |
* Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center
|
sl@0
|
7 |
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* See the file "license.terms" for information on usage and redistribution
|
sl@0
|
10 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* RCS: @(#) $Id: tclMacAppInit.c,v 1.9 2001/11/23 01:27:13 das Exp $
|
sl@0
|
13 |
*/
|
sl@0
|
14 |
|
sl@0
|
15 |
#include "tcl.h"
|
sl@0
|
16 |
#include "tclInt.h"
|
sl@0
|
17 |
#include "tclPort.h"
|
sl@0
|
18 |
#include "tclMac.h"
|
sl@0
|
19 |
#include "tclMacInt.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
#if defined(THINK_C)
|
sl@0
|
22 |
# include <console.h>
|
sl@0
|
23 |
#elif defined(__MWERKS__)
|
sl@0
|
24 |
# include <SIOUX.h>
|
sl@0
|
25 |
EXTERN short InstallConsole _ANSI_ARGS_((short fd));
|
sl@0
|
26 |
#endif
|
sl@0
|
27 |
|
sl@0
|
28 |
#ifdef TCL_TEST
|
sl@0
|
29 |
extern int Procbodytest_Init _ANSI_ARGS_((Tcl_Interp *interp));
|
sl@0
|
30 |
extern int Procbodytest_SafeInit _ANSI_ARGS_((Tcl_Interp *interp));
|
sl@0
|
31 |
extern int TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
|
sl@0
|
32 |
extern int Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
|
sl@0
|
33 |
#endif /* TCL_TEST */
|
sl@0
|
34 |
|
sl@0
|
35 |
/*
|
sl@0
|
36 |
* Forward declarations for procedures defined later in this file:
|
sl@0
|
37 |
*/
|
sl@0
|
38 |
|
sl@0
|
39 |
static int MacintoshInit _ANSI_ARGS_((void));
|
sl@0
|
40 |
|
sl@0
|
41 |
/*
|
sl@0
|
42 |
*----------------------------------------------------------------------
|
sl@0
|
43 |
*
|
sl@0
|
44 |
* main --
|
sl@0
|
45 |
*
|
sl@0
|
46 |
* Main program for tclsh. This file can be used as a prototype
|
sl@0
|
47 |
* for other applications using the Tcl library.
|
sl@0
|
48 |
*
|
sl@0
|
49 |
* Results:
|
sl@0
|
50 |
* None. This procedure never returns (it exits the process when
|
sl@0
|
51 |
* it's done.
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* Side effects:
|
sl@0
|
54 |
* This procedure initializes the Macintosh world and then
|
sl@0
|
55 |
* calls Tcl_Main. Tcl_Main will never return except to exit.
|
sl@0
|
56 |
*
|
sl@0
|
57 |
*----------------------------------------------------------------------
|
sl@0
|
58 |
*/
|
sl@0
|
59 |
|
sl@0
|
60 |
void
|
sl@0
|
61 |
main(
|
sl@0
|
62 |
int argc, /* Number of arguments. */
|
sl@0
|
63 |
char **argv) /* Array of argument strings. */
|
sl@0
|
64 |
{
|
sl@0
|
65 |
char *newArgv[2];
|
sl@0
|
66 |
|
sl@0
|
67 |
if (MacintoshInit() != TCL_OK) {
|
sl@0
|
68 |
Tcl_Exit(1);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
argc = 1;
|
sl@0
|
72 |
newArgv[0] = "tclsh";
|
sl@0
|
73 |
newArgv[1] = NULL;
|
sl@0
|
74 |
Tcl_Main(argc, newArgv, Tcl_AppInit);
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
/*
|
sl@0
|
78 |
*----------------------------------------------------------------------
|
sl@0
|
79 |
*
|
sl@0
|
80 |
* Tcl_AppInit --
|
sl@0
|
81 |
*
|
sl@0
|
82 |
* This procedure performs application-specific initialization.
|
sl@0
|
83 |
* Most applications, especially those that incorporate additional
|
sl@0
|
84 |
* packages, will have their own version of this procedure.
|
sl@0
|
85 |
*
|
sl@0
|
86 |
* Results:
|
sl@0
|
87 |
* Returns a standard Tcl completion code, and leaves an error
|
sl@0
|
88 |
* message in the interp's result if an error occurs.
|
sl@0
|
89 |
*
|
sl@0
|
90 |
* Side effects:
|
sl@0
|
91 |
* Depends on the startup script.
|
sl@0
|
92 |
*
|
sl@0
|
93 |
*----------------------------------------------------------------------
|
sl@0
|
94 |
*/
|
sl@0
|
95 |
|
sl@0
|
96 |
int
|
sl@0
|
97 |
Tcl_AppInit(
|
sl@0
|
98 |
Tcl_Interp *interp) /* Interpreter for application. */
|
sl@0
|
99 |
{
|
sl@0
|
100 |
if (Tcl_Init(interp) == TCL_ERROR) {
|
sl@0
|
101 |
return TCL_ERROR;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
#ifdef TCL_TEST
|
sl@0
|
105 |
if (Tcltest_Init(interp) == TCL_ERROR) {
|
sl@0
|
106 |
return TCL_ERROR;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
|
sl@0
|
109 |
(Tcl_PackageInitProc *) NULL);
|
sl@0
|
110 |
if (TclObjTest_Init(interp) == TCL_ERROR) {
|
sl@0
|
111 |
return TCL_ERROR;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
if (Procbodytest_Init(interp) == TCL_ERROR) {
|
sl@0
|
114 |
return TCL_ERROR;
|
sl@0
|
115 |
}
|
sl@0
|
116 |
Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init,
|
sl@0
|
117 |
Procbodytest_SafeInit);
|
sl@0
|
118 |
#endif /* TCL_TEST */
|
sl@0
|
119 |
|
sl@0
|
120 |
/*
|
sl@0
|
121 |
* Call the init procedures for included packages. Each call should
|
sl@0
|
122 |
* look like this:
|
sl@0
|
123 |
*
|
sl@0
|
124 |
* if (Mod_Init(interp) == TCL_ERROR) {
|
sl@0
|
125 |
* return TCL_ERROR;
|
sl@0
|
126 |
* }
|
sl@0
|
127 |
*
|
sl@0
|
128 |
* where "Mod" is the name of the module.
|
sl@0
|
129 |
*/
|
sl@0
|
130 |
|
sl@0
|
131 |
/*
|
sl@0
|
132 |
* Call Tcl_CreateCommand for application-specific commands, if
|
sl@0
|
133 |
* they weren't already created by the init procedures called above.
|
sl@0
|
134 |
* Each call would loo like this:
|
sl@0
|
135 |
*
|
sl@0
|
136 |
* Tcl_CreateCommand(interp, "tclName", CFuncCmd, NULL, NULL);
|
sl@0
|
137 |
*/
|
sl@0
|
138 |
|
sl@0
|
139 |
/*
|
sl@0
|
140 |
* Specify a user-specific startup script to invoke if the application
|
sl@0
|
141 |
* is run interactively. On the Mac we can specifiy either a TEXT resource
|
sl@0
|
142 |
* which contains the script or the more UNIX like file location
|
sl@0
|
143 |
* may also used. (I highly recommend using the resource method.)
|
sl@0
|
144 |
*/
|
sl@0
|
145 |
|
sl@0
|
146 |
Tcl_SetVar(interp, "tcl_rcRsrcName", "tclshrc", TCL_GLOBAL_ONLY);
|
sl@0
|
147 |
/* Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); */
|
sl@0
|
148 |
|
sl@0
|
149 |
return TCL_OK;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
/*
|
sl@0
|
153 |
*----------------------------------------------------------------------
|
sl@0
|
154 |
*
|
sl@0
|
155 |
* MacintoshInit --
|
sl@0
|
156 |
*
|
sl@0
|
157 |
* This procedure calls initalization routines to set up a simple
|
sl@0
|
158 |
* console on a Macintosh. This is necessary as the Mac doesn't
|
sl@0
|
159 |
* have a stdout & stderr by default.
|
sl@0
|
160 |
*
|
sl@0
|
161 |
* Results:
|
sl@0
|
162 |
* Returns TCL_OK if everything went fine. If it didn't the
|
sl@0
|
163 |
* application should probably fail.
|
sl@0
|
164 |
*
|
sl@0
|
165 |
* Side effects:
|
sl@0
|
166 |
* Inits the appropiate console package.
|
sl@0
|
167 |
*
|
sl@0
|
168 |
*----------------------------------------------------------------------
|
sl@0
|
169 |
*/
|
sl@0
|
170 |
|
sl@0
|
171 |
static int
|
sl@0
|
172 |
MacintoshInit()
|
sl@0
|
173 |
{
|
sl@0
|
174 |
#if GENERATING68K && !GENERATINGCFM
|
sl@0
|
175 |
SetApplLimit(GetApplLimit() - (TCL_MAC_68K_STACK_GROWTH));
|
sl@0
|
176 |
#endif
|
sl@0
|
177 |
MaxApplZone();
|
sl@0
|
178 |
|
sl@0
|
179 |
#if defined(THINK_C)
|
sl@0
|
180 |
|
sl@0
|
181 |
/* Set options for Think C console package */
|
sl@0
|
182 |
/* The console package calls the Mac init calls */
|
sl@0
|
183 |
console_options.pause_atexit = 0;
|
sl@0
|
184 |
console_options.title = "\pTcl Interpreter";
|
sl@0
|
185 |
|
sl@0
|
186 |
#elif defined(__MWERKS__)
|
sl@0
|
187 |
|
sl@0
|
188 |
/* Set options for CodeWarrior SIOUX package */
|
sl@0
|
189 |
SIOUXSettings.autocloseonquit = true;
|
sl@0
|
190 |
SIOUXSettings.showstatusline = true;
|
sl@0
|
191 |
SIOUXSettings.asktosaveonclose = false;
|
sl@0
|
192 |
SIOUXSettings.wasteusetempmemory = true;
|
sl@0
|
193 |
InstallConsole(0);
|
sl@0
|
194 |
SIOUXSetTitle("\pTcl Interpreter");
|
sl@0
|
195 |
|
sl@0
|
196 |
#elif defined(applec)
|
sl@0
|
197 |
|
sl@0
|
198 |
/* Init packages used by MPW SIOW package */
|
sl@0
|
199 |
InitGraf((Ptr)&qd.thePort);
|
sl@0
|
200 |
InitFonts();
|
sl@0
|
201 |
InitWindows();
|
sl@0
|
202 |
InitMenus();
|
sl@0
|
203 |
TEInit();
|
sl@0
|
204 |
InitDialogs(nil);
|
sl@0
|
205 |
InitCursor();
|
sl@0
|
206 |
|
sl@0
|
207 |
#endif
|
sl@0
|
208 |
|
sl@0
|
209 |
Tcl_MacSetEventProc((Tcl_MacConvertEventPtr) SIOUXHandleOneEvent);
|
sl@0
|
210 |
|
sl@0
|
211 |
/* No problems with initialization */
|
sl@0
|
212 |
return TCL_OK;
|
sl@0
|
213 |
}
|