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