home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / scan.n < prev    next >
Text File  |  1993-08-04  |  6KB  |  150 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/scan.n,v 1.3 93/08/04 17:18:42 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS scan tcl
  25. .BS
  26. '\" Note:  do not modify the .SH NAME line immediately below!
  27. .SH NAME
  28. scan \- Parse string using conversion specifiers in the style of sscanf
  29. .SH SYNOPSIS
  30. \fBscan \fIstring format varName \fR?\fIvarName ...\fR?
  31. .BE
  32.  
  33. .SH INTRODUCTION
  34. .PP
  35. This command parses fields from an input string in the same fashion
  36. as the ANSI C \fBsscanf\fR procedure and returns a count of the number
  37. of fields sucessfully parsed.
  38. \fIString\fR gives the input to be parsed and \fIformat\fR indicates
  39. how to parse it, using \fB%\fR conversion specifiers as in \fBsscanf\fR.
  40. Each \fIvarName\fR gives the name of a variable; when a field is
  41. scanned from \fIstring\fR the result is converted back into a string
  42. and assigned to the corresponding variable.
  43.  
  44. .SH "DETAILS ON SCANNING"
  45. .PP
  46. \fBScan\fR operates by scanning \fIstring\fR and \fIformatString\fR together.
  47. If the next character in \fIformatString\fR is a blank or tab then it
  48. is ignored.
  49. Otherwise, if it isn't a \fB%\fR character then it 
  50. must match the next non-white-space character of \fIstring\fR.
  51. When a \fB%\fR is encountered in \fIformatString\fR, it indicates
  52. the start of a conversion specifier.
  53. A conversion specifier contains three fields after the \fB%\fR:
  54. a \fB*\fR, which indicates that the converted value is to be discarded 
  55. instead of assigned to a variable; a number indicating a maximum field
  56. width; and a conversion character.
  57. All of these fields are optional except for the conversion character.
  58. .PP
  59. When \fBscan\fR finds a conversion specifier in \fIformatString\fR, it
  60. first skips any white-space characters in \fIstring\fR.
  61. Then it converts the next input characters according to the 
  62. conversion specifier and stores the result in the variable given
  63. by the next argument to \fBscan\fR.
  64. The following conversion characters are supported:
  65. .TP 10
  66. \fBd\fR
  67. The input field must be a decimal integer.
  68. It is read in and the value is stored in the variable as a decimal string.
  69. .TP 10
  70. \fBo\fR
  71. The input field must be an octal integer. It is read in and the 
  72. value is stored in the variable as a decimal string.
  73. .TP 10
  74. \fBx\fR
  75. The input field must be a hexadecimal integer. It is read in 
  76. and the value is stored in the variable as a decimal string.
  77. .TP 10
  78. \fBc\fR
  79. A single character is read in and its binary value is stored in 
  80. the variable as a decimal string.
  81. Initial white space is not skipped in this case, so the input
  82. field may be a white-space character.
  83. This conversion is different from the ANSI standard in that the
  84. input field always consists of a single character and no field
  85. width may be specified.
  86. .TP 10
  87. \fBs\fR
  88. The input field consists of all the characters up to the next 
  89. white-space character; the characters are copied to the variable.
  90. .TP 10
  91. \fBe\fR or \fBf\fR or \fBg\fR
  92. The input field must be a floating-point number consisting 
  93. of an optional sign, a string of decimal digits possibly con
  94. taining a decimal point, and an optional exponent consisting 
  95. of an \fBe\fR or \fBE\fR followed by an optional sign and a string of 
  96. decimal digits.
  97. It is read in and stored in the variable as a floating-point string.
  98. .TP 10
  99. \fB[\fIchars\fB]
  100. The input field consists of any number of characters in 
  101. \fIchars\fR.
  102. The matching string is stored in the variable.
  103. If the first character between the brackets is a \fB]\fR then
  104. it is treated as part of \fIchars\fR rather than the closing
  105. bracket for the set.
  106. .TP 10
  107. \fB[^\fIchars\fB]
  108. The input field consists of any number of characters not in 
  109. \fIchars\fR.
  110. The matching string is stored in the variable.
  111. If the character immediately following the \fB^\fR is a \fB]\fR then it is 
  112. treated as part of the set rather than the closing bracket for 
  113. the set.
  114. .LP
  115. The number of characters read from the input for a conversion is the
  116. largest number that makes sense for that particular conversion (e.g.
  117. as many decimal digits as possible for \fB%d\fR, as 
  118. many octal digits as possible for \fB%o\fR, and so on).
  119. The input field for a given conversion terminates either when a
  120. white-space character is encountered or when the maximum field 
  121. width has been reached, whichever comes first.
  122. If a \fB*\fR is present in the conversion specifier 
  123. then no variable is assigned and the next scan argument is not consumed.
  124.  
  125. .SH "DIFFERENCES FROM ANSI SSCANF"
  126. .PP
  127. The behavior of the \fBscan\fR command is the same as the behavior of
  128. the ANSI C \fBsscanf\fR procedure except for the following differences:
  129. .IP [1]
  130. .VS
  131. \fB%p\fR and \fB%n\fR conversion specifiers are not currently
  132. supported.
  133. .VE
  134. .IP [2]
  135. For \fB%c\fR conversions a single character value is
  136. converted to a decimal string, which is then assigned to the
  137. corresponding \fIvarName\fR;
  138. no field width may be specified for this conversion.
  139. .IP [3]
  140. .VS
  141. The \fBl\fR, \fBh\fR, and \fBL\fR modifiers are ignored;  integer
  142. values are always converted as if there were no modifier present
  143. and real values are always converted as if the \fBl\fR modifier
  144. were present (i.e. type \fBdouble\fR is used for the internal
  145. representation).
  146. .VE
  147.  
  148. .SH KEYWORDS
  149. conversion specifier, parse, scan
  150.