getopt.c revision 99112
1#include <sys/cdefs.h>
2__FBSDID("$FreeBSD: head/usr.bin/getopt/getopt.c 99112 2002-06-30 05:25:07Z obrien $");
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7
8int
9main(argc, argv)
10int argc;
11char *argv[];
12{
13	int c;
14	int status = 0;
15
16	optind = 2;	/* Past the program name and the option letters. */
17	while ((c = getopt(argc, argv, argv[1])) != -1)
18		switch (c) {
19		case '?':
20			status = 1;	/* getopt routine gave message */
21			break;
22		default:
23			if (optarg != NULL)
24				printf(" -%c %s", c, optarg);
25			else
26				printf(" -%c", c);
27			break;
28		}
29	printf(" --");
30	for (; optind < argc; optind++)
31		printf(" %s", argv[optind]);
32	printf("\n");
33	return status;
34}
35