tclAppInit.c

Go to the documentation of this file.
00001 /*
00002  * tclAppInit.c --
00003  *
00004  *      Provides a default version of the main program and Tcl_AppInit
00005  *      function for Tcl applications (without Tk).
00006  *
00007  * Copyright (c) 1993 The Regents of the University of California.
00008  * Copyright (c) 1994-1997 Sun Microsystems, Inc.
00009  * Copyright (c) 1998-1999 by Scriptics Corporation.
00010  *
00011  * See the file "license.terms" for information on usage and redistribution of
00012  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
00013  *
00014  * RCS: @(#) $Id: tclAppInit.c,v 1.17 2007/04/16 13:36:35 dkf Exp $
00015  */
00016 
00017 #include "tcl.h"
00018 
00019 #ifdef TCL_TEST
00020 
00021 #include "tclInt.h"
00022 
00023 extern Tcl_PackageInitProc      Procbodytest_Init;
00024 extern Tcl_PackageInitProc      Procbodytest_SafeInit;
00025 extern Tcl_PackageInitProc      TclObjTest_Init;
00026 extern Tcl_PackageInitProc      Tcltest_Init;
00027 
00028 #endif /* TCL_TEST */
00029 
00030 #ifdef TCL_XT_TEST
00031 extern void             XtToolkitInitialize _ANSI_ARGS_((void));
00032 extern int              Tclxttest_Init _ANSI_ARGS_((Tcl_Interp *interp));
00033 #endif
00034 
00035 /*
00036  *----------------------------------------------------------------------
00037  *
00038  * main --
00039  *
00040  *      This is the main program for the application.
00041  *
00042  * Results:
00043  *      None: Tcl_Main never returns here, so this function never returns
00044  *      either.
00045  *
00046  * Side effects:
00047  *      Whatever the application does.
00048  *
00049  *----------------------------------------------------------------------
00050  */
00051 
00052 int
00053 main(
00054     int argc,                   /* Number of command-line arguments. */
00055     char **argv)                /* Values of command-line arguments. */
00056 {
00057     /*
00058      * The following #if block allows you to change the AppInit function by
00059      * using a #define of TCL_LOCAL_APPINIT instead of rewriting this entire
00060      * file. The #if checks for that #define and uses Tcl_AppInit if it does
00061      * not exist.
00062      */
00063 
00064 #ifndef TCL_LOCAL_APPINIT
00065 #define TCL_LOCAL_APPINIT Tcl_AppInit
00066 #endif
00067     extern int TCL_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp));
00068 
00069     /*
00070      * The following #if block allows you to change how Tcl finds the startup
00071      * script, prime the library or encoding paths, fiddle with the argv,
00072      * etc., without needing to rewrite Tcl_Main()
00073      */
00074 
00075 #ifdef TCL_LOCAL_MAIN_HOOK
00076     extern int TCL_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv));
00077 #endif
00078 
00079 #ifdef TCL_XT_TEST
00080     XtToolkitInitialize();
00081 #endif
00082 
00083 #ifdef TCL_LOCAL_MAIN_HOOK
00084     TCL_LOCAL_MAIN_HOOK(&argc, &argv);
00085 #endif
00086 
00087     Tcl_Main(argc, argv, TCL_LOCAL_APPINIT);
00088 
00089     return 0;                   /* Needed only to prevent compiler warning. */
00090 }
00091 
00092 /*
00093  *----------------------------------------------------------------------
00094  *
00095  * Tcl_AppInit --
00096  *
00097  *      This function performs application-specific initialization. Most
00098  *      applications, especially those that incorporate additional packages,
00099  *      will have their own version of this function.
00100  *
00101  * Results:
00102  *      Returns a standard Tcl completion code, and leaves an error message in
00103  *      the interp's result if an error occurs.
00104  *
00105  * Side effects:
00106  *      Depends on the startup script.
00107  *
00108  *----------------------------------------------------------------------
00109  */
00110 
00111 int
00112 Tcl_AppInit(
00113     Tcl_Interp *interp)         /* Interpreter for application. */
00114 {
00115     if (Tcl_Init(interp) == TCL_ERROR) {
00116         return TCL_ERROR;
00117     }
00118 
00119 #ifdef TCL_TEST
00120 #ifdef TCL_XT_TEST
00121     if (Tclxttest_Init(interp) == TCL_ERROR) {
00122         return TCL_ERROR;
00123     }
00124 #endif
00125     if (Tcltest_Init(interp) == TCL_ERROR) {
00126         return TCL_ERROR;
00127     }
00128     Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
00129             (Tcl_PackageInitProc *) NULL);
00130     if (TclObjTest_Init(interp) == TCL_ERROR) {
00131         return TCL_ERROR;
00132     }
00133     if (Procbodytest_Init(interp) == TCL_ERROR) {
00134         return TCL_ERROR;
00135     }
00136     Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init,
00137             Procbodytest_SafeInit);
00138 #endif /* TCL_TEST */
00139 
00140     /*
00141      * Call the init functions for included packages. Each call should look
00142      * like this:
00143      *
00144      * if (Mod_Init(interp) == TCL_ERROR) {
00145      *     return TCL_ERROR;
00146      * }
00147      *
00148      * where "Mod" is the name of the module. (Dynamically-loadable packages
00149      * should have the same entry-point name.)
00150      */
00151 
00152     /*
00153      * Call Tcl_CreateCommand for application-specific commands, if they
00154      * weren't already created by the init functions called above.
00155      */
00156 
00157     /*
00158      * Specify a user-specific startup file to invoke if the application is
00159      * run interactively. Typically the startup file is "~/.apprc" where "app"
00160      * is the name of the application. If this line is deleted then no user-
00161      * specific startup file will be run under any conditions.
00162      */
00163 
00164 #ifdef DJGPP
00165     Tcl_SetVar(interp, "tcl_rcFileName", "~/tclsh.rc", TCL_GLOBAL_ONLY);
00166 #else
00167     Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);
00168 #endif
00169 
00170     return TCL_OK;
00171 }
00172 
00173 /*
00174  * Local Variables:
00175  * mode: c
00176  * c-basic-offset: 4
00177  * fill-column: 78
00178  * End:
00179  */



Generated on Wed Mar 12 12:18:25 2008 by  doxygen 1.5.1