home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / switch.n < prev    next >
Text File  |  1993-06-17  |  4KB  |  123 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/switch.n,v 1.2 93/06/17 13:31:26 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS switch tcl 7.0
  25. .BS
  26. '\" Note:  do not modify the .SH NAME line immediately below!
  27. .SH NAME
  28. switch \- Evaluate one of several scripts, depending on a given value
  29. .SH SYNOPSIS
  30. \fBswitch\fI \fR?\fIoptions\fR?\fI string \fIpattern body \fR?\fIpattern body \fR...?
  31. .br
  32. \fBswitch\fI \fR?\fIoptions\fR?\fI string \fR{\fIpattern body \fR?\fIpattern body \fR...?}
  33. .BE
  34.  
  35. .SH DESCRIPTION
  36. .PP
  37. The \fBswitch\fR command matches its \fIstring\fR argument against each of
  38. the \fIpattern\fR arguments in order.
  39. As soon as it finds a \fIpattern\fR that matches \fIstring\fR it
  40. evaluates the following \fIbody\fR argument by passing it recursively
  41. to the Tcl interpreter and returns the result of that evaluation.
  42. If the last \fIpattern\fR argument is \fBdefault\fR then it matches
  43. anything.
  44. If no \fIpattern\fR argument
  45. matches \fIstring\fR and no default is given, then the \fBswitch\fR
  46. command returns an empty string.
  47. .PP
  48. If the initial arguments to \fBswitch\fR start with \fB\-\fR then
  49. they are treated as options.  The following options are
  50. currently supported:
  51. .TP 10
  52. \fB\-exact\fR
  53. Use exact matching when comparing \fIstring\fR to a pattern.  This
  54. is the default.
  55. .TP 10
  56. \fB\-glob\fR
  57. When matching \fIstring\fR to the patterns, use glob-style matching
  58. (i.e. the same as implemented by the \fBstring match\fR command).
  59. .TP 10
  60. \fB\-regexp\fR
  61. When matching \fIstring\fR to the patterns, use regular
  62. expression matching
  63. (i.e. the same as implemented by the \fBregexp\fR command).
  64. .TP 10
  65. \fB\-\|\-\fR
  66. Marks the end of options.  The argument following this one will
  67. be treated as \fIstring\fR even if it starts with a \fB\-.
  68. .PP
  69. Two syntaxes are provided for the \fIpattern\fR and \fIbody\fR arguments.
  70. The first uses a separate argument for each of the patterns and commands;
  71. this form is convenient if substitutions are desired on some of the
  72. patterns or commands.
  73. The second form places all of the patterns and commands together into
  74. a single argument; the argument must have proper list structure, with
  75. the elements of the list being the patterns and commands.
  76. The second form makes it easy to construct multi-line switch commands,
  77. since the braces around the whole list make it unnecessary to include a
  78. backslash at the end of each line.
  79. Since the \fIpattern\fR arguments are in braces in the second form,
  80. no command or variable substitutions are performed on them;  this makes
  81. the behavior of the second form different than the first form in some
  82. cases.
  83. .PP
  84. If a \fIbody\fR is specified as ``\fB\-\fR'' it means that the \fIbody\fR
  85. for the next pattern should also be used as the body for this
  86. pattern (if the next pattern also has a body of ``\fB\-\fR''
  87. then the body after that is used, and so on).
  88. This feature makes it possible to share a single \fIbody\fR among
  89. several patterns.
  90. .PP
  91. Below are some examples of \fBswitch\fR commands:
  92. .DS
  93. \fBswitch\0abc\0a\0\-\0b\0{format 1}\0abc\0{format 2}\0default\0{format 3}
  94. .DE
  95. will return \fB2\fR, 
  96. .DS
  97. .ta .5c 1c
  98. \fBswitch\0\-regexp\0aaab {
  99.     ^a.*b$\0\-
  100.     b\0{format 1}
  101.     a*\0{format 2}
  102.     default\0{format 3}
  103. }
  104. .DE
  105. will return \fB1\fR, and
  106. .DS
  107. .ta .5c 1c
  108. \fBswitch\0xyz {
  109.     a
  110.         \-
  111.     b
  112.         {format 1}
  113.     a*
  114.         {format 2}
  115.     default
  116.         {format 3}
  117. }
  118. .DE
  119. will return \fB3\fR.
  120.  
  121. .SH KEYWORDS
  122. switch, match, regular expression
  123.