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