[25] | 1 | /* |
---|
| 2 | * tclAppInit.c -- |
---|
| 3 | * |
---|
| 4 | * Provides a default version of the main program and Tcl_AppInit |
---|
| 5 | * function for Tcl applications (without Tk). |
---|
| 6 | * |
---|
| 7 | * Copyright (c) 1993 The Regents of the University of California. |
---|
| 8 | * Copyright (c) 1994-1997 Sun Microsystems, Inc. |
---|
| 9 | * Copyright (c) 1998-1999 by Scriptics Corporation. |
---|
| 10 | * |
---|
| 11 | * See the file "license.terms" for information on usage and redistribution of |
---|
| 12 | * this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 13 | * |
---|
| 14 | * RCS: @(#) $Id: tclAppInit.c,v 1.17 2007/04/16 13:36:35 dkf Exp $ |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include "tcl.h" |
---|
| 18 | |
---|
| 19 | #ifdef TCL_TEST |
---|
| 20 | |
---|
| 21 | #include "tclInt.h" |
---|
| 22 | |
---|
| 23 | extern Tcl_PackageInitProc Procbodytest_Init; |
---|
| 24 | extern Tcl_PackageInitProc Procbodytest_SafeInit; |
---|
| 25 | extern Tcl_PackageInitProc TclObjTest_Init; |
---|
| 26 | extern Tcl_PackageInitProc Tcltest_Init; |
---|
| 27 | |
---|
| 28 | #endif /* TCL_TEST */ |
---|
| 29 | |
---|
| 30 | #ifdef TCL_XT_TEST |
---|
| 31 | extern void XtToolkitInitialize _ANSI_ARGS_((void)); |
---|
| 32 | extern int Tclxttest_Init _ANSI_ARGS_((Tcl_Interp *interp)); |
---|
| 33 | #endif |
---|
| 34 | |
---|
| 35 | /* |
---|
| 36 | *---------------------------------------------------------------------- |
---|
| 37 | * |
---|
| 38 | * main -- |
---|
| 39 | * |
---|
| 40 | * This is the main program for the application. |
---|
| 41 | * |
---|
| 42 | * Results: |
---|
| 43 | * None: Tcl_Main never returns here, so this function never returns |
---|
| 44 | * either. |
---|
| 45 | * |
---|
| 46 | * Side effects: |
---|
| 47 | * Whatever the application does. |
---|
| 48 | * |
---|
| 49 | *---------------------------------------------------------------------- |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | int |
---|
| 53 | main( |
---|
| 54 | int argc, /* Number of command-line arguments. */ |
---|
| 55 | char **argv) /* Values of command-line arguments. */ |
---|
| 56 | { |
---|
| 57 | /* |
---|
| 58 | * The following #if block allows you to change the AppInit function by |
---|
| 59 | * using a #define of TCL_LOCAL_APPINIT instead of rewriting this entire |
---|
| 60 | * file. The #if checks for that #define and uses Tcl_AppInit if it does |
---|
| 61 | * not exist. |
---|
| 62 | */ |
---|
| 63 | |
---|
| 64 | #ifndef TCL_LOCAL_APPINIT |
---|
| 65 | #define TCL_LOCAL_APPINIT Tcl_AppInit |
---|
| 66 | #endif |
---|
| 67 | extern int TCL_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp)); |
---|
| 68 | |
---|
| 69 | /* |
---|
| 70 | * The following #if block allows you to change how Tcl finds the startup |
---|
| 71 | * script, prime the library or encoding paths, fiddle with the argv, |
---|
| 72 | * etc., without needing to rewrite Tcl_Main() |
---|
| 73 | */ |
---|
| 74 | |
---|
| 75 | #ifdef TCL_LOCAL_MAIN_HOOK |
---|
| 76 | extern int TCL_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv)); |
---|
| 77 | #endif |
---|
| 78 | |
---|
| 79 | #ifdef TCL_XT_TEST |
---|
| 80 | XtToolkitInitialize(); |
---|
| 81 | #endif |
---|
| 82 | |
---|
| 83 | #ifdef TCL_LOCAL_MAIN_HOOK |
---|
| 84 | TCL_LOCAL_MAIN_HOOK(&argc, &argv); |
---|
| 85 | #endif |
---|
| 86 | |
---|
| 87 | Tcl_Main(argc, argv, TCL_LOCAL_APPINIT); |
---|
| 88 | |
---|
| 89 | return 0; /* Needed only to prevent compiler warning. */ |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /* |
---|
| 93 | *---------------------------------------------------------------------- |
---|
| 94 | * |
---|
| 95 | * Tcl_AppInit -- |
---|
| 96 | * |
---|
| 97 | * This function performs application-specific initialization. Most |
---|
| 98 | * applications, especially those that incorporate additional packages, |
---|
| 99 | * will have their own version of this function. |
---|
| 100 | * |
---|
| 101 | * Results: |
---|
| 102 | * Returns a standard Tcl completion code, and leaves an error message in |
---|
| 103 | * the interp's result if an error occurs. |
---|
| 104 | * |
---|
| 105 | * Side effects: |
---|
| 106 | * Depends on the startup script. |
---|
| 107 | * |
---|
| 108 | *---------------------------------------------------------------------- |
---|
| 109 | */ |
---|
| 110 | |
---|
| 111 | int |
---|
| 112 | Tcl_AppInit( |
---|
| 113 | Tcl_Interp *interp) /* Interpreter for application. */ |
---|
| 114 | { |
---|
| 115 | if (Tcl_Init(interp) == TCL_ERROR) { |
---|
| 116 | return TCL_ERROR; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | #ifdef TCL_TEST |
---|
| 120 | #ifdef TCL_XT_TEST |
---|
| 121 | if (Tclxttest_Init(interp) == TCL_ERROR) { |
---|
| 122 | return TCL_ERROR; |
---|
| 123 | } |
---|
| 124 | #endif |
---|
| 125 | if (Tcltest_Init(interp) == TCL_ERROR) { |
---|
| 126 | return TCL_ERROR; |
---|
| 127 | } |
---|
| 128 | Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init, |
---|
| 129 | (Tcl_PackageInitProc *) NULL); |
---|
| 130 | if (TclObjTest_Init(interp) == TCL_ERROR) { |
---|
| 131 | return TCL_ERROR; |
---|
| 132 | } |
---|
| 133 | if (Procbodytest_Init(interp) == TCL_ERROR) { |
---|
| 134 | return TCL_ERROR; |
---|
| 135 | } |
---|
| 136 | Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init, |
---|
| 137 | Procbodytest_SafeInit); |
---|
| 138 | #endif /* TCL_TEST */ |
---|
| 139 | |
---|
| 140 | /* |
---|
| 141 | * Call the init functions for included packages. Each call should look |
---|
| 142 | * like this: |
---|
| 143 | * |
---|
| 144 | * if (Mod_Init(interp) == TCL_ERROR) { |
---|
| 145 | * return TCL_ERROR; |
---|
| 146 | * } |
---|
| 147 | * |
---|
| 148 | * where "Mod" is the name of the module. (Dynamically-loadable packages |
---|
| 149 | * should have the same entry-point name.) |
---|
| 150 | */ |
---|
| 151 | |
---|
| 152 | /* |
---|
| 153 | * Call Tcl_CreateCommand for application-specific commands, if they |
---|
| 154 | * weren't already created by the init functions called above. |
---|
| 155 | */ |
---|
| 156 | |
---|
| 157 | /* |
---|
| 158 | * Specify a user-specific startup file to invoke if the application is |
---|
| 159 | * run interactively. Typically the startup file is "~/.apprc" where "app" |
---|
| 160 | * is the name of the application. If this line is deleted then no user- |
---|
| 161 | * specific startup file will be run under any conditions. |
---|
| 162 | */ |
---|
| 163 | |
---|
| 164 | #ifdef DJGPP |
---|
| 165 | Tcl_SetVar(interp, "tcl_rcFileName", "~/tclsh.rc", TCL_GLOBAL_ONLY); |
---|
| 166 | #else |
---|
| 167 | Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); |
---|
| 168 | #endif |
---|
| 169 | |
---|
| 170 | return TCL_OK; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | /* |
---|
| 174 | * Local Variables: |
---|
| 175 | * mode: c |
---|
| 176 | * c-basic-offset: 4 |
---|
| 177 | * fill-column: 78 |
---|
| 178 | * End: |
---|
| 179 | */ |
---|