home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume25 / tcl / part14 < prev    next >
Encoding:
Text File  |  1991-11-14  |  39.7 KB  |  1,075 lines

  1. Newsgroups: comp.sources.misc
  2. From: karl@sugar.neosoft.com (Karl Lehenbauer)
  3. Subject:  v25i082:  tcl - tool command language, version 6.1, Part14/33
  4. Message-ID: <1991Nov14.203138.24209@sparky.imd.sterling.com>
  5. X-Md4-Signature: bc16ef153ac873ba9b22b57e656dcd86
  6. Date: Thu, 14 Nov 1991 20:31:38 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: karl@sugar.neosoft.com (Karl Lehenbauer)
  10. Posting-number: Volume 25, Issue 82
  11. Archive-name: tcl/part14
  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 14 (of 33)."
  21. # Contents:  tcl6.1/doc/TraceVar.man tcl6.1/tests/expr.test
  22. # Wrapped by karl@one on Tue Nov 12 19:44:22 1991
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'tcl6.1/doc/TraceVar.man' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'tcl6.1/doc/TraceVar.man'\"
  26. else
  27. echo shar: Extracting \"'tcl6.1/doc/TraceVar.man'\" \(17059 characters\)
  28. sed "s/^X//" >'tcl6.1/doc/TraceVar.man' <<'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/TraceVar.man,v 1.6 91/08/27 13:46:37 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.HS Tcl_TraceVar tcl
  216. X.VS
  217. X.BS
  218. X.SH NAME
  219. XTcl_TraceVar, Tcl_TraceVar2, Tcl_UntraceVar, Tcl_UntraceVar2, \
  220. XTcl_VarTraceInfo, Tcl_VarTraceInfo2 \- monitor accesses to a variable
  221. X.SH SYNOPSIS
  222. X.nf
  223. X\fB#include <tcl.h>\fR
  224. X.sp
  225. Xint
  226. X\fBTcl_TraceVar(\fIinterp, varName, flags, proc, clientData\fB)\fR
  227. X.sp
  228. Xint
  229. X\fBTcl_TraceVar2(\fIinterp, name1, name2, flags, proc, clientData\fB)\fR
  230. X.sp
  231. X\fBTcl_UnTraceVar(\fIinterp, varName, flags, proc, clientData\fB)\fR
  232. X.sp
  233. X\fBTcl_UnTraceVar2(\fIinterp, name1, name2, flags, proc, clientData\fB)\fR
  234. X.sp
  235. XClientData
  236. X\fBTcl_VarTraceInfo(\fIinterp, varName, flags, proc, prevClientData\fB)\fR
  237. X.sp
  238. XClientData
  239. X\fBTcl_VarTraceInfo2(\fIinterp, name1, name2, flags, proc, prevClientData\fB)\fR
  240. X.SH ARGUMENTS
  241. X.AS Tcl_VarTraceProc prevClientData
  242. X.AP Tcl_Interp *interp in
  243. XInterpreter containing variable.
  244. X.AP char *varName in
  245. XName of variable.  May refer to a scalar variable, to
  246. Xan array variable with no index, or to an array variable
  247. Xwith a parenthesized index.
  248. X.AP int flags in
  249. XOR-ed combination of the values TCL_TRACE_READS, TCL_TRACE_WRITES, and
  250. XTCL_TRACE_UNSETS, and TCL_GLOBAL_ONLY.  Not all flags are used by all
  251. Xprocedures.  See below for more information.
  252. X.AP Tcl_VarTraceProc *proc in
  253. XProcedure to invoke whenever one of the traced operations occurs.
  254. X.AP ClientData clientData in
  255. XArbitrary one-word value to pass to \fIproc\fR.
  256. X.AP char *name1 in
  257. XName of scalar or array variable (without array index).
  258. X.AP char *name2 in
  259. XFor a trace on an element of an array, gives the index of the
  260. Xelement.  For traces on scalar variables or on whole arrays,
  261. Xis NULL.
  262. X.AP ClientData prevClientData in
  263. XIf non-NULL, gives last value returned by \fBTcl_VarTraceInfo\fR or
  264. X\fBTcl_VarTraceInfo2\fR, so this call will return information about
  265. Xnext trace.  If NULL, this call will return information about first
  266. Xtrace.
  267. X.BE
  268. X
  269. X.SH DESCRIPTION
  270. X.PP
  271. X\fBTcl_TraceVar\fR allows a C procedure to monitor and control
  272. Xaccess to a Tcl variable, so that the C procedure is invoked
  273. Xwhenever the variable is read or written or unset.
  274. XIf the trace is created successfully then \fBTcl_TraceVar\fR returns
  275. XTCL_OK.  If an error occurred (e.g. \fIvarName\fR specifies an element
  276. Xof an array, but the actual variable isn't an array) then TCL_ERROR
  277. Xis returned and an error message is left in \fIinterp->result\fR.
  278. X.PP
  279. XThe \fIflags\fR argument to \fBTcl_TraceVar\fR indicates when the
  280. Xtrace procedure is to be invoked and provides information
  281. Xfor setting up the trace.  It consists of an OR-ed combination
  282. Xof any of the following values:
  283. X.TP
  284. X\fBTCL_GLOBAL_ONLY\fR
  285. XNormally, the variable will be looked up at the current level of
  286. Xprocedure call;  if this bit is set then the variable will be looked
  287. Xup at global level, ignoring any active procedures.
  288. X.TP
  289. X\fBTCL_TRACE_READS\fR
  290. XInvoke \fIproc\fR whenever an attempt is made to read the variable.
  291. X.TP
  292. X\fBTCL_TRACE_WRITES\fR
  293. XInvoke \fIproc\fR whenever an attempt is made to modify the variable.
  294. X.TP
  295. X\fBTCL_TRACE_UNSETS\fR
  296. XInvoke \fIproc\fR whenever the variable is unset.
  297. XA variable may be unset either explicitly by an \fBunset\fR command,
  298. Xor implicitly when a procedure returns (its local variables are
  299. Xautomatically unset) or when the interpreter is deleted (all
  300. Xvariables are automatically unset).
  301. X.PP
  302. XWhenever one of the specified operations occurs on the variable,
  303. X\fIproc\fR will be invoked.
  304. XIt should have arguments and result that match the type
  305. X\fBTcl_VarTraceProc\fR:
  306. X.nf
  307. X.RS
  308. Xtypedef char *Tcl_VarTraceProc(
  309. X.RS
  310. XClientData \fIclientData\fR,
  311. XTcl_Interp *\fIinterp\fR,
  312. Xchar *\fIname1\fR,
  313. Xchar *\fIname2\fR,
  314. Xint \fIflags\fR);
  315. X.RE
  316. X.RE
  317. X.fi
  318. XThe \fIclientData\fP and \fIinterp\fP parameters will
  319. Xhave the same values as those passed to \fBTcl_TraceVar\fR when the
  320. Xtrace was created.
  321. X\fIClientData\fR typically points to an application-specific
  322. Xdata structure that describes what to do when \fIproc\fR
  323. Xis invoked.
  324. X\fIName1\fR and \fIname2\fR give the name of the traced variable
  325. Xin the normal two-part form (see the description of \fBTcl_TraceVar2\fR
  326. Xbelow for details).
  327. X\fIFlags\fR is an OR-ed combination of bits providing several
  328. Xpieces of information.
  329. XOne of the bits TCL_TRACE_READS, TCL_TRACE_WRITES, or TCL_TRACE_UNSETS
  330. Xwill be set in \fIflags\fR to indicate which operation is being performed
  331. Xon the variable.
  332. XThe bit TCL_GLOBAL_ONLY will be set whenever the variable being
  333. Xaccessed is a global one not accessible from the current level of
  334. Xprocedure call:  the trace procedure will need to pass this flag
  335. Xback to variable-related procedures like \fBTcl_GetVar\fR if it
  336. Xattempts to access the variable.
  337. XThe bit TCL_TRACE_DESTROYED will be set in \fIflags\fR if the trace is
  338. Xabout to be destroyed;  this information may be useful to \fIproc\fR
  339. Xso that it can clean up its own internal data structures (see
  340. Xthe section TCL_TRACE_DESTROYED below for more details).
  341. XLastly, the bit TCL_INTERP_DESTROYED will be set if the entire
  342. Xinterpreter is being destroyed.
  343. XWhen this bit is set, \fIproc\fR must be especially careful in
  344. Xthe things it does (see the section TCL_INTERP_DESTROYED below).
  345. XThe trace procedure's return value should normally be NULL;  see
  346. XERROR RETURNS below for information on other possibilities.
  347. X.PP
  348. X\fBTcl_UnsetTrace\fR may be used to remove a trace.
  349. XIf the variable specified by \fIinterp\fR, \fIvarName\fR, and \fIflags\fR
  350. Xhas a trace set with \fIflags\fR, \fIproc\fR, and
  351. X\fIclientData\fR, then the corresponding trace is removed.
  352. XIf no such trace exists, then the call to \fBTcl_UnsetTrace\fR
  353. Xhas no effect.
  354. XThe same bits are valid for \fIflags\fR as for calls to \fBTcl_TraceVars\fR.
  355. X.PP
  356. X\fBTcl_VarTraceInfo\fR may be used to retrieve information about
  357. Xtraces set on a given variable.
  358. XThe return value from \fBTcl_VarTraceInfo\fR is the \fIclientData\fR
  359. Xassociated with a particular trace.
  360. XThe trace must be on the variable specified by the \fIinterp\fR,
  361. X\fIvarName\fR, and \fIflags\fR arguments (only the TCL_GLOBAL_ONLY
  362. Xbit from \fIflags\fR is used;  other bits are ignored) and its trace procedure
  363. Xmust the same as the \fIproc\fR argument.
  364. XIf the \fIprevClientData\fR argument is NULL then the return
  365. Xvalue corresponds to the first (most recently created) matching
  366. Xtrace, or NULL if there are no matching traces.
  367. XIf the \fIprevClientData\fR argument isn't NULL, then it should
  368. Xbe the return value from a previous call to \fBTcl_VarTraceInfo\fR.
  369. XIn this case, the new return value will correspond to the next
  370. Xmatching trace after the one whose \fIclientData\fR matches
  371. X\fIprevClientData\fR, or NULL if no trace matches \fIprevClientData\fR
  372. Xor if there are no more matching traces after it.
  373. XThis mechanism makes it possible to step through all of the
  374. Xtraces for a given variable that have the same \fIproc\fR.
  375. X
  376. X.SH "TWO-PART NAMES"
  377. X.PP
  378. XThe procedures \fBTcl_TraceVar2\fR, \fBTcl_UntraceVar2\fR, and
  379. X\fBTcl_VarTraceInfo2\fR are identical to \fBTcl_TraceVar\fR,
  380. X\fBTcl_UntraceVar\fR, and \fBTcl_VarTraceInfo\fR, respectively,
  381. Xexcept that the name of the variable has already been
  382. Xseparated by the caller into two parts.
  383. X\fIName1\fR gives the name of a scalar variable or array,
  384. Xand \fIname2\fR gives the name of an element within an
  385. Xarray.
  386. XIf \fIname2\fR is NULL it means that either the variable is
  387. Xa scalar or the trace is to be set on the entire array rather
  388. Xthan an individual element (see WHOLE-ARRAY TRACES below for
  389. Xmore information).
  390. X
  391. X.SH "ACCESSING VARIABLES DURING TRACES"
  392. X.PP
  393. XDuring read and write traces, the
  394. Xtrace procedure can read or write the value of the traced
  395. Xvariable using \fBTcl_GetVar2\fR, \fBTcl_SetVar2\fR, and
  396. Xother procedures.
  397. XWhile \fIproc\fR is executing, traces are temporarily disabled
  398. Xfor the variable, so that calls to \fBTcl_GetVar2\fR and
  399. X\fBTcl_SetVar2\fR will not cause \fIproc\fR or other trace procedures
  400. Xto be invoked again.
  401. XDisabling only occurs for the variable whose trace procedure
  402. Xis active;  accesses to other variables will still be traced.
  403. X.PP
  404. XDuring unset traces the variable has already been completely
  405. Xexpunged.
  406. XIt is possible for the trace procedure to read or write the
  407. Xvariable, but this will be a new version of the variable.
  408. XTraces are not disabled during unset traces as they are for
  409. Xread and write traces, but existing traces have been removed
  410. Xfrom the variable before any trace procedures are invoked.
  411. XIf new traces are set by unset trace procedures, these traces
  412. Xwill be invoked on accesses to the variable by the trace
  413. Xprocedures.
  414. X
  415. X.SH "CALLBACK TIMING"
  416. X.PP
  417. XWhen read tracing has been specified for a variable, the trace
  418. Xprocedure will be invoked whenever the variable's value is
  419. Xread.  This includes \fBset\fR Tcl commands, \fB$\fR-notation
  420. Xin Tcl commands, and invocations of the \fBTcl_GetVar\fR
  421. Xand \fBTcl_GetVar2\fR procedures.
  422. X\fIProc\fR is invoked just before the variable's value is
  423. Xreturned.
  424. XIt may modify the value of the variable to affect what
  425. Xis returned by the traced access.
  426. X.PP
  427. XWhen write tracing has been specified for a variable, the
  428. Xtrace procedure will be invoked whenever the variable's value
  429. Xis modified.  This includes \fBset\fR commands\fR,
  430. Xcommands that modify variables as side effects (such as
  431. X\fBcatch\fR and \fBscan\fR), and calls to the \fBTcl_SetVar\fR
  432. Xand \fBTcl_SetVar2\fR procedures).
  433. X\fIProc\fR will be invoked after the variable's value has been
  434. Xmodified, but before the new value of the variable has been
  435. Xreturned.
  436. XIt may modify the value of the variable to override the change
  437. Xand to determine the value actually returned by the traced
  438. Xaccess.
  439. X.PP
  440. XWhen unset tracing has been specified, the trace procedure
  441. Xwill be invoked whenever the variable is destroyed.
  442. XThe traces will be called after the variable has been
  443. Xcompletely unset.
  444. X
  445. X.SH "WHOLE-ARRAY TRACES"
  446. X.PP
  447. XIf a call to \fBTcl_TraceVar\fR or \fBTcl_TraceVar2\fR specifies
  448. Xthe name of an array variable without an index into the array,
  449. Xthen the trace will be set on the array as a whole.
  450. XThis means that \fIproc\fR will be invoked whenever any
  451. Xelement of the array is accessed in the ways specified by
  452. X\fIflags\fR.
  453. XWhen an array is unset, a whole-array trace will be invoked
  454. Xjust once, with \fIname1\fR equal to the name of the array
  455. Xand \fIname2\fR NULL;  it will not be invoked once for each
  456. Xelement.
  457. X
  458. X.SH "MULTIPLE TRACES"
  459. X.PP
  460. XIt is possible for multiple traces to exist on the same variable.
  461. XWhen this happens, all of the trace procedures will be invoked on each
  462. Xaccess, in order from most-recently-created to least-recently-created.
  463. XWhen there exist whole-array traces for an array as well as
  464. Xtraces on individual elements, the whole-array traces are invoked
  465. Xbefore the individual-element traces.
  466. X
  467. X.SH "ERROR RETURNS"
  468. X.PP
  469. XUnder normal conditions trace procedures should return NULL, indicating
  470. Xsuccessful completion.
  471. XIf \fIproc\fR returns a non-NULL value it signifies that an
  472. Xerror occurred.
  473. XThe return value must be a pointer to a static character string
  474. Xcontaining an error message.
  475. XIf a trace procedure returns an error, no further traces are
  476. Xinvoked for the access and the traced access aborts with the
  477. Xgiven message.
  478. XTrace procedures can use this facility to make variables
  479. Xread-only, for example (but note that the value of the variable
  480. Xwill already have been modified before the trace procedure is
  481. Xcalled, so the trace procedure will have to restore the correct
  482. Xvalue).
  483. X.PP
  484. XThe return value from \fIproc\fR is only used during read and
  485. Xwrite tracing.
  486. XDuring unset traces, the return value is ignored and all relevant
  487. Xtrace procedures will always be invoked.
  488. X
  489. X.SH "RESTRICTIONS"
  490. X.PP
  491. XIt is not legal to delete a variable while a trace procedure
  492. Xis active for the variable.
  493. X
  494. X.SH "UNDEFINED VARIABLES"
  495. X.PP
  496. XIt is legal to set a trace on an undefined variable.
  497. XThe variable will still appear to be undefined until the
  498. Xfirst time its value is set.
  499. XIf an undefined variable is traced and then unset, the unset will fail
  500. Xwith an error (``no such variable''), but the trace
  501. Xprocedure will still be invoked.
  502. X
  503. X.SH "TCL_TRACE_DELETED FLAG"
  504. X.PP
  505. XIn an unset callback to \fIproc\fR, the TCL_TRACE_DELETED bit
  506. Xis set in \fIflags\fR if the trace is being removed as part
  507. Xof the deletion.
  508. XTraces on a variable are always removed whenever the variable
  509. Xis deleted;  the only time TCL_TRACE_DELETED isn't set is for
  510. Xa whole-array trace invoked when only a single element of an
  511. Xarray is unset.
  512. X
  513. X.SH "TCL_INTERP_DESTROYED"
  514. X.PP
  515. XWhen an interpreter is destroyed, unset traces are called for
  516. Xall of its variables.
  517. XThe TCL_INTERP_DESTROYED bit will be set in the \fIflags\fR
  518. Xargument passed to the trace procedures.
  519. XTrace procedures must be extremely careful in what they do if
  520. Xthe TCL_INTERP_DESTROYED bit is set.
  521. XIt is not safe for the procedures to invoke any Tcl procedures
  522. Xon the interpreter, since its state is partially deleted.
  523. XAll that trace procedures should do under these circumstances is
  524. Xto clean up and free their own internal data structures.
  525. X
  526. X.SH BUGS
  527. X.PP
  528. XTcl doesn't do any error checking to prevent trace procedures
  529. Xfrom misusing the interpreter during traces with TCL_INTERP_DESTROYED
  530. Xset.
  531. X
  532. X.SH KEYWORDS
  533. XclientData, trace, variable
  534. X.VE
  535. END_OF_FILE
  536. if test 17059 -ne `wc -c <'tcl6.1/doc/TraceVar.man'`; then
  537.     echo shar: \"'tcl6.1/doc/TraceVar.man'\" unpacked with wrong size!
  538. fi
  539. # end of 'tcl6.1/doc/TraceVar.man'
  540. fi
  541. if test -f 'tcl6.1/tests/expr.test' -a "${1}" != "-c" ; then 
  542.   echo shar: Will not clobber existing file \"'tcl6.1/tests/expr.test'\"
  543. else
  544. echo shar: Extracting \"'tcl6.1/tests/expr.test'\" \(19899 characters\)
  545. sed "s/^X//" >'tcl6.1/tests/expr.test' <<'END_OF_FILE'
  546. X# Commands covered:  expr
  547. X#
  548. X# This file contains a collection of tests for one or more of the Tcl
  549. X# built-in commands.  Sourcing this file into Tcl runs the tests and
  550. X# generates output for errors.  No output means no errors were found.
  551. X#
  552. X# $Header: /user6/ouster/tcl/tests/RCS/expr.test,v 1.11 91/10/31 16:40:46 ouster Exp $ (Berkeley)
  553. X
  554. Xif {[string compare test [info procs test]] == 1} then {source defs}
  555. X
  556. X# First, test all of the integer operators individually.
  557. X
  558. Xtest expr-1.1 {integer operators} {expr -4} -4
  559. Xtest expr-1.2 {integer operators} {expr -(1+4)} -5
  560. Xtest expr-1.3 {integer operators} {expr ~3} -4
  561. Xtest expr-1.4 {integer operators} {expr !2} 0
  562. Xtest expr-1.5 {integer operators} {expr !0} 1
  563. Xtest expr-1.6 {integer operators} {expr 4*6} 24
  564. Xtest expr-1.7 {integer operators} {expr 36/12} 3
  565. Xtest expr-1.8 {integer operators} {expr 27/4} 6
  566. Xtest expr-1.9 {integer operators} {expr 27%4} 3
  567. Xtest expr-1.10 {integer operators} {expr 2+2} 4
  568. Xtest expr-1.11 {integer operators} {expr 2-6} -4
  569. Xtest expr-1.12 {integer operators} {expr 1<<3} 8
  570. Xtest expr-1.13 {integer operators} {expr 0xff>>2} 63
  571. Xtest expr-1.14 {integer operators} {expr -1>>2} -1
  572. Xtest expr-1.15 {integer operators} {expr 3>2} 1
  573. Xtest expr-1.16 {integer operators} {expr 2>2} 0
  574. Xtest expr-1.17 {integer operators} {expr 1>2} 0
  575. Xtest expr-1.18 {integer operators} {expr 3<2} 0
  576. Xtest expr-1.19 {integer operators} {expr 2<2} 0
  577. Xtest expr-1.20 {integer operators} {expr 1<2} 1
  578. Xtest expr-1.21 {integer operators} {expr 3>=2} 1
  579. Xtest expr-1.22 {integer operators} {expr 2>=2} 1
  580. Xtest expr-1.23 {integer operators} {expr 1>=2} 0
  581. Xtest expr-1.24 {integer operators} {expr 3<=2} 0
  582. Xtest expr-1.25 {integer operators} {expr 2<=2} 1
  583. Xtest expr-1.26 {integer operators} {expr 1<=2} 1
  584. Xtest expr-1.27 {integer operators} {expr 3==2} 0
  585. Xtest expr-1.28 {integer operators} {expr 2==2} 1
  586. Xtest expr-1.29 {integer operators} {expr 3!=2} 1
  587. Xtest expr-1.30 {integer operators} {expr 2!=2} 0
  588. Xtest expr-1.31 {integer operators} {expr 7&0x13} 3
  589. Xtest expr-1.32 {integer operators} {expr 7^0x13} 20
  590. Xtest expr-1.33 {integer operators} {expr 7|0x13} 23
  591. Xtest expr-1.34 {integer operators} {expr 0&&1} 0
  592. Xtest expr-1.35 {integer operators} {expr 0&&0} 0
  593. Xtest expr-1.36 {integer operators} {expr 1&&3} 1
  594. Xtest expr-1.37 {integer operators} {expr 0||1} 1
  595. Xtest expr-1.38 {integer operators} {expr 3||0} 1
  596. Xtest expr-1.39 {integer operators} {expr 0||0} 0
  597. Xtest expr-1.40 {integer operators} {expr 3>2?44:66} 44
  598. Xtest expr-1.41 {integer operators} {expr 2>3?44:66} 66
  599. X
  600. X# Check the floating-point operators individually, along with
  601. X# automatic conversion to integers where needed.
  602. X
  603. Xtest expr-2.1 {floating-point operators} {expr -4.2} -4.2
  604. Xtest expr-2.2 {floating-point operators} {expr -(1.1+4.2)} -5.3
  605. Xtest expr-2.3 {floating-point operators} {expr !2.1} 0
  606. Xtest expr-2.4 {floating-point operators} {expr !0.0} 1
  607. Xtest expr-2.5 {floating-point operators} {expr 4.2*6.3} 26.46
  608. Xtest expr-2.6 {floating-point operators} {expr 36.0/12.0} 3
  609. Xtest expr-2.7 {floating-point operators} {expr 27/4.0} 6.75
  610. Xtest expr-2.8 {floating-point operators} {expr 2.3+2.1} 4.4
  611. Xtest expr-2.9 {floating-point operators} {expr 2.3-6.5} -4.2
  612. Xtest expr-2.10 {floating-point operators} {expr 3.1>2.1} 1
  613. Xtest expr-2.11 {floating-point operators} {expr {2.1 > 2.1}} 0
  614. Xtest expr-2.12 {floating-point operators} {expr 1.23>2.34e+1} 0
  615. Xtest expr-2.13 {floating-point operators} {expr 3.45<2.34} 0
  616. Xtest expr-2.14 {floating-point operators} {expr 0.002e3<--200e-2} 0
  617. Xtest expr-2.15 {floating-point operators} {expr 1.1<2.1} 1
  618. Xtest expr-2.16 {floating-point operators} {expr 3.1>=2.2} 1
  619. Xtest expr-2.17 {floating-point operators} {expr 2.345>=2.345} 1
  620. Xtest expr-2.18 {floating-point operators} {expr 1.1>=2.2} 0
  621. Xtest expr-2.19 {floating-point operators} {expr 3.0<=2.0} 0
  622. Xtest expr-2.20 {floating-point operators} {expr 2.2<=2.2} 1
  623. Xtest expr-2.21 {floating-point operators} {expr 2.2<=2.2001} 1
  624. Xtest expr-2.22 {floating-point operators} {expr 3.2==2.2} 0
  625. Xtest expr-2.23 {floating-point operators} {expr 2.2==2.2} 1
  626. Xtest expr-2.24 {floating-point operators} {expr 3.2!=2.2} 1
  627. Xtest expr-2.25 {floating-point operators} {expr 2.2!=2.2} 0
  628. Xtest expr-2.26 {floating-point operators} {expr 0.0&&0.0} 0
  629. Xtest expr-2.27 {floating-point operators} {expr 0.0&&1.3} 0
  630. Xtest expr-2.28 {floating-point operators} {expr 1.3&&0.0} 0
  631. Xtest expr-2.29 {floating-point operators} {expr 1.3&&3.3} 1
  632. Xtest expr-2.30 {floating-point operators} {expr 0.0||0.0} 0
  633. Xtest expr-2.31 {floating-point operators} {expr 0.0||1.3} 1
  634. Xtest expr-2.32 {floating-point operators} {expr 1.3||0.0} 1
  635. Xtest expr-2.33 {floating-point operators} {expr 3.3||0.0} 1
  636. Xtest expr-2.34 {floating-point operators} {expr 3.3>2.3?44.3:66.3} 44.3
  637. Xtest expr-2.35 {floating-point operators} {expr 2.3>3.3?44.3:66.3} 66.3
  638. X
  639. X# Operators that aren't legal on floating-point numbers
  640. X
  641. Xtest expr-3.1 {illegal floating-point operations} {
  642. X    list [catch {expr ~4.0} msg] $msg
  643. X} {1 {can't use floating-point value as operand of "~"}}
  644. Xtest expr-3.2 {illegal floating-point operations} {
  645. X    list [catch {expr 27%4.0} msg] $msg
  646. X} {1 {can't use floating-point value as operand of "%"}}
  647. Xtest expr-3.3 {illegal floating-point operations} {
  648. X    list [catch {expr 27.0%4} msg] $msg
  649. X} {1 {can't use floating-point value as operand of "%"}}
  650. Xtest expr-3.4 {illegal floating-point operations} {
  651. X    list [catch {expr 1.0<<3} msg] $msg
  652. X} {1 {can't use floating-point value as operand of "<<"}}
  653. Xtest expr-3.5 {illegal floating-point operations} {
  654. X    list [catch {expr 3<<1.0} msg] $msg
  655. X} {1 {can't use floating-point value as operand of "<<"}}
  656. Xtest expr-3.6 {illegal floating-point operations} {
  657. X    list [catch {expr 24.0>>3} msg] $msg
  658. X} {1 {can't use floating-point value as operand of ">>"}}
  659. Xtest expr-3.7 {illegal floating-point operations} {
  660. X    list [catch {expr 24>>3.0} msg] $msg
  661. X} {1 {can't use floating-point value as operand of ">>"}}
  662. Xtest expr-3.8 {illegal floating-point operations} {
  663. X    list [catch {expr 24&3.0} msg] $msg
  664. X} {1 {can't use floating-point value as operand of "&"}}
  665. Xtest expr-3.9 {illegal floating-point operations} {
  666. X    list [catch {expr 24.0|3} msg] $msg
  667. X} {1 {can't use floating-point value as operand of "|"}}
  668. Xtest expr-3.10 {illegal floating-point operations} {
  669. X    list [catch {expr 24.0^3} msg] $msg
  670. X} {1 {can't use floating-point value as operand of "^"}}
  671. X
  672. X# Check the string operators individually.
  673. X
  674. Xtest expr-4.1 {string operators} {expr {"abc" > "def"}} 0
  675. Xtest expr-4.2 {string operators} {expr {"def" > "def"}} 0
  676. Xtest expr-4.3 {string operators} {expr {"g" > "def"}} 1
  677. Xtest expr-4.4 {string operators} {expr {"abc" < "abd"}} 1
  678. Xtest expr-4.5 {string operators} {expr {"abd" < "abd"}} 0
  679. Xtest expr-4.6 {string operators} {expr {"abe" < "abd"}} 0
  680. Xtest expr-4.7 {string operators} {expr {"abc" >= "def"}} 0
  681. Xtest expr-4.8 {string operators} {expr {"def" >= "def"}} 1
  682. Xtest expr-4.9 {string operators} {expr {"g" >= "def"}} 1
  683. Xtest expr-4.10 {string operators} {expr {"abc" <= "abd"}} 1
  684. Xtest expr-4.11 {string operators} {expr {"abd" <= "abd"}} 1
  685. Xtest expr-4.12 {string operators} {expr {"abe" <= "abd"}} 0
  686. Xtest expr-4.13 {string operators} {expr {"abc" == "abd"}} 0
  687. Xtest expr-4.14 {string operators} {expr {"abd" == "abd"}} 1
  688. Xtest expr-4.15 {string operators} {expr {"abc" != "abd"}} 1
  689. Xtest expr-4.16 {string operators} {expr {"abd" != "abd"}} 0
  690. Xtest expr-4.17 {string operators} {expr {"0y" < "0x12"}} 1
  691. Xtest expr-4.18 {string operators} {expr {1?"foo":"bar"}} foo
  692. Xtest expr-4.19 {string operators} {expr {0?"foo":"bar"}} bar
  693. X
  694. X# Operators that aren't legal on string operands.
  695. X
  696. Xtest expr-5.1 {illegal string operations} {
  697. X    list [catch {expr {-"a"}} msg] $msg
  698. X} {1 {can't use non-numeric string as operand of "-"}}
  699. Xtest expr-5.2 {illegal string operations} {
  700. X    list [catch {expr {~"a"}} msg] $msg
  701. X} {1 {can't use non-numeric string as operand of "~"}}
  702. Xtest expr-5.3 {illegal string operations} {
  703. X    list [catch {expr {!"a"}} msg] $msg
  704. X} {1 {can't use non-numeric string as operand of "!"}}
  705. Xtest expr-5.4 {illegal string operations} {
  706. X    list [catch {expr {"a"*"b"}} msg] $msg
  707. X} {1 {can't use non-numeric string as operand of "*"}}
  708. Xtest expr-5.5 {illegal string operations} {
  709. X    list [catch {expr {"a"/"b"}} msg] $msg
  710. X} {1 {can't use non-numeric string as operand of "/"}}
  711. Xtest expr-5.6 {illegal string operations} {
  712. X    list [catch {expr {"a"%"b"}} msg] $msg
  713. X} {1 {can't use non-numeric string as operand of "%"}}
  714. Xtest expr-5.7 {illegal string operations} {
  715. X    list [catch {expr {"a"+"b"}} msg] $msg
  716. X} {1 {can't use non-numeric string as operand of "+"}}
  717. Xtest expr-5.8 {illegal string operations} {
  718. X    list [catch {expr {"a"-"b"}} msg] $msg
  719. X} {1 {can't use non-numeric string as operand of "-"}}
  720. Xtest expr-5.9 {illegal string operations} {
  721. X    list [catch {expr {"a"<<"b"}} msg] $msg
  722. X} {1 {can't use non-numeric string as operand of "<<"}}
  723. Xtest expr-5.10 {illegal string operations} {
  724. X    list [catch {expr {"a">>"b"}} msg] $msg
  725. X} {1 {can't use non-numeric string as operand of ">>"}}
  726. Xtest expr-5.11 {illegal string operations} {
  727. X    list [catch {expr {"a"&"b"}} msg] $msg
  728. X} {1 {can't use non-numeric string as operand of "&"}}
  729. Xtest expr-5.12 {illegal string operations} {
  730. X    list [catch {expr {"a"^"b"}} msg] $msg
  731. X} {1 {can't use non-numeric string as operand of "^"}}
  732. Xtest expr-5.13 {illegal string operations} {
  733. X    list [catch {expr {"a"|"b"}} msg] $msg
  734. X} {1 {can't use non-numeric string as operand of "|"}}
  735. Xtest expr-5.14 {illegal string operations} {
  736. X    list [catch {expr {"a"&&"b"}} msg] $msg
  737. X} {1 {can't use non-numeric string as operand of "&&"}}
  738. Xtest expr-5.15 {illegal string operations} {
  739. X    list [catch {expr {"a"||"b"}} msg] $msg
  740. X} {1 {can't use non-numeric string as operand of "||"}}
  741. Xtest expr-5.16 {illegal string operations} {
  742. X    list [catch {expr {"a"?4:2}} msg] $msg
  743. X} {1 {can't use non-numeric string as operand of "?"}}
  744. X
  745. X# Check precedence pairwise.
  746. X
  747. Xtest expr-6.1 {precedence checks} {expr -~3} 4
  748. Xtest expr-6.2 {precedence checks} {expr -!3} 0
  749. Xtest expr-6.3 {precedence checks} {expr -~0} 1
  750. X
  751. Xtest expr-7.1 {precedence checks} {expr 2*4/6} 1
  752. Xtest expr-7.2 {precedence checks} {expr 24/6*3} 12
  753. Xtest expr-7.3 {precedence checks} {expr 24/6/2} 2
  754. X
  755. Xtest expr-8.1 {precedence checks} {expr -2+4} 2
  756. Xtest expr-8.2 {precedence checks} {expr -2-4} -6
  757. X
  758. Xtest expr-9.1 {precedence checks} {expr 2*3+4} 10
  759. Xtest expr-9.2 {precedence checks} {expr 8/2+4} 8
  760. Xtest expr-9.3 {precedence checks} {expr 8%3+4} 6
  761. Xtest expr-9.4 {precedence checks} {expr 2*3-1} 5
  762. Xtest expr-9.5 {precedence checks} {expr 8/2-1} 3
  763. Xtest expr-9.6 {precedence checks} {expr 8%3-1} 1
  764. X
  765. Xtest expr-10.1 {precedence checks} {expr 6-3-2} 1
  766. X
  767. Xtest expr-11.1 {precedence checks} {expr 7+1>>2} 2
  768. Xtest expr-11.2 {precedence checks} {expr 7+1<<2} 32
  769. Xtest expr-11.3 {precedence checks} {expr 7>>3-2} 3
  770. Xtest expr-11.4 {precedence checks} {expr 7<<3-2} 14
  771. X
  772. Xtest expr-12.1 {precedence checks} {expr 6>>1>4} 0
  773. Xtest expr-12.2 {precedence checks} {expr 6>>1<2} 0
  774. Xtest expr-12.3 {precedence checks} {expr 6>>1>=3} 1
  775. Xtest expr-12.4 {precedence checks} {expr 6>>1<=2} 0
  776. Xtest expr-12.5 {precedence checks} {expr 6<<1>5} 1
  777. Xtest expr-12.6 {precedence checks} {expr 6<<1<5} 0
  778. Xtest expr-12.7 {precedence checks} {expr 5<=6<<1} 1
  779. Xtest expr-12.8 {precedence checks} {expr 5>=6<<1} 0
  780. X
  781. Xtest expr-13.1 {precedence checks} {expr 2<3<4} 1
  782. Xtest expr-13.2 {precedence checks} {expr 0<4>2} 0
  783. Xtest expr-13.3 {precedence checks} {expr 4>2<1} 0
  784. Xtest expr-13.4 {precedence checks} {expr 4>3>2} 0
  785. Xtest expr-13.5 {precedence checks} {expr 4>3>=2} 0
  786. Xtest expr-13.6 {precedence checks} {expr 4>=3>2} 0
  787. Xtest expr-13.7 {precedence checks} {expr 4>=3>=2} 0
  788. Xtest expr-13.8 {precedence checks} {expr 0<=4>=2} 0
  789. Xtest expr-13.9 {precedence checks} {expr 4>=2<=0} 0
  790. Xtest expr-10.10 {precedence checks} {expr 2<=3<=4} 1
  791. X
  792. Xtest expr-14.1 {precedence checks} {expr 1==4>3} 1
  793. Xtest expr-14.2 {precedence checks} {expr 0!=4>3} 1
  794. Xtest expr-14.3 {precedence checks} {expr 1==3<4} 1
  795. Xtest expr-14.4 {precedence checks} {expr 0!=3<4} 1
  796. Xtest expr-14.5 {precedence checks} {expr 1==4>=3} 1
  797. Xtest expr-14.6 {precedence checks} {expr 0!=4>=3} 1
  798. Xtest expr-14.7 {precedence checks} {expr 1==3<=4} 1
  799. Xtest expr-14.8 {precedence checks} {expr 0!=3<=4} 1
  800. X
  801. Xtest expr-15.1 {precedence checks} {expr 1==3==3} 0
  802. Xtest expr-15.2 {precedence checks} {expr 3==3!=2} 1
  803. Xtest expr-15.3 {precedence checks} {expr 2!=3==3} 0
  804. Xtest expr-15.4 {precedence checks} {expr 2!=1!=1} 0
  805. X
  806. Xtest expr-16.1 {precedence checks} {expr 2&3==2} 0
  807. Xtest expr-16.2 {precedence checks} {expr 1&3!=3} 0
  808. X
  809. Xtest expr-17.1 {precedence checks} {expr 7&3^0x10} 19
  810. Xtest expr-17.2 {precedence checks} {expr 7^0x10&3} 7
  811. X
  812. Xtest expr-18.1 {precedence checks} {expr 7^0x10|3} 23
  813. Xtest expr-18.2 {precedence checks} {expr 7|0x10^3} 23
  814. X
  815. Xtest expr-19.1 {precedence checks} {expr 7|3&&1} 1
  816. Xtest expr-19.2 {precedence checks} {expr 1&&3|7} 1
  817. Xtest expr-19.3 {precedence checks} {expr 0&&1||1} 1
  818. Xtest expr-19.4 {precedence checks} {expr 1||1&&0} 1
  819. X
  820. Xtest expr-20.1 {precedence checks} {expr 1||0?3:4} 3
  821. Xtest expr-20.2 {precedence checks} {expr 1?0:4||1} 0
  822. X
  823. X# Parentheses.
  824. X
  825. Xtest expr-21.1 {parenthesization} {expr (2+4)*6} 36
  826. Xtest expr-21.2 {parenthesization} {expr (1?0:4)||1} 1
  827. X
  828. X# Embedded commands and variable names.
  829. X
  830. Xset a 16
  831. Xtest expr-22.1 {embedded variables} {expr {2*$a}} 32
  832. Xtest expr-22.2 {embedded variables} {
  833. X    set x -5
  834. X    set y 10
  835. X    expr {$x + $y}
  836. X} {5}
  837. Xtest expr-22.3 {embedded commands and variables} {expr {[set a] - 14}} 2
  838. Xtest expr-22.4 {embedded commands and variables} {
  839. X    list [catch {expr {12 - [bad_command_name]}} msg] $msg
  840. X} {1 {invalid command name: "bad_command_name"}}
  841. X
  842. X# Double-quotes and things inside them.
  843. X
  844. Xtest expr-23.1 {double-quotes} {expr {"abc"}} abc
  845. Xtest expr-23.2 {double-quotes} {
  846. X    set a 189
  847. X    expr {"$a.bc"}
  848. X} 189.bc
  849. Xtest expr-23.3 {double-quotes} {
  850. X    set b2 xyx
  851. X    expr {"$b2$b2$b2.[set b2].[set b2]"}
  852. X} xyxxyxxyx.xyx.xyx
  853. Xtest expr-23.4 {double-quotes} {expr {"11\}\}22"}} 11}}22
  854. Xtest expr-23.5 {double-quotes} {expr {"\abc"}} {\abc}
  855. Xtest expr-23.6 {double-quotes} {
  856. X    catch {unset bogus__}
  857. X    list [catch {expr {"$bogus__"}} msg] $msg
  858. X} {1 {can't read "bogus__": no such variable}}
  859. Xtest expr-23.7 {double-quotes} {
  860. X    list [catch {expr {"a[error Testing]bc"}} msg] $msg
  861. X} {1 Testing}
  862. X
  863. X# Numbers in various bases.
  864. X
  865. Xtest expr-24.1 {numbers in different bases} {expr 0x20} 32
  866. Xtest expr-24.2 {numbers in different bases} {expr 015} 13
  867. X
  868. X# Conversions between various data types.
  869. X
  870. Xtest expr-25.1 {type conversions} {expr 2+2.5} 4.5
  871. Xtest expr-25.2 {type conversions} {expr 2.5+2} 4.5
  872. Xtest expr-25.3 {type conversions} {expr 2-2.5} -0.5
  873. Xtest expr-25.4 {type conversions} {expr 2/2.5} 0.8
  874. Xtest expr-25.5 {type conversions} {expr 2>2.5} 0
  875. Xtest expr-25.6 {type conversions} {expr 2.5>2} 1
  876. Xtest expr-25.7 {type conversions} {expr 2<2.5} 1
  877. Xtest expr-25.8 {type conversions} {expr 2>=2.5} 0
  878. Xtest expr-25.9 {type conversions} {expr 2<=2.5} 1
  879. Xtest expr-25.10 {type conversions} {expr 2==2.5} 0
  880. Xtest expr-25.11 {type conversions} {expr 2!=2.5} 1
  881. Xtest expr-25.12 {type conversions} {expr 2>"ab"} 0
  882. Xtest expr-25.13 {type conversions} {expr {2>" "}} 1
  883. Xtest expr-25.14 {type conversions} {expr {"24.1a" > 24.1}} 1
  884. Xtest expr-25.15 {type conversions} {expr {24.1 > "24.1a"}} 0
  885. Xtest expr-25.16 {type conversions} {expr 2+2.5} 4.5
  886. Xtest expr-25.17 {type conversions} {expr 2+2.5} 4.5
  887. X
  888. X# Various error conditions.
  889. X
  890. Xtest expr-26.1 {error conditions} {
  891. X    list [catch {expr 2+"a"} msg] $msg
  892. X} {1 {can't use non-numeric string as operand of "+"}}
  893. Xtest expr-26.2 {error conditions} {
  894. X    list [catch {expr 2+4*} msg] $msg
  895. X} {1 {syntax error in expression "2+4*"}}
  896. Xtest expr-26.3 {error conditions} {
  897. X    list [catch {expr 2+4*(} msg] $msg
  898. X} {1 {syntax error in expression "2+4*("}}
  899. Xcatch {unset _non_existent_}
  900. Xtest expr-26.4 {error conditions} {
  901. X    list [catch {expr 2+$_non_existent_} msg] $msg
  902. X} {1 {can't read "_non_existent_": no such variable}}
  903. Xset a xx
  904. Xtest expr-26.5 {error conditions} {
  905. X    list [catch {expr {2+$a}} msg] $msg
  906. X} {1 {can't use non-numeric string as operand of "+"}}
  907. Xtest expr-26.6 {error conditions} {
  908. X    list [catch {expr {2+[set a]}} msg] $msg
  909. X} {1 {can't use non-numeric string as operand of "+"}}
  910. Xtest expr-26.7 {error conditions} {
  911. X    list [catch {expr {2+(4}} msg] $msg
  912. X} {1 {unmatched parentheses in expression "2+(4"}}
  913. Xtest expr-26.8 {error conditions} {
  914. X    list [catch {expr 2/0} msg] $msg
  915. X} {1 {divide by zero}}
  916. Xtest expr-26.9 {error conditions} {
  917. X    list [catch {expr 2%0} msg] $msg
  918. X} {1 {divide by zero}}
  919. Xtest expr-26.10 {error conditions} {
  920. X    list [catch {expr 2#} msg] $msg
  921. X} {1 {syntax error in expression "2#"}}
  922. Xtest expr-26.11 {error conditions} {
  923. X    list [catch {expr a.b} msg] $msg
  924. X} {1 {syntax error in expression "a.b"}}
  925. Xtest expr-26.12 {error conditions} {
  926. X    list [catch {expr {"a"/"b"}} msg] $msg
  927. X} {1 {can't use non-numeric string as operand of "/"}}
  928. Xtest expr-26.13 {error conditions} {
  929. X    list [catch {expr 2:3} msg] $msg
  930. X} {1 {can't have : operator without ? first}}
  931. Xtest expr-26.14 {error conditions} {
  932. X    list [catch {expr a@b} msg] $msg
  933. X} {1 {syntax error in expression "a@b"}}
  934. Xtest expr-26.15 {error conditions} {
  935. X    list [catch {expr a@b} msg] $msg
  936. X} {1 {syntax error in expression "a@b"}}
  937. Xtest expr-26.16 {error conditions} {
  938. X    list [catch {expr a[b} msg] $msg
  939. X} {1 {missing close-bracket}}
  940. Xtest expr-26.17 {error conditions} {
  941. X    list [catch {expr a`b} msg] $msg
  942. X} {1 {syntax error in expression "a`b"}}
  943. Xtest expr-26.18 {error conditions} {
  944. X    list [catch {expr \"a\"\{b} msg] $msg
  945. X} {1 {missing close-brace}}
  946. Xtest expr-26.19 {error conditions} {
  947. X    list [catch {expr a} msg] $msg
  948. X} {1 {syntax error in expression "a"}}
  949. X
  950. X# Cancelled evaluation.
  951. X
  952. Xtest expr-27.1 {cancelled evaluation} {
  953. X    set a 1
  954. X    expr {0&&[set a 2]}
  955. X    set a
  956. X} 1
  957. Xtest expr-27.2 {cancelled evaluation} {
  958. X    set a 1
  959. X    expr {1||[set a 2]}
  960. X    set a
  961. X} 1
  962. Xtest expr-27.3 {cancelled evaluation} {
  963. X    set a 1
  964. X    expr {0?[set a 2]:1}
  965. X    set a
  966. X} 1
  967. Xtest expr-27.4 {cancelled evaluation} {
  968. X    set a 1
  969. X    expr {1?2:[set a 2]}
  970. X    set a
  971. X} 1
  972. X
  973. X# Tcl_ExprBool as used in "if" statements
  974. X
  975. Xtest expr-28.1 {Tcl_ExprBoolean usage} {
  976. X    set a 1
  977. X    if {2} {
  978. X    set a 2
  979. X    }
  980. X    set a
  981. X} 2
  982. Xtest expr-28.2 {Tcl_ExprBoolean usage} {
  983. X    set a 1
  984. X    if {0} {
  985. X    set a 2
  986. X    }
  987. X    set a
  988. X} 1
  989. Xtest expr-28.3 {Tcl_ExprBoolean usage} {
  990. X    set a 1
  991. X    if {1.2} {
  992. X    set a 2
  993. X    }
  994. X    set a
  995. X} 2
  996. Xtest expr-28.4 {Tcl_ExprBoolean usage} {
  997. X    set a 1
  998. X    if {-1.1} {
  999. X    set a 2
  1000. X    }
  1001. X    set a
  1002. X} 2
  1003. Xtest expr-28.5 {Tcl_ExprBoolean usage} {
  1004. X    set a 1
  1005. X    if {0.0} {
  1006. X    set a 2
  1007. X    }
  1008. X    set a
  1009. X} 1
  1010. Xtest expr-28.6 {Tcl_ExprBool usage} {
  1011. X    list [catch {if {"abc"} {}} msg] $msg
  1012. X} {1 {expression didn't have numeric value}}
  1013. X
  1014. X# Operands enclosed in braces
  1015. X
  1016. Xtest expr-29.1 {braces} {expr {{abc}}} abc
  1017. Xtest expr-29.2 {braces} {expr {{00010}}} 8
  1018. Xtest expr-29.3 {braces} {expr {{3.1200000}}} 3.12
  1019. Xtest expr-29.4 {braces} {expr {{a{b}{1 {2 3}}c}}} "a{b}{1 {2 3}}c"
  1020. Xtest expr-29.5 {braces} {
  1021. X    list [catch {expr "\{abc"} msg] $msg
  1022. X} {1 {missing close-brace}}
  1023. X
  1024. X# Very long values
  1025. X
  1026. Xtest expr-30.1 {long values} {
  1027. X    set a "0000 1111 2222 3333 4444"
  1028. X    set a "$a | $a | $a | $a | $a"
  1029. X    set a "$a || $a || $a || $a || $a"
  1030. X    expr {$a}
  1031. X} {0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 \
  1032. X4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 \
  1033. X3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 \
  1034. X2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 \
  1035. X1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | \
  1036. X0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 \
  1037. X4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 \
  1038. X3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 \
  1039. X2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444}
  1040. Xtest expr-30.2 {long values} {
  1041. X    set a "000000000000000000000000000000"
  1042. X    set a "$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a${a}5"
  1043. X    expr $a
  1044. X} 5
  1045. END_OF_FILE
  1046. if test 19899 -ne `wc -c <'tcl6.1/tests/expr.test'`; then
  1047.     echo shar: \"'tcl6.1/tests/expr.test'\" unpacked with wrong size!
  1048. fi
  1049. # end of 'tcl6.1/tests/expr.test'
  1050. fi
  1051. echo shar: End of archive 14 \(of 33\).
  1052. cp /dev/null ark14isdone
  1053. MISSING=""
  1054. 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
  1055.     if test ! -f ark${I}isdone ; then
  1056.     MISSING="${MISSING} ${I}"
  1057.     fi
  1058. done
  1059. if test "${MISSING}" = "" ; then
  1060.     echo You have unpacked all 33 archives.
  1061.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1062. else
  1063.     echo You still need to unpack the following archives:
  1064.     echo "        " ${MISSING}
  1065. fi
  1066. ##  End of shell archive.
  1067. exit 0
  1068.  
  1069. exit 0 # Just in case...
  1070. -- 
  1071. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1072. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1073. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1074. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1075.