|
NAMEgetsubopt —
get sub options from an argument
LIBRARYStandard C Library (libc, -lc)SYNOPSIS#include <stdlib.h>
extern char *suboptarg; int
DESCRIPTIONThegetsubopt () function parses a string containing
tokens delimited by one or more tab, space or comma
(‘, ’) characters. It is intended for use
in parsing groups of option arguments provided as part of a utility command
line.
The argument optionp is a pointer to a
pointer to the string. The argument tokens is a
pointer to a The If the token is of the form ``name=value'', the location referenced by valuep will be set to point to the start of the ``value'' portion of the token. On return from EXAMPLESchar *tokens[] = { #define ONE 0 "one", #define TWO 1 "two", NULL }; ... extern char *optarg, *suboptarg; char *options, *value; while ((ch = getopt(argc, argv, "ab:")) != -1) { switch(ch) { case 'a': /* process ``a'' option */ break; case 'b': options = optarg; while (*options) { switch(getsubopt(&options, tokens, &value)) { case ONE: /* process ``one'' sub option */ break; case TWO: /* process ``two'' sub option */ if (!value) error("no value for two"); i = atoi(value); break; case -1: if (suboptarg) error("illegal sub option %s", suboptarg); else error("missing sub option"); break; } } break; } } SEE ALSOgetopt(3), strsep(3)HISTORYThegetsubopt () function first appeared in
4.4BSD.
Visit the GSP FreeBSD Man Page Interface. |