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