tkAppInit.c (4191B)
1 /* 2 * tkAppInit.c -- 3 * 4 * Provides a default version of the main program and Tcl_AppInit 5 * procedure for wish and other Tk-based applications. 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 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 15 #undef BUILD_tk 16 #undef STATIC_BUILD 17 #include "tk.h" 18 19 #ifdef TK_TEST 20 extern Tcl_PackageInitProc Tktest_Init; 21 #endif /* TK_TEST */ 22 23 /* 24 * The following #if block allows you to change the AppInit function by using 25 * a #define of TCL_LOCAL_APPINIT instead of rewriting this entire file. The 26 * #if checks for that #define and uses Tcl_AppInit if it doesn't exist. 27 */ 28 29 #ifndef TK_LOCAL_APPINIT 30 #define TK_LOCAL_APPINIT Tcl_AppInit 31 #endif 32 #ifndef MODULE_SCOPE 33 # define MODULE_SCOPE extern 34 #endif 35 MODULE_SCOPE int TK_LOCAL_APPINIT(Tcl_Interp *); 36 MODULE_SCOPE int main(int, char **); 37 38 /* 39 * The following #if block allows you to change how Tcl finds the startup 40 * script, prime the library or encoding paths, fiddle with the argv, etc., 41 * without needing to rewrite Tk_Main() 42 */ 43 44 #ifdef TK_LOCAL_MAIN_HOOK 45 MODULE_SCOPE int TK_LOCAL_MAIN_HOOK(int *argc, char ***argv); 46 #endif 47 48 /* Make sure the stubbed variants of those are never used. */ 49 #undef Tcl_ObjSetVar2 50 #undef Tcl_NewStringObj 51 52 /* 53 *---------------------------------------------------------------------- 54 * 55 * main -- 56 * 57 * This is the main program for the application. 58 * 59 * Results: 60 * None: Tk_Main never returns here, so this procedure never returns 61 * either. 62 * 63 * Side effects: 64 * Just about anything, since from here we call arbitrary Tcl code. 65 * 66 *---------------------------------------------------------------------- 67 */ 68 69 int 70 main( 71 int argc, /* Number of command-line arguments. */ 72 char **argv) /* Values of command-line arguments. */ 73 { 74 #ifdef TK_LOCAL_MAIN_HOOK 75 TK_LOCAL_MAIN_HOOK(&argc, &argv); 76 #endif 77 78 Tk_Main(argc, argv, TK_LOCAL_APPINIT); 79 return 0; /* Needed only to prevent compiler warning. */ 80 } 81 82 /* 83 *---------------------------------------------------------------------- 84 * 85 * Tcl_AppInit -- 86 * 87 * This procedure performs application-specific initialization. Most 88 * applications, especially those that incorporate additional packages, 89 * will have their own version of this procedure. 90 * 91 * Results: 92 * Returns a standard Tcl completion code, and leaves an error message in 93 * the interp's result if an error occurs. 94 * 95 * Side effects: 96 * Depends on the startup script. 97 * 98 *---------------------------------------------------------------------- 99 */ 100 101 int 102 Tcl_AppInit( 103 Tcl_Interp *interp) /* Interpreter for application. */ 104 { 105 if ((Tcl_Init)(interp) == TCL_ERROR) { 106 return TCL_ERROR; 107 } 108 109 if (Tk_Init(interp) == TCL_ERROR) { 110 return TCL_ERROR; 111 } 112 Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit); 113 114 #ifdef TK_TEST 115 if (Tktest_Init(interp) == TCL_ERROR) { 116 return TCL_ERROR; 117 } 118 Tcl_StaticPackage(interp, "Tktest", Tktest_Init, 0); 119 #endif /* TK_TEST */ 120 121 /* 122 * Call the init procedures for included packages. Each call should look 123 * like this: 124 * 125 * if (Mod_Init(interp) == TCL_ERROR) { 126 * return TCL_ERROR; 127 * } 128 * 129 * where "Mod" is the name of the module. (Dynamically-loadable packages 130 * should have the same entry-point name.) 131 */ 132 133 /* 134 * Call Tcl_CreateObjCommand for application-specific commands, if they 135 * weren't already created by the init procedures called above. 136 */ 137 138 /* 139 * Specify a user-specific startup file to invoke if the application is 140 * run interactively. Typically the startup file is "~/.apprc" where "app" 141 * is the name of the application. If this line is deleted then no user- 142 * specific startup file will be run under any conditions. 143 */ 144 145 Tcl_ObjSetVar2(interp, Tcl_NewStringObj("tcl_rcFileName", -1), NULL, 146 Tcl_NewStringObj("~/.wishrc", -1), TCL_GLOBAL_ONLY); 147 return TCL_OK; 148 } 149 150 /* 151 * Local Variables: 152 * mode: c 153 * c-basic-offset: 4 154 * fill-column: 78 155 * End: 156 */