Annotation of src/usr.bin/getopt/getopt.c, Revision 1.3
1.3 ! millert 1: /* $OpenBSD: getopt.c,v 1.2 1996/06/26 05:33:45 deraadt Exp $ */
1.2 deraadt 2:
1.1 deraadt 3: #ifndef lint
1.3 ! millert 4: static char rcsid[] = "$OpenBSD: getopt.c,v 1.2 1996/06/26 05:33:45 deraadt Exp $";
1.1 deraadt 5: #endif /* not lint */
6:
7: #include <stdio.h>
8:
9: main(argc, argv)
10: int argc;
11: char *argv[];
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: }