mirror of https://github.com/mkerrisk/man-pages
getopt.3: ffix
Reported-by: Sam Varshavchik <mrsam@courier-mta.com> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
3426f62cea
commit
66af361c68
|
@ -447,23 +447,23 @@ main(int argc, char *argv[])
|
|||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
.EX
|
||||
.EE
|
||||
.SS getopt_long()
|
||||
The following example program illustrates the use of
|
||||
.BR getopt_long ()
|
||||
with most of its features.
|
||||
.PP
|
||||
.EE
|
||||
.EX
|
||||
#include <stdio.h> /* for printf */
|
||||
#include <stdlib.h> /* for exit */
|
||||
#include <getopt.h>
|
||||
.PP
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
int digit_optind = 0;
|
||||
.PP
|
||||
|
||||
while (1) {
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
int option_index = 0;
|
||||
|
@ -476,12 +476,12 @@ main(int argc, char **argv)
|
|||
{"file", required_argument, 0, 0 },
|
||||
{0, 0, 0, 0 }
|
||||
};
|
||||
.PP
|
||||
|
||||
c = getopt_long(argc, argv, "abc:d:012",
|
||||
long_options, &option_index);
|
||||
if (c == \-1)
|
||||
break;
|
||||
.PP
|
||||
|
||||
switch (c) {
|
||||
case 0:
|
||||
printf("option %s", long_options[option_index].name);
|
||||
|
@ -489,7 +489,7 @@ main(int argc, char **argv)
|
|||
printf(" with arg %s", optarg);
|
||||
printf("\\n");
|
||||
break;
|
||||
.PP
|
||||
|
||||
case \(aq0\(aq:
|
||||
case \(aq1\(aq:
|
||||
case \(aq2\(aq:
|
||||
|
@ -498,38 +498,38 @@ main(int argc, char **argv)
|
|||
digit_optind = this_option_optind;
|
||||
printf("option %c\\n", c);
|
||||
break;
|
||||
.PP
|
||||
|
||||
case \(aqa\(aq:
|
||||
printf("option a\\n");
|
||||
break;
|
||||
.PP
|
||||
|
||||
case \(aqb\(aq:
|
||||
printf("option b\\n");
|
||||
break;
|
||||
.PP
|
||||
|
||||
case \(aqc\(aq:
|
||||
printf("option c with value \(aq%s\(aq\\n", optarg);
|
||||
break;
|
||||
.PP
|
||||
|
||||
case \(aqd\(aq:
|
||||
printf("option d with value \(aq%s\(aq\\n", optarg);
|
||||
break;
|
||||
.PP
|
||||
|
||||
case \(aq?\(aq:
|
||||
break;
|
||||
.PP
|
||||
|
||||
default:
|
||||
printf("?? getopt returned character code 0%o ??\\n", c);
|
||||
}
|
||||
}
|
||||
.PP
|
||||
|
||||
if (optind < argc) {
|
||||
printf("non\-option ARGV\-elements: ");
|
||||
while (optind < argc)
|
||||
printf("%s ", argv[optind++]);
|
||||
printf("\\n");
|
||||
}
|
||||
.PP
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
.EE
|
||||
|
|
Loading…
Reference in New Issue