1 /* $OpenBSD: getopt.c,v 1.4 2001/07/12 05:17:09 deraadt Exp $ */ 2 3 #ifndef lint 4 static char rcsid[] = "$OpenBSD: getopt.c,v 1.4 2001/07/12 05:17:09 deraadt Exp $"; 5 #endif /* not lint */ 6 7 #include <stdio.h> 8 #include <unistd.h> 9 10 int 11 main(argc, argv) 12 int argc; 13 char *argv[]; 14 { 15 extern int optind; 16 extern char *optarg; 17 int c; 18 int status = 0; 19 20 optind = 2; /* Past the program name and the option letters. */ 21 while ((c = getopt(argc, argv, argv[1])) != -1) 22 switch (c) { 23 case '?': 24 status = 1; /* getopt routine gave message */ 25 break; 26 default: 27 if (optarg != NULL) 28 printf(" -%c %s", c, optarg); 29 else 30 printf(" -%c", c); 31 break; 32 } 33 printf(" --"); 34 for (; optind < argc; optind++) 35 printf(" %s", argv[optind]); 36 printf("\n"); 37 exit(status); 38 } 39