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