Tcl_Main.3
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:6k
- '"
- '" Copyright (c) 1994 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '" Copyright (c) 2000 Ajuba Solutions.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: Tcl_Main.3,v 1.9 2002/07/01 18:24:39 jenglish Exp $
- '"
- .so man.macros
- .TH Tcl_Main 3 8.4 Tcl "Tcl Library Procedures"
- .BS
- .SH NAME
- Tcl_Main, Tcl_SetMainLoop - main program and event loop definition for Tcl-based applications
- .SH SYNOPSIS
- .nf
- fB#include <tcl.h>fR
- .sp
- fBTcl_MainfR(fIargc, argv, appInitProcfR)
- .sp
- fBTcl_SetMainLoopfR(fImainLoopProcfR)
- .SH ARGUMENTS
- .AS Tcl_AppInitProc *appInitProc
- .AP int argc in
- Number of elements in fIargvfR.
- .AP char *argv[] in
- Array of strings containing command-line arguments.
- .AP Tcl_AppInitProc *appInitProc in
- Address of an application-specific initialization procedure.
- The value for this argument is usually fBTcl_AppInitfR.
- .AP Tcl_MainLoopProc *mainLoopProc in
- Address of an application-specific event loop procedure.
- .BE
- .SH DESCRIPTION
- .PP
- fBTcl_MainfR can serve as the main program for Tcl-based shell
- applications. A ``shell application'' is a program
- like tclsh or wish that supports both interactive interpretation
- of Tcl and evaluation of a script contained in a file given as
- a command line argument. fBTcl_MainfR is offered as a convenience
- to developers of shell applications, so they do not have to
- reproduce all of the code for proper initialization of the Tcl
- library and interactive shell operation. Other styles of embedding
- Tcl in an application are not supported by fBTcl_MainfR. Those
- must be achieved by calling lower level functions in the Tcl library
- directly.
- The fBTcl_MainfR function has been offered by the Tcl library
- since release Tcl 7.4. In older releases of Tcl, the Tcl library
- itself defined a function fBmainfR, but that lacks flexibility
- of embedding style and having a function fBmainfR in a library
- (particularly a shared library) causes problems on many systems.
- Having fBmainfR in the Tcl library would also make it hard to use
- Tcl in C++ programs, since C++ programs must have special C++
- fBmainfR functions.
- .PP
- Normally each shell application contains a small fBmainfR function
- that does nothing but invoke fBTcl_MainfR.
- fBTcl_MainfR then does all the work of creating and running a
- fBtclshfR-like application.
- .PP
- fBTcl_MainfR is not provided by the public interface of Tcl's
- stub library. Programs that call fBTcl_MainfR must be linked
- against the standard Tcl library. Extensions (stub-enabled or
- not) are not intended to call fBTcl_MainfR.
- .PP
- fBTcl_MainfR is not thread-safe. It should only be called by
- a single master thread of a multi-threaded application. This
- restriction is not a problem with normal use described above.
- .PP
- fBTcl_MainfR and therefore all applications based upon it, like
- fBtclshfR, use fBTcl_GetStdChannelfR to initialize the standard
- channels to their default values. See fBTcl_StandardChannelsfR for
- more information.
- .PP
- fBTcl_MainfR supports two modes of operation, depending on the
- values of fIargcfR and fIargvfR. If fIargv[1]fR exists and
- does not begin with the character fI-fR, it is taken to be the
- name of a file containing a fIstartup scriptfR, which fBTcl_MainfR
- will attempt to evaluate. Otherwise, fBTcl_MainfR will enter an
- interactive mode.
- .PP
- In either mode, fBTcl_MainfR will define in its master interpreter
- the Tcl variables fIargcfR, fIargvfR, fIargv0fR, and
- fItcl_interactivefR, as described in the documentation for fBtclshfR.
- .PP
- When it has finished its own initialization, but before it processes
- commands, fBTcl_MainfR calls the procedure given by the
- fIappInitProcfR argument. This procedure provides a ``hook'' for
- the application to perform its own initialization of the interpreter
- created by fBTcl_MainfR, such as defining application-specific
- commands. The procedure must have an interface that matches the
- type fBTcl_AppInitProcfR:
- .CS
- typedef int Tcl_AppInitProc(Tcl_Interp *fIinterpfR);
- .CE
- fIAppInitProcfR is almost always a pointer to fBTcl_AppInitfR; for more
- details on this procedure, see the documentation for fBTcl_AppInitfR.
- .PP
- When the fIappInitProcfR is finished, fBTcl_MainfR enters one
- of its two modes. If a startup script has been provided, fBTcl_MainfR
- attempts to evaluate it. Otherwise, interactive mode begins with
- examination of the variable fItcl_rcFileNamefR in the master
- interpreter. If that variable exists and holds the name of a readable
- file, the contents of that file are evaluated in the master interpreter.
- Then interactive operations begin,
- with prompts and command evaluation results written to the standard
- output channel, and commands read from the standard input channel
- and then evaluated. The prompts written to the standard output
- channel may be customized by defining the Tcl variables fItcl_prompt1fR
- and fItcl_prompt2fR as described in the documentation for fBtclshfR.
- The prompts and command evaluation results are written to the standard
- output channel only if the Tcl variable fItcl_interactivefR in the
- master interpreter holds a non-zero integer value.
- .PP
- .VS 8.4
- fBTcl_SetMainLoopfR allows setting an event loop procedure to be run.
- This allows, for example, Tk to be dynamically loaded and set its event
- loop. The event loop will run following the startup script. If you
- are in interactive mode, setting the main loop procedure will cause the
- prompt to become fileevent based and then the loop procedure is called.
- When the loop procedure returns in interactive mode, interactive operation
- will continue.
- The main loop procedure must have an interface that matches the type
- fBTcl_MainLoopProcfR:
- .CS
- typedef void Tcl_MainLoopProc(void);
- .CE
- .VE 8.4
- .PP
- fBTcl_MainfR does not return. Normally a program based on
- fBTcl_MainfR will terminate when the fBexitfR command is
- evaluated. In interactive mode, if an EOF or channel error
- is encountered on the standard input channel, then fBTcl_MainfR
- itself will evaluate the fBexitfR command after the main loop
- procedure (if any) returns. In non-interactive mode, after
- fBTcl_MainfR evaluates the startup script, and the main loop
- procedure (if any) returns, fBTcl_MainfR will also evaluate
- the fBexitfR command.
- .SH "SEE ALSO"
- tclsh(1), Tcl_GetStdChannel(3), Tcl_StandardChannels(3), Tcl_AppInit(3),
- exit(n)
- .SH KEYWORDS
- application-specific initialization, command-line arguments, main program