HP C/iX Library Reference Manual (30026-90004)

Chapter 5 201
HP C/iX Library Function Descriptions
getopt
beyond .
Options can be any ASCII characters except colon (:), question mark (?), or null (\0). It is
impossible to distinguish between a ? used as a legal option, and the character that getopt
returns when it encounters an invalid option character in the input.
Set opterr to 0 to disable getopt from printing error messages on the standard error
device. Otherwise, getopt prints an error message on the stderr and returns a question
mark (?) when it encounters an option letter not included in
optstring
.
Example
The following code fragment shows how you can process the arguments for a command
that can take the mutually exclusive options a and b, and the options f and o, both of
which require arguments:
main (argc, argv)
int argc;
char **argv;
{
int c;
extern char *optarg;
extern int optind;
while ((c = getopt(argc, argv, "abf:o:")) != EOF)
switch (c) {
case 'a':
if (bflg)
errflg++;
else
aflg++;
break;
case 'b':
if (aflg)
errflg++;
else
bproc( );
break;
case 'f':
ifile = optarg;
break;
case 'o':
ofile = optarg;
break;
case '?':
errflg++;
}
if (errflg) {
(void) fprintf(stderr, "usage: ...");
exit (2);
}
for ( ; optind argc; optind++) {
if (access(argv[optind], 4)) {