Home | History | Annotate | Line # | Download | only in getopt
getopt.c revision 1.5
      1  1.5    perry /*	$NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry Exp $	*/
      2  1.3      tls 
      3  1.4    lukem #include <sys/cdefs.h>
      4  1.2  mycroft #ifndef lint
      5  1.5    perry __RCSID("$NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry Exp $");
      6  1.2  mycroft #endif /* not lint */
      7  1.2  mycroft 
      8  1.4    lukem #include <errno.h>
      9  1.1   brezak #include <stdio.h>
     10  1.5    perry #include <unistd.h>
     11  1.1   brezak 
     12  1.4    lukem int	main __P((int, char **));
     13  1.4    lukem 
     14  1.4    lukem int
     15  1.1   brezak main(argc, argv)
     16  1.4    lukem 	int argc;
     17  1.4    lukem 	char *argv[];
     18  1.1   brezak {
     19  1.1   brezak 	int c;
     20  1.1   brezak 	int status = 0;
     21  1.1   brezak 
     22  1.1   brezak 	optind = 2;	/* Past the program name and the option letters. */
     23  1.4    lukem 	while ((c = getopt(argc, argv, argv[1])) != -1)
     24  1.1   brezak 		switch (c) {
     25  1.1   brezak 		case '?':
     26  1.1   brezak 			status = 1;	/* getopt routine gave message */
     27  1.1   brezak 			break;
     28  1.1   brezak 		default:
     29  1.1   brezak 			if (optarg != NULL)
     30  1.1   brezak 				printf(" -%c %s", c, optarg);
     31  1.1   brezak 			else
     32  1.1   brezak 				printf(" -%c", c);
     33  1.1   brezak 			break;
     34  1.1   brezak 		}
     35  1.1   brezak 	printf(" --");
     36  1.1   brezak 	for (; optind < argc; optind++)
     37  1.1   brezak 		printf(" %s", argv[optind]);
     38  1.1   brezak 	printf("\n");
     39  1.1   brezak 	exit(status);
     40  1.1   brezak }
     41