⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcl_main.3

📁 tcl是工具命令语言
💻 3
字号:
'\"'\" 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 NAMETcl_Main, Tcl_SetMainLoop \- main program and event loop definition for Tcl-based applications.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.sp\fBTcl_Main\fR(\fIargc, argv, appInitProc\fR).sp\fBTcl_SetMainLoop\fR(\fImainLoopProc\fR).SH ARGUMENTS.AS Tcl_AppInitProc *appInitProc.AP int argc inNumber of elements in \fIargv\fR..AP char *argv[] inArray of strings containing command-line arguments..AP Tcl_AppInitProc *appInitProc inAddress of an application-specific initialization procedure.The value for this argument is usually \fBTcl_AppInit\fR..AP Tcl_MainLoopProc *mainLoopProc inAddress of an application-specific event loop procedure..BE.SH DESCRIPTION.PP\fBTcl_Main\fR can serve as the main program for Tcl-based shellapplications.  A ``shell application'' is a programlike tclsh or wish that supports both interactive interpretationof Tcl and evaluation of a script contained in a file given asa command line argument.  \fBTcl_Main\fR is offered as a convenienceto developers of shell applications, so they do not have to reproduce all of the code for proper initialization of the Tcllibrary and interactive shell operation.  Other styles of embeddingTcl in an application are not supported by \fBTcl_Main\fR.  Thosemust be achieved by calling lower level functions in the Tcl librarydirectly.The \fBTcl_Main\fR function has been offered by the Tcl librarysince release Tcl 7.4.  In older releases of Tcl, the Tcl libraryitself defined a function \fBmain\fR, but that lacks flexibilityof embedding style and having a function \fBmain\fR in a library(particularly a shared library) causes problems on many systems.Having \fBmain\fR in the Tcl library would also make it hard to useTcl in C++ programs, since C++ programs must have special C++\fBmain\fR functions..PPNormally each shell application contains a small \fBmain\fR functionthat does nothing but invoke \fBTcl_Main\fR.\fBTcl_Main\fR then does all the work of creating and running a\fBtclsh\fR-like application..PP\fBTcl_Main\fR is not provided by the public interface of Tcl'sstub library.  Programs that call \fBTcl_Main\fR must be linkedagainst the standard Tcl library.  Extensions (stub-enabled ornot) are not intended to call \fBTcl_Main\fR..PP\fBTcl_Main\fR is not thread-safe.  It should only be called bya single master thread of a multi-threaded application.  Thisrestriction is not a problem with normal use described above..PP\fBTcl_Main\fR and therefore all applications based upon it, like\fBtclsh\fR, use \fBTcl_GetStdChannel\fR to initialize the standardchannels to their default values. See \fBTcl_StandardChannels\fR formore information..PP\fBTcl_Main\fR supports two modes of operation, depending on thevalues of \fIargc\fR and \fIargv\fR.  If \fIargv[1]\fR exists anddoes not begin with the character \fI-\fR, it is taken to be thename of a file containing a \fIstartup script\fR, which \fBTcl_Main\fRwill attempt to evaluate.  Otherwise, \fBTcl_Main\fR will enter aninteractive mode..PPIn either mode, \fBTcl_Main\fR will define in its master interpreterthe Tcl variables \fIargc\fR, \fIargv\fR, \fIargv0\fR, and\fItcl_interactive\fR, as described in the documentation for \fBtclsh\fR..PPWhen it has finished its own initialization, but before it processescommands, \fBTcl_Main\fR calls the procedure given by the\fIappInitProc\fR argument.  This procedure provides a ``hook'' forthe application to perform its own initialization of the interpretercreated by \fBTcl_Main\fR, such as defining application-specificcommands.  The procedure must have an interface that matches thetype \fBTcl_AppInitProc\fR:.CStypedef int Tcl_AppInitProc(Tcl_Interp *\fIinterp\fR);.CE\fIAppInitProc\fR is almost always a pointer to \fBTcl_AppInit\fR; for moredetails on this procedure, see the documentation for \fBTcl_AppInit\fR..PPWhen the \fIappInitProc\fR is finished, \fBTcl_Main\fR enters oneof its two modes.  If a startup script has been provided, \fBTcl_Main\fRattempts to evaluate it.  Otherwise, interactive mode begins withexamination of the variable \fItcl_rcFileName\fR in the masterinterpreter.  If that variable exists and holds the name of a readablefile, the contents of that file are evaluated in the master interpreter.Then interactive operations begin,with prompts and command evaluation results written to the standardoutput channel, and commands read from the standard input channeland then evaluated.  The prompts written to the standard outputchannel may be customized by defining the Tcl variables \fItcl_prompt1\fRand \fItcl_prompt2\fR as described in the documentation for \fBtclsh\fR.The prompts and command evaluation results are written to the standardoutput channel only if the Tcl variable \fItcl_interactive\fR in themaster interpreter holds a non-zero integer value..PP.VS 8.4\fBTcl_SetMainLoop\fR allows setting an event loop procedure to be run.This allows, for example, Tk to be dynamically loaded and set its eventloop.  The event loop will run following the startup script.  If youare in interactive mode, setting the main loop procedure will cause theprompt to become fileevent based and then the loop procedure is called.When the loop procedure returns in interactive mode, interactive operationwill continue.The main loop procedure must have an interface that matches the type\fBTcl_MainLoopProc\fR:.CStypedef void Tcl_MainLoopProc(void);.CE.VE 8.4.PP\fBTcl_Main\fR does not return.  Normally a program based on\fBTcl_Main\fR will terminate when the \fBexit\fR command isevaluated.  In interactive mode, if an EOF or channel erroris encountered on the standard input channel, then \fBTcl_Main\fRitself will evaluate the \fBexit\fR command after the main loopprocedure (if any) returns.  In non-interactive mode, after\fBTcl_Main\fR evaluates the startup script, and the main loopprocedure (if any) returns, \fBTcl_Main\fR will also evaluatethe \fBexit\fR command..SH "SEE ALSO"tclsh(1), Tcl_GetStdChannel(3), Tcl_StandardChannels(3), Tcl_AppInit(3),exit(n).SH KEYWORDSapplication-specific initialization, command-line arguments, main program

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -