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  * Changes:
11  * Added tkgeomap headers and initializing functions.
12  * Gordon D. Carrie, 2003.
13  *
14  * See the file "license.terms" for information on usage and redistribution
15  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16  *
17  * RCS: @(#) $Id: tkAppInit.c,v 1.1 2004/02/18 20:26:21 tkgeomap Exp $
18  */
19 
20 #include "tkgeomap.h"
21 
22 /*
23  * The following variable is a special hack that is needed in order for
24  * Sun shared libraries to be used for Tcl.
25  */
26 
27 extern int matherr();
28 int *tclDummyMathPtr = (int *) matherr;
29 
30 #ifdef TK_TEST
31 extern int		Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
32 extern int		Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));
33 #endif /* TK_TEST */
34 
35 /*
36  *----------------------------------------------------------------------
37  *
38  * main --
39  *
40  *	This is the main program for the application.
41  *
42  * Results:
43  *	None: Tk_Main never returns here, so this procedure never
44  *	returns either.
45  *
46  * Side effects:
47  *	Whatever the application does.
48  *
49  *----------------------------------------------------------------------
50  */
51 
52 int
main(argc,argv)53 main(argc, argv)
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
59      * function by using a #define of TCL_LOCAL_APPINIT instead
60      * of rewriting this entire file.  The #if checks for that
61      * #define and uses Tcl_AppInit if it doesn't exist.
62      */
63 
64 #ifndef TK_LOCAL_APPINIT
65 #define TK_LOCAL_APPINIT Tcl_AppInit
66 #endif
67     extern int TK_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 Tk_Main()
73      */
74 
75 #ifdef TK_LOCAL_MAIN_HOOK
76     extern int TK_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv));
77     TK_LOCAL_MAIN_HOOK(&argc, &argv);
78 #endif
79 
80     Tk_Main(argc, argv, TK_LOCAL_APPINIT);
81     return 0;			/* Needed only to prevent compiler warning. */
82 }
83 
84 /*
85  *----------------------------------------------------------------------
86  *
87  * Tcl_AppInit --
88  *
89  *	This procedure performs application-specific initialization.
90  *	Most applications, especially those that incorporate additional
91  *	packages, will have their own version of this procedure.
92  *
93  * Results:
94  *	Returns a standard Tcl completion code, and leaves an error
95  *	message in the interp's result if an error occurs.
96  *
97  * Side effects:
98  *	Depends on the startup script.
99  *
100  *----------------------------------------------------------------------
101  */
102 
103 int
Tcl_AppInit(interp)104 Tcl_AppInit(interp)
105     Tcl_Interp *interp;		/* Interpreter for application. */
106 {
107     if (Tcl_Init(interp) == TCL_ERROR) {
108 	return TCL_ERROR;
109     }
110     if (Tk_Init(interp) == TCL_ERROR) {
111 	return TCL_ERROR;
112     }
113     Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
114 #ifdef TK_TEST
115     if (Tcltest_Init(interp) == TCL_ERROR) {
116 	return TCL_ERROR;
117     }
118     Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
119             (Tcl_PackageInitProc *) NULL);
120     if (Tktest_Init(interp) == TCL_ERROR) {
121 	return TCL_ERROR;
122     }
123     Tcl_StaticPackage(interp, "Tktest", Tktest_Init,
124             (Tcl_PackageInitProc *) NULL);
125 #endif /* TK_TEST */
126 
127 
128     /*
129      * Call the init procedures for included packages.  Each call should
130      * look like this:
131      *
132      * if (Mod_Init(interp) == TCL_ERROR) {
133      *     return TCL_ERROR;
134      * }
135      *
136      * where "Mod" is the name of the module.
137      */
138 
139     if (Tclgeomap_Init(interp) == TCL_ERROR) {
140 	return TCL_ERROR;
141     }
142     if (Tkgeomap_Init(interp) == TCL_ERROR) {
143         return TCL_ERROR;
144     }
145 
146     /*
147      * Call Tcl_CreateCommand for application-specific commands, if
148      * they weren't already created by the init procedures called above.
149      */
150 
151     /*
152      * Specify a user-specific startup file to invoke if the application
153      * is run interactively.  Typically the startup file is "~/.apprc"
154      * where "app" is the name of the application.  If this line is deleted
155      * then no user-specific startup file will be run under any conditions.
156      */
157 
158     Tcl_SetVar(interp, "tcl_rcFileName", "~/.wishrc", TCL_GLOBAL_ONLY);
159     return TCL_OK;
160 }
161