1 /* $NetBSD: tclAppInit.c,v 1.2 2021/08/14 16:14:50 christos Exp $ */
2
3 /*
4 * tclAppInit.c --
5 *
6 * Provides a default version of the main program and Tcl_AppInit
7 * procedure for Tcl applications (without Tk).
8 *
9 * Copyright (c) 1993 The Regents of the University of California.
10 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
11 *
12 * See the file "license.terms" for information on usage and redistribution
13 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 *
15 * SCCS: @(#) tclAppInit.c 1.17 96/03/26 12:45:29
16 */
17
18 #include "tcl.h"
19
20 /*
21 * The following variable is a special hack that is needed in order for
22 * Sun shared libraries to be used for Tcl.
23 */
24
25 extern int matherr();
26 int *tclDummyMathPtr = (int *) matherr;
27
28 #ifdef TCL_TEST
29 EXTERN int Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
30 #endif /* TCL_TEST */
31
32 /*
33 *----------------------------------------------------------------------
34 *
35 * main --
36 *
37 * This is the main program for the application.
38 *
39 * Results:
40 * None: Tcl_Main never returns here, so this procedure never
41 * returns either.
42 *
43 * Side effects:
44 * Whatever the application does.
45 *
46 *----------------------------------------------------------------------
47 */
48
49 int
main(argc,argv)50 main(argc, argv)
51 int argc; /* Number of command-line arguments. */
52 char **argv; /* Values of command-line arguments. */
53 {
54 #ifdef USE_TCLX
55 TclX_Main(argc, argv, Tcl_AppInit);
56 #else
57 Tcl_Main(argc, argv, Tcl_AppInit);
58 #endif
59 return 0; /* Needed only to prevent compiler warning. */
60 }
61
62 /*
63 *----------------------------------------------------------------------
64 *
65 * Tcl_AppInit --
66 *
67 * This procedure performs application-specific initialization.
68 * Most applications, especially those that incorporate additional
69 * packages, will have their own version of this procedure.
70 *
71 * Results:
72 * Returns a standard Tcl completion code, and leaves an error
73 * message in interp->result if an error occurs.
74 *
75 * Side effects:
76 * Depends on the startup script.
77 *
78 *----------------------------------------------------------------------
79 */
80
81 int
Tcl_AppInit(interp)82 Tcl_AppInit(interp)
83 Tcl_Interp *interp; /* Interpreter for application. */
84 {
85 if (Tcl_Init(interp) == TCL_ERROR) {
86 return TCL_ERROR;
87 }
88
89 #ifdef USE_ITCL
90 if (Itcl_Init(interp) == TCL_ERROR) {
91 return TCL_ERROR;
92 }
93 Tcl_StaticPackage (interp, "Itcl", Itcl_Init, NULL);
94 #endif
95
96 #ifdef TCL_TEST
97 if (Tcltest_Init(interp) == TCL_ERROR) {
98 return TCL_ERROR;
99 }
100 Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
101 (Tcl_PackageInitProc *) NULL);
102 #endif /* TCL_TEST */
103
104 #ifdef USE_TCLX
105 if (Tclx_Init (interp) == TCL_ERROR) {
106 return TCL_ERROR;
107 }
108 Tcl_StaticPackage (interp, "Tclx", Tclx_Init, NULL);
109 #endif
110
111 if (Ldaptcl_Init(interp) == TCL_ERROR) {
112 return TCL_ERROR;
113 }
114 Tcl_StaticPackage(interp, "Ldaptcl", Ldaptcl_Init,
115 (Tcl_PackageInitProc *) NULL);
116
117 /*
118 * Call the init procedures for included packages. Each call should
119 * look like this:
120 *
121 * if (Mod_Init(interp) == TCL_ERROR) {
122 * return TCL_ERROR;
123 * }
124 *
125 * where "Mod" is the name of the module.
126 */
127
128 /*
129 * Call Tcl_CreateCommand for application-specific commands, if
130 * they weren't already created by the init procedures called above.
131 */
132
133 /*
134 * Specify a user-specific startup file to invoke if the application
135 * is run interactively. Typically the startup file is "~/.apprc"
136 * where "app" is the name of the application. If this line is deleted
137 * then no user-specific startup file will be run under any conditions.
138 */
139
140 Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);
141 return TCL_OK;
142 }
143