1 #include <sys/cdefs.h> 2 __FBSDID("$FreeBSD$"); 3 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <unistd.h> 7 8 int 9 main(argc, argv) 10 int argc; 11 char *argv[]; 12 { 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])) != -1) 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 return status; 34 } 35