| 1 |
'\" |
| 2 |
'\" Copyright (c) 2008 Donal K. Fellows |
| 3 |
'\" |
| 4 |
'\" See the file "license.terms" for information on usage and redistribution |
| 5 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 6 |
'\" |
| 7 |
.TH Tcl_ParseArgsObjv 3 8.6 Tcl "Tcl Library Procedures" |
| 8 |
.so man.macros |
| 9 |
.BS |
| 10 |
.SH NAME |
| 11 |
Tcl_ParseArgsObjv \- parse arguments according to a tabular description |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
\fB#include <tcl.h>\fR |
| 15 |
.sp |
| 16 |
int |
| 17 |
\fBTcl_ParseArgsObjv\fR(\fIinterp, argTable, objcPtr, objv, remObjv\fR) |
| 18 |
.SH ARGUMENTS |
| 19 |
.AS "const Tcl_ArgvInfo" ***remObjv in/out |
| 20 |
.AP Tcl_Interp *interp out |
| 21 |
Where to store error messages. |
| 22 |
.AP "const Tcl_ArgvInfo" *argTable in |
| 23 |
Pointer to array of option descriptors. |
| 24 |
.AP int *objcPtr in/out |
| 25 |
A pointer to variable holding number of arguments in \fIobjv\fR. Will be |
| 26 |
modified to hold number of arguments left in the unprocessed argument list |
| 27 |
stored in \fIremObjv\fR. |
| 28 |
.AP "Tcl_Obj *const" *objv in |
| 29 |
The array of arguments to be parsed. |
| 30 |
.AP Tcl_Obj ***remObjv out |
| 31 |
Pointer to a variable that will hold the array of unprocessed arguments. |
| 32 |
Should be NULL if no return of unprocessed arguments is required. If |
| 33 |
\fIobjcPtr\fR is updated to a non-zero value, the array returned through this |
| 34 |
must be deallocated using \fBckfree\fR. |
| 35 |
.BE |
| 36 |
.SH DESCRIPTION |
| 37 |
.PP |
| 38 |
The \fBTcl_ParseArgsObjv\fR function provides a system for parsing argument |
| 39 |
lists of the form |
| 40 |
.QW "\fB\-someName \fIsomeValue\fR ..." . |
| 41 |
Such argument lists are commonly found both in the arguments to a program and |
| 42 |
in the arguments to an individual Tcl command. This parser assumes that the |
| 43 |
order of the arguments does not matter, other than in so far as later copies |
| 44 |
of a duplicated option overriding earlier ones. |
| 45 |
.PP |
| 46 |
The argument array is described by the \fIobjcPtr\fR and \fIobjv\fR |
| 47 |
parameters, and an array of unprocessed arguments is returned through the |
| 48 |
\fIobjcPtr\fR and \fIremObjv\fR parameters; if no return of unprocessed |
| 49 |
arguments is desired, the \fIremObjv\fR parameter should be NULL. If any |
| 50 |
problems happen, including if the |
| 51 |
.QW "generate help" |
| 52 |
option is selected, an error message is left in the interpreter result and |
| 53 |
TCL_ERROR is returned. Otherwise, the interpreter result is left unchanged and |
| 54 |
TCL_OK is returned. |
| 55 |
.PP |
| 56 |
The collection of arguments to be parsed is described by the \fIargTable\fR |
| 57 |
parameter. This points to a table of descriptor structures that is terminated |
| 58 |
by an entry with the \fItype\fR field set to TCL_ARGV_END. As convenience, the |
| 59 |
following prototypical entries are provided: |
| 60 |
.TP |
| 61 |
\fBTCL_ARGV_AUTO_HELP\fR |
| 62 |
. |
| 63 |
Enables the argument processor to provide help when passed the argument |
| 64 |
.QW \fB\-help\fR . |
| 65 |
.TP |
| 66 |
\fBTCL_ARGV_AUTO_REST\fR |
| 67 |
. |
| 68 |
Instructs the argument processor that arguments after |
| 69 |
.QW \fB\-\-\fR |
| 70 |
are to be unprocessed. |
| 71 |
.TP |
| 72 |
\fBTCL_ARGV_TABLE_END\fR |
| 73 |
. |
| 74 |
Marks the end of the table of argument descriptors. |
| 75 |
.SS "ARGUMENT DESCRIPTOR ENTRIES" |
| 76 |
.PP |
| 77 |
Each entry of the argument descriptor table must be a structure of type |
| 78 |
\fBTcl_ArgvInfo\fR. The structure is defined as this: |
| 79 |
.PP |
| 80 |
.CS |
| 81 |
typedef struct { |
| 82 |
int \fItype\fR; |
| 83 |
const char *\fIkeyStr\fR; |
| 84 |
void *\fIsrcPtr\fR; |
| 85 |
void *\fIdstPtr\fR; |
| 86 |
const char *\fIhelpStr\fR; |
| 87 |
ClientData \fIclientData\fR; |
| 88 |
} \fBTcl_ArgvInfo\fR; |
| 89 |
.CE |
| 90 |
.PP |
| 91 |
The \fIkeyStr\fR field contains the name of the option; by convention, this |
| 92 |
will normally begin with a |
| 93 |
.QW \fB\-\fR |
| 94 |
character. The \fItype\fR, \fIsrcPtr\fR, \fIdstPtr\fR and \fIclientData\fR |
| 95 |
fields describe the interpretation of the value of the argument, as described |
| 96 |
below. The \fIhelpStr\fR field gives some text that is used to provide help to |
| 97 |
users when they request it. |
| 98 |
.PP |
| 99 |
As noted above, the \fItype\fR field is used to describe the interpretation of |
| 100 |
the argument's value. The following values are acceptable values for |
| 101 |
\fItype\fR: |
| 102 |
.TP |
| 103 |
\fBTCL_ARGV_CONSTANT\fR |
| 104 |
. |
| 105 |
The argument does not take any following value argument. If this argument is |
| 106 |
present, the (integer) value of the \fIsrcPtr\fR field is copied to the variable |
| 107 |
pointed to by the \fIdstPtr\fR field. The \fIclientData\fR field is ignored. |
| 108 |
.TP |
| 109 |
\fBTCL_ARGV_END\fR |
| 110 |
. |
| 111 |
This value marks the end of all option descriptors in the table. All other |
| 112 |
fields are ignored. |
| 113 |
.TP |
| 114 |
\fBTCL_ARGV_FLOAT\fR |
| 115 |
. |
| 116 |
This argument takes a following floating point value argument. The value (once |
| 117 |
parsed by \fBTcl_GetDoubleFromObj\fR) will be stored as a double-precision |
| 118 |
value in the variable pointed to by the \fIdstPtr\fR field. The \fIsrcPtr\fR |
| 119 |
and \fIclientData\fR fields are ignored. |
| 120 |
.TP |
| 121 |
\fBTCL_ARGV_FUNC\fR |
| 122 |
. |
| 123 |
This argument optionally takes a following value argument; it is up to the |
| 124 |
handler callback function passed in \fIsrcPtr\fR to decide. That function will |
| 125 |
have the following signature: |
| 126 |
.RS |
| 127 |
.PP |
| 128 |
.CS |
| 129 |
typedef int (\fBTcl_ArgvFuncProc\fR)( |
| 130 |
ClientData \fIclientData\fR, |
| 131 |
Tcl_Obj *\fIobjPtr\fR, |
| 132 |
void *\fIdstPtr\fR); |
| 133 |
.CE |
| 134 |
.PP |
| 135 |
The result is a boolean value indicating whether to consume the following |
| 136 |
argument. The \fIclientData\fR is the value from the table entry, the |
| 137 |
\fIobjPtr\fR is the value that represents the following argument or NULL if |
| 138 |
there are no following arguments at all, and the \fIdstPtr\fR argument to the |
| 139 |
\fBTcl_ArgvFuncProc\fR is the location to write the parsed value to. |
| 140 |
.RE |
| 141 |
.TP |
| 142 |
\fBTCL_ARGV_GENFUNC\fR |
| 143 |
. |
| 144 |
This argument takes zero or more following arguments; the handler callback |
| 145 |
function passed in \fIsrcPtr\fR returns how many (or a negative number to |
| 146 |
signal an error, in which case it should also set the interpreter result). The |
| 147 |
function will have the following signature: |
| 148 |
.RS |
| 149 |
.PP |
| 150 |
.CS |
| 151 |
typedef int (\fBTcl_ArgvGenFuncProc\fR)( |
| 152 |
ClientData \fIclientData\fR, |
| 153 |
Tcl_Interp *\fIinterp\fR, |
| 154 |
int \fIobjc\fR, |
| 155 |
Tcl_Obj *const *\fIobjv\fR, |
| 156 |
void *\fIdstPtr\fR); |
| 157 |
.CE |
| 158 |
.PP |
| 159 |
The \fIclientData\fR is the value from the table entry, the \fIinterp\fR |
| 160 |
is where to store any error messages, \fIobjc\fR and \fIobjv\fR describe |
| 161 |
an array of all the remaining arguments, and \fIdstPtr\fR argument to the |
| 162 |
\fBTcl_ArgvGenFuncProc\fR is the location to write the parsed value |
| 163 |
(or values) to. |
| 164 |
.RE |
| 165 |
.TP |
| 166 |
\fBTCL_ARGV_HELP\fR |
| 167 |
. |
| 168 |
This special argument does not take any following value argument, but instead |
| 169 |
causes \fBTcl_ParseArgsObjv\fR to generate an error message describing the |
| 170 |
arguments supported. All other fields except the \fIhelpStr\fR field are |
| 171 |
ignored. |
| 172 |
.TP |
| 173 |
\fBTCL_ARGV_INT\fR |
| 174 |
. |
| 175 |
This argument takes a following integer value argument. The value (once parsed |
| 176 |
by \fBTcl_GetIntFromObj\fR) will be stored as an int in the variable pointed |
| 177 |
to by the \fIdstPtr\fR field. The \fIsrcPtr\fR field is ignored. |
| 178 |
.TP |
| 179 |
\fBTCL_ARGV_REST\fR |
| 180 |
. |
| 181 |
This special argument does not take any following value argument, but instead |
| 182 |
marks all following arguments to be left unprocessed. The \fIsrcPtr\fR, |
| 183 |
\fIdstPtr\fR and \fIclientData\fR fields are ignored. |
| 184 |
.TP |
| 185 |
\fBTCL_ARGV_STRING\fR |
| 186 |
. |
| 187 |
This argument takes a following string value argument. A pointer to the string |
| 188 |
will be stored at \fIdstPtr\fR; the string inside will have a lifetime linked |
| 189 |
to the lifetime of the string representation of the argument value that it |
| 190 |
came from, and so should be copied if it needs to be retained. The |
| 191 |
\fIsrcPtr\fR and \fIclientData\fR fields are ignored. |
| 192 |
.SH "SEE ALSO" |
| 193 |
Tcl_GetIndexFromObj(3), Tcl_Main(3), Tcl_CreateObjCommand(3) |
| 194 |
.SH KEYWORDS |
| 195 |
argument, parse |
| 196 |
'\" Local Variables: |
| 197 |
'\" fill-column: 78 |
| 198 |
'\" End: |