in src/generic/args.c [190:256]
int argIndexOfFirstArg(int objc, Tcl_Obj * CONST objv[],
TCLCONST char *params[], int *Nparams)
{
int pos = -1;
int first = -1;
int pidx = 0;
if (objc < 2)
return objc;
if (objv == NULL)
return objc;
if (argOptionType(objv[1]) == OPTION_TYPE_NONE)
return 1;
first = argIndexOfFirstOpt(objc, objv);
/* --------------------------------------------------------------------------
* no switches
* ----------------------------------------------------------------------- */
if (first == -1)
first = 1;
/* --------------------------------------------------------------------------
* scan to the last param
* ----------------------------------------------------------------------- */
pos = first;
while (pos < objc) {
if (objv[pos] != NULL) {
switch (argOptionType(objv[pos])) {
case OPTION_TYPE_NONE:
/* we found the fisrt argument */
return pos;
case OPTION_TYPE_DASHDASH:
/* first arg is i + 1, and no more options to be expected */
pos++;
return pos;
break;
case OPTION_TYPE_PARAM:
/* switch: i ==> -unbuffered --> first arg is i + 1 + 0
* simple param: i ==> -format "$m" --> first arg is i + 1 + 1
* param: i ==> -postdata a b c --> first arg is i + 1 + 3
*/
if ((pidx =
argPosParam(params, Tcl_GetString(objv[pos]))) != -1) {
if (Nparams != NULL)
pos += Nparams[pidx];
else
pos++;
}
pos++;
break;
default:
pos++;
break;
}
}
}
/* ----------------------------------------------------------------------
* no args (switches only)
* ------------------------------------------------------------------- */
return objc;
}