home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume25 / tcl / part27 < prev    next >
Encoding:
Text File  |  1991-11-15  |  37.6 KB  |  1,056 lines

  1. Newsgroups: comp.sources.misc
  2. From: karl@sugar.neosoft.com (Karl Lehenbauer)
  3. Subject:  v25i095:  tcl - tool command language, version 6.1, Part27/33
  4. Message-ID: <1991Nov15.225555.21767@sparky.imd.sterling.com>
  5. X-Md4-Signature: d29e4a97a7aec6cca1efcb2c13436270
  6. Date: Fri, 15 Nov 1991 22:55:55 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: karl@sugar.neosoft.com (Karl Lehenbauer)
  10. Posting-number: Volume 25, Issue 95
  11. Archive-name: tcl/part27
  12. Environment: UNIX
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then unpack
  16. # it by saving it into a file and typing "sh file".  To overwrite existing
  17. # files, type "sh file -c".  You can also feed this as standard input via
  18. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  19. # will see the following message at the end:
  20. #        "End of archive 27 (of 33)."
  21. # Contents:  tcl6.1/doc/Tcl.man.1
  22. # Wrapped by karl@one on Tue Nov 12 19:44:30 1991
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'tcl6.1/doc/Tcl.man.1' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'tcl6.1/doc/Tcl.man.1'\"
  26. else
  27. echo shar: Extracting \"'tcl6.1/doc/Tcl.man.1'\" \(35297 characters\)
  28. sed "s/^X//" >'tcl6.1/doc/Tcl.man.1' <<'END_OF_FILE'
  29. X'\" Copyright 1989 Regents of the University of California
  30. X'\" Permission to use, copy, modify, and distribute this
  31. X'\" documentation for any purpose and without fee is hereby
  32. X'\" granted, provided that this notice appears in all copies.
  33. X'\" The University of California makes no representations about
  34. X'\" the suitability of this material for any purpose.  It is
  35. X'\" provided "as is" without express or implied warranty.
  36. X'\" 
  37. X'\" $Header: /user6/ouster/tcl/doc/RCS/Tcl.man,v 1.86 91/10/31 13:35:32 ouster Exp $ SPRITE (Berkeley)
  38. X'
  39. X.\" The definitions below are for supplemental macros used in Sprite
  40. X.\" manual entries.
  41. X.\"
  42. X.\" .HS name section [date [version]]
  43. X.\"    Replacement for .TH in other man pages.  See below for valid
  44. X.\"    section names.
  45. X.\"
  46. X.\" .AP type name in/out [indent]
  47. X.\"    Start paragraph describing an argument to a library procedure.
  48. X.\"    type is type of argument (int, etc.), in/out is either "in", "out",
  49. X.\"    or "in/out" to describe whether procedure reads or modifies arg,
  50. X.\"    and indent is equivalent to second arg of .IP (shouldn't ever be
  51. X.\"    needed;  use .AS below instead)
  52. X.\"
  53. X.\" .AS [type [name]]
  54. X.\"    Give maximum sizes of arguments for setting tab stops.  Type and
  55. X.\"    name are examples of largest possible arguments that will be passed
  56. X.\"    to .AP later.  If args are omitted, default tab stops are used.
  57. X.\"
  58. X.\" .BS
  59. X.\"    Start box enclosure.  From here until next .BE, everything will be
  60. X.\"    enclosed in one large box.
  61. X.\"
  62. X.\" .BE
  63. X.\"    End of box enclosure.
  64. X.\"
  65. X.\" .VS
  66. X.\"    Begin vertical sidebar, for use in marking newly-changed parts
  67. X.\"    of man pages.
  68. X.\"
  69. X.\" .VE
  70. X.\"    End of vertical sidebar.
  71. X.\"
  72. X.\" .DS
  73. X.\"    Begin an indented unfilled display.
  74. X.\"
  75. X.\" .DE
  76. X.\"    End of indented unfilled display.
  77. X.\"
  78. X'    # Heading for Sprite man pages
  79. X.de HS
  80. X.if '\\$2'cmds'       .TH \\$1 1 \\$3 \\$4
  81. X.if '\\$2'lib'        .TH \\$1 3 \\$3 \\$4
  82. X.if '\\$2'tcl'        .TH \\$1 3 \\$3 \\$4
  83. X.if '\\$2'tk'         .TH \\$1 3 \\$3 \\$4
  84. X.if t .wh -1.3i ^B
  85. X.nr ^l \\n(.l
  86. X.ad b
  87. X..
  88. X'    # Start an argument description
  89. X.de AP
  90. X.ie !"\\$4"" .TP \\$4
  91. X.el \{\
  92. X.   ie !"\\$2"" .TP \\n()Cu
  93. X.   el          .TP 15
  94. X.\}
  95. X.ie !"\\$3"" \{\
  96. X.ta \\n()Au \\n()Bu
  97. X\&\\$1    \\fI\\$2\\fP    (\\$3)
  98. X.\".b
  99. X.\}
  100. X.el \{\
  101. X.br
  102. X.ie !"\\$2"" \{\
  103. X\&\\$1    \\fI\\$2\\fP
  104. X.\}
  105. X.el \{\
  106. X\&\\fI\\$1\\fP
  107. X.\}
  108. X.\}
  109. X..
  110. X'    # define tabbing values for .AP
  111. X.de AS
  112. X.nr )A 10n
  113. X.if !"\\$1"" .nr )A \\w'\\$1'u+3n
  114. X.nr )B \\n()Au+15n
  115. X.\"
  116. X.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
  117. X.nr )C \\n()Bu+\\w'(in/out)'u+2n
  118. X..
  119. X'    # BS - start boxed text
  120. X'    # ^y = starting y location
  121. X'    # ^b = 1
  122. X.de BS
  123. X.br
  124. X.mk ^y
  125. X.nr ^b 1u
  126. X.if n .nf
  127. X.if n .ti 0
  128. X.if n \l'\\n(.lu\(ul'
  129. X.if n .fi
  130. X..
  131. X'    # BE - end boxed text (draw box now)
  132. X.de BE
  133. X.nf
  134. X.ti 0
  135. X.mk ^t
  136. X.ie n \l'\\n(^lu\(ul'
  137. X.el \{\
  138. X.\"    Draw four-sided box normally, but don't draw top of
  139. X.\"    box if the box started on an earlier page.
  140. X.ie !\\n(^b-1 \{\
  141. X\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  142. X.\}
  143. X.el \}\
  144. X\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  145. X.\}
  146. X.\}
  147. X.fi
  148. X.br
  149. X.nr ^b 0
  150. X..
  151. X'    # VS - start vertical sidebar
  152. X'    # ^Y = starting y location
  153. X'    # ^v = 1 (for troff;  for nroff this doesn't matter)
  154. X.de VS
  155. X.mk ^Y
  156. X.ie n 'mc \s12\(br\s0
  157. X.el .nr ^v 1u
  158. X..
  159. X'    # VE - end of vertical sidebar
  160. X.de VE
  161. X.ie n 'mc
  162. X.el \{\
  163. X.ev 2
  164. X.nf
  165. X.ti 0
  166. X.mk ^t
  167. X\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
  168. X.sp -1
  169. X.fi
  170. X.ev
  171. X.\}
  172. X.nr ^v 0
  173. X..
  174. X'    # Special macro to handle page bottom:  finish off current
  175. X'    # box/sidebar if in box/sidebar mode, then invoked standard
  176. X'    # page bottom macro.
  177. X.de ^B
  178. X.ev 2
  179. X'ti 0
  180. X'nf
  181. X.mk ^t
  182. X.if \\n(^b \{\
  183. X.\"    Draw three-sided box if this is the box's first page,
  184. X.\"    draw two sides but no top otherwise.
  185. X.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
  186. X.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  187. X.\}
  188. X.if \\n(^v \{\
  189. X.nr ^x \\n(^tu+1v-\\n(^Yu
  190. X\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
  191. X.\}
  192. X.bp
  193. X'fi
  194. X.ev
  195. X.if \\n(^b \{\
  196. X.mk ^y
  197. X.nr ^b 2
  198. X.\}
  199. X.if \\n(^v \{\
  200. X.mk ^Y
  201. X.\}
  202. X..
  203. X'    # DS - begin display
  204. X.de DS
  205. X.RS
  206. X.nf
  207. X.sp
  208. X..
  209. X'    # DE - end display
  210. X.de DE
  211. X.fi
  212. X.RE
  213. X.sp .5
  214. X..
  215. X.de UL
  216. X\\$1\l'|0\(ul'\\$2
  217. X..
  218. X.HS Tcl tcl
  219. X.BS
  220. X.SH NAME
  221. XTcl \- overview of tool command language facilities
  222. X.BE
  223. X
  224. X.SH INTRODUCTION
  225. X.PP
  226. XTcl stands for ``tool command language'' and is pronounced ``tickle.''
  227. XIt is actually two things:
  228. Xa language and a library.
  229. XFirst, Tcl is a simple textual language,
  230. Xintended primarily for issuing commands to interactive programs such
  231. Xas text editors, debuggers, illustrators, and shells.  It has
  232. Xa simple syntax and is also programmable, so
  233. XTcl users can write command procedures to provide more powerful
  234. Xcommands than those in the built-in set.
  235. X.PP
  236. XSecond, Tcl is a library package that can be embedded in application
  237. Xprograms.  The Tcl library consists of a parser for the Tcl
  238. Xlanguage, routines to implement the Tcl built-in commands, and
  239. Xprocedures that allow each application to extend Tcl with additional
  240. Xcommands specific to that application.  The application program
  241. Xgenerates Tcl commands and passes them to the Tcl parser for
  242. Xexecution.  Commands may be generated
  243. Xby reading characters from an input
  244. Xsource, or by associating command strings with elements of the
  245. Xapplication's user interface, such as menu entries, buttons, or
  246. Xkeystrokes.
  247. XWhen the Tcl library receives commands it parses them
  248. Xinto component fields and executes built-in commands directly.
  249. XFor commands implemented by the
  250. Xapplication, Tcl calls back to the application to execute the
  251. Xcommands.  In many cases commands will invoke recursive invocations
  252. Xof the Tcl interpreter by passing in additional strings to execute
  253. X(procedures, looping commands, and conditional commands all work
  254. Xin this way).
  255. X.PP
  256. XAn application program gains three advantages by using Tcl for
  257. Xits command language.  First, Tcl provides a standard syntax:  once
  258. Xusers know Tcl, they will be able to issue commands easily
  259. Xto any Tcl-based application.  Second, Tcl provides programmability.
  260. XAll a Tcl application needs to do is to implement a few
  261. Xapplication-specific low-level commands.  Tcl provides many utility
  262. Xcommands plus a general programming interface for building up
  263. Xcomplex command procedures.  By using Tcl, applications need not
  264. Xre-implement these features.  Third, Tcl can be used as
  265. X.VS
  266. Xa common language for communicating between applications.
  267. XInter-application communication is not built into the Tcl core
  268. Xdescribed here, but various add-on libraries, such as the Tk toolkit,
  269. Xallow applications to issue commands to each other.
  270. XThis makes it possible for applications to work together in much
  271. Xmore powerful ways than was previously possible.
  272. X.VE
  273. X.PP
  274. XThis manual page focuses primarily on the Tcl language.  It describes
  275. Xthe language syntax and the built-in commands that will be available in
  276. Xany application based on Tcl.  The individual library
  277. Xprocedures are described in more detail in separate manual pages, one
  278. Xper procedure.
  279. X
  280. X.SH "INTERPRETERS"
  281. X.PP
  282. XThe central data structure in Tcl is an interpreter (C type
  283. X``Tcl_Interp'').  An interpreter consists of a set of command
  284. Xbindings, a set of variable values, and a few other miscellaneous
  285. Xpieces of state.  Each Tcl command is interpreted in the context
  286. Xof a particular interpreter.
  287. XSome Tcl-based applications will maintain
  288. Xmultiple interpreters simultaneously, each associated with a
  289. Xdifferent widget or portion of the application.
  290. XInterpreters are relatively lightweight structures.  They can
  291. Xbe created and deleted quickly, so application programmers should feel free to
  292. Xuse multiple interpreters if that simplifies the application.
  293. XEventually Tcl will provide a mechanism for sending Tcl commands
  294. Xand results back and forth between interpreters, even if the
  295. Xinterpreters are managed by different processes.
  296. X
  297. X.SH "DATA TYPES"
  298. X.PP
  299. XTcl supports only one type of data:  strings.  All commands,
  300. Xall arguments to commands, all command results, and all variable values
  301. Xare strings.
  302. XWhere commands require numeric arguments or return numeric results,
  303. Xthe arguments and results are passed as strings.
  304. XMany commands expect their string arguments to have certain formats,
  305. Xbut this interpretation is
  306. Xup to the individual commands.  For example, arguments often contain
  307. XTcl command strings, which may get executed as part of the commands.
  308. XThe easiest way to understand the Tcl interpreter is to remember that
  309. Xeverything is just an operation on a string.  In many cases Tcl constructs
  310. Xwill look similar to more structured constructs from other languages.
  311. XHowever, the Tcl constructs
  312. Xare not structured at all; they are just strings of characters, and this
  313. Xgives them a different behavior than the structures they may look like.
  314. X.PP
  315. XAlthough the exact interpretation of a Tcl string depends on who is
  316. Xdoing the interpretation, there are three common forms that strings
  317. Xtake:  commands, expressions, and lists.  The major sections below
  318. Xdiscuss these three forms in more detail.
  319. X
  320. X.SH "BASIC COMMAND SYNTAX"
  321. X.PP
  322. XThe Tcl language has syntactic similarities to both the Unix shells
  323. Xand Lisp.  However, the interpretation of commands is different
  324. Xin Tcl than in either of those other two systems.
  325. XA Tcl command string consists of one or more commands separated
  326. Xby newline characters or semi-colons.
  327. XEach command consists of a collection of fields separated by
  328. Xwhite space (spaces or tabs).
  329. XThe first field must be the name of a command, and the
  330. Xadditional fields, if any, are arguments that will be passed to
  331. Xthat command.  For example, the command
  332. X.DS
  333. X\fBset a 22\fR
  334. X.DE
  335. Xhas three fields:  the first, \fBset\fR, is the name of a Tcl command, and
  336. Xthe last two, \fBa\fR and \fB22\fR, will be passed as arguments to
  337. Xthe \fBset\fR command.  The command name may refer either to a built-in
  338. XTcl command, an application-specific command bound in with the library
  339. Xprocedure \fBTcl_CreateCommand\fR, or a command procedure defined with the
  340. X\fBproc\fR built-in command.
  341. XArguments are passed literally as
  342. Xtext strings.  Individual commands may interpret those strings in any
  343. Xfashion they wish.  The \fBset\fR command, for example, will treat its
  344. Xfirst argument as the name of a variable and its second argument as a
  345. Xstring value to assign to that variable.  For other commands arguments
  346. Xmay be interpreted as integers, lists, file names, or Tcl commands.
  347. X.PP
  348. X.VS
  349. XCommand names should normally be typed completely (e.g. no abbreviations).
  350. XHowever, if the Tcl interpreter cannot locate a command it invokes a
  351. Xspecial command named \fBunknown\fR which attempts to find or create
  352. Xthe command.
  353. XFor example, at many sites \fBunknown\fR will search
  354. Xthrough library directories for the desired command and create it
  355. Xas a Tcl procedure if it is found.
  356. XThe \fBunknown\fR command often provides automatic completion of
  357. Xabbreviated commands, but usually only for commands that were typed
  358. Xinteractively.
  359. XIt's probably a bad idea to use abbreviations in command scripts
  360. Xand other forms that will be re-used over time:  changes
  361. Xto the command set may cause abbreviations to become ambiguous,
  362. Xresulting in scripts that no longer work.
  363. X.VE
  364. X
  365. X.SH "COMMENTS"
  366. X.PP
  367. XIf the first non-blank character in a command is \fB#\fR, then everything
  368. Xfrom the \fB#\fR up through the next newline character is treated as
  369. Xa comment and ignored.  When comments are embedded inside nested
  370. Xcommands (e.g. fields enclosed in braces) they must have properly-matched
  371. Xbraces (this is necessary because when Tcl parses the top-level command
  372. Xit doesn't yet know that the nested field will be used as a command so
  373. Xit cannot process the nested comment character as a comment).
  374. X
  375. X.SH "GROUPING ARGUMENTS WITH DOUBLE-QUOTES"
  376. X.PP
  377. XNormally each argument field ends at the next white space, but
  378. Xdouble-quotes may be used to create arguments with embedded
  379. Xspace.  If an argument
  380. Xfield begins with a double-quote, then the argument isn't
  381. Xterminated by white space (including newlines) or a semi-colon
  382. X(see below for information on semi-colons); instead it ends at the next
  383. Xdouble-quote character.  The double-quotes are not included
  384. Xin the resulting argument.  For example, the
  385. Xcommand
  386. X.DS
  387. X\fBset a "This is a single argument"\fR
  388. X.DE
  389. Xwill pass two arguments to \fBset\fR:  \fBa\fR and
  390. X\fBThis is a single argument\fR.  Within double-quotes, command
  391. Xsubstitutions, variable substitutions, and backslash substitutions
  392. Xstill occur, as described below.  If the first character of a
  393. Xcommand field is not a quote, then quotes receive no special
  394. Xinterpretation in the parsing of that field.
  395. X
  396. X.SH "GROUPING ARGUMENTS WITH BRACES"
  397. X.PP
  398. XCurly braces may also be used for grouping arguments.  They are
  399. Xsimilar to quotes except for two differences.  First, they nest;
  400. Xthis makes them easier to use for complicated arguments like nested Tcl
  401. Xcommand strings.  Second, the substitutions described below for
  402. Xcommands, variables, and backslashes do \fInot\fR occur in arguments
  403. Xenclosed in braces, so braces can be used to prevent substitutions
  404. Xwhere they are undesirable.
  405. XIf an argument field
  406. Xbegins with a left brace, then the argument ends at the matching
  407. Xright brace.  Tcl will strip off the outermost layer of braces
  408. Xand pass the information between the braces to the command without
  409. Xany further modification.  For example, in the command
  410. X.DS
  411. X\fBset a {xyz a {b c d}}\fR
  412. X.DE
  413. Xthe \fBset\fR command will receive two arguments: \fBa\fR
  414. Xand \fBxyz a {b c d}\fR.
  415. X.PP
  416. XWhen braces or quotes are in effect, the matching brace
  417. Xor quote need not be on
  418. Xthe same line as the starting quote or brace; in this case
  419. Xthe newline will be
  420. Xincluded in the argument field along with any other characters up to the
  421. Xmatching brace or quote.  For example, the \fBeval\fR command
  422. Xtakes one
  423. Xargument, which is a command string; \fBeval\fR invokes the Tcl
  424. Xinterpreter to execute the command string.  The command
  425. X.DS
  426. X\fBeval {
  427. X    set a 22
  428. X    set b 33
  429. X}\fR
  430. X.DE
  431. Xwill assign the value \fB22\fR to \fBa\fR and \fB33\fR to \fBb\fR.
  432. X.PP
  433. XIf the first character of a command field is not a left
  434. Xbrace, then neither left nor right
  435. Xbraces in the field will be treated specially (except as part of
  436. Xvariable substitution; see below).
  437. X
  438. X.SH "COMMAND SUBSTITUTION WITH BRACKETS"
  439. X.PP
  440. XIf an open bracket occurs in a field of a command, then
  441. Xcommand substitution occurs (except for fields enclosed in
  442. Xbraces).  All of the text up to the matching
  443. Xclose bracket is treated as a Tcl command and executed immediately.
  444. XThen the result of that command is substituted for the bracketed
  445. Xtext.  For example, consider the command
  446. X.DS
  447. X\fBset a [set b]\fR
  448. X.DE
  449. XWhen the \fBset\fR command has only a single argument, it is the
  450. Xname of a variable and \fBset\fR returns the contents of that
  451. Xvariable.  In this case, if variable \fBb\fR has the value \fBfoo\fR,
  452. Xthen the command above is equivalent to the command
  453. X.DS
  454. X\fBset a foo\fR
  455. X.DE
  456. XBrackets can be used in more complex ways.  For example, if the
  457. Xvariable \fBb\fR has the value \fBfoo\fR and the variable \fBc\fR
  458. Xhas the value \fBgorp\fR, then the command
  459. X.DS
  460. X\fBset a xyz[set b].[set c]\fR
  461. X.DE
  462. Xis equivalent to the command
  463. X.DS
  464. X\fBset a xyzfoo.gorp\fR
  465. X.DE
  466. X.VS
  467. XA bracketed command may contain multiple commands separated by
  468. Xnewlines or semi-colons in the usual fashion.
  469. XIn this case the value of the last command is used for substitution.
  470. XFor example, the command
  471. X.DS
  472. X\fBset a x[set b 22
  473. Xexpr $b+2]x\fR
  474. X.DE
  475. Xis equivalent to the command
  476. X.DS
  477. X\fBset a x24x\fR
  478. X.DE
  479. X.VE
  480. XIf a field is enclosed in braces then the brackets and the characters
  481. Xbetween them are not interpreted specially; they are passed through
  482. Xto the argument verbatim.
  483. X
  484. X.SH "VARIABLE SUBSTITUTION WITH $"
  485. X.PP
  486. XThe dollar sign (\fB$\fR) may be used as a special shorthand form
  487. Xfor substituting variable values.
  488. XIf \fB$\fR appears in an argument that isn't enclosed in braces
  489. Xthen variable substitution will occur.  The characters after
  490. Xthe \fB$\fR, up to the first character that isn't a number, letter, or
  491. Xunderscore, are taken as a variable name and the string value of that
  492. Xvariable is substituted for the name.
  493. X.VS
  494. XFor example, if variable \fBfoo\fR
  495. Xhas the value \fBtest\fR, then the command
  496. X.DS C
  497. X\fBset a $foo.c\fR
  498. X.DE
  499. Xis equivalent to the command
  500. X.DS C
  501. X\fBset a test.c\fR
  502. X.DE
  503. X.PP
  504. XThere are two special forms for variable substitution.
  505. XIf the next character after the name of the variable is an
  506. Xopen parenthesis, then the variable is assumed to be an array
  507. Xname, and all of the characters between the open parenthesis
  508. Xand the next close parenthesis are taken as an index into the array.
  509. XCommand substitutions and variable substitutions are
  510. Xperformed on the information between the parentheses before it is
  511. Xused as an index.
  512. XFor example, if the variable \fBx\fR is an array with one element
  513. Xnamed \fBfirst\fR and value \fB87\fR and another element named
  514. X\fB14\fR and value \fBmore\fR, then the command
  515. X.DS C
  516. X\fBset a xyz$x(first)zyx
  517. X.DE
  518. Xis equivalent to the command
  519. X.DS C
  520. X\fBset a xyz87zyx\fR
  521. X.DE
  522. XIf the variable \fBindex\fR has the value \fB14\fR, then the command
  523. X.DS C
  524. X\fBset a xyz$x($index)zyx
  525. X.DE
  526. Xis equivalent to the command
  527. X.DS C
  528. X\fBset a xyzmorezyx
  529. X.DE
  530. XFor more information on arrays, see VARIABLES AND ARRAYS below.
  531. X.PP
  532. XThe second special form for variables occurs when
  533. Xthe dollar sign is followed by an open curly brace.
  534. XIn this case the variable name consists of all the characters
  535. Xup to the next curly brace.
  536. XArray references are not possible in this form:  the name
  537. Xbetween braces is assumed to refer to a scalar variable.
  538. XFor example, if variable \fBfoo\fR has the value \fBtest\fR,
  539. Xthen the command
  540. X.DS C
  541. X\fBset a abc${foo}bar\fR
  542. X.DE
  543. Xis equivalent to the command
  544. X.DS C
  545. X\fBset a abctestbar\fR
  546. X.DE
  547. X.VE
  548. XVariable substitution does not occur in arguments that are enclosed
  549. Xin braces:  the
  550. Xdollar sign and variable name are passed through to the argument verbatim.
  551. X.PP
  552. XThe dollar sign abbreviation is simply a shorthand form.  \fB$a\fR is
  553. Xcompletely equivalent to \fB[set a]\fR; it is provided as a convenience
  554. Xto reduce typing.
  555. X
  556. X.SH "SEPARATING COMMANDS WITH SEMI-COLONS"
  557. X.PP
  558. XNormally, each command occupies one line (the command is terminated by
  559. Xa newline character).  However, semi-colon (``;'') is treated
  560. Xas a command separator character; multiple commands may be placed
  561. Xon one line by separating them with a semi-colon.  Semi-colons are
  562. Xnot treated as command separators if they appear within curly braces
  563. Xor double-quotes.
  564. X
  565. X.SH "BACKSLASH SUBSTITUTION"
  566. X.PP
  567. XBackslashes may be used to insert non-printing characters into
  568. Xcommand fields and also to insert special characters like
  569. Xbraces and brackets into fields
  570. Xwithout them being interpreted specially as described above.
  571. XThe backslash sequences understood by the Tcl interpreter are
  572. Xlisted below.  In each case, the backslash
  573. Xsequence is replaced by the given character:
  574. X.TP 20
  575. X\fB\eb\fR
  576. XBackspace (0x8).
  577. X.TP 20
  578. X\fB\ef\fR
  579. XForm feed (0xc).
  580. X.TP 20
  581. X\fB\en\fR
  582. XNewline (0xa).
  583. X.TP 20
  584. X\fB\er\fR
  585. XCarriage-return (0xd).
  586. X.TP 20
  587. X\fB\et\fR
  588. XTab (0x9).
  589. X.TP 20
  590. X\fB\ev\fR
  591. XVertical tab (0xb).
  592. X.TP 20
  593. X\fB\e{\fR
  594. XLeft brace (``{'').
  595. X.TP 20
  596. X\fB\e}\fR
  597. XRight brace (``}'').
  598. X.TP 20
  599. X\fB\e[\fR
  600. XOpen bracket (``['').
  601. X.TP 20
  602. X\fB\e]\fR
  603. XClose bracket (``]'').
  604. X.TP 20
  605. X\fB\e$\fR
  606. XDollar sign (``$'').
  607. X.TP 20
  608. X\fB\e<space>\fR
  609. XSpace (`` ''): doesn't terminate argument.
  610. X.br
  611. X.TP 20
  612. X\fB\e;\fR
  613. XSemi-colon: doesn't terminate command.
  614. X.TP 20
  615. X\fB\e"\fR
  616. XDouble-quote.
  617. X.TP 20
  618. X\fB\e<newline>\fR
  619. XNothing:  this joins two lines together
  620. Xinto a single line.  This backslash feature is unique in that
  621. Xit will be applied even when the sequence occurs within braces.
  622. X.TP 20
  623. X\fB\e\e\fR
  624. XBackslash (``\e'').
  625. X.TP 20
  626. X\fB\e\fIddd\fR
  627. XThe digits \fIddd\fR (one, two, or three of them) give the octal value of
  628. Xthe character.  Null characters may not be embedded in command fields;
  629. Xif \fIddd\fR is zero then the backslash sequence is ignored (i.e. it
  630. Xmaps to an empty string).
  631. X.PP
  632. XFor example, in the command
  633. X.DS
  634. X\fBset a \e{x\e[\e\0yz\e141\fR
  635. X.DE
  636. Xthe second argument to \fBset\fR will be ``\fB{x[\0yza\fR''.
  637. X.PP
  638. XIf a backslash is followed by something other than one of the options
  639. Xdescribed above, then the backslash is transmitted to the argument
  640. Xfield without any special processing, and the Tcl scanner continues
  641. Xnormal processing with the next character.  For example, in the
  642. Xcommand
  643. X.DS
  644. X\fBset \e*a \e\e\e{foo\fR
  645. X.DE
  646. XThe first argument to \fBset\fR will be \fB\e*a\fR and the second
  647. Xargument will be \fB\e{foo\fR.
  648. X.PP
  649. XIf an argument is enclosed in braces, then backslash sequences inside
  650. Xthe argument are parsed but no substitution occurs (except for
  651. Xbackslash-newline):  the backslash
  652. Xsequence is passed through to the argument as is, without making
  653. Xany special interpretation of the characters in the backslash sequence.
  654. XIn particular, backslashed braces are not counted in locating the
  655. Xmatching right brace that terminates the argument.
  656. XFor example, in the
  657. Xcommand
  658. X.DS
  659. X\fBset a {\e{abc}\fR
  660. X.DE
  661. Xthe second argument to \fBset\fR will be \fB\e{abc\fR.
  662. X.PP
  663. XThis backslash mechanism is not sufficient to generate absolutely
  664. Xany argument structure; it only covers the
  665. Xmost common cases.  To produce particularly complicated arguments
  666. Xit is probably easiest to use the \fBformat\fR command along with
  667. Xcommand substitution.
  668. X
  669. X.SH "COMMAND SUMMARY"
  670. X.IP [1]
  671. XA command is just a string.
  672. X.IP [2]
  673. XWithin a string commands are separated by newlines or semi-colons
  674. X(unless the newline or semi-colon is within braces or brackets
  675. Xor is backslashed).
  676. X.IP [3]
  677. XA command consists of fields.  The first field is the name of the command,
  678. Xand may be abbreviated.
  679. XThe other fields are strings that are passed to that command as arguments.
  680. X.IP [4]
  681. XFields are normally separated by white space.
  682. X.IP [5]
  683. XDouble-quotes allow white space and semi-colons to appear within
  684. Xa single argument.
  685. XCommand substitution, variable substitution, and backslash substitution
  686. Xstill occur inside quotes.
  687. X.IP [6]
  688. XBraces defer interpretation of special characters.
  689. XIf a field begins with a left brace, then it consists of everything
  690. Xbetween the left brace and the matching right brace. The
  691. Xbraces themselves are not included in the argument.
  692. XNo further processing is done on the information between the braces
  693. Xexcept that backslash-newline sequences are eliminated.
  694. X.IP [7]
  695. XIf a field doesn't begin with a brace then backslash,
  696. Xvariable, and command substitution are done on the field.  Only a
  697. Xsingle level of processing is done:  the results of one substitution
  698. Xare not scanned again for further substitutions or any other
  699. Xspecial treatment.  Substitution can
  700. Xoccur on any field of a command, including the command name
  701. Xas well as the arguments.
  702. X.IP [8]
  703. XIf the first non-blank character of a command is a \fB#\fR, everything
  704. Xfrom the \fB#\fR up through the next newline is treated as a comment
  705. Xand ignored.
  706. X
  707. X.SH "EXPRESSIONS"
  708. X.VS
  709. X.PP
  710. XThe second major interpretation applied to strings in Tcl is
  711. Xas expressions.  Several commands, such as \fBexpr\fR, \fBfor\fR,
  712. Xand \fBif\fR, treat one or more of their arguments as expressions
  713. Xand call the Tcl expression processors (\fBTcl_ExprLong\fR,
  714. X\fBTcl_ExprBoolean\fR, etc.) to evaluate them.
  715. XThe operators permitted in Tcl expressions are a subset of
  716. Xthe operators permitted in C expressions, and they have the
  717. Xsame meaning and precedence as the corresponding C operators.
  718. XExpressions almost always yield numeric results
  719. X(integer or floating-point values).
  720. XFor example, the expression
  721. X.DS
  722. X\fB8.2 + 6\fR
  723. X.DE
  724. Xevaluates to 14.2.
  725. XTcl expressions differ from C expressions in the way that
  726. Xoperands are specified, and in that Tcl expressions support
  727. Xnon-numeric operands and string comparisons.
  728. X.PP
  729. XA Tcl expression consists of a combination of operands, operators,
  730. Xand parentheses.
  731. XWhite space may be used between the operands and operators and
  732. Xparentheses; it is ignored by the expression processor.
  733. XWhere possible, operands are interpreted as integer values.
  734. XInteger values may be specified in decimal (the normal case), in octal (if the
  735. Xfirst character of the operand is \fB0\fR), or in hexadecimal (if the first
  736. Xtwo characters of the operand are \fB0x\fR).
  737. XIf an operand does not have one of the integer formats given
  738. Xabove, then it is treated as a floating-point number if that is
  739. Xpossible.  Floating-point numbers may be specified in any of the
  740. Xways accepted by an ANSI-compliant C compiler (except that the
  741. X``f'', ``F'', ``l'', and ``L'' suffixes will not be permitted in
  742. Xmost installations).  For example, all of the
  743. Xfollowing are valid floating-point numbers:  2.1, 3., 6e4, 7.91e+16.
  744. XIf no numeric interpretation is possible, then an operand is left
  745. Xas a string (and only a limited set of operators may be applied to
  746. Xit).
  747. X.PP
  748. XOperators may be specified in any of the following ways:
  749. X.IP [1]
  750. XAs an numeric value, either integer or floating-point.
  751. X.IP [2]
  752. XAs a Tcl variable, using standard \fB$\fR notation.
  753. XThe variable's value will be used as the operand.
  754. X.IP [3]
  755. XAs a string enclosed in double-quotes.
  756. XThe expression parser will perform backslash, variable, and
  757. Xcommand substitutions on the information between the quotes,
  758. Xand use the resulting value as the operand
  759. X.IP [4]
  760. XAs a string enclosed in braces.
  761. XThe characters between the open brace and matching close brace
  762. Xwill be used as the operand without any substitutions.
  763. X.IP [5]
  764. XAs a Tcl command enclosed in brackets.
  765. XThe command will be executed and its result will be used as
  766. Xthe operand.
  767. X.IP [6]
  768. XAn unquoted string consisting of any number of letters, digits,
  769. Xand underscores (but a digit may not be the first character).
  770. X.LP
  771. XWhere substitutions occur above (e.g. inside quoted strings), they
  772. Xare performed by the expression processor.
  773. XHowever, an additional layer of substitution may already have
  774. Xbeen performed by the command parser before the expression
  775. Xprocessor was called.
  776. XAs discussed below, it is usually best to enclose expressions
  777. Xin braces to prevent the command parser from performing substitutions
  778. Xon the contents.
  779. X.PP
  780. XFor some examples of simple expressions, suppose the variable
  781. X\fBa\fR has the value 3 and
  782. Xthe variable \fBb\fR has the value 6.
  783. XThen the expression on the left side of each of the lines below
  784. Xwill evaluate to the value on the right side of the line:
  785. X.DS
  786. X.ta 6c
  787. X\fB3.1 + $a    6.1
  788. X2 + "$a.$b"    5.6
  789. X4*[length "6 2"]    8
  790. X{word one} < "word $a"    0\fR
  791. X.DE
  792. X.PP
  793. XThe valid operators are listed below, grouped in decreasing order
  794. Xof precedence:
  795. X.TP 20
  796. X\fB\-\0\0~\0\0!\fR
  797. XUnary minus, bit-wise NOT, logical NOT.  None of these operands
  798. Xmay be applied to string operands, and bit-wise NOT may be
  799. Xapplied only to integers.
  800. X.TP 20
  801. X\fB*\0\0/\0\0%\fR
  802. XMultiply, divide, remainder.  None of these operands may be
  803. Xapplied to string operands, and remainder may be applied only
  804. Xto integers.
  805. X.TP 20
  806. X\fB+\0\0\-\fR
  807. XAdd and subtract.  Valid for any numeric operands.
  808. X.TP 20
  809. X\fB<<\0\0>>\fR
  810. XLeft and right shift.  Valid for integer operands only.
  811. X.TP 20
  812. X\fB<\0\0>\0\0<=\0\0>=\fR
  813. XBoolean less, greater, less than or equal, and greater than or equal.
  814. XEach operator produces 1 if the condition is true, 0 otherwise.
  815. XThese operators may be applied to strings as well as numeric operands,
  816. Xin which case string comparison is used.
  817. X.TP 20
  818. X\fB==\0\0!=\fR
  819. XBoolean equal and not equal.  Each operator produces a zero/one result.
  820. XValid for all operand types.
  821. X.TP 20
  822. X\fB&\fR
  823. XBit-wise AND.  Valid for integer operands only.
  824. X.TP 20
  825. X\fB^\fR
  826. XBit-wise exclusive OR.  Valid for integer operands only.
  827. X.TP 20
  828. X\fB|\fR
  829. XBit-wise OR.  Valid for integer operands only.
  830. X.TP 20
  831. X\fB&&\fR
  832. XLogical AND.  Produces a 1 result if both operands are non-zero, 0 otherwise.
  833. XValid for numeric operands only (integers or floating-point).
  834. X.TP 20
  835. X\fB||\fR
  836. XLogical OR.  Produces a 0 result if both operands are zero, 1 otherwise.
  837. XValid for numeric operands only (integers or floating-point).
  838. X.TP 20
  839. X\fIx\fB?\fIy\fB:\fIz\fR
  840. XIf-then-else, as in C.  If \fIx\fR
  841. Xevaluates to non-zero, then the result is the value of \fIy\fR.
  842. XOtherwise the result is the value of \fIz\fR.
  843. XThe \fIx\fR operand must have a numeric value.
  844. X.LP
  845. XSee the C manual for more details on the results
  846. Xproduced by each operator.
  847. XAll of the binary operators group left-to-right within the same
  848. Xprecedence level.  For example, the expression
  849. X.DS
  850. X\fB4*2 < 7\fR
  851. X.DE
  852. Xevaluates to 0.
  853. X.PP
  854. XThe \fB&&\fP, \fB||\fP, and \fB?:\fP operators have ``lazy
  855. Xevaluation'', just as in C, 
  856. Xwhich means that operands are not evaluated if they are
  857. Xnot needed to determine the outcome.  For example, in
  858. X.DS
  859. X\fB$v ? [a] : [b]\fR
  860. X.DE
  861. Xonly one of \fB[a]\fR or \fB[b]\fR will actually be evaluated,
  862. Xdepending on the value of \fB$v\fP.
  863. X.PP
  864. XAll internal computations involving integers are done with the C type
  865. X\fIlong\fP, and all internal computations involving floating-point are
  866. Xdone with the C type \fIdouble\fP.
  867. XWhen converting a string to floating-point, exponent overflow is
  868. Xdetected and results in a Tcl error.
  869. XFor conversion to integer from string, detection of overflow depends
  870. Xon the behavior of some routines in the local C library, so it should
  871. Xbe regarded as unreliable.
  872. XIn any case, overflow and underflow are generally not detected
  873. Xreliably for intermediate results.
  874. X.PP
  875. XConversion among internal representations for integer, floating-point,
  876. Xand string operands is done automatically as needed.
  877. XFor arithmetic computations, integers are used until some
  878. Xfloating-point number is introduced, after which floating-point is used.
  879. XFor example,
  880. X.DS
  881. X\fB5 / 4\fR
  882. X.DE
  883. Xyields the result 1, while
  884. X.DS
  885. X\fB5 / 4.0\fR
  886. X\fB5 / ( [length "abcd" chars] + 0.0 )
  887. X.DE
  888. Xboth yield the result 1.25.
  889. X.PP
  890. XString values may be used as operands of the comparison operators,
  891. Xalthough the expression evaluator tries to do comparisons as integer
  892. Xor floating-point when it can.
  893. XIf one of the operands of a comparison is a string and the other
  894. Xhas a numeric value, the numeric operand is converted back to
  895. Xa string using the C \fIsprintf\fP format specifier
  896. X\fB%d\fR for integers and \fB%g\fR for floating-point values.
  897. XFor example, the expressions
  898. X.DS
  899. X\fB"0x03" > "2"\fR
  900. X\fB"0y" < "0x12"\fR
  901. X.DE
  902. Xboth evaluate to 1.  The first comparison is done using integer
  903. Xcomparison, and the second is done using string comparison after
  904. Xthe second operand is converted to the string ``18''.
  905. X.VE
  906. X.PP
  907. XIn general it is safest to enclose an expression in braces when
  908. Xentering it in a command:  otherwise, if the expression contains
  909. Xany white space then the Tcl interpreter will split it
  910. Xamong several arguments.  For example, the command
  911. X.DS C
  912. X\fBexpr $a + $b\fR
  913. X.DE
  914. Xresults in three arguments being passed to \fBexpr\fR:  \fB$a\fR,
  915. X\fB+\fR, and \fB$b\fR.  In addition, if the expression isn't in braces
  916. Xthen the Tcl interpreter will perform variable and command substitution
  917. Ximmediately (it will happen in the command parser rather than in
  918. Xthe expression parser).  In many cases the expression is being
  919. Xpassed to a command that will evaluate the expression later (or
  920. Xeven many times if, for example, the expression is to be used to
  921. Xdecide when to exit a loop).  Usually the desired goal is to re-do
  922. Xthe variable or command substitutions each time the expression is
  923. Xevaluated, rather than once and for all at the beginning.  For example,
  924. Xthe command
  925. X.DS C
  926. X.ta 7c
  927. X\fBfor {set i 1} $i<=10 {incr i} {...}\fR    *** WRONG ***
  928. X.DE
  929. Xis probably intended to iterate over all values of \fBi\fR from 1 to 10.
  930. XAfter each iteration of the body of the loop, \fBfor\fR will pass
  931. Xits second argument to the expression evaluator to see whether or not
  932. Xto continue processing.  Unfortunately, in this case the value of \fBi\fR
  933. Xin the second argument will be substituted once and for all when the
  934. X\fBfor\fR command is parsed.  If \fBi\fR was 0 before the \fBfor\fR
  935. Xcommand was invoked then \fBfor\fR's second argument will be \fB0<=10\fR
  936. Xwhich will always evaluate to 1, even though \fBi\fR's value eventually
  937. Xbecomes greater than 10.  In the above case the loop will never
  938. Xterminate.  Instead, the expression should be placed in braces:
  939. X.DS C
  940. X.ta 7c
  941. X\fBfor {set i 1} {$i<=10} {incr i} {...}\fR    *** RIGHT ***
  942. X.DE
  943. XThis causes the substitution of \fBi\fR's
  944. Xvalue to be delayed; it will be re-done each time the expression is
  945. Xevaluated, which is the desired result.
  946. X
  947. X.SH LISTS
  948. X.PP
  949. XThe third major way that strings are interpreted in Tcl is as lists.
  950. XA list is just a string with a list-like structure
  951. Xconsisting of fields separated by white space.  For example, the
  952. Xstring
  953. X.DS
  954. X\fBAl Sue Anne John\fR
  955. X.DE
  956. Xis a list with four elements or fields.
  957. XLists have the same basic structure as command strings, except
  958. Xthat a newline character in a list is treated as a field separator
  959. Xjust like space or tab.  Conventions for braces and quotes
  960. Xand backslashes are the same for lists as for commands.  For example,
  961. Xthe string
  962. X.DS
  963. X\fBa b\e c {d e {f g h}}\fR
  964. X.DE
  965. Xis a list with three elements:  \fBa\fR, \fBb c\fR, and \fBd e {f g h}\fR.
  966. XWhenever an element
  967. Xis extracted from a list, the same rules about braces and quotes and
  968. Xbackslashes are applied as for commands.  Thus in the example above
  969. Xwhen the third element is extracted from the list, the result is
  970. X.DS
  971. X\fBd e {f g h}\fR
  972. X.DE
  973. X(when the field was extracted, all that happened was to strip off
  974. Xthe outermost layer of braces).  Command substitution and
  975. Xvariable substitution are never
  976. Xmade on a list (at least, not by the list-processing commands; the
  977. Xlist can always be passed to the Tcl interpreter for evaluation).
  978. X.PP
  979. XThe Tcl commands \fBconcat\fR, \fBforeach\fR, 
  980. X.VS
  981. X\fBlappend\fR, \fBlindex\fR, \fBlinsert\fR, \fBlist\fR, \fBllength\fR,
  982. X\fBlrange\fR, \fBlreplace\fR, \fBlsearch\fR, and \fBlsort\fR allow
  983. Xyou to build lists,
  984. X.VE
  985. Xextract elements from them, search them, and perform other list-related
  986. Xfunctions.
  987. X
  988. X.SH "REGULAR EXPRESSIONS"
  989. X.VS
  990. X.PP
  991. XTcl provides two commands that support string matching using
  992. X\fBegrep\fR-style regular expressions: \fBregexp\fR and \fBregsub\fR.
  993. XRegular expressions are implemented using Henry Spencer's package,
  994. Xand the description of regular expressions below is copied verbatim
  995. Xfrom his manual entry.
  996. X.PP
  997. XA regular expression is zero or more \fIbranches\fR, separated by ``|''.
  998. XIt matches anything that matches one of the branches.
  999. X.PP
  1000. XA branch is zero or more \fIpieces\fR, concatenated.
  1001. XIt matches a match for the first, followed by a match for the second, etc.
  1002. X.PP
  1003. XA piece is an \fIatom\fR possibly followed by ``*'', ``+'', or ``?''.
  1004. XAn atom followed by ``*'' matches a sequence of 0 or more matches of the atom.
  1005. XAn atom followed by ``+'' matches a sequence of 1 or more matches of the atom.
  1006. XAn atom followed by ``?'' matches a match of the atom, or the null string.
  1007. X.PP
  1008. XAn atom is a regular expression in parentheses (matching a match for the
  1009. Xregular expression), a \fIrange\fR (see below), ``.''
  1010. X(matching any single character), ``^'' (matching the null string at the
  1011. Xbeginning of the input string), ``$'' (matching the null string at the
  1012. Xend of the input string), a ``\e'' followed by a single character (matching
  1013. Xthat character), or a single character with no other significance
  1014. X(matching that character).
  1015. X.PP
  1016. XA \fIrange\fR is a sequence of characters enclosed in ``[]''.
  1017. XIt normally matches any single character from the sequence.
  1018. XIf the sequence begins with ``^'',
  1019. Xit matches any single character \fInot\fR from the rest of the sequence.
  1020. XIf two characters in the sequence are separated by ``\-'', this is shorthand
  1021. Xfor the full list of ASCII characters between them
  1022. X(e.g. ``[0-9]'' matches any decimal digit).
  1023. XTo include a literal ``]'' in the sequence, make it the first character
  1024. X(following a possible ``^'').
  1025. XTo include a literal ``\-'', make it the first or last character.
  1026. END_OF_FILE
  1027. if test 35297 -ne `wc -c <'tcl6.1/doc/Tcl.man.1'`; then
  1028.     echo shar: \"'tcl6.1/doc/Tcl.man.1'\" unpacked with wrong size!
  1029. fi
  1030. # end of 'tcl6.1/doc/Tcl.man.1'
  1031. fi
  1032. echo shar: End of archive 27 \(of 33\).
  1033. cp /dev/null ark27isdone
  1034. MISSING=""
  1035. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
  1036.     if test ! -f ark${I}isdone ; then
  1037.     MISSING="${MISSING} ${I}"
  1038.     fi
  1039. done
  1040. if test "${MISSING}" = "" ; then
  1041.     echo You have unpacked all 33 archives.
  1042.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1043. else
  1044.     echo You still need to unpack the following archives:
  1045.     echo "        " ${MISSING}
  1046. fi
  1047. ##  End of shell archive.
  1048. exit 0
  1049.  
  1050. exit 0 # Just in case...
  1051. -- 
  1052. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1053. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1054. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1055. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1056.