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