nxtarg - parse arguments from a string
extern char _argbreak;
char *nxtarg (p,brk);
const char *brk;
Nxtarg is used to parse a string, picking off one argument with
each call of nxtarg. The arguments are separated by some special
"break" characters, and may additionally be surrounded by leading
and trailing blanks and tabs.
When you have a string which you
wish to parse, you should declare
a pointer and point to the start of the string:
char string; /* the arg
char *pointer; /* a pointer */
char *argument; /* one argument */
pointer = string; /* start of arg list */
Then, each call to nxtarg will fetch the next argument:
argument = nxtarg (&pointer,"delimiters");
Each call to nxtarg will space
the pointer up to one of the
delimiters or the end of the string, whichever comes first. Then,
the string will be chopped into two pieces: the part containing the
argument just parsed, and the rest of the string. The address of
the first part will be returned; the pointer will be left pointing
to the second part, all ready for the next call to nxtarg. Note
that the pointer must not be in a register, since it is passed by
The delimiter character (or null
character at the end of the
string) encountered is placed into the external variable called,
_argbreak. You may look at this value to see what delimiter was
encountered. If no delimiters were encountered before the end of
the string, then the null character will be placed into _argbreak.
If brk, the list of break
characters, is 0, then the space
character will be used as the only delimiter.
scanf(3), boolarg(3), intarg(3), stabarg(3), strarg(3), etc.
If the argument points to the null string, or the end of the string
is reached, then a pointer to the null string will be returned. At
the end of the string, nxtarg() may be repeated any number of times
-- it will continue to leave the pointer unchanged, and return a
pointer to the null string.