OpenBSD-4.6/share/misc/getopt

/*	$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);
}