OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / man / mann / scan.n
1 '\"
2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4 '\" Copyright (c) 2000 Scriptics Corporation.
5 '\"
6 '\" See the file "license.terms" for information on usage and redistribution
7 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 '\" 
9 .TH scan n 8.4 Tcl "Tcl Built-In Commands"
10 .\" The -*- nroff -*- definitions below are for supplemental macros used
11 .\" in Tcl/Tk manual entries.
12 .\"
13 .\" .AP type name in/out ?indent?
14 .\"     Start paragraph describing an argument to a library procedure.
15 .\"     type is type of argument (int, etc.), in/out is either "in", "out",
16 .\"     or "in/out" to describe whether procedure reads or modifies arg,
17 .\"     and indent is equivalent to second arg of .IP (shouldn't ever be
18 .\"     needed;  use .AS below instead)
19 .\"
20 .\" .AS ?type? ?name?
21 .\"     Give maximum sizes of arguments for setting tab stops.  Type and
22 .\"     name are examples of largest possible arguments that will be passed
23 .\"     to .AP later.  If args are omitted, default tab stops are used.
24 .\"
25 .\" .BS
26 .\"     Start box enclosure.  From here until next .BE, everything will be
27 .\"     enclosed in one large box.
28 .\"
29 .\" .BE
30 .\"     End of box enclosure.
31 .\"
32 .\" .CS
33 .\"     Begin code excerpt.
34 .\"
35 .\" .CE
36 .\"     End code excerpt.
37 .\"
38 .\" .VS ?version? ?br?
39 .\"     Begin vertical sidebar, for use in marking newly-changed parts
40 .\"     of man pages.  The first argument is ignored and used for recording
41 .\"     the version when the .VS was added, so that the sidebars can be
42 .\"     found and removed when they reach a certain age.  If another argument
43 .\"     is present, then a line break is forced before starting the sidebar.
44 .\"
45 .\" .VE
46 .\"     End of vertical sidebar.
47 .\"
48 .\" .DS
49 .\"     Begin an indented unfilled display.
50 .\"
51 .\" .DE
52 .\"     End of indented unfilled display.
53 .\"
54 .\" .SO ?manpage?
55 .\"     Start of list of standard options for a Tk widget. The manpage
56 .\"     argument defines where to look up the standard options; if
57 .\"     omitted, defaults to "options". The options follow on successive
58 .\"     lines, in three columns separated by tabs.
59 .\"
60 .\" .SE
61 .\"     End of list of standard options for a Tk widget.
62 .\"
63 .\" .OP cmdName dbName dbClass
64 .\"     Start of description of a specific option.  cmdName gives the
65 .\"     option's name as specified in the class command, dbName gives
66 .\"     the option's name in the option database, and dbClass gives
67 .\"     the option's class in the option database.
68 .\"
69 .\" .UL arg1 arg2
70 .\"     Print arg1 underlined, then print arg2 normally.
71 .\"
72 .\" .QW arg1 ?arg2?
73 .\"     Print arg1 in quotes, then arg2 normally (for trailing punctuation).
74 .\"
75 .\" .PQ arg1 ?arg2?
76 .\"     Print an open parenthesis, arg1 in quotes, then arg2 normally
77 .\"     (for trailing punctuation) and then a closing parenthesis.
78 .\"
79 .\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
80 .if t .wh -1.3i ^B
81 .nr ^l \n(.l
82 .ad b
83 .\"     # Start an argument description
84 .de AP
85 .ie !"\\$4"" .TP \\$4
86 .el \{\
87 .   ie !"\\$2"" .TP \\n()Cu
88 .   el          .TP 15
89 .\}
90 .ta \\n()Au \\n()Bu
91 .ie !"\\$3"" \{\
92 \&\\$1 \\fI\\$2\\fP (\\$3)
93 .\".b
94 .\}
95 .el \{\
96 .br
97 .ie !"\\$2"" \{\
98 \&\\$1  \\fI\\$2\\fP
99 .\}
100 .el \{\
101 \&\\fI\\$1\\fP
102 .\}
103 .\}
104 ..
105 .\"     # define tabbing values for .AP
106 .de AS
107 .nr )A 10n
108 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
109 .nr )B \\n()Au+15n
110 .\"
111 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
112 .nr )C \\n()Bu+\\w'(in/out)'u+2n
113 ..
114 .AS Tcl_Interp Tcl_CreateInterp in/out
115 .\"     # BS - start boxed text
116 .\"     # ^y = starting y location
117 .\"     # ^b = 1
118 .de BS
119 .br
120 .mk ^y
121 .nr ^b 1u
122 .if n .nf
123 .if n .ti 0
124 .if n \l'\\n(.lu\(ul'
125 .if n .fi
126 ..
127 .\"     # BE - end boxed text (draw box now)
128 .de BE
129 .nf
130 .ti 0
131 .mk ^t
132 .ie n \l'\\n(^lu\(ul'
133 .el \{\
134 .\"     Draw four-sided box normally, but don't draw top of
135 .\"     box if the box started on an earlier page.
136 .ie !\\n(^b-1 \{\
137 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
138 .\}
139 .el \}\
140 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
141 .\}
142 .\}
143 .fi
144 .br
145 .nr ^b 0
146 ..
147 .\"     # VS - start vertical sidebar
148 .\"     # ^Y = starting y location
149 .\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
150 .de VS
151 .if !"\\$2"" .br
152 .mk ^Y
153 .ie n 'mc \s12\(br\s0
154 .el .nr ^v 1u
155 ..
156 .\"     # VE - end of vertical sidebar
157 .de VE
158 .ie n 'mc
159 .el \{\
160 .ev 2
161 .nf
162 .ti 0
163 .mk ^t
164 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
165 .sp -1
166 .fi
167 .ev
168 .\}
169 .nr ^v 0
170 ..
171 .\"     # Special macro to handle page bottom:  finish off current
172 .\"     # box/sidebar if in box/sidebar mode, then invoked standard
173 .\"     # page bottom macro.
174 .de ^B
175 .ev 2
176 'ti 0
177 'nf
178 .mk ^t
179 .if \\n(^b \{\
180 .\"     Draw three-sided box if this is the box's first page,
181 .\"     draw two sides but no top otherwise.
182 .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
183 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
184 .\}
185 .if \\n(^v \{\
186 .nr ^x \\n(^tu+1v-\\n(^Yu
187 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
188 .\}
189 .bp
190 'fi
191 .ev
192 .if \\n(^b \{\
193 .mk ^y
194 .nr ^b 2
195 .\}
196 .if \\n(^v \{\
197 .mk ^Y
198 .\}
199 ..
200 .\"     # DS - begin display
201 .de DS
202 .RS
203 .nf
204 .sp
205 ..
206 .\"     # DE - end display
207 .de DE
208 .fi
209 .RE
210 .sp
211 ..
212 .\"     # SO - start of list of standard options
213 .de SO
214 'ie '\\$1'' .ds So \\fBoptions\\fR
215 'el .ds So \\fB\\$1\\fR
216 .SH "STANDARD OPTIONS"
217 .LP
218 .nf
219 .ta 5.5c 11c
220 .ft B
221 ..
222 .\"     # SE - end of list of standard options
223 .de SE
224 .fi
225 .ft R
226 .LP
227 See the \\*(So manual entry for details on the standard options.
228 ..
229 .\"     # OP - start of full description for a single option
230 .de OP
231 .LP
232 .nf
233 .ta 4c
234 Command-Line Name:      \\fB\\$1\\fR
235 Database Name:  \\fB\\$2\\fR
236 Database Class: \\fB\\$3\\fR
237 .fi
238 .IP
239 ..
240 .\"     # CS - begin code excerpt
241 .de CS
242 .RS
243 .nf
244 .ta .25i .5i .75i 1i
245 ..
246 .\"     # CE - end code excerpt
247 .de CE
248 .fi
249 .RE
250 ..
251 .\"     # UL - underline word
252 .de UL
253 \\$1\l'|0\(ul'\\$2
254 ..
255 .\"     # QW - apply quotation marks to word
256 .de QW
257 .ie '\\*(lq'"' ``\\$1''\\$2
258 .\"" fix emacs highlighting
259 .el \\*(lq\\$1\\*(rq\\$2
260 ..
261 .\"     # PQ - apply parens and quotation marks to word
262 .de PQ
263 .ie '\\*(lq'"' (``\\$1''\\$2)\\$3
264 .\"" fix emacs highlighting
265 .el (\\*(lq\\$1\\*(rq\\$2)\\$3
266 ..
267 .\"     # QR - quoted range
268 .de QR
269 .ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3
270 .\"" fix emacs highlighting
271 .el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3
272 ..
273 .\"     # MT - "empty" string
274 .de MT
275 .QW ""
276 ..
277 .BS
278 '\" Note:  do not modify the .SH NAME line immediately below!
279 .SH NAME
280 scan \- Parse string using conversion specifiers in the style of sscanf
281 .SH SYNOPSIS
282 \fBscan \fIstring format \fR?\fIvarName varName ...\fR?
283 .BE
284 .SH INTRODUCTION
285 .PP
286 This command parses substrings from an input string in a fashion similar
287 to the ANSI C \fBsscanf\fR procedure and returns a count of the number of
288 conversions performed, or -1 if the end of the input string is reached
289 before any conversions have been performed.  \fIString\fR gives the input
290 to be parsed and \fIformat\fR indicates how to parse it, using \fB%\fR
291 conversion specifiers as in \fBsscanf\fR.  Each \fIvarName\fR gives the
292 name of a variable; when a substring is scanned from \fIstring\fR that
293 matches a conversion specifier, the substring is assigned to the
294 corresponding variable.
295 If no \fIvarName\fR variables are specified, then \fBscan\fR works in an
296 inline manner, returning the data that would otherwise be stored in the
297 variables as a list.  In the inline case, an empty string is returned when
298 the end of the input string is reached before any conversions have been
299 performed.
300 .SH "DETAILS ON SCANNING"
301 .PP
302 \fBScan\fR operates by scanning \fIstring\fR and \fIformat\fR together.
303 If the next character in \fIformat\fR is a blank or tab then it
304 matches any number of white space characters in \fIstring\fR (including
305 zero).
306 Otherwise, if it is not a \fB%\fR character then it 
307 must match the next character of \fIstring\fR.
308 When a \fB%\fR is encountered in \fIformat\fR, it indicates
309 the start of a conversion specifier.
310 A conversion specifier contains up to four fields after the \fB%\fR:
311 a XPG3 position specifier (or a \fB*\fR to indicate the converted
312 value is to be discarded instead of assigned to any variable); a number
313 indicating a maximum substring width; a size modifier; and a
314 conversion character.
315 All of these fields are optional except for the conversion character.
316 The fields that are present must appear in the order given above.
317 .PP
318 When \fBscan\fR finds a conversion specifier in \fIformat\fR, it
319 first skips any white-space characters in \fIstring\fR (unless the
320 conversion character is \fB[\fR or \fBc\fR).
321 Then it converts the next input characters according to the 
322 conversion specifier and stores the result in the variable given
323 by the next argument to \fBscan\fR.
324 .SS "OPTIONAL POSITIONAL SPECIFIER"
325 .PP
326 If the \fB%\fR is followed by a decimal number and a \fB$\fR, as in
327 .QW \fB%2$d\fR ,
328 then the variable to use is not taken from the next
329 sequential argument.  Instead, it is taken from the argument indicated
330 by the number, where 1 corresponds to the first \fIvarName\fR.  If
331 there are any positional specifiers in \fIformat\fR then all of the
332 specifiers must be positional.  Every \fIvarName\fR on the argument
333 list must correspond to exactly one conversion specifier or an error
334 is generated, or in the inline case, any position can be specified
335 at most once and the empty positions will be filled in with empty strings.
336 .SS "OPTIONAL SIZE MODIFIER"
337 .PP
338 The size modifier field is used only when scanning a substring into
339 one of Tcl's integer values.  The size modifier field dictates the
340 integer range acceptable to be stored in a variable, or, for the inline
341 case, in a position in the result list.
342 The syntactically valid values for the size modifier are \fBh\fR, \fBL\fR,
343 \fBl\fR, and \fBll\fR.  The \fBh\fR size modifier value is equivalent
344 to the absence of a size modifier in the the conversion specifier.
345 Either one indicates the integer range to be stored is limited to
346 the same range produced by the \fBint()\fR function of the \fBexpr\fR
347 command.  The \fBL\fR size modifier is equivalent to the \fBl\fR size
348 modifier. Either one indicates the integer range to be stored is
349 limited to the same range produced by the \fBwide()\fR function of
350 the \fBexpr\fR command.  The \fBll\fR size modifier indicates that
351 the integer range to be stored is unlimited.
352 .SS "MANDATORY CONVERSION CHARACTER"
353 .PP
354 The following conversion characters are supported:
355 .TP
356 \fBd\fR
357 .
358 The input substring must be a decimal integer.
359 It is read in and the integer value is stored in the variable,
360 truncated as required by the size modifier value.
361 .TP
362 \fBo\fR
363 .
364 The input substring must be an octal integer. It is read in and the 
365 integer value is stored in the variable,
366 truncated as required by the size modifier value.
367 .TP
368 \fBx\fR or \fBX\fR
369 .
370 The input substring must be a hexadecimal integer.
371 It is read in and the integer value is stored in the variable,
372 truncated as required by the size modifier value.
373 .TP
374 \fBb\fR
375 .
376 The input substring must be a binary integer.
377 It is read in and the integer value is stored in the variable,
378 truncated as required by the size modifier value.
379 .TP
380 \fBu\fR
381 .
382 The input substring must be a decimal integer.
383 The integer value is truncated as required by the size modifier
384 value, and the corresponding unsigned value for that truncated
385 range is computed and stored in the variable as a decimal string.
386 The conversion makes no sense without reference to a truncation range,
387 so the size modifier \fBll\fR is not permitted in combination
388 with conversion character \fBu\fR.
389 .TP
390 \fBi\fR
391 .
392 The input substring must be an integer.  The base (i.e. decimal, binary,
393 octal, or hexadecimal) is determined in the same fashion as described in
394 \fBexpr\fR.  The integer value is stored in the variable,
395 truncated as required by the size modifier value.
396 .TP
397 \fBc\fR
398 .
399 A single character is read in and its Unicode value is stored in 
400 the variable as an integer value.
401 Initial white space is not skipped in this case, so the input
402 substring may be a white-space character.
403 .TP
404 \fBs\fR
405 .
406 The input substring consists of all the characters up to the next 
407 white-space character; the characters are copied to the variable.
408 .TP
409 \fBe\fR or \fBf\fR or \fBg\fR or \fBE\fR or \fBG\fR
410 .
411 The input substring must be a floating-point number consisting 
412 of an optional sign, a string of decimal digits possibly
413 containing a decimal point, and an optional exponent consisting 
414 of an \fBe\fR or \fBE\fR followed by an optional sign and a string of 
415 decimal digits.
416 It is read in and stored in the variable as a floating-point value.
417 .TP
418 \fB[\fIchars\fB]\fR
419 .
420 The input substring consists of one or more characters in \fIchars\fR.
421 The matching string is stored in the variable.
422 If the first character between the brackets is a \fB]\fR then
423 it is treated as part of \fIchars\fR rather than the closing
424 bracket for the set.
425 If \fIchars\fR
426 contains a sequence of the form \fIa\fB\-\fIb\fR then any
427 character between \fIa\fR and \fIb\fR (inclusive) will match.
428 If the first or last character between the brackets is a \fB\-\fR, then
429 it is treated as part of \fIchars\fR rather than indicating a range.
430 .TP
431 \fB[^\fIchars\fB]\fR
432 .
433 The input substring consists of one or more characters not in \fIchars\fR.
434 The matching string is stored in the variable.
435 If the character immediately following the \fB^\fR is a \fB]\fR then it is 
436 treated as part of the set rather than the closing bracket for 
437 the set.
438 If \fIchars\fR
439 contains a sequence of the form \fIa\fB\-\fIb\fR then any
440 character between \fIa\fR and \fIb\fR (inclusive) will be excluded
441 from the set.
442 If the first or last character between the brackets is a \fB\-\fR, then
443 it is treated as part of \fIchars\fR rather than indicating a range value.
444 .TP
445 \fBn\fR
446 .
447 No input is consumed from the input string.  Instead, the total number
448 of characters scanned from the input string so far is stored in the variable.
449 .PP
450 The number of characters read from the input for a conversion is the
451 largest number that makes sense for that particular conversion (e.g.
452 as many decimal digits as possible for \fB%d\fR, as 
453 many octal digits as possible for \fB%o\fR, and so on).
454 The input substring for a given conversion terminates either when a
455 white-space character is encountered or when the maximum substring 
456 width has been reached, whichever comes first.
457 If a \fB*\fR is present in the conversion specifier 
458 then no variable is assigned and the next scan argument is not consumed.
459 .SH "DIFFERENCES FROM ANSI SSCANF"
460 .PP
461 The behavior of the \fBscan\fR command is the same as the behavior of
462 the ANSI C \fBsscanf\fR procedure except for the following differences:
463 .IP [1]
464 \fB%p\fR conversion specifier is not supported.
465 .IP [2]
466 For \fB%c\fR conversions a single character value is
467 converted to a decimal string, which is then assigned to the
468 corresponding \fIvarName\fR;
469 no substring width may be specified for this conversion.
470 .IP [3]
471 The \fBh\fR modifier is always ignored and the \fBl\fR and \fBL\fR
472 modifiers are ignored when converting real values (i.e. type
473 \fBdouble\fR is used for the internal representation).  The \fBll\fR
474 modifier has no \fBsscanf\fR counterpart.
475 .IP [4]
476 If the end of the input string is reached before any conversions have been
477 performed and no variables are given, an empty string is returned.
478 .SH EXAMPLES
479 .PP
480 Convert a UNICODE character to its numeric value:
481 .PP
482 .CS
483 set char "x"
484 set value [\fBscan\fR $char %c]
485 .CE
486 .PP
487 Parse a simple color specification of the form \fI#RRGGBB\fR using
488 hexadecimal conversions with substring sizes:
489 .PP
490 .CS
491 set string "#08D03F"
492 \fBscan\fR $string "#%2x%2x%2x" r g b
493 .CE
494 .PP
495 Parse a \fIHH:MM\fR time string, noting that this avoids problems with
496 octal numbers by forcing interpretation as decimals (if we did not
497 care, we would use the \fB%i\fR conversion instead):
498 .PP
499 .CS
500 set string "08:08"   ;# *Not* octal!
501 if {[\fBscan\fR $string "%d:%d" hours minutes] != 2} {
502     error "not a valid time string"
503 }
504 # We have to understand numeric ranges ourselves...
505 if {$minutes < 0 || $minutes > 59} {
506     error "invalid number of minutes"
507 }
508 .CE
509 .PP
510 Break a string up into sequences of non-whitespace characters (note
511 the use of the \fB%n\fR conversion so that we get skipping over
512 leading whitespace correct):
513 .PP
514 .CS
515 set string " a string {with braced words} + leading space "
516 set words {}
517 while {[\fBscan\fR $string %s%n word length] == 2} {
518     lappend words $word
519     set string [string range $string $length end]
520 }
521 .CE
522 .PP
523 Parse a simple coordinate string, checking that it is complete by
524 looking for the terminating character explicitly:
525 .PP
526 .CS
527 set string "(5.2,-4e-2)"
528 # Note that the spaces before the literal parts of
529 # the scan pattern are significant, and that ")" is
530 # the Unicode character \eu0029
531 if {
532     [\fBscan\fR $string " (%f ,%f %c" x y last] != 3
533     || $last != 0x0029
534 } then {
535     error "invalid coordinate string"
536 }
537 puts "X=$x, Y=$y"
538 .CE
539 .PP
540 An interactive session demonstrating the truncation of integer
541 values determined by size modifiers:
542 .PP
543 .CS
544 \fI%\fR set tcl_platform(wordSize)
545 4
546 \fI%\fR scan 20000000000000000000 %d
547 2147483647
548 \fI%\fR scan 20000000000000000000 %ld
549 9223372036854775807
550 \fI%\fR scan 20000000000000000000 %lld
551 20000000000000000000
552 .CE
553 .SH "SEE ALSO"
554 format(n), sscanf(3)
555 .SH KEYWORDS
556 conversion specifier, parse, scan
557 '\" Local Variables:
558 '\" mode: nroff
559 '\" End: