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