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