/* c-getopt -- template for use of getopt */

/* $Id$ */
/* Carlos Duarte, 980517 */

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

#include <unistd.h>

#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif

#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif

/* protos */
int main(int argc, char *argv[]);
static char *mk_progname(char *s);
static void usage(void);

static char *program_name; 

int
main(int argc, char *argv[])
{
	int c; 

	program_name = mk_progname(argv[0]); 
	while ((c = getopt(argc, argv, "abc")) != EOF) 
		switch (c) {
		case 'a':
			break; 
		case 'b': 
			break; 
		case 'c': 
			break; 
		case '?': 
		default: 
			usage(); 
		}
	argv += optind; 
	argc -= optind; 

	/* 
	 * rest of code
	 * use from argv[0] to argv[argc-1], like: 
	 *	for (i=0; i<argc; i++) do_this(argv[i]);
	 * echo example: 
	 { int i; 
	 for (i=0; i<argc; i++)
		printf("%s ", argv[i]); 
	 printf("\n"); 
	 }
	 */

	exit(EXIT_SUCCESS); 
}

static char *
mk_progname(char *s)
{
	char *t; 

	if (s == NULL)
		return "????"; 

	t = strrchr(s, '/'); 
	if (t)
		return t+1; 
	return s; 
}

static void
usage(void)
{
	fprintf(stderr, "usage: %s [-abc] ...\n", program_name); 
	exit(EXIT_FAILURE); 
}
