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