1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * This is a support file needed to build a new version of Wish.
8 * Normally, this capability is found in TkAppInit.c, but this creates
9 * tons of namespace problems for many applications.
10 * ----------------------------------------------------------------------------- */
13 #include <ToolUtils.h>
23 typedef int (*TclMacConvertEventPtr) _ANSI_ARGS_((EventRecord *eventPtr));
24 Tcl_Interp *gStdoutInterp = NULL;
26 void TclMacSetEventProc _ANSI_ARGS_((TclMacConvertEventPtr procPtr));
27 int TkMacConvertEvent _ANSI_ARGS_((EventRecord *eventPtr));
30 * Prototypes for functions the ANSI library needs to link against.
32 short InstallConsole _ANSI_ARGS_((short fd));
33 void RemoveConsole _ANSI_ARGS_((void));
34 long WriteCharsToConsole _ANSI_ARGS_((char *buff, long n));
35 long ReadCharsFromConsole _ANSI_ARGS_((char *buff, long n));
36 char * __ttyname _ANSI_ARGS_((long fildes));
37 short SIOUXHandleOneEvent _ANSI_ARGS_((EventRecord *event));
40 * Forward declarations for procedures defined later in this file:
44 *----------------------------------------------------------------------
48 * This procedure calls Mac specific initilization calls. Most of
49 * these calls must be made as soon as possible in the startup
53 * Returns TCL_OK if everything went fine. If it didn't the
54 * application should probably fail.
57 * Inits the application.
59 *----------------------------------------------------------------------
66 long result, mask = 0x0700; /* mask = system 7.x */
69 * Tk needs us to set the qd pointer it uses. This is needed
70 * so Tk doesn't have to assume the availablity of the qd global
71 * variable. Which in turn allows Tk to be used in code resources.
75 InitGraf(&tcl_macQdPtr->thePort);
79 InitDialogs((long) NULL);
83 * Make sure we are running on system 7 or higher
86 if ((NGetTrapAddress(_Gestalt, ToolTrap) ==
87 NGetTrapAddress(_Unimplemented, ToolTrap))
88 || (((Gestalt(gestaltSystemVersion, &result) != noErr)
89 || (mask != (result & mask))))) {
90 panic("Tcl/Tk requires System 7 or higher.");
94 * Make sure we have color quick draw
95 * (this means we can't run on 68000 macs)
98 if (((Gestalt(gestaltQuickdrawVersion, &result) != noErr)
99 || (result < gestalt32BitQD13))) {
100 panic("Tk requires Color QuickDraw.");
104 FlushEvents(everyEvent, 0);
105 SetEventMask(everyEvent);
108 * Set up stack & heap sizes
112 SetAppLimit(GetAppLimit() - 8192);
115 for (i = 0; i < 4; i++) {
116 (void) MoreMasters();
119 TclMacSetEventProc(TkMacConvertEvent);
126 *----------------------------------------------------------------------
130 * This procedure calls initalization routines require a Tcl
131 * interp as an argument. This call effectively makes the passed
132 * iterpreter the "main" interpreter for the application.
135 * Returns TCL_OK if everything went fine. If it didn't the
136 * application should probably fail.
139 * More initilization.
141 *----------------------------------------------------------------------
149 * Initialize the console only if we are running as an interactive
153 TkMacInitAppleEvents(interp);
154 TkMacInitMenus(interp);
156 if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1")
158 if (TkConsoleInit(interp) == TCL_ERROR) {
164 * Attach the global interpreter to tk's expected global console
167 gStdoutInterp = interp;
172 panic(interp->result);
177 *----------------------------------------------------------------------
179 * InstallConsole, RemoveConsole, etc. --
181 * The following functions provide the UI for the console package.
182 * Users wishing to replace SIOUX with their own console package
183 * need only provide the four functions below in a library.
186 * See SIOUX documentation for details.
189 * See SIOUX documentation for details.
191 *----------------------------------------------------------------------
195 InstallConsole(short fd)
208 WriteCharsToConsole(char *buffer, long n)
210 TkConsolePrint(gStdoutInterp, TCL_STDOUT, buffer, n);
215 ReadCharsFromConsole(char *buffer, long n)
221 __ttyname(long fildes)
223 static char *devicename = "null device";
225 if (fildes >= 0 && fildes <= 2) {
233 SIOUXHandleOneEvent(EventRecord *event)