| verzia 1.5, 2001/11/27 15:15:25 |
verzia 1.6, 2001/11/27 17:11:30 |
|
|
| #include <limits.h> |
#include <limits.h> |
| #include <float.h> |
#include <float.h> |
| #include <errno.h> |
#include <errno.h> |
| |
#include <ctype.h> |
| |
|
| #include "str/strplus.h" |
#include "str/strplus.h" |
| |
|
| Riadok 36 static int cfg_cmdline_get_next_opt(cons |
|
| Riadok 37 static int cfg_cmdline_get_next_opt(cons |
|
| } |
} |
| |
|
| return 0; |
return 0; |
| */ |
*/ |
| |
|
| register int opt_idx; |
register int opt_idx; |
| |
register int arg_used; |
| |
|
| while (con->argv[con->cur_idx] != NULL) { |
while (con->argv[con->cur_idx] != NULL) { |
| |
|
| |
arg_used = 0; |
| |
|
| if (con->cur_opt_type & CFG_SHORT_OPTIONS) { |
if (con->cur_opt_type & CFG_SHORT_OPTIONS) { |
| con->cur_opt[0] = con->cur_arg[0]; |
con->cur_opt[0] = con->cur_arg[0]; |
| strdel(con->cur_arg); |
strdel(con->cur_arg); |
| Riadok 128 static int cfg_cmdline_get_next_opt(cons |
|
| Riadok 132 static int cfg_cmdline_get_next_opt(cons |
|
| (unsigned int) value; |
(unsigned int) value; |
| } |
} |
| else { |
else { |
| printf("testing: %ld < %d < (%ld) < %d < %ld\n", |
/* TODO: remove this |
| LONG_MIN, |
printf("testing: %ld < %d < (%ld) < %d < %ld\n", |
| INT_MIN, |
LONG_MIN, |
| value, |
INT_MIN, |
| INT_MAX, |
value, |
| LONG_MAX); |
INT_MAX, |
| |
LONG_MAX); |
| |
*/ |
| |
|
| if (value >= INT_MAX || value <= INT_MIN) |
if (value >= INT_MAX || value <= INT_MIN) |
| return CFG_ERROR_OVERFLOW; |
return CFG_ERROR_OVERFLOW; |
| Riadok 142 static int cfg_cmdline_get_next_opt(cons |
|
| Riadok 148 static int cfg_cmdline_get_next_opt(cons |
|
| *((int *)con->options[opt_idx].value) = |
*((int *)con->options[opt_idx].value) = |
| (int) value; |
(int) value; |
| } |
} |
| |
|
| if (! (con->cur_opt_type & CFG_LONG_SEPINIT) |
|
| && ! (con->cur_opt_type |
|
| & CFG_SHORT_OPTIONS)) { |
|
| puts("[1] moving cur_idx"); |
|
| con->cur_idx++; |
|
| } |
|
| } |
} |
| |
|
| if (con->cur_opt_type & CFG_SHORT_OPTIONS) |
arg_used = 1; |
| con->cur_opt_type -= CFG_SHORT_OPTIONS; |
|
| |
|
| break; |
break; |
| |
|
| case CFG_UNSIGNED_LONG: |
case CFG_UNSIGNED_LONG: |
| Riadok 169 static int cfg_cmdline_get_next_opt(cons |
|
| Riadok 166 static int cfg_cmdline_get_next_opt(cons |
|
| if (!(end && *end == '\0')) |
if (!(end && *end == '\0')) |
| return CFG_ERROR_BADNUMBER; |
return CFG_ERROR_BADNUMBER; |
| |
|
| if (value == ULONG_MAX /* || value == 0 */) |
/* Fix strange strtoul() behaviour. */ |
| |
for (end = con->cur_arg; isspace(*end); end++) ; |
| |
|
| |
/* Testing errno after strtoul() is not needed here. */ |
| |
if (*end == '-' || value == ULONG_MAX /* || value == 0 */) |
| return CFG_ERROR_OVERFLOW; |
return CFG_ERROR_OVERFLOW; |
| |
|
| if (con->options[opt_idx].value != NULL) |
if (con->options[opt_idx].value != NULL) |
| *((unsigned long *)con->options[opt_idx].value) = value; |
*((unsigned long *)con->options[opt_idx].value) = value; |
| } |
} |
| |
|
| |
arg_used = 1; |
| break; |
break; |
| |
|
| case CFG_FLOAT: |
case CFG_FLOAT: |
| Riadok 197 static int cfg_cmdline_get_next_opt(cons |
|
| Riadok 200 static int cfg_cmdline_get_next_opt(cons |
|
| return CFG_ERROR_OVERFLOW; |
return CFG_ERROR_OVERFLOW; |
| |
|
| if (con->options[opt_idx].type == CFG_FLOAT) { |
if (con->options[opt_idx].type == CFG_FLOAT) { |
| #ifdef ABS |
#ifdef ABS /* Borrowed from popt library. */ |
| #undef ABS |
#undef ABS |
| #endif |
#endif |
| #define ABS(a) (((a) < 0) ? -(a) : (a)) |
#define ABS(a) (((a) < 0) ? -(a) : (a)) |
| Riadok 211 static int cfg_cmdline_get_next_opt(cons |
|
| Riadok 214 static int cfg_cmdline_get_next_opt(cons |
|
| *((float *)con->options[opt_idx].value) = |
*((float *)con->options[opt_idx].value) = |
| (float) value; |
(float) value; |
| } |
} |
| else { |
else { /* type == CFG_DOUBLE */ |
| if (con->options[opt_idx].value != NULL) |
if (con->options[opt_idx].value != NULL) |
| *((double *)con->options[opt_idx].value) = value; |
*((double *)con->options[opt_idx].value) = value; |
| } |
} |
| } |
} |
| /* |
|
| case POPT_ARG_FLOAT: |
arg_used = 1; |
| case POPT_ARG_DOUBLE: |
|
| { double aDouble = 0.0; |
|
| char *end; |
|
| |
|
| if (con->os->nextArg) { |
|
| aDouble = strtod(con->os->nextArg, &end); |
|
| if (*end) |
|
| return POPT_ERROR_BADNUMBER; |
|
| } |
|
| |
|
| if (aDouble == +HUGE_VAL || aDouble == -HUGE_VAL) |
|
| return POPT_ERROR_OVERFLOW; |
|
| if (aDouble == 0.0 && errno == ERANGE) |
|
| return POPT_ERROR_OVERFLOW; |
|
| if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_DOUBLE) { |
|
| *((double *) opt->arg) = aDouble; |
|
| } else { |
|
| #ifdef ABS |
|
| #undef ABS |
|
| #endif |
|
| #define ABS(a) (((a) < 0) ? -(a) : (a)) |
|
| if (ABS(aDouble) > FLT_MAX) |
|
| return POPT_ERROR_OVERFLOW; |
|
| if (ABS(aDouble) < FLT_MIN) |
|
| return POPT_ERROR_OVERFLOW; |
|
| *((float *) opt->arg) = aDouble; |
|
| } |
|
| } break; |
|
| */ |
|
| break; |
break; |
| |
|
| case CFG_STRING: |
case CFG_STRING: |
| break; |
break; |
| } |
} |
| |
|
| printf("%d vs. %d\n", con->cur_opt_type, CFG_SHORT_OPTIONS); |
if (arg_used) { |
| |
if (! (con->cur_opt_type & CFG_LONG_SEPINIT) |
| |
&& !(con->cur_opt_type & CFG_SHORT_OPTIONS)) |
| |
{ |
| |
puts("[1] argument used, moving cur_idx"); |
| |
con->cur_idx++; |
| |
} |
| |
|
| |
if (con->cur_opt_type & CFG_SHORT_OPTIONS) |
| |
con->cur_opt_type -= CFG_SHORT_OPTIONS; |
| |
} |
| |
|
| if (! (con->cur_opt_type & CFG_SHORT_OPTIONS)) { |
if (! (con->cur_opt_type & CFG_SHORT_OPTIONS)) { |
| puts("[2] moving cur_idx"); |
puts("[2] moving cur_idx"); |
| Riadok 395 static int search_cur_opt(const CFG_CONT |
|
| Riadok 379 static int search_cur_opt(const CFG_CONT |
|
| con->cur_opt, |
con->cur_opt, |
| con->options[i].cmdline_long_name, |
con->options[i].cmdline_long_name, |
| con->options[i].cmdline_short_name); |
con->options[i].cmdline_short_name); |
| */ |
*/ |
| |
|
| if ((con->cur_opt_type & CFG_LONG_OPTION && ! strcmp(con->cur_opt, |
if ((con->cur_opt_type & CFG_LONG_OPTION && ! strcmp(con->cur_opt, |
| con->options[i].cmdline_long_name)) |
con->options[i].cmdline_long_name)) |
| Riadok 411 static int search_cur_opt(const CFG_CONT |
|
| Riadok 395 static int search_cur_opt(const CFG_CONT |
|
| return -1; |
return -1; |
| } |
} |
| |
|
| /* 0 - No, 1 - Short, 2 - Long */ |
|
| /* |
|
| static int is_cmdline_option(const CFG_CONTEXT con, char *s) { |
|
| register int i, size, ret; |
|
| |
|
| size = ret = 0; |
|
| |
|
| for (i = 0; con->short_option_prefix[i] != NULL; i++) { |
|
| if (strstr(s, con->short_option_prefix[i]) == s) { |
|
| size = strlen(con->short_option_prefix[i]); |
|
| ret = 1; |
|
| break; |
|
| } |
|
| } |
|
| |
|
| for (i = 0; con->long_option_prefix[i] != NULL; i++) { |
|
| if (ret == 1 && strlen(con->long_option_prefix[i]) <= size) |
|
| continue; |
|
| |
|
| if (strstr(s, con->long_option_prefix[i]) == s) { |
|
| size = strlen(con->long_option_prefix[i]); |
|
| ret = 2; |
|
| break; |
|
| } |
|
| } |
|
| |
|
| return ret; |
|
| } |
|
| */ |
|
| |
|