| version 1.25, 2002/10/07 10:54:44 |
version 1.26, 2002/12/27 17:49:19 |
|
|
| * http://www.platon.sk/projects/libcfg+/ |
* http://www.platon.sk/projects/libcfg+/ |
| */ |
*/ |
| |
|
| /* $Platon: shared.c,v 1.23 2002/08/27 13:19:18 rajo Exp $ */ |
/* $Platon: libcfg+/src/shared.c,v 1.25 2002/10/07 10:54:44 rajo Exp $ */ |
| |
|
| /* Includes {{{ */ |
/* Includes {{{ */ |
| #ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
| Line 315 __cfg_cmdline_set_currents(con) |
|
| Line 315 __cfg_cmdline_set_currents(con) |
|
| register char *s, *s_sep, *s_tmp; |
register char *s, *s_sep, *s_tmp; |
| register char *ptr; |
register char *ptr; |
| |
|
| size = 0; |
size = -1; /* size of matched prefix (0 is also valid) */ |
| s = con->argv[con->cur_idx]; |
s = con->argv[con->cur_idx]; /* string to scan */ |
| |
|
| |
/* Explicit `size_t' to `int' typecastings are required here near strlen() |
| |
calls, else strlen("") == 0 will be considered as smaller than -1. */ |
| |
|
| for (i = 0; (ptr = con->prop[CFG_LINE_SHORT_OPTION_PREFIX][i]) != NULL; i++) |
for (i = 0; (ptr = con->prop[CFG_LINE_SHORT_OPTION_PREFIX][i]) != NULL; i++) |
| if (strlen(ptr) > size && strstr(s, ptr) == s) |
if ((int) strlen(ptr) > size && strstr(s, ptr) == s) { |
| size = strlen(ptr); |
size = strlen(ptr); |
| |
con->cur_opt_type = CFG_SHORT_OPTION; |
| size = -size; |
} |
| |
|
| for (i = 0; (ptr = con->prop[CFG_LINE_LONG_OPTION_PREFIX][i]) != NULL; i++) |
for (i = 0; (ptr = con->prop[CFG_LINE_LONG_OPTION_PREFIX][i]) != NULL; i++) |
| if (strlen(ptr) > (size < 0 ? -size : size) && strstr(s, ptr) == s) |
if ((int) strlen(ptr) > size && strstr(s, ptr) == s) { |
| size = strlen(ptr); |
size = strlen(ptr); |
| |
con->cur_opt_type = CFG_LONG_OPTION; |
| |
} |
| |
|
| s_sep = NULL; |
s_sep = NULL; |
| |
|
| if (size == 0) { |
switch (con->cur_opt_type) { |
| con->cur_opt_type = CFG_NONE_OPTION; |
default: |
| } |
case CFG_NONE_OPTION: /* None option prefix */ |
| else if (size < 0) { /* Short option prefix */ |
break; |
| s += -size; |
|
| s_sep = strlen(s) > 0 ? s + 1 : s; |
|
| |
|
| if (strlen(s_sep) > 0) { |
case CFG_SHORT_OPTION: /* Short option prefix */ |
| con->cur_opt_type = CFG_SHORT_OPTION + CFG_SHORT_OPTIONS; |
s += size; |
| |
s_sep = strlen(s) > 0 ? s + 1 : s; |
| |
|
| if ((con->cur_arg = strdup(s_sep)) == NULL) |
if (strlen(s_sep) > 0) { |
| return 0; |
con->cur_opt_type += CFG_SHORT_OPTIONS; |
| } |
|
| else { |
|
| con->cur_opt_type = CFG_SHORT_OPTION; |
|
| |
|
| if (con->argv[con->cur_idx + 1] != NULL) { |
if ((con->cur_arg = strdup(s_sep)) == NULL) |
| con->cur_arg = strdup(con->argv[con->cur_idx + 1]); |
|
| if (con->cur_arg == NULL) |
|
| return 0; |
return 0; |
| } |
} |
| else |
else { |
| con->cur_arg = NULL; |
if (con->argv[con->cur_idx + 1] != NULL) { |
| } |
con->cur_arg = strdup(con->argv[con->cur_idx + 1]); |
| } |
if (con->cur_arg == NULL) |
| else { /* Long option prefix */ |
return 0; |
| con->cur_opt_type = CFG_LONG_OPTION; |
} |
| |
else |
| |
con->cur_arg = NULL; |
| |
} |
| |
break; |
| |
|
| s += size; |
case CFG_LONG_OPTION: /* Long option prefix */ |
| size = 0; |
s += size; |
| |
size = 0; |
| |
|
| |
for (i = 0; (ptr = con->prop[CFG_LINE_OPTION_ARG_SEPARATOR][i]) |
| |
!= NULL; i++) |
| |
if ((s_tmp = strstr(s, ptr)) != NULL) |
| |
if (s_sep == NULL || s_tmp < s_sep |
| |
|| (s_tmp == s_sep && strlen(ptr) > size)) { |
| |
s_sep = s_tmp; |
| |
size = strlen(ptr); |
| |
} |
| |
|
| for (i = 0; (ptr = con->prop[CFG_LINE_OPTION_ARG_SEPARATOR][i]) |
if (s_sep == NULL) { |
| != NULL; i++) |
if (con->argv[con->cur_idx + 1] != NULL) { |
| if ((s_tmp = strstr(s, ptr)) != NULL) |
con->cur_arg = strdup(con->argv[con->cur_idx + 1]); |
| if (s_sep == NULL || s_tmp < s_sep |
if (con->cur_arg == NULL) |
| || (s_tmp == s_sep && strlen(ptr) > size)) { |
return 0; |
| s_sep = s_tmp; |
|
| size = strlen(ptr); |
|
| } |
} |
| |
else |
| if (s_sep == NULL) { |
con->cur_arg = NULL; |
| if (con->argv[con->cur_idx + 1] != NULL) { |
} |
| con->cur_arg = strdup(con->argv[con->cur_idx + 1]); |
else { |
| if (con->cur_arg == NULL) |
con->cur_opt_type += CFG_LONG_SEPINIT; |
| |
if ((con->cur_arg = strdup(s_sep + size)) == NULL) |
| return 0; |
return 0; |
| } |
} |
| else |
|
| con->cur_arg = NULL; |
|
| } |
|
| else { |
|
| con->cur_opt_type += CFG_LONG_SEPINIT; |
|
| if ((con->cur_arg = strdup(s_sep + size)) == NULL) |
|
| return 0; |
|
| } |
|
| } |
} |
| |
|
| if (s_sep == NULL) |
if (s_sep == NULL) |