1 /* This is a support file needed to build a new version of Wish 
   2    Normally, this capability is found in TkAppInit.c, but this creates 
   3    tons of namespace problems for many applications. */ 
  16 typedef int (*TclMacConvertEventPtr
) _ANSI_ARGS_((EventRecord 
*eventPtr
)); 
  17 Tcl_Interp 
*gStdoutInterp 
= NULL
; 
  19 void    TclMacSetEventProc 
_ANSI_ARGS_((TclMacConvertEventPtr procPtr
)); 
  20 int     TkMacConvertEvent 
_ANSI_ARGS_((EventRecord 
*eventPtr
)); 
  23  * Prototypes for functions the ANSI library needs to link against. 
  25 short                   InstallConsole 
_ANSI_ARGS_((short fd
)); 
  26 void                    RemoveConsole 
_ANSI_ARGS_((void)); 
  27 long                    WriteCharsToConsole 
_ANSI_ARGS_((char *buff
, long n
)); 
  28 long                    ReadCharsFromConsole 
_ANSI_ARGS_((char *buff
, long n
)); 
  29 extern char *           __ttyname 
_ANSI_ARGS_((long fildes
)); 
  30 short                   SIOUXHandleOneEvent 
_ANSI_ARGS_((EventRecord 
*event
)); 
  33  * Forward declarations for procedures defined later in this file: 
  37  *---------------------------------------------------------------------- 
  41  *      This procedure calls Mac specific initilization calls.  Most of 
  42  *      these calls must be made as soon as possible in the startup 
  46  *      Returns TCL_OK if everything went fine.  If it didn't the  
  47  *      application should probably fail. 
  50  *      Inits the application. 
  52  *---------------------------------------------------------------------- 
  59     long result
, mask 
= 0x0700;                 /* mask = system 7.x */ 
  62      * Tk needs us to set the qd pointer it uses.  This is needed 
  63      * so Tk doesn't have to assume the availablity of the qd global 
  64      * variable.  Which in turn allows Tk to be used in code resources. 
  68     InitGraf(&tcl_macQdPtr
->thePort
); 
  72     InitDialogs((long) NULL
);            
  76      * Make sure we are running on system 7 or higher 
  79     if ((NGetTrapAddress(_Gestalt
, ToolTrap
) ==  
  80             NGetTrapAddress(_Unimplemented
, ToolTrap
)) 
  81             || (((Gestalt(gestaltSystemVersion
, &result
) != noErr
) 
  82             || (mask 
!= (result 
& mask
))))) { 
  83         panic("Tcl/Tk requires System 7 or higher."); 
  87      * Make sure we have color quick draw  
  88      * (this means we can't run on 68000 macs) 
  91     if (((Gestalt(gestaltQuickdrawVersion
, &result
) != noErr
) 
  92             || (result 
< gestalt32BitQD13
))) { 
  93         panic("Tk requires Color QuickDraw."); 
  97     FlushEvents(everyEvent
, 0); 
  98     SetEventMask(everyEvent
); 
 101      * Set up stack & heap sizes 
 105        SetAppLimit(GetAppLimit() - 8192); 
 108     for (i 
= 0; i 
< 4; i
++) { 
 109         (void) MoreMasters(); 
 112     TclMacSetEventProc(TkMacConvertEvent
); 
 119  *---------------------------------------------------------------------- 
 123  *      This procedure calls initalization routines require a Tcl  
 124  *      interp as an argument.  This call effectively makes the passed 
 125  *      iterpreter the "main" interpreter for the application. 
 128  *      Returns TCL_OK if everything went fine.  If it didn't the  
 129  *      application should probably fail. 
 132  *      More initilization. 
 134  *---------------------------------------------------------------------- 
 142      * Initialize the console only if we are running as an interactive 
 146     TkMacInitAppleEvents(interp
); 
 147     TkMacInitMenus(interp
); 
 149     if (strcmp(Tcl_GetVar(interp
, "tcl_interactive", TCL_GLOBAL_ONLY
), "1") 
 151         if (TkConsoleInit(interp
) == TCL_ERROR
) { 
 157      * Attach the global interpreter to tk's expected global console 
 160     gStdoutInterp 
= interp
; 
 165     panic(interp
->result
); 
 170  *---------------------------------------------------------------------- 
 172  * InstallConsole, RemoveConsole, etc. -- 
 174  *      The following functions provide the UI for the console package. 
 175  *      Users wishing to replace SIOUX with their own console package  
 176  *      need only provide the four functions below in a library. 
 179  *      See SIOUX documentation for details. 
 182  *      See SIOUX documentation for details. 
 184  *---------------------------------------------------------------------- 
 188 InstallConsole(short fd
) 
 201 WriteCharsToConsole(char *buffer
, long n
) 
 203     TkConsolePrint(gStdoutInterp
, TCL_STDOUT
, buffer
, n
); 
 208 ReadCharsFromConsole(char *buffer
, long n
) 
 214 __ttyname(long fildes
) 
 216     static char *__devicename 
= "null device"; 
 218     if (fildes 
>= 0 && fildes 
<= 2) { 
 219         return (__devicename
); 
 226 SIOUXHandleOneEvent(EventRecord 
*event
)