2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 .TH Tcl_AppInit 3 7.0 Tcl "Tcl Library Procedures"
12 Tcl_AppInit \- perform application-specific initialization
15 \fB#include <tcl.h>\fR
18 \fBTcl_AppInit\fR(\fIinterp\fR)
20 .AS Tcl_Interp *interp
21 .AP Tcl_Interp *interp in
22 Interpreter for the application.
27 \fBTcl_AppInit\fR is a
29 procedure that is invoked by
30 the main programs for Tcl applications such as \fBtclsh\fR and \fBwish\fR.
31 Its purpose is to allow new Tcl applications to be created without
32 modifying the main programs provided as part of Tcl and Tk.
33 To create a new application you write a new version of
34 \fBTcl_AppInit\fR to replace the default version provided by Tcl,
35 then link your new \fBTcl_AppInit\fR with the Tcl library.
37 \fBTcl_AppInit\fR is invoked by \fBTcl_Main\fR and \fBTk_Main\fR
38 after their own initialization and before entering the main loop
40 Here are some examples of things that \fBTcl_AppInit\fR might do:
42 Call initialization procedures for various packages used by
44 Each initialization procedure adds new commands to \fIinterp\fR
45 for its package and performs other package-specific initialization.
47 Process command-line arguments, which can be accessed from the
48 Tcl variables \fBargv\fR and \fBargv0\fR in \fIinterp\fR.
50 Invoke a startup script to initialize the application.
52 Use the routines \fBTcl_SetStartupScript\fR and
53 \fBTcl_GetStartupScript\fR to set or query the file and encoding
54 that the active \fBTcl_Main\fR or \fBTk_Main\fR routine will
55 use as a startup script.
57 \fBTcl_AppInit\fR returns \fBTCL_OK\fR or \fBTCL_ERROR\fR.
58 If it returns \fBTCL_ERROR\fR then it must leave an error message in
59 for the interpreter's result; otherwise the result is ignored.
61 In addition to \fBTcl_AppInit\fR, your application should also contain
62 a procedure \fBmain\fR that calls \fBTcl_Main\fR as follows:
65 Tcl_Main(argc, argv, Tcl_AppInit);
68 The third argument to \fBTcl_Main\fR gives the address of the
69 application-specific initialization procedure to invoke.
70 This means that you do not have to use the name \fBTcl_AppInit\fR
71 for the procedure, but in practice the name is nearly always
72 \fBTcl_AppInit\fR (in versions before Tcl 7.4 the name \fBTcl_AppInit\fR
73 was implicit; there was no way to specify the procedure explicitly).
74 The best way to get started is to make a copy of the file
75 \fBtclAppInit.c\fR from the Tcl library or source directory.
76 It already contains a \fBmain\fR procedure and a template for
77 \fBTcl_AppInit\fR that you can modify for your application.
83 application, argument, command, initialization, interpreter