]> git.saurik.com Git - apple/shell_cmds.git/blob - getopt/getopt.c
7a977ea6052e134818a529c8d9066bbadef996d2
[apple/shell_cmds.git] / getopt / getopt.c
1 /* $NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry Exp $ */
2
3 #include <sys/cdefs.h>
4 #ifndef lint
5 __RCSID("$NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry Exp $");
6 #endif /* not lint */
7
8 #include <errno.h>
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12
13 int main __P((int, char **));
14
15 int
16 main(argc, argv)
17 int argc;
18 char *argv[];
19 {
20 int c;
21 int status = 0;
22
23 optind = 2; /* Past the program name and the option letters. */
24 while ((c = getopt(argc, argv, argv[1])) != -1)
25 switch (c) {
26 case '?':
27 status = 1; /* getopt routine gave message */
28 break;
29 default:
30 if (optarg != NULL)
31 printf(" -%c %s", c, optarg);
32 else
33 printf(" -%c", c);
34 break;
35 }
36 printf(" --");
37 for (; optind < argc; optind++)
38 printf(" %s", argv[optind]);
39 printf("\n");
40 exit(status);
41 }