Documentation generated from fossil trunk
Tcl_ParseArgsObjv -
parse arguments according to a tabular description
#include <tcl.h> int Tcl_ParseArgsObjv(interp, argTable, objcPtr, objv, remObjv)
Type | Name | Mode |
---|---|---|
Tcl_Interp | *interp | out |
Where to store error messages. | ||
const Tcl_ArgvInfo | *argTable | in |
Pointer to array of option descriptors. | ||
int | *objcPtr | in/out |
A pointer to variable holding number of arguments in objv. Will be modified to hold number of arguments left in the unprocessed argument list stored in remObjv. | ||
Tcl_Obj *const | *objv | in |
The array of arguments to be parsed. | ||
Tcl_Obj | ***remObjv | out |
Pointer to a variable that will hold the array of unprocessed arguments. Should be NULL if no return of unprocessed arguments is required. If objcPtr is updated to a non-zero value, the array returned through this must be deallocated using ckfree. |
The Tcl_ParseArgsObjv function provides a system for parsing argument lists of the form "-someName someValue ...". Such argument lists are commonly found both in the arguments to a program and in the arguments to an individual Tcl command. This parser assumes that the order of the arguments does not matter, other than in so far as later copies of a duplicated option overriding earlier ones.
The argument array is described by the objcPtr and objv parameters, and an array of unprocessed arguments is returned through the objcPtr and remObjv parameters; if no return of unprocessed arguments is desired, the remObjv parameter should be NULL. If any problems happen, including if the "generate help" option is selected, an error message is left in the interpreter result and TCL_ERROR is returned. Otherwise, the interpreter result is left unchanged and TCL_OK is returned.
The collection of arguments to be parsed is described by the argTable parameter. This points to a table of descriptor structures that is terminated by an entry with the type field set to TCL_ARGV_END. As convenience, the following prototypical entries are provided:
Each entry of the argument descriptor table must be a structure of type Tcl_ArgvInfo. The structure is defined as this:
typedef struct { int type; const char *keyStr; void *srcPtr; void *dstPtr; const char *helpStr; ClientData clientData; } Tcl_ArgvInfo;
The keyStr field contains the name of the option; by convention, this will normally begin with a "-" character. The type, srcPtr, dstPtr and clientData fields describe the interpretation of the value of the argument, as described below. The helpStr field gives some text that is used to provide help to users when they request it.
As noted above, the type field is used to describe the interpretation of the argument's value. The following values are acceptable values for type:
typedef int (Tcl_ArgvFuncProc)( ClientData clientData, Tcl_Obj *objPtr, void *dstPtr);
The result is a boolean value indicating whether to consume the following argument. The clientData is the value from the table entry, the objPtr is the value that represents the following argument or NULL if there are no following arguments at all, and the dstPtr argument to the Tcl_ArgvFuncProc is the location to write the parsed value to.
typedef int (Tcl_ArgvGenFuncProc)( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv, void *dstPtr);
The clientData is the value from the table entry, the interp is where to store any error messages, the keyStr is the name of the argument, objc and objv describe an array of all the remaining arguments, and dstPtr argument to the Tcl_ArgvGenFuncProc is the location to write the parsed value (or values) to.
Tcl_GetIndexFromObj(3), Tcl_Main(3), Tcl_CreateObjCommand(3)