getopt

    科技2023-09-24  86

    static const struct  option  options[] = { {"help"         , no_argument      , NULL, 'h'}, {"output"       , required_argument, NULL, 'o'}, {"level"        , required_argument, NULL, 'l'}, {"size"         , required_argument, NULL, 's'}, {"symversion"   , required_argument, NULL, 'v'}, {"margin"       , required_argument, NULL, 'm'}, {"structured"   , no_argument      , NULL, 'S'}, {"kanji"        , no_argument      , NULL, 'k'}, {"casesensitive", no_argument      , NULL, 'c'}, {"ignorecase"   , no_argument      , NULL, 'i'}, {"8bit"         , no_argument      , NULL, '8'}, {"version"      , no_argument      , NULL, 'V'}, {NULL, 0, NULL, 0} };

    它声明了一个数组options,元素的类型是一个静态结构常量。

    static const 静态常变量 struct  option 变量类型  options[]变量名

    struct option { const char *name; //name表示的是长参数名 int has_arg; //has_arg有3个值,no_argument(或者是0),表示该参数后面不跟参数值 // required_argument(或者是1),表示该参数后面一定要跟个参数值 // optional_argument(或者是2),表示该参数后面可以跟,也可以不跟参数值 int *flag; //用来决定,getopt_long()的返回值到底是什么。如果这个指针为NULL, //那么getopt_long()返回该结构val字段中的数值。如果该指针不为NULL, //getopt_long()会使得它所指向的变量中填入val字段中的数值,并且getopt_long()返回0。 //如果flag不是NULL,但未发现长选项,那么它所指向的变量的数值不变。 int val; //和flag联合决定返回值 这个值是发现了长选项时的返回值, //或者flag不是 NULL时载入*flag中的值。典型情况下,若flag不是NULL, //那么val是个真/假值,譬如1 或0;另一方面,如 果flag是NULL,那么val通常是字符常量, //若长选项与短选项一致,那么该字符常量应该与optstring中出现的这个选项的参数相同。 }
    Processed: 0.013, SQL: 8