Chinaunix

标题: The Summarize of getopt() Function in POSIX [打印本页]

作者: yifei_wang    时间: 2011-10-18 22:56
标题: The Summarize of getopt() Function in POSIX
Format:
        int getopt(int argc, char *const argv[], const char *optstring);

        extern char *optarg;
        extern int optind, opterr, optopt;

global variables:
        1. optind:
                a. the index of the next element to be processed in argv.
                b. initialized to 1: at the beginning or scan a new argument vector.
        2. opterr:
                a. the return value is '?' when getopt() didn't recognize the option character.
                b. when set to 0, it may prevent the error message to print.
        3. optopt:
                a. store the illegal option

rules:
        1. argument:
                a. optstring
                        1. contained the legitimate optons characters.
                        2. character which followed by a colon requires an argument.
                  *        3. two colons mean an option takes an optional arg.
                        4. "-oarg" means "-o arg" (GNU extension)
                        5. "W;" --> "-W foo" means "--foo"
                        6. '+' in the first character of optstring or the evironment variable POSIXLY_CORRECT is set, option processing stops as soon as s nooption argument is encountered.
                        7. '-' in the first character, each nonoption argv-element is handled as if it were the argument of an  option with  character  code  1

        2. return value:
                a. return '?':
                        1. encounter illegal option
                        2. detect a missing option argument (the first character of optstring isn't a colon)
                b. return ':':
                        1. detect a missing option argument, and the first charater of optstring is a colon.
                c. return -1:
                        1. all command-line options have been parsed.
                d. return option character:
                        1. option was successfully found.
作者: yifei_wang    时间: 2011-10-19 11:01
本帖最后由 yifei_wang 于 2011-10-19 18:08 编辑

fix the lib function "getopt()":
1. remove the fourth argument;
2. add two error processing conditions;
3. update the coding style.

0001-fix-the-lib-function-getopt.patch.tar.bz2 (10 KB, 下载次数: 36)
作者: 陈思明    时间: 2011-10-19 17:26
Fix getopt() function of fold "boot", "disk", "display". boot_disk_display_fix.patch.tar.bz2 (1.63 KB, 下载次数: 41)
作者: wangyyet    时间: 2011-10-19 17:37
本帖最后由 wangyyet 于 2011-10-19 17:40 编辑

The patch of serial, shell and sysconf
serial_shell_sysconf_fix.patch.bz2 (966 Bytes, 下载次数: 24)
作者: zkw0320    时间: 2011-10-19 17:42
fix "memory","misc","net"

mem_misc_net.fix.tar.bz2

10 KB, 下载次数: 15


作者: dongshengzou    时间: 2011-10-19 18:27
flash_fs_led_fix.patch.tar.bz2 (859 Bytes, 下载次数: 21)
flash, fs, led   patch.
only document "flash" calls the function getopt().
作者: yifei_wang    时间: 2011-10-19 18:35
update the using of "getopt()" function in each app

0001-update-the-using-of-getopt-function-in-each-app.patch.tar.bz2 (20 KB, 下载次数: 27)




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2