getsubopt.3c (2010 09)
g
getsubopt(3C) getsubopt(3C)
char *options, *value;
extern char *optarg;
extern int optind;
.
.
.
while ((c = getopt(argc, argv, "abf:o:")) != EOF)
switch (c) {
case ’a’: /* process ’a’ option */
break;
case ’b’: /* process ’b’ option */
break;
case ’f’:
ofile = optarg;
break;
case ’?’:
errflag++;
break;
case ’o’:
options = optarg;
while (*options != ’\0’) {
switch(getsubopt(&options, myopts, &value)) {
case READONLY: /* process ro option */
break;
case READWRITE: /* process rw option */
break;
case WRITESIZE: /* process wsize option */
if (value == NULL) {
error_no_arg();
errflag++;
}
else
write_size = atoi(value);
break;
case READSIZE: /* process rsize option */
if (value == NULL) {
error_no_arg();
errflag++;
}
else
read_size = atoi(value);
break;
default:
/* process unknown token */
error_bad_token(value);
errflag++;
break;
}
}
break;
}
}
if (errflg) {
fprintf(stderr, "usage:...");
exit (2);
}
for ( ; optind < argc; optind++) {
/* process remaining arguments */
.
.
.
}
2 Hewlett-Packard Company − 2 − HP-UX 11i Version 3: September 2010