os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/mac/tclMacBOAAppInit.c
First public contribution.
2 * tclMacBOAAppInit.c --
4 * Provides a version of the Tcl_AppInit procedure for a
5 * Macintosh Background Only Application.
7 * Copyright (c) 1997 Sun Microsystems, Inc.
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 * RCS: @(#) $Id: tclMacBOAAppInit.c,v 1.5 2001/06/14 00:48:51 dgp Exp $
19 #include "tclMacInt.h"
27 #include <AppleEvents.h>
29 #include <ToolUtils.h>
33 #elif defined(__MWERKS__)
35 short InstallConsole _ANSI_ARGS_((short fd));
38 void TkMacInitAppleEvents(Tcl_Interp *interp);
39 int HandleHighLevelEvents(EventRecord *eventPtr);
42 EXTERN int TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
43 EXTERN int Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
47 * Forward declarations for procedures defined later in this file:
50 static int MacintoshInit _ANSI_ARGS_((void));
53 *----------------------------------------------------------------------
57 * Main program for tclsh. This file can be used as a prototype
58 * for other applications using the Tcl library.
61 * None. This procedure never returns (it exits the process when
65 * This procedure initializes the Macintosh world and then
66 * calls Tcl_Main. Tcl_Main will never return except to exit.
68 *----------------------------------------------------------------------
73 int argc, /* Number of arguments. */
74 char **argv) /* Array of argument strings. */
78 if (MacintoshInit() != TCL_OK) {
84 newArgv[1] = "bgScript.tcl";
86 Tcl_Main(argc, newArgv, Tcl_AppInit);
90 *----------------------------------------------------------------------
94 * This procedure performs application-specific initialization.
95 * Most applications, especially those that incorporate additional
96 * packages, will have their own version of this procedure.
99 * Returns a standard Tcl completion code, and leaves an error
100 * message in the interp's result if an error occurs.
103 * Depends on the startup script.
105 *----------------------------------------------------------------------
110 Tcl_Interp *interp) /* Interpreter for application. */
112 Tcl_Channel tempChan;
114 if (Tcl_Init(interp) == TCL_ERROR) {
119 if (Tcltest_Init(interp) == TCL_ERROR) {
122 Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
123 (Tcl_PackageInitProc *) NULL);
124 if (TclObjTest_Init(interp) == TCL_ERROR) {
127 #endif /* TCL_TEST */
130 * Call the init procedures for included packages. Each call should
133 * if (Mod_Init(interp) == TCL_ERROR) {
137 * where "Mod" is the name of the module.
141 * Call Tcl_CreateCommand for application-specific commands, if
142 * they weren't already created by the init procedures called above.
143 * Each call would loo like this:
145 * Tcl_CreateCommand(interp, "tclName", CFuncCmd, NULL, NULL);
149 * Specify a user-specific startup script to invoke if the application
150 * is run interactively. On the Mac we can specifiy either a TEXT resource
151 * which contains the script or the more UNIX like file location
152 * may also used. (I highly recommend using the resource method.)
155 Tcl_SetVar(interp, "tcl_rcRsrcName", "tclshrc", TCL_GLOBAL_ONLY);
157 /* Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); */
160 * We have to support at least the quit Apple Event.
163 TkMacInitAppleEvents(interp);
166 * Open a file channel to put stderr, stdin, stdout...
169 tempChan = Tcl_OpenFileChannel(interp, ":temp.in", "a+", 0);
170 Tcl_SetStdChannel(tempChan,TCL_STDIN);
171 Tcl_RegisterChannel(interp, tempChan);
172 Tcl_SetChannelOption(NULL, tempChan, "-translation", "cr");
173 Tcl_SetChannelOption(NULL, tempChan, "-buffering", "line");
175 tempChan = Tcl_OpenFileChannel(interp, ":temp.out", "a+", 0);
176 Tcl_SetStdChannel(tempChan,TCL_STDOUT);
177 Tcl_RegisterChannel(interp, tempChan);
178 Tcl_SetChannelOption(NULL, tempChan, "-translation", "cr");
179 Tcl_SetChannelOption(NULL, tempChan, "-buffering", "line");
181 tempChan = Tcl_OpenFileChannel(interp, ":temp.err", "a+", 0);
182 Tcl_SetStdChannel(tempChan,TCL_STDERR);
183 Tcl_RegisterChannel(interp, tempChan);
184 Tcl_SetChannelOption(NULL, tempChan, "-translation", "cr");
185 Tcl_SetChannelOption(NULL, tempChan, "-buffering", "none");
192 *----------------------------------------------------------------------
196 * This procedure calls initalization routines to set up a simple
197 * console on a Macintosh. This is necessary as the Mac doesn't
198 * have a stdout & stderr by default.
201 * Returns TCL_OK if everything went fine. If it didn't the
202 * application should probably fail.
205 * Inits the appropiate console package.
207 *----------------------------------------------------------------------
213 THz theZone = GetZone();
218 * There is a bug in systems earlier that 7.5.5, where a second BOA will
219 * get a corrupted heap. This is the fix from TechNote 1070
222 SysEnvirons(1, &sys);
224 if (sys.systemVersion < 0x0755)
226 if ( LMGetHeapEnd() != theZone->bkLim) {
227 LMSetHeapEnd(theZone->bkLim);
231 #if GENERATING68K && !GENERATINGCFM
232 SetApplLimit(GetApplLimit() - (TCL_MAC_68K_STACK_GROWTH));
236 InitGraf((Ptr)&qd.thePort);
238 /* No problems with initialization */
239 Tcl_MacSetEventProc(HandleHighLevelEvents);
245 HandleHighLevelEvents(
246 EventRecord *eventPtr)
248 int eventFound = false;
250 if (eventPtr->what == kHighLevelEvent) {
251 AEProcessAppleEvent(eventPtr);
253 } else if (eventPtr->what == nullEvent) {