Annotation of src/usr.bin/getopt/getopt.c, Revision 1.5
1.5 ! deraadt 1: /* $OpenBSD: getopt.c,v 1.4 2001/07/12 05:17:09 deraadt Exp $ */
1.2 deraadt 2:
1.1 deraadt 3: #ifndef lint
1.5 ! deraadt 4: static char rcsid[] = "$OpenBSD: getopt.c,v 1.4 2001/07/12 05:17:09 deraadt Exp $";
1.1 deraadt 5: #endif /* not lint */
6:
7: #include <stdio.h>
1.4 deraadt 8: #include <unistd.h>
1.1 deraadt 9:
1.4 deraadt 10: int
1.5 ! deraadt 11: main(int argc, char *argv[])
1.1 deraadt 12: {
13: extern int optind;
14: extern char *optarg;
15: int c;
16: int status = 0;
17:
18: optind = 2; /* Past the program name and the option letters. */
1.3 millert 19: while ((c = getopt(argc, argv, argv[1])) != -1)
1.1 deraadt 20: switch (c) {
21: case '?':
22: status = 1; /* getopt routine gave message */
23: break;
24: default:
25: if (optarg != NULL)
26: printf(" -%c %s", c, optarg);
27: else
28: printf(" -%c", c);
29: break;
30: }
31: printf(" --");
32: for (; optind < argc; optind++)
33: printf(" %s", argv[optind]);
34: printf("\n");
35: exit(status);
36: }