sl@0: /* sl@0: * tclAppInit.c -- sl@0: * sl@0: * Provides a default version of the main program and Tcl_AppInit sl@0: * procedure for Tcl applications (without Tk). sl@0: * sl@0: * Copyright (c) 1993 The Regents of the University of California. sl@0: * Copyright (c) 1994-1997 Sun Microsystems, Inc. sl@0: * Copyright (c) 1998-1999 by Scriptics Corporation. 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: tclAppInit.c,v 1.11 2002/05/31 22:20:22 dgp Exp $ sl@0: */ sl@0: sl@0: #include "tcl.h" sl@0: sl@0: #ifdef TCL_TEST sl@0: sl@0: #include "tclInt.h" sl@0: 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: #ifdef TCL_THREADS sl@0: extern int TclThread_Init _ANSI_ARGS_((Tcl_Interp *interp)); sl@0: #endif sl@0: sl@0: #endif /* TCL_TEST */ sl@0: sl@0: #ifdef TCL_XT_TEST sl@0: extern void XtToolkitInitialize _ANSI_ARGS_((void)); sl@0: extern int Tclxttest_Init _ANSI_ARGS_((Tcl_Interp *interp)); sl@0: #endif sl@0: sl@0: /* sl@0: *---------------------------------------------------------------------- sl@0: * sl@0: * main -- sl@0: * sl@0: * This is the main program for the application. sl@0: * sl@0: * Results: sl@0: * None: Tcl_Main never returns here, so this procedure never sl@0: * returns either. sl@0: * sl@0: * Side effects: sl@0: * Whatever the application does. sl@0: * sl@0: *---------------------------------------------------------------------- sl@0: */ sl@0: sl@0: int sl@0: main(argc, argv) sl@0: int argc; /* Number of command-line arguments. */ sl@0: char **argv; /* Values of command-line arguments. */ sl@0: { sl@0: /* sl@0: * The following #if block allows you to change the AppInit sl@0: * function by using a #define of TCL_LOCAL_APPINIT instead sl@0: * of rewriting this entire file. The #if checks for that sl@0: * #define and uses Tcl_AppInit if it doesn't exist. sl@0: */ sl@0: sl@0: #ifndef TCL_LOCAL_APPINIT sl@0: #define TCL_LOCAL_APPINIT Tcl_AppInit sl@0: #endif sl@0: extern int TCL_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp)); sl@0: sl@0: /* sl@0: * The following #if block allows you to change how Tcl finds the startup sl@0: * script, prime the library or encoding paths, fiddle with the argv, sl@0: * etc., without needing to rewrite Tcl_Main() sl@0: */ sl@0: sl@0: #ifdef TCL_LOCAL_MAIN_HOOK sl@0: extern int TCL_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv)); sl@0: #endif sl@0: sl@0: #ifdef TCL_XT_TEST sl@0: XtToolkitInitialize(); sl@0: #endif sl@0: sl@0: #ifdef TCL_LOCAL_MAIN_HOOK sl@0: TCL_LOCAL_MAIN_HOOK(&argc, &argv); sl@0: #endif sl@0: sl@0: Tcl_Main(argc, argv, TCL_LOCAL_APPINIT); sl@0: sl@0: return 0; /* Needed only to prevent compiler warning. */ 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(interp) 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: #ifdef TCL_XT_TEST sl@0: if (Tclxttest_Init(interp) == TCL_ERROR) { sl@0: return TCL_ERROR; sl@0: } sl@0: #endif 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: #ifdef TCL_THREADS sl@0: if (TclThread_Init(interp) == TCL_ERROR) { sl@0: return TCL_ERROR; sl@0: } sl@0: #endif 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: */ sl@0: sl@0: /* sl@0: * Specify a user-specific startup file to invoke if the application sl@0: * is run interactively. Typically the startup file is "~/.apprc" sl@0: * where "app" is the name of the application. If this line is deleted sl@0: * then no user-specific startup file will be run under any conditions. sl@0: */ sl@0: sl@0: #ifdef DJGPP sl@0: Tcl_SetVar(interp, "tcl_rcFileName", "~/tclsh.rc", TCL_GLOBAL_ONLY); sl@0: #else sl@0: Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); sl@0: #endif sl@0: return TCL_OK; sl@0: }