30 |
/* Shorts options. */ |
/* Shorts options. */ |
31 |
const char *shortopts = "yvegdhrltknVo:b:p:S:"; |
const char *shortopts = "yvegdhrltknVo:b:p:S:"; |
32 |
|
|
|
/* Long options. */ |
|
|
struct option *longopts = NULL; |
|
|
|
|
|
struct percent_table_struct *percent_table = NULL; |
|
|
|
|
33 |
/* A CLI option only. |
/* A CLI option only. |
34 |
Arguments is the policy: `no', `optional', `required'. |
Arguments is the policy: `no', `optional', `required'. |
35 |
OptionChar is the value given to the Var if the latter is specified. */ |
OptionChar is the value given to the Var if the latter is specified. */ |
130 |
{0, 0, 0, 0, 0, 0} |
{0, 0, 0, 0, 0, 0} |
131 |
}; |
}; |
132 |
|
|
133 |
|
|
134 |
/*--------------------------------------------------------. |
/*--------------------------------------------------------. |
135 |
| Create the longoptions structure from the option_table, | |
| Create the longoptions structure from the option_table, | |
136 |
| for the getopt file. | |
| for the getopt file. | |
137 |
`--------------------------------------------------------*/ |
`--------------------------------------------------------*/ |
138 |
void |
|
139 |
create_long_option_table () |
struct option * |
140 |
|
long_option_table_new () |
141 |
{ |
{ |
142 |
|
struct option *res = NULL; |
143 |
int i = 0; |
int i = 0; |
144 |
int j = 0; |
int j = 0; |
145 |
int number_options; |
int number_options; |
149 |
|| option_table[i].access == opt_both) |
|| option_table[i].access == opt_both) |
150 |
++number_options; |
++number_options; |
151 |
|
|
152 |
longopts = XMALLOC (struct option, number_options + 1); |
res = XMALLOC (struct option, number_options + 1); |
153 |
for (i = 0; option_table[i].name; i++) |
for (i = 0; option_table[i].name; i++) |
154 |
if (option_table[i].access == opt_cmd_line |
if (option_table[i].access == opt_cmd_line |
155 |
|| option_table[i].access == opt_both) |
|| option_table[i].access == opt_both) |
156 |
{ |
{ |
157 |
/* Copy the struct information in the longoptions. */ |
/* Copy the struct information in the longoptions. */ |
158 |
longopts[j].name = option_table[i].name; |
res[j].name = option_table[i].name; |
159 |
longopts[j].has_arg = option_table[i].has_arg; |
res[j].has_arg = option_table[i].has_arg; |
160 |
/* When an options is declared having 'optional_argument' and |
/* When an options is declared having 'optional_argument' and |
161 |
a flag is specified to be set, the option is skipped on |
a flag is specified to be set, the option is skipped on |
162 |
command line. So we never use a flag when a command line |
command line. So we never use a flag when a command line |
163 |
option is declared 'optional_argument. */ |
option is declared 'optional_argument. */ |
164 |
if (longopts[j].has_arg == optional_argument) |
if (res[j].has_arg == optional_argument) |
165 |
longopts[j].flag = NULL; |
res[j].flag = NULL; |
166 |
else |
else |
167 |
longopts[j].flag = option_table[i].set_flag; |
res[j].flag = option_table[i].set_flag; |
168 |
longopts[j++].val = option_table[i].val; |
res[j++].val = option_table[i].val; |
169 |
} |
} |
170 |
longopts[number_options].name = NULL; |
res[number_options].name = NULL; |
171 |
longopts[number_options].has_arg = 0; |
res[number_options].has_arg = 0; |
172 |
longopts[number_options].flag = NULL; |
res[number_options].flag = NULL; |
173 |
longopts[number_options].val = 0; |
res[number_options].val = 0; |
174 |
|
|
175 |
|
return res; |
176 |
} |
} |