[BACK]Return to getopt.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / getopt

Annotation of src/usr.bin/getopt/getopt.c, Revision 1.6

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