Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / man / man3 / Tk_ParseArgv.3
CommitLineData
920dae64
AT
1'\"
2'\" Copyright (c) 1990-1992 The Regents of the University of California.
3'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4'\"
5'\" See the file "license.terms" for information on usage and redistribution
6'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7'\"
8'\" RCS: @(#) $Id: ParseArgv.3,v 1.3 2002/01/25 21:09:36 dgp Exp $
9'\"
10'\" The definitions below are for supplemental macros used in Tcl/Tk
11'\" 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
55'\" Start of list of standard options for a Tk widget. The
56'\" options follow on successive lines, in four columns separated
57'\" by tabs.
58'\"
59'\" .SE
60'\" End of list of standard options for a Tk widget.
61'\"
62'\" .OP cmdName dbName dbClass
63'\" Start of description of a specific option. cmdName gives the
64'\" option's name as specified in the class command, dbName gives
65'\" the option's name in the option database, and dbClass gives
66'\" the option's class in the option database.
67'\"
68'\" .UL arg1 arg2
69'\" Print arg1 underlined, then print arg2 normally.
70'\"
71'\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $
72'\"
73'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
74.if t .wh -1.3i ^B
75.nr ^l \n(.l
76.ad b
77'\" # Start an argument description
78.de AP
79.ie !"\\$4"" .TP \\$4
80.el \{\
81. ie !"\\$2"" .TP \\n()Cu
82. el .TP 15
83.\}
84.ta \\n()Au \\n()Bu
85.ie !"\\$3"" \{\
86\&\\$1 \\fI\\$2\\fP (\\$3)
87.\".b
88.\}
89.el \{\
90.br
91.ie !"\\$2"" \{\
92\&\\$1 \\fI\\$2\\fP
93.\}
94.el \{\
95\&\\fI\\$1\\fP
96.\}
97.\}
98..
99'\" # define tabbing values for .AP
100.de AS
101.nr )A 10n
102.if !"\\$1"" .nr )A \\w'\\$1'u+3n
103.nr )B \\n()Au+15n
104.\"
105.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
106.nr )C \\n()Bu+\\w'(in/out)'u+2n
107..
108.AS Tcl_Interp Tcl_CreateInterp in/out
109'\" # BS - start boxed text
110'\" # ^y = starting y location
111'\" # ^b = 1
112.de BS
113.br
114.mk ^y
115.nr ^b 1u
116.if n .nf
117.if n .ti 0
118.if n \l'\\n(.lu\(ul'
119.if n .fi
120..
121'\" # BE - end boxed text (draw box now)
122.de BE
123.nf
124.ti 0
125.mk ^t
126.ie n \l'\\n(^lu\(ul'
127.el \{\
128.\" Draw four-sided box normally, but don't draw top of
129.\" box if the box started on an earlier page.
130.ie !\\n(^b-1 \{\
131\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
132.\}
133.el \}\
134\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
135.\}
136.\}
137.fi
138.br
139.nr ^b 0
140..
141'\" # VS - start vertical sidebar
142'\" # ^Y = starting y location
143'\" # ^v = 1 (for troff; for nroff this doesn't matter)
144.de VS
145.if !"\\$2"" .br
146.mk ^Y
147.ie n 'mc \s12\(br\s0
148.el .nr ^v 1u
149..
150'\" # VE - end of vertical sidebar
151.de VE
152.ie n 'mc
153.el \{\
154.ev 2
155.nf
156.ti 0
157.mk ^t
158\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
159.sp -1
160.fi
161.ev
162.\}
163.nr ^v 0
164..
165'\" # Special macro to handle page bottom: finish off current
166'\" # box/sidebar if in box/sidebar mode, then invoked standard
167'\" # page bottom macro.
168.de ^B
169.ev 2
170'ti 0
171'nf
172.mk ^t
173.if \\n(^b \{\
174.\" Draw three-sided box if this is the box's first page,
175.\" draw two sides but no top otherwise.
176.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
177.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
178.\}
179.if \\n(^v \{\
180.nr ^x \\n(^tu+1v-\\n(^Yu
181\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
182.\}
183.bp
184'fi
185.ev
186.if \\n(^b \{\
187.mk ^y
188.nr ^b 2
189.\}
190.if \\n(^v \{\
191.mk ^Y
192.\}
193..
194'\" # DS - begin display
195.de DS
196.RS
197.nf
198.sp
199..
200'\" # DE - end display
201.de DE
202.fi
203.RE
204.sp
205..
206'\" # SO - start of list of standard options
207.de SO
208.SH "STANDARD OPTIONS"
209.LP
210.nf
211.ta 5.5c 11c
212.ft B
213..
214'\" # SE - end of list of standard options
215.de SE
216.fi
217.ft R
218.LP
219See the \\fBoptions\\fR manual entry for details on the standard options.
220..
221'\" # OP - start of full description for a single option
222.de OP
223.LP
224.nf
225.ta 4c
226Command-Line Name: \\fB\\$1\\fR
227Database Name: \\fB\\$2\\fR
228Database Class: \\fB\\$3\\fR
229.fi
230.IP
231..
232'\" # CS - begin code excerpt
233.de CS
234.RS
235.nf
236.ta .25i .5i .75i 1i
237..
238'\" # CE - end code excerpt
239.de CE
240.fi
241.RE
242..
243.de UL
244\\$1\l'|0\(ul'\\$2
245..
246.TH Tk_ParseArgv 3 "" Tk "Tk Library Procedures"
247.BS
248.SH NAME
249Tk_ParseArgv \- process command-line options
250.SH SYNOPSIS
251.nf
252\fB#include <tk.h>\fR
253.sp
254int
255\fBTk_ParseArgv\fR(\fIinterp, tkwin, argcPtr, argv, argTable, flags\fR)
256.SH ARGUMENTS
257.AS Tk_ArgvInfo *argTable
258.AP Tcl_Interp *interp in
259Interpreter to use for returning error messages.
260.AP Tk_Window tkwin in
261Window to use when arguments specify Tk options. If NULL, then
262no Tk options will be processed.
263.AP int argcPtr in/out
264Pointer to number of arguments in argv; gets modified to hold
265number of unprocessed arguments that remain after the call.
266.AP "CONST char" **argv in/out
267Command line arguments passed to main program. Modified to
268hold unprocessed arguments that remain after the call.
269.AP Tk_ArgvInfo *argTable in
270Array of argument descriptors, terminated by element with
271type TK_ARGV_END.
272.AP int flags in
273If non-zero, then it specifies one or more flags that control the
274parsing of arguments. Different flags may be OR'ed together.
275The flags currently defined are TK_ARGV_DONT_SKIP_FIRST_ARG,
276TK_ARGV_NO_ABBREV, TK_ARGV_NO_LEFTOVERS, and TK_ARGV_NO_DEFAULTS.
277.BE
278.SH DESCRIPTION
279.PP
280\fBTk_ParseArgv\fR processes an array of command-line arguments according
281to a table describing the kinds of arguments that are expected.
282Each of the arguments in \fIargv\fR is processed in turn: if it matches
283one of the entries in \fIargTable\fR, the argument is processed
284according to that entry and discarded. The arguments that do not
285match anything in \fIargTable\fR are copied down to the beginning
286of \fIargv\fR (retaining their original order) and returned to
287the caller. At the end of the call
288\fBTk_ParseArgv\fR sets \fI*argcPtr\fR to hold the number of
289arguments that are left in \fIargv\fR, and \fIargv[*argcPtr]\fR
290will hold the value NULL. Normally, \fBTk_ParseArgv\fR
291assumes that \fIargv[0]\fR is a command name, so it is treated like
292an argument that doesn't match \fIargTable\fR and returned to the
293caller; however, if the TK_ARGV_DONT_SKIP_FIRST_ARG bit is set in
294\fIflags\fR then \fIargv[0]\fR will be processed just like the other
295elements of \fIargv\fR.
296.PP
297\fBTk_ParseArgv\fR normally returns the value TCL_OK. If an error
298occurs while parsing the arguments, then TCL_ERROR is returned and
299\fBTk_ParseArgv\fR will leave an error message in \fIinterp->result\fR
300in the standard Tcl fashion. In
301the event of an error return, \fI*argvPtr\fR will not have been
302modified, but \fIargv\fR could have been partially modified. The
303possible causes of errors are explained below.
304.PP
305The \fIargTable\fR array specifies the kinds of arguments that are
306expected; each of its entries has the following structure:
307.CS
308typedef struct {
309 char *\fIkey\fR;
310 int \fItype\fR;
311 char *\fIsrc\fR;
312 char *\fIdst\fR;
313 char *\fIhelp\fR;
314} Tk_ArgvInfo;
315.CE
316The \fIkey\fR field is a string such as ``\-display'' or ``\-bg''
317that is compared with the values in \fIargv\fR. \fIType\fR
318indicates how to process an argument that matches \fIkey\fR
319(more on this below). \fISrc\fR and \fIdst\fR are additional
320values used in processing the argument. Their exact usage
321depends on \fItype\fR, but typically \fIsrc\fR indicates
322a value and \fIdst\fR indicates where to store the
323value. The \fBchar *\fR declarations for \fIsrc\fR and \fIdst\fR
324are placeholders: the actual types may be different. Lastly,
325\fIhelp\fR is a string giving a brief description
326of this option; this string is printed when users ask for help
327about command-line options.
328.PP
329When processing an argument in \fIargv\fR, \fBTk_ParseArgv\fR
330compares the argument to each of the \fIkey\fR's in \fIargTable\fR.
331\fBTk_ParseArgv\fR selects the first specifier whose \fIkey\fR matches
332the argument exactly, if such a specifier exists. Otherwise
333\fBTk_ParseArgv\fR selects a specifier for which the argument
334is a unique abbreviation. If the argument is a unique abbreviation
335for more than one specifier, then an error is returned. If there
336is no matching entry in \fIargTable\fR, then the argument is
337skipped and returned to the caller.
338.PP
339Once a matching argument specifier is found, \fBTk_ParseArgv\fR
340processes the argument according to the \fItype\fR field of the
341specifier. The argument that matched \fIkey\fR is called ``the matching
342argument'' in the descriptions below. As part of the processing,
343\fBTk_ParseArgv\fR may also use the next argument in \fIargv\fR
344after the matching argument, which is called ``the following
345argument''. The legal values for \fItype\fR, and the processing
346that they cause, are as follows:
347.TP
348\fBTK_ARGV_END\fR
349Marks the end of the table. The last entry in \fIargTable\fR
350must have this type; all of its other fields are ignored and it
351will never match any arguments.
352.TP
353\fBTK_ARGV_CONSTANT\fR
354\fISrc\fR is treated as an integer and \fIdst\fR is treated
355as a pointer to an integer. \fISrc\fR is stored at \fI*dst\fR.
356The matching argument is discarded.
357.TP
358\fBTK_ARGV_INT\fR
359The following argument must contain an
360integer string in the format accepted by \fBstrtol\fR (e.g. ``0''
361and ``0x'' prefixes may be used to specify octal or hexadecimal
362numbers, respectively). \fIDst\fR is treated as a pointer to an
363integer; the following argument is converted to an integer value
364and stored at \fI*dst\fR. \fISrc\fR is ignored. The matching
365and following arguments are discarded from \fIargv\fR.
366.TP
367\fBTK_ARGV_FLOAT\fR
368The following argument must contain a floating-point number in
369the format accepted by \fBstrtol\fR.
370\fIDst\fR is treated as the address of an double-precision
371floating point value; the following argument is converted to a
372double-precision value and stored at \fI*dst\fR. The matching
373and following arguments are discarded from \fIargv\fR.
374.TP
375\fBTK_ARGV_STRING\fR
376In this form, \fIdst\fR is treated as a pointer to a (char *);
377\fBTk_ParseArgv\fR stores at \fI*dst\fR a pointer to the following
378argument, and discards the matching and following arguments from
379\fIargv\fR. \fISrc\fR is ignored.
380.TP
381\fBTK_ARGV_UID\fR
382This form is similar to TK_ARGV_STRING, except that the argument
383is turned into a Tk_Uid by calling \fBTk_GetUid\fR.
384\fIDst\fR is treated as a pointer to a
385Tk_Uid; \fBTk_ParseArgv\fR stores at \fI*dst\fR the Tk_Uid
386corresponding to the following
387argument, and discards the matching and following arguments from
388\fIargv\fR. \fISrc\fR is ignored.
389.TP
390\fBTK_ARGV_CONST_OPTION\fR
391This form causes a Tk option to be set (as if the \fBoption\fR
392command had been invoked). The \fIsrc\fR field is treated as a
393pointer to a string giving the value of an option, and \fIdst\fR
394is treated as a pointer to the name of the option. The matching
395argument is discarded. If \fItkwin\fR is NULL, then argument
396specifiers of this type are ignored (as if they did not exist).
397.TP
398\fBTK_ARGV_OPTION_VALUE\fR
399This form is similar to TK_ARGV_CONST_OPTION, except that the
400value of the option is taken from the following argument instead
401of from \fIsrc\fR. \fIDst\fR is used as the name of the option.
402\fISrc\fR is ignored. The matching and following arguments
403are discarded. If \fItkwin\fR is NULL, then argument
404specifiers of this type are ignored (as if they did not exist).
405.TP
406\fBTK_ARGV_OPTION_NAME_VALUE\fR
407In this case the following argument is taken as the name of a Tk
408option and the argument after that is taken as the value for that
409option. Both \fIsrc\fR and \fIdst\fR are ignored. All three
410arguments are discarded from \fIargv\fR. If \fItkwin\fR is NULL,
411then argument
412specifiers of this type are ignored (as if they did not exist).
413.TP
414\fBTK_ARGV_HELP\fR
415When this kind of option is encountered, \fBTk_ParseArgv\fR uses the
416\fIhelp\fR fields of \fIargTable\fR to format a message describing
417all the valid arguments. The message is placed in \fIinterp->result\fR
418and \fBTk_ParseArgv\fR returns TCL_ERROR. When this happens, the
419caller normally prints the help message and aborts. If the \fIkey\fR
420field of a TK_ARGV_HELP specifier is NULL, then the specifier will
421never match any arguments; in this case the specifier simply provides
422extra documentation, which will be included when some other
423TK_ARGV_HELP entry causes help information to be returned.
424.TP
425\fBTK_ARGV_REST\fR
426This option is used by programs or commands that allow the last
427several of their options to be the name and/or options for some
428other program. If a \fBTK_ARGV_REST\fR argument is found, then
429\fBTk_ParseArgv\fR doesn't process any
430of the remaining arguments; it returns them all at
431the beginning of \fIargv\fR (along with any other unprocessed arguments).
432In addition, \fBTk_ParseArgv\fR treats \fIdst\fR as the address of an
433integer value, and stores at \fI*dst\fR the index of the first of the
434\fBTK_ARGV_REST\fR options in the returned \fIargv\fR. This allows the
435program to distinguish the \fBTK_ARGV_REST\fR options from other
436unprocessed options that preceded the \fBTK_ARGV_REST\fR.
437.TP
438\fBTK_ARGV_FUNC\fR
439For this kind of argument, \fIsrc\fR is treated as the address of
440a procedure, which is invoked to process the following argument.
441The procedure should have the following structure:
442.RS
443.CS
444int
445\fIfunc\fR(\fIdst\fR, \fIkey\fR, \fInextArg\fR)
446 char *\fIdst\fR;
447 char *\fIkey\fR;
448 char *\fInextArg\fR;
449{
450}
451.CE
452The \fIdst\fR and \fIkey\fR parameters will contain the
453corresponding fields from the \fIargTable\fR entry, and
454\fInextArg\fR will point to the following argument from \fIargv\fR
455(or NULL if there aren't any more arguments left in \fIargv\fR).
456If \fIfunc\fR uses \fInextArg\fR (so that
457\fBTk_ParseArgv\fR should discard it), then it should return 1. Otherwise it
458should return 0 and \fBTkParseArgv\fR will process the following
459argument in the normal fashion. In either event the matching argument
460is discarded.
461.RE
462.TP
463\fBTK_ARGV_GENFUNC\fR
464This form provides a more general procedural escape. It treats
465\fIsrc\fR as the address of a procedure, and passes that procedure
466all of the remaining arguments. The procedure should have the following
467form:
468.RS
469.CS
470int
471\fIgenfunc\fR(dst, interp, key, argc, argv)
472 char *\fIdst\fR;
473 Tcl_Interp *\fIinterp\fR;
474 char *\fIkey\fR;
475 int \fIargc\fR;
476 char **\fIargv\fR;
477{
478}
479.CE
480The \fIdst\fR and \fIkey\fR parameters will contain the
481corresponding fields from the \fIargTable\fR entry. \fIInterp\fR
482will be the same as the \fIinterp\fR argument to \fBTcl_ParseArgv\fR.
483\fIArgc\fR and \fIargv\fR refer to all of the options after the
484matching one. \fIGenfunc\fR should behave in a fashion similar
485to \fBTk_ParseArgv\fR: parse as many of the remaining arguments as it can,
486then return any that are left by compacting them to the beginning of
487\fIargv\fR (starting at \fIargv\fR[0]). \fIGenfunc\fR
488should return a count of how many arguments are left in \fIargv\fR;
489\fBTk_ParseArgv\fR will process them. If \fIgenfunc\fR encounters
490an error then it should leave an error message in \fIinterp->result\fR,
491in the usual Tcl fashion, and return -1; when this happens
492\fBTk_ParseArgv\fR will abort its processing and return TCL_ERROR.
493.RE
494
495.SH "FLAGS"
496.TP
497\fBTK_ARGV_DONT_SKIP_FIRST_ARG\fR
498\fBTk_ParseArgv\fR normally treats \fIargv[0]\fR as a program
499or command name, and returns it to the caller just as if it
500hadn't matched \fIargTable\fR. If this flag is given, then
501\fIargv[0]\fR is not given special treatment.
502.TP
503\fBTK_ARGV_NO_ABBREV\fR
504Normally, \fBTk_ParseArgv\fR accepts unique abbreviations for
505\fIkey\fR values in \fIargTable\fR. If this flag is given then
506only exact matches will be acceptable.
507.TP
508\fBTK_ARGV_NO_LEFTOVERS\fR
509Normally, \fBTk_ParseArgv\fR returns unrecognized arguments to the
510caller. If this bit is set in \fIflags\fR then \fBTk_ParseArgv\fR
511will return an error if it encounters any argument that doesn't
512match \fIargTable\fR. The only exception to this rule is \fIargv[0]\fR,
513which will be returned to the caller with no errors as
514long as TK_ARGV_DONT_SKIP_FIRST_ARG isn't specified.
515.TP
516\fBTK_ARGV_NO_DEFAULTS\fR
517Normally, \fBTk_ParseArgv\fR searches an internal table of
518standard argument specifiers in addition to \fIargTable\fR. If
519this bit is set in \fIflags\fR, then \fBTk_ParseArgv\fR will
520use only \fIargTable\fR and not its default table.
521
522.SH EXAMPLE
523.PP
524Here is an example definition of an \fIargTable\fR and
525some sample command lines that use the options. Note the effect
526on \fIargc\fR and \fIargv\fR; arguments processed by \fBTk_ParseArgv\fR
527are eliminated from \fIargv\fR, and \fIargc\fR
528is updated to reflect reduced number of arguments.
529.CS
530/*
531 * Define and set default values for globals.
532 */
533int debugFlag = 0;
534int numReps = 100;
535char defaultFileName[] = "out";
536char *fileName = defaultFileName;
537Boolean exec = FALSE;
538
539/*
540 * Define option descriptions.
541 */
542Tk_ArgvInfo argTable[] = {
543 {"-X", TK_ARGV_CONSTANT, (char *) 1, (char *) &debugFlag,
544 "Turn on debugging printfs"},
545 {"-N", TK_ARGV_INT, (char *) NULL, (char *) &numReps,
546 "Number of repetitions"},
547 {"-of", TK_ARGV_STRING, (char *) NULL, (char *) &fileName,
548 "Name of file for output"},
549 {"x", TK_ARGV_REST, (char *) NULL, (char *) &exec,
550 "File to exec, followed by any arguments (must be last argument)."},
551 {(char *) NULL, TK_ARGV_END, (char *) NULL, (char *) NULL,
552 (char *) NULL}
553};
554
555main(argc, argv)
556 int argc;
557 char *argv[];
558{
559 \&...
560
561 if (Tk_ParseArgv(interp, tkwin, &argc, argv, argTable, 0) != TCL_OK) {
562 fprintf(stderr, "%s\en", interp->result);
563 exit(1);
564 }
565
566 /*
567 * Remainder of the program.
568 */
569}
570.CE
571.PP
572Note that default values can be assigned to variables named in
573\fIargTable\fR: the variables will only be overwritten if the
574particular arguments are present in \fIargv\fR.
575Here are some example command lines and their effects.
576.CS
577prog -N 200 infile # just sets the numReps variable to 200
578prog -of out200 infile # sets fileName to reference "out200"
579prog -XN 10 infile # sets the debug flag, also sets numReps
580.CE
581In all of the above examples, \fIargc\fR will be set by \fBTk_ParseArgv\fR to 2,
582\fIargv\fR[0] will be ``prog'', \fIargv\fR[1] will be ``infile'',
583and \fIargv\fR[2] will be NULL.
584
585.SH KEYWORDS
586arguments, command line, options