Annotation of researchv10no/cmd/uucp/unused/getopt.c, revision 1.1

1.1     ! root        1: /*     /sccs/src/cmd/uucp/s.getopt.c
        !             2:        getopt.c        1.1     8/30/84 17:37:21
        !             3: */
        !             4: #include "uucp.h"
        !             5: VERSION(@(#)getopt.c   1.1);
        !             6: 
        !             7: /*     @(#)getopt.c    1.2     */
        !             8: /*     3.0 SID #       1.2     */
        !             9: /*LINTLIBRARY*/
        !            10: #define ERR(s, c)      if(opterr){(void)fprintf(stderr, "%s%s%c\n", argv[0], s, c);}
        !            11: 
        !            12: extern int strcmp();
        !            13: extern char *strchr();
        !            14: 
        !            15: int    opterr = 1;
        !            16: int    optind = 1;
        !            17: int    optopt;
        !            18: char   *optarg;
        !            19: 
        !            20: int
        !            21: getopt(argc, argv, opts)
        !            22: int    argc;
        !            23: char   **argv, *opts;
        !            24: {
        !            25:        static int sp = 1;
        !            26:        register int c;
        !            27:        register char *cp;
        !            28: 
        !            29:        if(sp == 1)
        !            30:                if(optind >= argc ||
        !            31:                   argv[optind][0] != '-' || argv[optind][1] == '\0')
        !            32:                        return(EOF);
        !            33:                else if(strcmp(argv[optind], "--") == NULL) {
        !            34:                        optind++;
        !            35:                        return(EOF);
        !            36:                }
        !            37:        optopt = c = argv[optind][sp];
        !            38:        if(c == ':' || (cp=strchr(opts, c)) == NULL) {
        !            39:                ERR(": illegal option -- ", c);
        !            40:                if(argv[optind][++sp] == '\0') {
        !            41:                        optind++;
        !            42:                        sp = 1;
        !            43:                }
        !            44:                return('?');
        !            45:        }
        !            46:        if(*++cp == ':') {
        !            47:                if(argv[optind][sp+1] != '\0')
        !            48:                        optarg = &argv[optind++][sp+1];
        !            49:                else if(++optind >= argc) {
        !            50:                        ERR(": option requires an argument -- ", c);
        !            51:                        sp = 1;
        !            52:                        return('?');
        !            53: #ifndef NO_MINUS
        !            54:                } else
        !            55:                        optarg = argv[optind++];
        !            56: #else NO_MINUS
        !            57:                } else {
        !            58:                        optarg = argv[optind++];
        !            59:                        if (*optarg == '-') {
        !            60:                            ERR(": option requires an argument -- ", c);
        !            61:                            sp = 1;
        !            62:                            return('?');
        !            63:                        }
        !            64:                }
        !            65: #endif NO_MINUS
        !            66:                sp = 1;
        !            67:        } else {
        !            68:                if(argv[optind][++sp] == '\0') {
        !            69:                        sp = 1;
        !            70:                        optind++;
        !            71:                }
        !            72:                optarg = NULL;
        !            73:        }
        !            74:        return(c);
        !            75: }

unix.superglobalmegacorp.com

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