| version 1.10, 2001/12/02 23:28:35 |
version 1.11, 2001/12/03 16:48:39 |
| Line 65 static int cfg_cmdline_get_next_opt(cons |
|
| Line 65 static int cfg_cmdline_get_next_opt(cons |
|
| |
|
| #if defined(DEBUG) && DEBUG |
#if defined(DEBUG) && DEBUG |
| fprintf(stderr, "--\nDEBUG|%d|%s|%s|%s|%d|flags=%x[", |
fprintf(stderr, "--\nDEBUG|%d|%s|%s|%s|%d|flags=%x[", |
| con->cur_idx, con->argv[con->cur_idx], |
con->cur_idx, con->argv[con->cur_idx], |
| con->cur_opt == NULL ? "[NULL]" : con->cur_opt, |
con->cur_opt == NULL ? "[NULL]" : con->cur_opt, |
| con->cur_arg == NULL ? "[NULL]" : con->cur_arg, |
con->cur_arg == NULL ? "[NULL]" : con->cur_arg, |
| opt_idx, con->cur_opt_type); |
opt_idx, con->cur_opt_type); |
| |
|
| if (con->cur_opt_type & CFG_LONG_OPTION) |
if (con->cur_opt_type & CFG_LONG_OPTION) |
| fputs("-LONG-", stderr); |
fputs("-LONG-", stderr); |
| Line 82 static int cfg_cmdline_get_next_opt(cons |
|
| Line 82 static int cfg_cmdline_get_next_opt(cons |
|
| fputs("]\n", stderr); |
fputs("]\n", stderr); |
| #endif |
#endif |
| |
|
| if (opt_idx < 0) { |
if (opt_idx < 0) |
| return CFG_ERROR_UNKNOWN; |
return CFG_ERROR_UNKNOWN; |
| } |
|
| |
|
| if ( ! (con->flags & CFG_IGNORE_MULTI) |
if ( ! (con->flags & CFG_IGNORE_MULTI) |
| && ! (con->options[opt_idx].type & CFG_MULTI)) { |
&& ! (con->options[opt_idx].type & CFG_MULTI)) { |
| int ret = 0; |
int ret = 0; |
| |
|
| ret = add_to_used_opt_idx(con, opt_idx); |
ret = add_to_used_opt_idx(con, opt_idx); |
| Line 104 static int cfg_cmdline_get_next_opt(cons |
|
| Line 103 static int cfg_cmdline_get_next_opt(cons |
|
| opt_f_multi = con->options[opt_idx].type & CFG_MULTI; |
opt_f_multi = con->options[opt_idx].type & CFG_MULTI; |
| opt_f_multi_sep = con->options[opt_idx].type & |
opt_f_multi_sep = con->options[opt_idx].type & |
| (CFG_MULTI_SEPARATED & ~CFG_MULTI); |
(CFG_MULTI_SEPARATED & ~CFG_MULTI); |
| /* opt_f_leftover = con->options[opt_idx].type & CFG_LEFTOVER_ARGS; */ |
|
| |
|
| switch (opt_data_type) { |
switch (opt_data_type) { |
| default: |
default: |
| Line 115 static int cfg_cmdline_get_next_opt(cons |
|
| Line 113 static int cfg_cmdline_get_next_opt(cons |
|
| |
|
| case CFG_BOOLEAN: |
case CFG_BOOLEAN: |
| if (con->cur_opt_type & CFG_LONG_SEPINIT |
if (con->cur_opt_type & CFG_LONG_SEPINIT |
| && con->cur_arg != NULL) |
&& con->cur_arg != NULL) |
| return CFG_ERROR_NOTALLOWEDARG; |
return CFG_ERROR_NOTALLOWEDARG; |
| |
|
| if (con->options[opt_idx].value != NULL) |
if (con->options[opt_idx].value != NULL) |
| (*((int *)con->options[opt_idx].value))++; |
(*((int *) con->options[opt_idx].value))++; |
| break; |
break; |
| |
|
| /* Numeric (int, long, float and double) data types. */ |
/* Numeric (int, long, float and double) data types. */ |
| Line 143 static int cfg_cmdline_get_next_opt(cons |
|
| Line 141 static int cfg_cmdline_get_next_opt(cons |
|
| |
|
| if (opt_f_multi_sep) { |
if (opt_f_multi_sep) { |
| add = strdyn_explode_ar(con->cur_arg, |
add = strdyn_explode_ar(con->cur_arg, |
| con->multi_separator); |
con->multi_separator); |
| if (add == NULL) |
if (add == NULL) |
| return CFG_ERROR_NOMEM; |
return CFG_ERROR_NOMEM; |
| } |
} |
| Line 153 static int cfg_cmdline_get_next_opt(cons |
|
| Line 151 static int cfg_cmdline_get_next_opt(cons |
|
| } |
} |
| |
|
| ret = store_multi_arg(opt_data_type, |
ret = store_multi_arg(opt_data_type, |
| (const char **) add, |
(const char **) add, |
| con->options[opt_idx].value); |
con->options[opt_idx].value); |
| |
|
| if (add != static_add) |
if (add != static_add) |
| strdyn_free((char **) add); |
strdyn_free((char **) add); |
| } |
} |
| else |
else |
| ret = store_single_arg(opt_data_type, con->cur_arg, |
ret = store_single_arg(opt_data_type, con->cur_arg, |
| con->options[opt_idx].value); |
con->options[opt_idx].value); |
| |
|
| if (ret != CFG_OK) |
if (ret != CFG_OK) |
| return ret; |
return ret; |
| Line 180 static int cfg_cmdline_get_next_opt(cons |
|
| Line 178 static int cfg_cmdline_get_next_opt(cons |
|
| if (con->options[opt_idx].value != NULL) { |
if (con->options[opt_idx].value != NULL) { |
| if (opt_f_multi) { |
if (opt_f_multi) { |
| register char ***p; |
register char ***p; |
| p = (char ***)con->options[opt_idx].value; |
p = (char ***) con->options[opt_idx].value; |
| |
|
| if (opt_f_multi_sep) { |
if (opt_f_multi_sep) { |
| register char **ar; |
register char **ar; |
| |
|
| ar = strdyn_explode_ar(con->cur_arg, |
ar = strdyn_explode_ar(con->cur_arg, |
| con->multi_separator); |
con->multi_separator); |
| if (ar == NULL) |
if (ar == NULL) |
| return CFG_ERROR_NOMEM; |
return CFG_ERROR_NOMEM; |
| |
|
| Line 201 static int cfg_cmdline_get_next_opt(cons |
|
| Line 199 static int cfg_cmdline_get_next_opt(cons |
|
| } |
} |
| } |
} |
| else |
else |
| *((char **)con->options[opt_idx].value) = |
*((char **) con->options[opt_idx].value) = |
| strdup(con->cur_arg); |
strdup(con->cur_arg); |
| } |
} |
| |
|
| Line 211 static int cfg_cmdline_get_next_opt(cons |
|
| Line 209 static int cfg_cmdline_get_next_opt(cons |
|
| |
|
| if (arg_used) { |
if (arg_used) { |
| if (! (con->cur_opt_type & CFG_LONG_SEPINIT) |
if (! (con->cur_opt_type & CFG_LONG_SEPINIT) |
| && !(con->cur_opt_type & CFG_SHORT_OPTIONS) |
&& !(con->cur_opt_type & CFG_SHORT_OPTIONS) |
| && !(con->cur_opt_type == CFG_NONE_OPTION)) |
&& !(con->cur_opt_type == CFG_NONE_OPTION)) |
| { |
{ |
| /* puts("[1] argument used, moving cur_idx"); */ |
/* puts("[1] argument used, moving cur_idx"); */ |
| con->cur_idx_tmp++; |
con->cur_idx_tmp++; |
| Line 271 static int set_currents(const CFG_CONTEX |
|
| Line 269 static int set_currents(const CFG_CONTEX |
|
| |
|
| for (i = 0; con->short_option_prefix[i] != NULL; i++) |
for (i = 0; con->short_option_prefix[i] != NULL; i++) |
| if (strlen(con->short_option_prefix[i]) > size |
if (strlen(con->short_option_prefix[i]) > size |
| && strstr(s, con->short_option_prefix[i]) == s) |
&& strstr(s, con->short_option_prefix[i]) == s) |
| size = strlen(con->short_option_prefix[i]); |
size = strlen(con->short_option_prefix[i]); |
| |
|
| size = -size; |
size = -size; |
| |
|
| for (i = 0; con->long_option_prefix[i] != NULL; i++) |
for (i = 0; con->long_option_prefix[i] != NULL; i++) |
| if (strlen(con->long_option_prefix[i]) > (size < 0 ? -size : size) |
if (strlen(con->long_option_prefix[i]) > (size < 0 ? -size : size) |
| && strstr(s, con->long_option_prefix[i]) == s) |
&& strstr(s, con->long_option_prefix[i]) == s) |
| size = strlen(con->long_option_prefix[i]); |
size = strlen(con->long_option_prefix[i]); |
| |
|
| s_sep = NULL; |
s_sep = NULL; |
| Line 316 static int set_currents(const CFG_CONTEX |
|
| Line 314 static int set_currents(const CFG_CONTEX |
|
| |
|
| for (i = 0; con->line_option_arg_separator[i] != NULL; i++) |
for (i = 0; con->line_option_arg_separator[i] != NULL; i++) |
| if ((s_tmp = strstr(s, con->line_option_arg_separator[i])) != NULL) |
if ((s_tmp = strstr(s, con->line_option_arg_separator[i])) != NULL) |
| if (s_sep == NULL || s_tmp < s_sep || (s_tmp == s_sep |
if (s_sep == NULL || s_tmp < s_sep |
| && strlen(con->line_option_arg_separator[i]) > size)) |
|| (s_tmp == s_sep && |
| { |
strlen(con->line_option_arg_separator[i]) > size)) { |
| s_sep = s_tmp; |
s_sep = s_tmp; |
| size = strlen(con->line_option_arg_separator[i]); |
size = strlen(con->line_option_arg_separator[i]); |
| } |
} |
| Line 371 static int search_cur_opt_idx(const CFG_ |
|
| Line 369 static int search_cur_opt_idx(const CFG_ |
|
| register int i; |
register int i; |
| |
|
| for (i = 0; con->options[i].cmdline_long_name != NULL |
for (i = 0; con->options[i].cmdline_long_name != NULL |
| || con->options[i].cmdline_short_name != '\0' |
|| con->options[i].cmdline_short_name != '\0' |
| || con->options[i].cfgfile_name != NULL |
|| con->options[i].cfgfile_name != NULL |
| || con->options[i].type != CFG_END |
|| con->options[i].type != CFG_END |
| || con->options[i].value != NULL |
|| con->options[i].value != NULL |
| || con->options[i].val != 0; |
|| con->options[i].val != 0; |
| i++) |
i++) |
| { |
{ |
| |
|
| if ((con->cur_opt_type & CFG_LONG_OPTION && con->cur_opt != NULL |
if ((con->cur_opt_type & CFG_LONG_OPTION && con->cur_opt != NULL |
| && con->options[i].cmdline_long_name != NULL |
&& con->options[i].cmdline_long_name != NULL |
| && ! strcmp(con->cur_opt, |
&& ! strcmp(con->cur_opt, |
| con->options[i].cmdline_long_name)) |
con->options[i].cmdline_long_name)) |
| || (con->cur_opt_type & CFG_SHORT_OPTION && |
|| (con->cur_opt_type & CFG_SHORT_OPTION && |
| con->cur_opt[0] == |
con->cur_opt[0] == con->options[i].cmdline_short_name) |
| con->options[i].cmdline_short_name) |
|| (con->cur_opt_type == CFG_NONE_OPTION && |
| || (con->cur_opt_type == CFG_NONE_OPTION && |
con->options[i].type & CFG_LEFTOVER_ARGS)) |
| con->options[i].type & CFG_LEFTOVER_ARGS)) |
|
| |
|
| return i; |
return i; |
| } |
} |
| Line 439 static int add_to_used_opt_idx(const CFG |
|
| Line 436 static int add_to_used_opt_idx(const CFG |
|
| + 1 + CFG_USED_OPT_IDX_STEP; |
+ 1 + CFG_USED_OPT_IDX_STEP; |
| |
|
| con->used_opt_idx = (int *) realloc(con->used_opt_idx, |
con->used_opt_idx = (int *) realloc(con->used_opt_idx, |
| new_size * sizeof(int)); |
new_size * sizeof(int)); |
| |
|
| #if defined(DEBUG) && DEBUG |
#if defined(DEBUG) && DEBUG |
| printf("add_to_used_opt_idx(con, %d): realloc(%d) = %p\n", |
printf("add_to_used_opt_idx(con, %d): realloc(%d) = %p\n", |
| opt_idx, new_size, con->used_opt_idx); |
opt_idx, new_size, con->used_opt_idx); |
| #endif |
#endif |
| |
|
| if (con->used_opt_idx == NULL) |
if (con->used_opt_idx == NULL) |