| 1 |
/* |
| 2 |
* tkAppInit.c -- |
| 3 |
* |
| 4 |
* Provides a default version of the Tcl_AppInit procedure for |
| 5 |
* use in wish and similar Tk-based applications. |
| 6 |
* |
| 7 |
* Copyright (c) 1993 The Regents of the University of California. |
| 8 |
* Copyright (c) 1994-1997 Sun Microsystems, Inc. |
| 9 |
* |
| 10 |
* See the file "license.terms" for information on usage and redistribution |
| 11 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 12 |
* |
| 13 |
* RCS: @(#) $Id: tkAppInit.c,v 1.5 1999/12/02 02:05:39 redman Exp $ |
| 14 |
*/ |
| 15 |
|
| 16 |
#undef TCL_USE_STUBS |
| 17 |
|
| 18 |
#include "tk.h" |
| 19 |
#include "img.h" |
| 20 |
#ifndef I18N_IMPROVE |
| 21 |
#include "locale.h" |
| 22 |
#endif /* !I18N_IMPROVE */ |
| 23 |
|
| 24 |
/* |
| 25 |
* The following variable is a special hack that is needed in order for |
| 26 |
* Sun shared libraries to be used for Tcl. |
| 27 |
*/ |
| 28 |
|
| 29 |
extern int matherr(); |
| 30 |
int *tclDummyMathPtr = (int *) matherr; |
| 31 |
|
| 32 |
#ifdef TK_TEST |
| 33 |
extern int Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp)); |
| 34 |
extern int Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp)); |
| 35 |
#endif /* TK_TEST */ |
| 36 |
|
| 37 |
/* |
| 38 |
*---------------------------------------------------------------------- |
| 39 |
* |
| 40 |
* main -- |
| 41 |
* |
| 42 |
* This is the main program for the application. |
| 43 |
* |
| 44 |
* Results: |
| 45 |
* None: Tk_Main never returns here, so this procedure never |
| 46 |
* returns either. |
| 47 |
* |
| 48 |
* Side effects: |
| 49 |
* Whatever the application does. |
| 50 |
* |
| 51 |
*---------------------------------------------------------------------- |
| 52 |
*/ |
| 53 |
|
| 54 |
int |
| 55 |
main(argc, argv) |
| 56 |
int argc; /* Number of command-line arguments. */ |
| 57 |
char **argv; /* Values of command-line arguments. */ |
| 58 |
{ |
| 59 |
/* |
| 60 |
* The following #if block allows you to change the AppInit |
| 61 |
* function by using a #define of TCL_LOCAL_APPINIT instead |
| 62 |
* of rewriting this entire file. The #if checks for that |
| 63 |
* #define and uses Tcl_AppInit if it doesn't exist. |
| 64 |
*/ |
| 65 |
|
| 66 |
#ifndef TK_LOCAL_APPINIT |
| 67 |
#define TK_LOCAL_APPINIT Tcl_AppInit |
| 68 |
#endif |
| 69 |
extern int TK_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp)); |
| 70 |
|
| 71 |
/* |
| 72 |
* The following #if block allows you to change how Tcl finds the startup |
| 73 |
* script, prime the library or encoding paths, fiddle with the argv, |
| 74 |
* etc., without needing to rewrite Tk_Main() |
| 75 |
*/ |
| 76 |
|
| 77 |
#ifdef TK_LOCAL_MAIN_HOOK |
| 78 |
extern int TK_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv)); |
| 79 |
TK_LOCAL_MAIN_HOOK(&argc, &argv); |
| 80 |
#endif |
| 81 |
|
| 82 |
Tk_Main(argc, argv, TK_LOCAL_APPINIT); |
| 83 |
return 0; /* Needed only to prevent compiler warning. */ |
| 84 |
} |
| 85 |
|
| 86 |
/* |
| 87 |
*---------------------------------------------------------------------- |
| 88 |
* |
| 89 |
* Tcl_AppInit -- |
| 90 |
* |
| 91 |
* This procedure performs application-specific initialization. |
| 92 |
* Most applications, especially those that incorporate additional |
| 93 |
* packages, will have their own version of this procedure. |
| 94 |
* |
| 95 |
* Results: |
| 96 |
* Returns a standard Tcl completion code, and leaves an error |
| 97 |
* message in the interp's result if an error occurs. |
| 98 |
* |
| 99 |
* Side effects: |
| 100 |
* Depends on the startup script. |
| 101 |
* |
| 102 |
*---------------------------------------------------------------------- |
| 103 |
*/ |
| 104 |
|
| 105 |
int |
| 106 |
Tcl_AppInit(interp) |
| 107 |
Tcl_Interp *interp; /* Interpreter for application. */ |
| 108 |
{ |
| 109 |
if (Tcl_Init(interp) == TCL_ERROR) { |
| 110 |
return TCL_ERROR; |
| 111 |
} |
| 112 |
if (Tk_Init(interp) == TCL_ERROR) { |
| 113 |
return TCL_ERROR; |
| 114 |
} |
| 115 |
Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit); |
| 116 |
if (Img_Init(interp) == TCL_ERROR) { |
| 117 |
return TCL_ERROR; |
| 118 |
} |
| 119 |
Tcl_StaticPackage(interp, "Img", Img_Init, Img_SafeInit); |
| 120 |
#ifdef TK_TEST |
| 121 |
if (Tcltest_Init(interp) == TCL_ERROR) { |
| 122 |
return TCL_ERROR; |
| 123 |
} |
| 124 |
Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init, |
| 125 |
(Tcl_PackageInitProc *) NULL); |
| 126 |
if (Tktest_Init(interp) == TCL_ERROR) { |
| 127 |
return TCL_ERROR; |
| 128 |
} |
| 129 |
Tcl_StaticPackage(interp, "Tktest", Tktest_Init, |
| 130 |
(Tcl_PackageInitProc *) NULL); |
| 131 |
#endif /* TK_TEST */ |
| 132 |
|
| 133 |
|
| 134 |
/* |
| 135 |
* Call the init procedures for included packages. Each call should |
| 136 |
* look like this: |
| 137 |
* |
| 138 |
* if (Mod_Init(interp) == TCL_ERROR) { |
| 139 |
* return TCL_ERROR; |
| 140 |
* } |
| 141 |
* |
| 142 |
* where "Mod" is the name of the module. |
| 143 |
*/ |
| 144 |
|
| 145 |
/* |
| 146 |
* Call Tcl_CreateCommand for application-specific commands, if |
| 147 |
* they weren't already created by the init procedures called above. |
| 148 |
*/ |
| 149 |
|
| 150 |
/* |
| 151 |
* Specify a user-specific startup file to invoke if the application |
| 152 |
* is run interactively. Typically the startup file is "~/.apprc" |
| 153 |
* where "app" is the name of the application. If this line is deleted |
| 154 |
* then no user-specific startup file will be run under any conditions. |
| 155 |
*/ |
| 156 |
|
| 157 |
Tcl_SetVar(interp, "tcl_rcFileName", "~/.wishrc", TCL_GLOBAL_ONLY); |
| 158 |
return TCL_OK; |
| 159 |
} |