xref: /netbsd-src/usr.bin/getopt/getopt.c (revision d0fed6c87ddc40a8bffa6f99e7433ddfc864dd83)
1 /*	$NetBSD: getopt.c,v 1.3 1997/01/09 20:19:47 tls Exp $	*/
2 
3 #ifndef lint
4 static char rcsid[] = "$NetBSD: getopt.c,v 1.3 1997/01/09 20:19:47 tls Exp $";
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. */
19 	while ((c = getopt(argc, argv, argv[1])) != EOF)
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 }
37