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