Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | '\" |
2 | '\" Copyright (c) 1994 The Regents of the University of California. | |
3 | '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. | |
4 | '\" Copyright (c) 2000 Ajuba Solutions. | |
5 | '\" | |
6 | '\" See the file "license.terms" for information on usage and redistribution | |
7 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. | |
8 | '\" | |
9 | '\" RCS: @(#) $Id: Tcl_Main.3,v 1.9 2002/07/01 18:24:39 jenglish Exp $ | |
10 | '\" | |
11 | '\" The definitions below are for supplemental macros used in Tcl/Tk | |
12 | '\" manual entries. | |
13 | '\" | |
14 | '\" .AP type name in/out ?indent? | |
15 | '\" Start paragraph describing an argument to a library procedure. | |
16 | '\" type is type of argument (int, etc.), in/out is either "in", "out", | |
17 | '\" or "in/out" to describe whether procedure reads or modifies arg, | |
18 | '\" and indent is equivalent to second arg of .IP (shouldn't ever be | |
19 | '\" needed; use .AS below instead) | |
20 | '\" | |
21 | '\" .AS ?type? ?name? | |
22 | '\" Give maximum sizes of arguments for setting tab stops. Type and | |
23 | '\" name are examples of largest possible arguments that will be passed | |
24 | '\" to .AP later. If args are omitted, default tab stops are used. | |
25 | '\" | |
26 | '\" .BS | |
27 | '\" Start box enclosure. From here until next .BE, everything will be | |
28 | '\" enclosed in one large box. | |
29 | '\" | |
30 | '\" .BE | |
31 | '\" End of box enclosure. | |
32 | '\" | |
33 | '\" .CS | |
34 | '\" Begin code excerpt. | |
35 | '\" | |
36 | '\" .CE | |
37 | '\" End code excerpt. | |
38 | '\" | |
39 | '\" .VS ?version? ?br? | |
40 | '\" Begin vertical sidebar, for use in marking newly-changed parts | |
41 | '\" of man pages. The first argument is ignored and used for recording | |
42 | '\" the version when the .VS was added, so that the sidebars can be | |
43 | '\" found and removed when they reach a certain age. If another argument | |
44 | '\" is present, then a line break is forced before starting the sidebar. | |
45 | '\" | |
46 | '\" .VE | |
47 | '\" End of vertical sidebar. | |
48 | '\" | |
49 | '\" .DS | |
50 | '\" Begin an indented unfilled display. | |
51 | '\" | |
52 | '\" .DE | |
53 | '\" End of indented unfilled display. | |
54 | '\" | |
55 | '\" .SO | |
56 | '\" Start of list of standard options for a Tk widget. The | |
57 | '\" options follow on successive lines, in four columns separated | |
58 | '\" by tabs. | |
59 | '\" | |
60 | '\" .SE | |
61 | '\" End of list of standard options for a Tk widget. | |
62 | '\" | |
63 | '\" .OP cmdName dbName dbClass | |
64 | '\" Start of description of a specific option. cmdName gives the | |
65 | '\" option's name as specified in the class command, dbName gives | |
66 | '\" the option's name in the option database, and dbClass gives | |
67 | '\" the option's class in the option database. | |
68 | '\" | |
69 | '\" .UL arg1 arg2 | |
70 | '\" Print arg1 underlined, then print arg2 normally. | |
71 | '\" | |
72 | '\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $ | |
73 | '\" | |
74 | '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. | |
75 | .if t .wh -1.3i ^B | |
76 | .nr ^l \n(.l | |
77 | .ad b | |
78 | '\" # Start an argument description | |
79 | .de AP | |
80 | .ie !"\\$4"" .TP \\$4 | |
81 | .el \{\ | |
82 | . ie !"\\$2"" .TP \\n()Cu | |
83 | . el .TP 15 | |
84 | .\} | |
85 | .ta \\n()Au \\n()Bu | |
86 | .ie !"\\$3"" \{\ | |
87 | \&\\$1 \\fI\\$2\\fP (\\$3) | |
88 | .\".b | |
89 | .\} | |
90 | .el \{\ | |
91 | .br | |
92 | .ie !"\\$2"" \{\ | |
93 | \&\\$1 \\fI\\$2\\fP | |
94 | .\} | |
95 | .el \{\ | |
96 | \&\\fI\\$1\\fP | |
97 | .\} | |
98 | .\} | |
99 | .. | |
100 | '\" # define tabbing values for .AP | |
101 | .de AS | |
102 | .nr )A 10n | |
103 | .if !"\\$1"" .nr )A \\w'\\$1'u+3n | |
104 | .nr )B \\n()Au+15n | |
105 | .\" | |
106 | .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n | |
107 | .nr )C \\n()Bu+\\w'(in/out)'u+2n | |
108 | .. | |
109 | .AS Tcl_Interp Tcl_CreateInterp in/out | |
110 | '\" # BS - start boxed text | |
111 | '\" # ^y = starting y location | |
112 | '\" # ^b = 1 | |
113 | .de BS | |
114 | .br | |
115 | .mk ^y | |
116 | .nr ^b 1u | |
117 | .if n .nf | |
118 | .if n .ti 0 | |
119 | .if n \l'\\n(.lu\(ul' | |
120 | .if n .fi | |
121 | .. | |
122 | '\" # BE - end boxed text (draw box now) | |
123 | .de BE | |
124 | .nf | |
125 | .ti 0 | |
126 | .mk ^t | |
127 | .ie n \l'\\n(^lu\(ul' | |
128 | .el \{\ | |
129 | .\" Draw four-sided box normally, but don't draw top of | |
130 | .\" box if the box started on an earlier page. | |
131 | .ie !\\n(^b-1 \{\ | |
132 | \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' | |
133 | .\} | |
134 | .el \}\ | |
135 | \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' | |
136 | .\} | |
137 | .\} | |
138 | .fi | |
139 | .br | |
140 | .nr ^b 0 | |
141 | .. | |
142 | '\" # VS - start vertical sidebar | |
143 | '\" # ^Y = starting y location | |
144 | '\" # ^v = 1 (for troff; for nroff this doesn't matter) | |
145 | .de VS | |
146 | .if !"\\$2"" .br | |
147 | .mk ^Y | |
148 | .ie n 'mc \s12\(br\s0 | |
149 | .el .nr ^v 1u | |
150 | .. | |
151 | '\" # VE - end of vertical sidebar | |
152 | .de VE | |
153 | .ie n 'mc | |
154 | .el \{\ | |
155 | .ev 2 | |
156 | .nf | |
157 | .ti 0 | |
158 | .mk ^t | |
159 | \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' | |
160 | .sp -1 | |
161 | .fi | |
162 | .ev | |
163 | .\} | |
164 | .nr ^v 0 | |
165 | .. | |
166 | '\" # Special macro to handle page bottom: finish off current | |
167 | '\" # box/sidebar if in box/sidebar mode, then invoked standard | |
168 | '\" # page bottom macro. | |
169 | .de ^B | |
170 | .ev 2 | |
171 | 'ti 0 | |
172 | 'nf | |
173 | .mk ^t | |
174 | .if \\n(^b \{\ | |
175 | .\" Draw three-sided box if this is the box's first page, | |
176 | .\" draw two sides but no top otherwise. | |
177 | .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c | |
178 | .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c | |
179 | .\} | |
180 | .if \\n(^v \{\ | |
181 | .nr ^x \\n(^tu+1v-\\n(^Yu | |
182 | \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c | |
183 | .\} | |
184 | .bp | |
185 | 'fi | |
186 | .ev | |
187 | .if \\n(^b \{\ | |
188 | .mk ^y | |
189 | .nr ^b 2 | |
190 | .\} | |
191 | .if \\n(^v \{\ | |
192 | .mk ^Y | |
193 | .\} | |
194 | .. | |
195 | '\" # DS - begin display | |
196 | .de DS | |
197 | .RS | |
198 | .nf | |
199 | .sp | |
200 | .. | |
201 | '\" # DE - end display | |
202 | .de DE | |
203 | .fi | |
204 | .RE | |
205 | .sp | |
206 | .. | |
207 | '\" # SO - start of list of standard options | |
208 | .de SO | |
209 | .SH "STANDARD OPTIONS" | |
210 | .LP | |
211 | .nf | |
212 | .ta 5.5c 11c | |
213 | .ft B | |
214 | .. | |
215 | '\" # SE - end of list of standard options | |
216 | .de SE | |
217 | .fi | |
218 | .ft R | |
219 | .LP | |
220 | See the \\fBoptions\\fR manual entry for details on the standard options. | |
221 | .. | |
222 | '\" # OP - start of full description for a single option | |
223 | .de OP | |
224 | .LP | |
225 | .nf | |
226 | .ta 4c | |
227 | Command-Line Name: \\fB\\$1\\fR | |
228 | Database Name: \\fB\\$2\\fR | |
229 | Database Class: \\fB\\$3\\fR | |
230 | .fi | |
231 | .IP | |
232 | .. | |
233 | '\" # CS - begin code excerpt | |
234 | .de CS | |
235 | .RS | |
236 | .nf | |
237 | .ta .25i .5i .75i 1i | |
238 | .. | |
239 | '\" # CE - end code excerpt | |
240 | .de CE | |
241 | .fi | |
242 | .RE | |
243 | .. | |
244 | .de UL | |
245 | \\$1\l'|0\(ul'\\$2 | |
246 | .. | |
247 | .TH Tcl_Main 3 8.4 Tcl "Tcl Library Procedures" | |
248 | .BS | |
249 | .SH NAME | |
250 | Tcl_Main, Tcl_SetMainLoop \- main program and event loop definition for Tcl-based applications | |
251 | .SH SYNOPSIS | |
252 | .nf | |
253 | \fB#include <tcl.h>\fR | |
254 | .sp | |
255 | \fBTcl_Main\fR(\fIargc, argv, appInitProc\fR) | |
256 | .sp | |
257 | \fBTcl_SetMainLoop\fR(\fImainLoopProc\fR) | |
258 | .SH ARGUMENTS | |
259 | .AS Tcl_AppInitProc *appInitProc | |
260 | .AP int argc in | |
261 | Number of elements in \fIargv\fR. | |
262 | .AP char *argv[] in | |
263 | Array of strings containing command-line arguments. | |
264 | .AP Tcl_AppInitProc *appInitProc in | |
265 | Address of an application-specific initialization procedure. | |
266 | The value for this argument is usually \fBTcl_AppInit\fR. | |
267 | .AP Tcl_MainLoopProc *mainLoopProc in | |
268 | Address of an application-specific event loop procedure. | |
269 | .BE | |
270 | ||
271 | .SH DESCRIPTION | |
272 | .PP | |
273 | \fBTcl_Main\fR can serve as the main program for Tcl-based shell | |
274 | applications. A ``shell application'' is a program | |
275 | like tclsh or wish that supports both interactive interpretation | |
276 | of Tcl and evaluation of a script contained in a file given as | |
277 | a command line argument. \fBTcl_Main\fR is offered as a convenience | |
278 | to developers of shell applications, so they do not have to | |
279 | reproduce all of the code for proper initialization of the Tcl | |
280 | library and interactive shell operation. Other styles of embedding | |
281 | Tcl in an application are not supported by \fBTcl_Main\fR. Those | |
282 | must be achieved by calling lower level functions in the Tcl library | |
283 | directly. | |
284 | ||
285 | The \fBTcl_Main\fR function has been offered by the Tcl library | |
286 | since release Tcl 7.4. In older releases of Tcl, the Tcl library | |
287 | itself defined a function \fBmain\fR, but that lacks flexibility | |
288 | of embedding style and having a function \fBmain\fR in a library | |
289 | (particularly a shared library) causes problems on many systems. | |
290 | Having \fBmain\fR in the Tcl library would also make it hard to use | |
291 | Tcl in C++ programs, since C++ programs must have special C++ | |
292 | \fBmain\fR functions. | |
293 | .PP | |
294 | Normally each shell application contains a small \fBmain\fR function | |
295 | that does nothing but invoke \fBTcl_Main\fR. | |
296 | \fBTcl_Main\fR then does all the work of creating and running a | |
297 | \fBtclsh\fR-like application. | |
298 | .PP | |
299 | \fBTcl_Main\fR is not provided by the public interface of Tcl's | |
300 | stub library. Programs that call \fBTcl_Main\fR must be linked | |
301 | against the standard Tcl library. Extensions (stub-enabled or | |
302 | not) are not intended to call \fBTcl_Main\fR. | |
303 | .PP | |
304 | \fBTcl_Main\fR is not thread-safe. It should only be called by | |
305 | a single master thread of a multi-threaded application. This | |
306 | restriction is not a problem with normal use described above. | |
307 | .PP | |
308 | \fBTcl_Main\fR and therefore all applications based upon it, like | |
309 | \fBtclsh\fR, use \fBTcl_GetStdChannel\fR to initialize the standard | |
310 | channels to their default values. See \fBTcl_StandardChannels\fR for | |
311 | more information. | |
312 | .PP | |
313 | \fBTcl_Main\fR supports two modes of operation, depending on the | |
314 | values of \fIargc\fR and \fIargv\fR. If \fIargv[1]\fR exists and | |
315 | does not begin with the character \fI-\fR, it is taken to be the | |
316 | name of a file containing a \fIstartup script\fR, which \fBTcl_Main\fR | |
317 | will attempt to evaluate. Otherwise, \fBTcl_Main\fR will enter an | |
318 | interactive mode. | |
319 | .PP | |
320 | In either mode, \fBTcl_Main\fR will define in its master interpreter | |
321 | the Tcl variables \fIargc\fR, \fIargv\fR, \fIargv0\fR, and | |
322 | \fItcl_interactive\fR, as described in the documentation for \fBtclsh\fR. | |
323 | .PP | |
324 | When it has finished its own initialization, but before it processes | |
325 | commands, \fBTcl_Main\fR calls the procedure given by the | |
326 | \fIappInitProc\fR argument. This procedure provides a ``hook'' for | |
327 | the application to perform its own initialization of the interpreter | |
328 | created by \fBTcl_Main\fR, such as defining application-specific | |
329 | commands. The procedure must have an interface that matches the | |
330 | type \fBTcl_AppInitProc\fR: | |
331 | .CS | |
332 | typedef int Tcl_AppInitProc(Tcl_Interp *\fIinterp\fR); | |
333 | .CE | |
334 | ||
335 | \fIAppInitProc\fR is almost always a pointer to \fBTcl_AppInit\fR; for more | |
336 | details on this procedure, see the documentation for \fBTcl_AppInit\fR. | |
337 | .PP | |
338 | When the \fIappInitProc\fR is finished, \fBTcl_Main\fR enters one | |
339 | of its two modes. If a startup script has been provided, \fBTcl_Main\fR | |
340 | attempts to evaluate it. Otherwise, interactive mode begins with | |
341 | examination of the variable \fItcl_rcFileName\fR in the master | |
342 | interpreter. If that variable exists and holds the name of a readable | |
343 | file, the contents of that file are evaluated in the master interpreter. | |
344 | Then interactive operations begin, | |
345 | with prompts and command evaluation results written to the standard | |
346 | output channel, and commands read from the standard input channel | |
347 | and then evaluated. The prompts written to the standard output | |
348 | channel may be customized by defining the Tcl variables \fItcl_prompt1\fR | |
349 | and \fItcl_prompt2\fR as described in the documentation for \fBtclsh\fR. | |
350 | The prompts and command evaluation results are written to the standard | |
351 | output channel only if the Tcl variable \fItcl_interactive\fR in the | |
352 | master interpreter holds a non-zero integer value. | |
353 | .PP | |
354 | .VS 8.4 | |
355 | \fBTcl_SetMainLoop\fR allows setting an event loop procedure to be run. | |
356 | This allows, for example, Tk to be dynamically loaded and set its event | |
357 | loop. The event loop will run following the startup script. If you | |
358 | are in interactive mode, setting the main loop procedure will cause the | |
359 | prompt to become fileevent based and then the loop procedure is called. | |
360 | When the loop procedure returns in interactive mode, interactive operation | |
361 | will continue. | |
362 | The main loop procedure must have an interface that matches the type | |
363 | \fBTcl_MainLoopProc\fR: | |
364 | .CS | |
365 | typedef void Tcl_MainLoopProc(void); | |
366 | .CE | |
367 | .VE 8.4 | |
368 | .PP | |
369 | \fBTcl_Main\fR does not return. Normally a program based on | |
370 | \fBTcl_Main\fR will terminate when the \fBexit\fR command is | |
371 | evaluated. In interactive mode, if an EOF or channel error | |
372 | is encountered on the standard input channel, then \fBTcl_Main\fR | |
373 | itself will evaluate the \fBexit\fR command after the main loop | |
374 | procedure (if any) returns. In non-interactive mode, after | |
375 | \fBTcl_Main\fR evaluates the startup script, and the main loop | |
376 | procedure (if any) returns, \fBTcl_Main\fR will also evaluate | |
377 | the \fBexit\fR command. | |
378 | ||
379 | .SH "SEE ALSO" | |
380 | tclsh(1), Tcl_GetStdChannel(3), Tcl_StandardChannels(3), Tcl_AppInit(3), | |
381 | exit(n) | |
382 | ||
383 | .SH KEYWORDS | |
384 | application-specific initialization, command-line arguments, main program |