Annotation of researchv10dc/man/adm/man3/getopt.3, revision 1.1

1.1     ! root        1: .TH GETOPT 3
        !             2: .CT 2 data_man
        !             3: .SH NAME
        !             4: getopt \(mi get option letter from argv
        !             5: .SH SYNOPSIS
        !             6: .nf
        !             7: .B int getopt (argc, argv, optstring)
        !             8: .B int argc;
        !             9: .B char **argv;
        !            10: .B char *optstring;
        !            11: .PP
        !            12: .B extern char *optarg;
        !            13: .B extern int optind;
        !            14: .fi
        !            15: .SH DESCRIPTION
        !            16: .I Getopt
        !            17: returns the next option letter in
        !            18: .I argv
        !            19: that matches a letter in
        !            20: .IR optstring .
        !            21: .I Optstring
        !            22: is a string of recognized option letters;
        !            23: if a letter is followed by a colon, the option
        !            24: is expected to have an argument, which may or
        !            25: may not be separated from it by white space.
        !            26: .I Optarg
        !            27: is set to point to the start of the option argument
        !            28: on return from
        !            29: .IR getopt .
        !            30: .PP
        !            31: .I Getopt
        !            32: places in
        !            33: .I optind
        !            34: the
        !            35: .I argv
        !            36: index of the next argument to be processed.
        !            37: Since
        !            38: .I optind
        !            39: is external, it is normally initialized to zero
        !            40: automatically before the first call to
        !            41: .IR getopt .
        !            42: .PP
        !            43: Option letters appear in nonempty clusters preceded by 
        !            44: .BR - .
        !            45: When all options have been processed
        !            46: (i.e., up to the first non-option argument),
        !            47: .I getopt
        !            48: returns \-1.
        !            49: The special option
        !            50: .L --
        !            51: may be used to delimit the end of the options;
        !            52: \-1
        !            53: will be returned, and
        !            54: .L --
        !            55: will be skipped.
        !            56: .SH EXAMPLES
        !            57: This fragment processes arguments
        !            58: for a command that can take option
        !            59: .B a
        !            60: and option
        !            61: .BR f ,
        !            62: which requires an argument.
        !            63: .PP
        !            64: .EX
        !            65: .ta \w'12345678'u +\w'12345678'u
        !            66: main (argc, argv) char **argv;
        !            67: {
        !            68:        int c, errflg;
        !            69:        extern int optind;
        !            70:        extern char *optarg, *ifile;
        !            71:        while((c = getopt(argc, argv, "af:")) != -1)
        !            72:                switch (c){
        !            73:                case 'a':  aflg=1; break;
        !            74:                case 'f':  ifile = optarg; break;
        !            75:                case '?':  errflg=1; break;
        !            76:                }
        !            77:        if(errflg){
        !            78:                fprintf(stderr, "usage: . . . ");
        !            79:                exit(2);
        !            80:        }
        !            81:        for( ; optind < argc; optind++){
        !            82:                if(access(argv[optind], 4)){
        !            83:                        ...
        !            84:                }
        !            85:        }
        !            86:        ...
        !            87: }
        !            88: .EE
        !            89: .SH SEE ALSO
        !            90: .IR getflags (3)
        !            91: .SH DIAGNOSTICS
        !            92: .I Getopt
        !            93: prints an error message on
        !            94: .I stderr
        !            95: and returns a
        !            96: question mark
        !            97: .L ?
        !            98: when it encounters an option letter not included in
        !            99: .IR optstring .

unix.superglobalmegacorp.com

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