Home | History | Annotate | Line # | Download | only in getopt
      1  1.8      wiz /*	$NetBSD: getopt.c,v 1.8 2006/07/09 21:39:48 wiz Exp $	*/
      2  1.7      wiz 
      3  1.7      wiz /*
      4  1.7      wiz  * This material, written by Henry Spencer, was released by him
      5  1.7      wiz  * into the public domain and is thus not subject to any copyright.
      6  1.7      wiz  */
      7  1.3      tls 
      8  1.4    lukem #include <sys/cdefs.h>
      9  1.2  mycroft #ifndef lint
     10  1.8      wiz __RCSID("$NetBSD: getopt.c,v 1.8 2006/07/09 21:39:48 wiz Exp $");
     11  1.2  mycroft #endif /* not lint */
     12  1.2  mycroft 
     13  1.1   brezak #include <stdio.h>
     14  1.6     matt #include <stdlib.h>
     15  1.5    perry #include <unistd.h>
     16  1.1   brezak 
     17  1.4    lukem int
     18  1.8      wiz main(int argc, char *argv[])
     19  1.1   brezak {
     20  1.1   brezak 	int c;
     21  1.1   brezak 	int status = 0;
     22  1.1   brezak 
     23  1.1   brezak 	optind = 2;	/* Past the program name and the option letters. */
     24  1.4    lukem 	while ((c = getopt(argc, argv, argv[1])) != -1)
     25  1.1   brezak 		switch (c) {
     26  1.1   brezak 		case '?':
     27  1.1   brezak 			status = 1;	/* getopt routine gave message */
     28  1.1   brezak 			break;
     29  1.1   brezak 		default:
     30  1.1   brezak 			if (optarg != NULL)
     31  1.1   brezak 				printf(" -%c %s", c, optarg);
     32  1.1   brezak 			else
     33  1.1   brezak 				printf(" -%c", c);
     34  1.1   brezak 			break;
     35  1.1   brezak 		}
     36  1.1   brezak 	printf(" --");
     37  1.1   brezak 	for (; optind < argc; optind++)
     38  1.1   brezak 		printf(" %s", argv[optind]);
     39  1.1   brezak 	printf("\n");
     40  1.1   brezak 	exit(status);
     41  1.1   brezak }
     42