summaryrefslogtreecommitdiff
path: root/share/misc/getopt
blob: 45c61ad9f34b167b4818b126e72a45d77ece77f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*	$OpenBSD: getopt,v 1.8 2006/02/01 09:27:28 otto Exp $	*/
/*
 * Main/getopt(3) fragment.
 *
 *	from: @(#)getopt	5.3 (Berkeley) 3/28/94
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

__dead void usage(void);

int
main(int argc, char *argv[])
{
	int bflag, ch;
	char *file;

	bflag = 0;
	file = NULL;
	while ((ch = getopt(argc, argv, "bf:")) != -1)
		switch (ch) {
		case 'b':
			bflag = 1;
			break;
		case 'f':
			file = optarg;
			break;
		default:
			usage();
			/* NOTREACHED */
		}
	argc -= optind;
	argv += optind;

	return (0);
}

void
usage(void)
{
	extern char *__progname;

	(void)fprintf(stderr, "usage: %s [-b] [-f file]\n", __progname);
	exit(1);
}