OSDN Git Service

* unix/Makefile.in (TCL_RANLIB): Renamed from just "RANLIB".
[pf3gnuchains/pf3gnuchains3x.git] / tcl / unix / tclAppInit.c
1 /* 
2  * tclAppInit.c --
3  *
4  *      Provides a default version of the main program and Tcl_AppInit
5  *      procedure for Tcl 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 by Scriptics Corporation.
10  *
11  * See the file "license.terms" for information on usage and redistribution
12  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13  *
14  * RCS: @(#) $Id$
15  */
16
17 #include "tcl.h"
18
19 /*
20  * The following variable is a special hack that is needed in order for
21  * Sun shared libraries to be used for Tcl.
22  */
23
24 extern int matherr();
25 int *tclDummyMathPtr = (int *) matherr;
26
27
28 #ifdef TCL_TEST
29
30 #include "tclInt.h"
31
32 extern int              Procbodytest_Init _ANSI_ARGS_((Tcl_Interp *interp));
33 extern int              Procbodytest_SafeInit _ANSI_ARGS_((Tcl_Interp *interp));
34 extern int              TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
35 extern int              Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
36 #ifdef TCL_THREADS
37 extern int              TclThread_Init _ANSI_ARGS_((Tcl_Interp *interp));
38 #endif
39
40 #endif /* TCL_TEST */
41
42 #ifdef TCL_XT_TEST
43 extern void             XtToolkitInitialize _ANSI_ARGS_((void));
44 extern int              Tclxttest_Init _ANSI_ARGS_((Tcl_Interp *interp));
45 #endif
46 \f
47 /*
48  *----------------------------------------------------------------------
49  *
50  * main --
51  *
52  *      This is the main program for the application.
53  *
54  * Results:
55  *      None: Tcl_Main never returns here, so this procedure never
56  *      returns either.
57  *
58  * Side effects:
59  *      Whatever the application does.
60  *
61  *----------------------------------------------------------------------
62  */
63
64 int
65 main(argc, argv)
66     int argc;                   /* Number of command-line arguments. */
67     char **argv;                /* Values of command-line arguments. */
68 {
69     /*
70      * The following #if block allows you to change the AppInit
71      * function by using a #define of TCL_LOCAL_APPINIT instead
72      * of rewriting this entire file.  The #if checks for that
73      * #define and uses Tcl_AppInit if it doesn't exist.
74      */
75
76 #ifndef TCL_LOCAL_APPINIT
77 #define TCL_LOCAL_APPINIT Tcl_AppInit    
78 #endif
79     extern int TCL_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp));
80
81     /*
82      * The following #if block allows you to change how Tcl finds the startup
83      * script, prime the library or encoding paths, fiddle with the argv,
84      * etc., without needing to rewrite Tcl_Main()
85      */
86
87 #ifdef TCL_LOCAL_MAIN_HOOK
88     extern int TCL_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv));
89 #endif
90
91 #ifdef TCL_XT_TEST
92     XtToolkitInitialize();
93 #endif
94
95 #ifdef TCL_LOCAL_MAIN_HOOK
96     TCL_LOCAL_MAIN_HOOK(&argc, &argv);
97 #endif
98
99     Tcl_Main(argc, argv, TCL_LOCAL_APPINIT);
100
101     return 0;                   /* Needed only to prevent compiler warning. */
102 }
103 \f
104 /*
105  *----------------------------------------------------------------------
106  *
107  * Tcl_AppInit --
108  *
109  *      This procedure performs application-specific initialization.
110  *      Most applications, especially those that incorporate additional
111  *      packages, will have their own version of this procedure.
112  *
113  * Results:
114  *      Returns a standard Tcl completion code, and leaves an error
115  *      message in the interp's result if an error occurs.
116  *
117  * Side effects:
118  *      Depends on the startup script.
119  *
120  *----------------------------------------------------------------------
121  */
122
123 int
124 Tcl_AppInit(interp)
125     Tcl_Interp *interp;         /* Interpreter for application. */
126 {
127     if (Tcl_Init(interp) == TCL_ERROR) {
128         return TCL_ERROR;
129     }
130
131 #ifdef TCL_TEST
132 #ifdef TCL_XT_TEST
133      if (Tclxttest_Init(interp) == TCL_ERROR) {
134          return TCL_ERROR;
135      }
136 #endif
137     if (Tcltest_Init(interp) == TCL_ERROR) {
138         return TCL_ERROR;
139     }
140     Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
141             (Tcl_PackageInitProc *) NULL);
142     if (TclObjTest_Init(interp) == TCL_ERROR) {
143         return TCL_ERROR;
144     }
145 #ifdef TCL_THREADS
146     if (TclThread_Init(interp) == TCL_ERROR) {
147         return TCL_ERROR;
148     }
149 #endif
150     if (Procbodytest_Init(interp) == TCL_ERROR) {
151         return TCL_ERROR;
152     }
153     Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init,
154             Procbodytest_SafeInit);
155 #endif /* TCL_TEST */
156
157     /*
158      * Call the init procedures for included packages.  Each call should
159      * look like this:
160      *
161      * if (Mod_Init(interp) == TCL_ERROR) {
162      *     return TCL_ERROR;
163      * }
164      *
165      * where "Mod" is the name of the module.
166      */
167
168     /*
169      * Call Tcl_CreateCommand for application-specific commands, if
170      * they weren't already created by the init procedures called above.
171      */
172
173     /*
174      * Specify a user-specific startup file to invoke if the application
175      * is run interactively.  Typically the startup file is "~/.apprc"
176      * where "app" is the name of the application.  If this line is deleted
177      * then no user-specific startup file will be run under any conditions.
178      */
179
180     Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);
181     return TCL_OK;
182 }
183
184