1*fe7b9c06SThomas Cort /* $NetBSD: getopt.c,v 1.8 2006/07/09 21:39:48 wiz Exp $ */
2*fe7b9c06SThomas Cort
3*fe7b9c06SThomas Cort /*
4*fe7b9c06SThomas Cort * This material, written by Henry Spencer, was released by him
5*fe7b9c06SThomas Cort * into the public domain and is thus not subject to any copyright.
6*fe7b9c06SThomas Cort */
7*fe7b9c06SThomas Cort
8*fe7b9c06SThomas Cort #include <sys/cdefs.h>
9*fe7b9c06SThomas Cort #ifndef lint
10*fe7b9c06SThomas Cort __RCSID("$NetBSD: getopt.c,v 1.8 2006/07/09 21:39:48 wiz Exp $");
11*fe7b9c06SThomas Cort #endif /* not lint */
12*fe7b9c06SThomas Cort
13*fe7b9c06SThomas Cort #include <stdio.h>
14*fe7b9c06SThomas Cort #include <stdlib.h>
15*fe7b9c06SThomas Cort #include <unistd.h>
16*fe7b9c06SThomas Cort
17*fe7b9c06SThomas Cort int
main(int argc,char * argv[])18*fe7b9c06SThomas Cort main(int argc, char *argv[])
19*fe7b9c06SThomas Cort {
20*fe7b9c06SThomas Cort int c;
21*fe7b9c06SThomas Cort int status = 0;
22*fe7b9c06SThomas Cort
23*fe7b9c06SThomas Cort optind = 2; /* Past the program name and the option letters. */
24*fe7b9c06SThomas Cort while ((c = getopt(argc, argv, argv[1])) != -1)
25*fe7b9c06SThomas Cort switch (c) {
26*fe7b9c06SThomas Cort case '?':
27*fe7b9c06SThomas Cort status = 1; /* getopt routine gave message */
28*fe7b9c06SThomas Cort break;
29*fe7b9c06SThomas Cort default:
30*fe7b9c06SThomas Cort if (optarg != NULL)
31*fe7b9c06SThomas Cort printf(" -%c %s", c, optarg);
32*fe7b9c06SThomas Cort else
33*fe7b9c06SThomas Cort printf(" -%c", c);
34*fe7b9c06SThomas Cort break;
35*fe7b9c06SThomas Cort }
36*fe7b9c06SThomas Cort printf(" --");
37*fe7b9c06SThomas Cort for (; optind < argc; optind++)
38*fe7b9c06SThomas Cort printf(" %s", argv[optind]);
39*fe7b9c06SThomas Cort printf("\n");
40*fe7b9c06SThomas Cort exit(status);
41*fe7b9c06SThomas Cort }
42