| 1 |
'\" |
| 2 |
'\" Copyright (c) 1993 The Regents of the University of California. |
| 3 |
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. |
| 4 |
'\" |
| 5 |
'\" See the file "license.terms" for information on usage and redistribution |
| 6 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 7 |
'\" |
| 8 |
.TH Tcl_AppInit 3 7.0 Tcl "Tcl Library Procedures" |
| 9 |
.so man.macros |
| 10 |
.BS |
| 11 |
.SH NAME |
| 12 |
Tcl_AppInit \- perform application-specific initialization |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
\fB#include <tcl.h>\fR |
| 16 |
.sp |
| 17 |
int |
| 18 |
\fBTcl_AppInit\fR(\fIinterp\fR) |
| 19 |
.SH ARGUMENTS |
| 20 |
.AS Tcl_Interp *interp |
| 21 |
.AP Tcl_Interp *interp in |
| 22 |
Interpreter for the application. |
| 23 |
.BE |
| 24 |
|
| 25 |
.SH DESCRIPTION |
| 26 |
.PP |
| 27 |
\fBTcl_AppInit\fR is a |
| 28 |
.QW hook |
| 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. |
| 36 |
.PP |
| 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 |
| 39 |
to process commands. |
| 40 |
Here are some examples of things that \fBTcl_AppInit\fR might do: |
| 41 |
.IP [1] |
| 42 |
Call initialization procedures for various packages used by |
| 43 |
the application. |
| 44 |
Each initialization procedure adds new commands to \fIinterp\fR |
| 45 |
for its package and performs other package-specific initialization. |
| 46 |
.IP [2] |
| 47 |
Process command-line arguments, which can be accessed from the |
| 48 |
Tcl variables \fBargv\fR and \fBargv0\fR in \fIinterp\fR. |
| 49 |
.IP [3] |
| 50 |
Invoke a startup script to initialize the application. |
| 51 |
.IP [4] |
| 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. |
| 56 |
.LP |
| 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. |
| 60 |
.PP |
| 61 |
In addition to \fBTcl_AppInit\fR, your application should also contain |
| 62 |
a procedure \fBmain\fR that calls \fBTcl_Main\fR as follows: |
| 63 |
.PP |
| 64 |
.CS |
| 65 |
Tcl_Main(argc, argv, Tcl_AppInit); |
| 66 |
.CE |
| 67 |
.PP |
| 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. |
| 78 |
|
| 79 |
.SH "SEE ALSO" |
| 80 |
Tcl_Main(3) |
| 81 |
|
| 82 |
.SH KEYWORDS |
| 83 |
application, argument, command, initialization, interpreter |