Annotation of 43BSD/contrib/dipress/src/bin/ipf/getopt.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * getopt - get option letter from argv
                      3:  *     This software is in the public domain
                      4:  *     Originally written by Henry Spenser at the U. of Toronto
                      5:  */
                      6: 
                      7: #include <stdio.h>
                      8: 
                      9: char   *optarg;        /* Global argument pointer. */
                     10: int    optind = 0;     /* Global argv index. */
                     11: 
                     12: static char    *scan = NULL;   /* Private scan pointer. */
                     13: 
                     14: extern char    *index();
                     15: 
                     16: int
                     17: getopt(argc, argv, optstring)
                     18: int argc;
                     19: char *argv[];
                     20: char *optstring;
                     21: {
                     22:        register char c;
                     23:        register char *place;
                     24: 
                     25:        optarg = NULL;
                     26: 
                     27:        if (scan == NULL || *scan == '\0') {
                     28:                if (optind == 0)
                     29:                        optind++;
                     30:        
                     31:                if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
                     32:                        return(EOF);
                     33:                if (strcmp(argv[optind], "--")==0) {
                     34:                        optind++;
                     35:                        return(EOF);
                     36:                }
                     37:        
                     38:                scan = argv[optind]+1;
                     39:                optind++;
                     40:        }
                     41: 
                     42:        c = *scan++;
                     43:        place = index(optstring, c);
                     44: 
                     45:        if (place == NULL || c == ':') {
                     46:                fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
                     47:                return('?');
                     48:        }
                     49: 
                     50:        place++;
                     51:        if (*place == ':') {
                     52:                if (*scan != '\0') {
                     53:                        optarg = scan;
                     54:                        scan = NULL;
                     55:                } else {
                     56:                        optarg = argv[optind];
                     57:                        optind++;
                     58:                }
                     59:        }
                     60: 
                     61:        return(c);
                     62: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.