sl@0: /* sl@0: * tclMacAppInit.c -- sl@0: * sl@0: * Provides a version of the Tcl_AppInit procedure for the example shell. sl@0: * sl@0: * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center sl@0: * Copyright (c) 1995-1997 Sun Microsystems, Inc. sl@0: * sl@0: * See the file "license.terms" for information on usage and redistribution sl@0: * of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: * sl@0: * RCS: @(#) $Id: tclMacAppInit.c,v 1.9 2001/11/23 01:27:13 das Exp $ sl@0: */ sl@0: sl@0: #include "tcl.h" sl@0: #include "tclInt.h" sl@0: #include "tclPort.h" sl@0: #include "tclMac.h" sl@0: #include "tclMacInt.h" sl@0: sl@0: #if defined(THINK_C) sl@0: # include sl@0: #elif defined(__MWERKS__) sl@0: # include sl@0: EXTERN short InstallConsole _ANSI_ARGS_((short fd)); sl@0: #endif sl@0: sl@0: #ifdef TCL_TEST sl@0: extern int Procbodytest_Init _ANSI_ARGS_((Tcl_Interp *interp)); sl@0: extern int Procbodytest_SafeInit _ANSI_ARGS_((Tcl_Interp *interp)); sl@0: extern int TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp)); sl@0: extern int Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp)); sl@0: #endif /* TCL_TEST */ sl@0: sl@0: /* sl@0: * Forward declarations for procedures defined later in this file: sl@0: */ sl@0: sl@0: static int MacintoshInit _ANSI_ARGS_((void)); sl@0: sl@0: /* sl@0: *---------------------------------------------------------------------- sl@0: * sl@0: * main -- sl@0: * sl@0: * Main program for tclsh. This file can be used as a prototype sl@0: * for other applications using the Tcl library. sl@0: * sl@0: * Results: sl@0: * None. This procedure never returns (it exits the process when sl@0: * it's done. sl@0: * sl@0: * Side effects: sl@0: * This procedure initializes the Macintosh world and then sl@0: * calls Tcl_Main. Tcl_Main will never return except to exit. sl@0: * sl@0: *---------------------------------------------------------------------- sl@0: */ sl@0: sl@0: void sl@0: main( sl@0: int argc, /* Number of arguments. */ sl@0: char **argv) /* Array of argument strings. */ sl@0: { sl@0: char *newArgv[2]; sl@0: sl@0: if (MacintoshInit() != TCL_OK) { sl@0: Tcl_Exit(1); sl@0: } sl@0: sl@0: argc = 1; sl@0: newArgv[0] = "tclsh"; sl@0: newArgv[1] = NULL; sl@0: Tcl_Main(argc, newArgv, Tcl_AppInit); sl@0: } sl@0: sl@0: /* sl@0: *---------------------------------------------------------------------- sl@0: * sl@0: * Tcl_AppInit -- sl@0: * sl@0: * This procedure performs application-specific initialization. sl@0: * Most applications, especially those that incorporate additional sl@0: * packages, will have their own version of this procedure. sl@0: * sl@0: * Results: sl@0: * Returns a standard Tcl completion code, and leaves an error sl@0: * message in the interp's result if an error occurs. sl@0: * sl@0: * Side effects: sl@0: * Depends on the startup script. sl@0: * sl@0: *---------------------------------------------------------------------- sl@0: */ sl@0: sl@0: int sl@0: Tcl_AppInit( sl@0: Tcl_Interp *interp) /* Interpreter for application. */ sl@0: { sl@0: if (Tcl_Init(interp) == TCL_ERROR) { sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: #ifdef TCL_TEST sl@0: if (Tcltest_Init(interp) == TCL_ERROR) { sl@0: return TCL_ERROR; sl@0: } sl@0: Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init, sl@0: (Tcl_PackageInitProc *) NULL); sl@0: if (TclObjTest_Init(interp) == TCL_ERROR) { sl@0: return TCL_ERROR; sl@0: } sl@0: if (Procbodytest_Init(interp) == TCL_ERROR) { sl@0: return TCL_ERROR; sl@0: } sl@0: Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init, sl@0: Procbodytest_SafeInit); sl@0: #endif /* TCL_TEST */ sl@0: sl@0: /* sl@0: * Call the init procedures for included packages. Each call should sl@0: * look like this: sl@0: * sl@0: * if (Mod_Init(interp) == TCL_ERROR) { sl@0: * return TCL_ERROR; sl@0: * } sl@0: * sl@0: * where "Mod" is the name of the module. sl@0: */ sl@0: sl@0: /* sl@0: * Call Tcl_CreateCommand for application-specific commands, if sl@0: * they weren't already created by the init procedures called above. sl@0: * Each call would loo like this: sl@0: * sl@0: * Tcl_CreateCommand(interp, "tclName", CFuncCmd, NULL, NULL); sl@0: */ sl@0: sl@0: /* sl@0: * Specify a user-specific startup script to invoke if the application sl@0: * is run interactively. On the Mac we can specifiy either a TEXT resource sl@0: * which contains the script or the more UNIX like file location sl@0: * may also used. (I highly recommend using the resource method.) sl@0: */ sl@0: sl@0: Tcl_SetVar(interp, "tcl_rcRsrcName", "tclshrc", TCL_GLOBAL_ONLY); sl@0: /* Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); */ sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: *---------------------------------------------------------------------- sl@0: * sl@0: * MacintoshInit -- sl@0: * sl@0: * This procedure calls initalization routines to set up a simple sl@0: * console on a Macintosh. This is necessary as the Mac doesn't sl@0: * have a stdout & stderr by default. sl@0: * sl@0: * Results: sl@0: * Returns TCL_OK if everything went fine. If it didn't the sl@0: * application should probably fail. sl@0: * sl@0: * Side effects: sl@0: * Inits the appropiate console package. sl@0: * sl@0: *---------------------------------------------------------------------- sl@0: */ sl@0: sl@0: static int sl@0: MacintoshInit() sl@0: { sl@0: #if GENERATING68K && !GENERATINGCFM sl@0: SetApplLimit(GetApplLimit() - (TCL_MAC_68K_STACK_GROWTH)); sl@0: #endif sl@0: MaxApplZone(); sl@0: sl@0: #if defined(THINK_C) sl@0: sl@0: /* Set options for Think C console package */ sl@0: /* The console package calls the Mac init calls */ sl@0: console_options.pause_atexit = 0; sl@0: console_options.title = "\pTcl Interpreter"; sl@0: sl@0: #elif defined(__MWERKS__) sl@0: sl@0: /* Set options for CodeWarrior SIOUX package */ sl@0: SIOUXSettings.autocloseonquit = true; sl@0: SIOUXSettings.showstatusline = true; sl@0: SIOUXSettings.asktosaveonclose = false; sl@0: SIOUXSettings.wasteusetempmemory = true; sl@0: InstallConsole(0); sl@0: SIOUXSetTitle("\pTcl Interpreter"); sl@0: sl@0: #elif defined(applec) sl@0: sl@0: /* Init packages used by MPW SIOW package */ sl@0: InitGraf((Ptr)&qd.thePort); sl@0: InitFonts(); sl@0: InitWindows(); sl@0: InitMenus(); sl@0: TEInit(); sl@0: InitDialogs(nil); sl@0: InitCursor(); sl@0: sl@0: #endif sl@0: sl@0: Tcl_MacSetEventProc((Tcl_MacConvertEventPtr) SIOUXHandleOneEvent); sl@0: sl@0: /* No problems with initialization */ sl@0: return TCL_OK; sl@0: }