Tcl_ParseArgsObjv(3)
β¨ NAME β¨
Tcl_ParseArgsObjv β bestie, this is the one that parses your arguments according to a tabular description π
(it lives in the Tcl Library Procedures, iykyk)
πΈ SYNOPSIS πΈ
#include <tcl.h>
int
Tcl_ParseArgsObjv(interp, argTable, objcPtr, objv, remObjv)
π ARGUMENTS π
Tcl_Interp *interp(out) β where you stash those error messages, bestie.const Tcl_ArgvInfo *argTable(in) β a pointer to the array of option descriptors. it's giving lookup table energy.Tcl_Size | int *objcPtr(in/out) β a pointer to the variable holding the number of arguments inobjv. it gets modified to hold the number of arguments left in the unprocessed argument list stored inremObjv. it can be(Tcl_Size *)NULLwhen you're not using it. and lowkey: if it points to a variable whose type is notTcl_Size, a compiler warning will be generated. also, if your extension is compiled with-DTCL_8_API, this function will returnNULLfor argument lists with more thanINT_MAXelements (which should trigger proper error-handling), otherwise expect it to crash ππTcl_Obj *const *objv(in) β the array of arguments to be parsed, periodt.Tcl_Obj ***remObjv(out) β a pointer to a variable that will hold the array of unprocessed arguments. should beNULLif you don't need the unprocessed arguments handed back to you. and listen: ifobjcPtris updated to a non-zero value, the array returned through this must be deallocated usingTcl_Free. no skipping that, bestie π«Ά
π¦ DESCRIPTION π¦
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. so like, last one wins, iconic behavior honestly π
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 a convenience, the following prototypical entries are provided:
TCL_ARGV_AUTO_HELPβ enables the argument processor to provide help when passed the argumentβ-helpβ. so helpful fr fr π₯ΊTCL_ARGV_AUTO_RESTβ instructs the argument processor that arguments afterβ--βare to be unprocessed. yes ma'am, hands off those ones πTCL_ARGV_TABLE_ENDβ marks the end of the table of argument descriptors. that's the little bow on top π
π§ ARGUMENT DESCRIPTOR ENTRIES π§
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;
void *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:
TCL_ARGV_CONSTANTβ the argument does not take any following value argument. if this argument is present, the (integer) value of thesrcPtrfield is copied to the variable pointed to by thedstPtrfield. theclientDatafield is ignored. no thoughts, just vibes, no extra value needed πTCL_ARGV_ENDβ this value marks the end of all option descriptors in the table. all other fields are ignored. it's the β¨the endβ¨ of the table, literally.TCL_ARGV_FLOATβ this argument takes a following floating point value argument. the value (once parsed byTcl_GetDoubleFromObj) will be stored as a double-precision value in the variable pointed to by thedstPtrfield. thesrcPtrandclientDatafields are ignored πTCL_ARGV_FUNCβ this argument optionally takes a following value argument; it is up to the handler callback function passed insrcPtrto decide. that function will have the following signature:
typedef int (Tcl_ArgvFuncProc)(
void *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 π«Ά
TCL_ARGV_GENFUNCβ this argument takes zero or more following arguments; the handler callback function passed insrcPtrreturns how many (or a negative number to signal an error, in which case it should also set the interpreter result). the function will have the following signature:
typedef Tcl_Size (Tcl_ArgvGenFuncProc)(
void *clientData,
Tcl_Interp *interp,
Tcl_Size 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, 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_ARGV_HELPβ this special argument does not take any following value argument, but instead causesTcl_ParseArgsObjvto generate an error message describing the arguments supported. all other fields except thehelpStrfield are ignored. it's the "let me explain" option, and honestly? we love that for us π₯°TCL_ARGV_INTβ this argument takes a following integer value argument. the value (once parsed byTcl_GetIntFromObj) will be stored as anintin the variable pointed to by thedstPtrfield. thesrcPtrfield is ignored β¨TCL_ARGV_RESTβ this special argument does not take any following value argument, but instead marks all following arguments to be left unprocessed. thesrcPtr,dstPtrandclientDatafields are ignored. everything after this point is not our business, respectfully πTCL_ARGV_STRINGβ this argument takes a following string value argument. a pointer to the string will be stored atdstPtr; the string inside will have a lifetime linked to the lifetime of the string representation of the argument value that it came from, and so should be copied if it needs to be retained. thesrcPtrandclientDatafields are ignored. so like, copy it if you're gonna keep it, bestie, or it's gonna ghost you π»
π REFERENCE COUNT MANAGEMENT π
The values in the objv argument to Tcl_ParseArgsObjv will not have their reference counts modified by this function. the interpreter result may be modified on error; the values passed should not be the interpreter result with no further reference added. protect those refcounts, they're the main character energy here π
π SEE ALSO π
Tcl_GetIndexFromObj(3), Tcl_Main(3), Tcl_CreateObjCommand(3)
β KEYWORDS β
argument, parse
and that's the whole page, bestie β brought to you by Tcl 8.6, from the Tcl_ParseArgsObjv(3) era. go parse something iconic, you got this π
β¨π¦
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- Copyright (c) 2008 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms