| version 1.1, 2001/12/18 20:18:58 |
version 1.2, 2001/12/20 19:50:38 |
| Line 133 int __cfg_process_currents(const CFG_CON |
|
| Line 133 int __cfg_process_currents(const CFG_CON |
|
| char *static_add[2] = {NULL, NULL}; |
char *static_add[2] = {NULL, NULL}; |
| |
|
| if (opt_f_multi_sep) { |
if (opt_f_multi_sep) { |
| /* |
|
| add = strdyn_explode_ar(con->cur_arg, |
|
| con->type == CFG_LINE |
|
| ? con->line_multi_vals_separator |
|
| : con->file_multi_vals_separator); |
|
| */ |
|
| ret = split_multi_arg(con, con->cur_arg, &add); |
ret = split_multi_arg(con, con->cur_arg, &add); |
| |
|
| if (ret != CFG_OK) |
if (ret != CFG_OK) { |
| |
strdyn_safe_free(add); |
| return ret; |
return ret; |
| |
} |
| /* |
/* |
| if (add == NULL) |
if (add == NULL) |
| return CFG_ERROR_NOMEM; |
return CFG_ERROR_NOMEM; |
| Line 200 int __cfg_process_currents(const CFG_CON |
|
| Line 196 int __cfg_process_currents(const CFG_CON |
|
| return CFG_ERROR_NOMEM; |
return CFG_ERROR_NOMEM; |
| */ |
*/ |
| ret = split_multi_arg(con, con->cur_arg, &ar); |
ret = split_multi_arg(con, con->cur_arg, &ar); |
| if (ret != CFG_OK) |
if (ret != CFG_OK) { |
| return CFG_OK; |
strdyn_safe_free(ar); |
| |
return ret; |
| |
} |
| |
|
| if ((*p = strdyn_add_ar(*p, ar)) == NULL) |
if ((*p = strdyn_add_ar(*p, ar)) == NULL) |
| return CFG_ERROR_NOMEM; |
return CFG_ERROR_NOMEM; |
| Line 709 static int store_single_arg(const int ty |
|
| Line 707 static int store_single_arg(const int ty |
|
| |
|
| static int split_multi_arg(const CFG_CONTEXT con, char *arg, char ***ar) |
static int split_multi_arg(const CFG_CONTEXT con, char *arg, char ***ar) |
| { |
{ |
| register int i, ret, ret_code; |
register int i; |
| |
int sep_ar_idx, quote_prefix_idx, sep_size, tmp_sep_size; |
| *ar = strdyn_explode_ar(arg, |
char *p_quote, *p_sep, *tmp_s, *arg_base; |
| con->type == CFG_LINE |
register char **sep_ar; |
| ? con->line_multi_vals_separator |
|
| : con->file_multi_vals_separator); |
sep_ar = con->type == CFG_LINE |
| |
? con->line_multi_vals_separator |
| |
: con->file_multi_vals_separator; |
| |
|
| if (*ar == NULL) |
if ((*ar = strdyn_create()) == NULL) |
| return CFG_ERROR_NOMEM; |
return CFG_ERROR_NOMEM; |
| |
|
| for (ret_code = CFG_OK, i = 0; (*ar)[i] != NULL; i++) { |
arg_base = arg; |
| ret = unquote_single_arg(con, (*ar)[i]); |
|
| |
|
| if (ret != CFG_OK && ret_code == CFG_OK) |
do { |
| ret_code = ret; |
|
| } |
|
| |
|
| return ret_code; |
p_quote = strdyn_str2(arg, con->quote_prefix, "e_prefix_idx); |
| } |
|
| |
|
| static int unquote_single_arg(const CFG_CONTEXT con, char *arg) |
for (p_sep = NULL, sep_ar_idx = -1, sep_size = 0, i = 0; |
| { |
sep_ar[i] != NULL; i++) |
| return CFG_OK; |
if ((tmp_s = str_white_str(arg, sep_ar[i], &tmp_sep_size)) != NULL |
| } |
&& (p_sep == NULL || tmp_s < p_sep)) { |
| |
p_sep = tmp_s; |
| |
sep_ar_idx = i; |
| |
sep_size = tmp_sep_size; |
| |
} |
| |
|
| /* |
/* Quotations processing. */ |
| static int unquote_single_arg(const CFG_CONTEXT con, char *arg) |
if ((p_quote != NULL && p_sep == NULL) |
| { |
|| (p_quote != NULL && p_sep != NULL && p_quote < p_sep)) { |
| register int i, arg_len; |
|
| register char *p_prefix, *p_postfix; |
|
| |
|
| arg_len = strlen(arg); |
register char *end_ptr, *prefix, *postfix; |
| |
register int prefix_len, postfix_len; |
| |
|
| for (p_prefix = NULL, p_postfix = NULL, i = 0; |
prefix = con->quote_prefix[quote_prefix_idx]; |
| con->quote_prefix[i] != NULL |
postfix = con->quote_postfix[quote_prefix_idx]; |
| && con->quote_postfix[i] != NULL; |
|
| i++) |
if (prefix == NULL || postfix == NULL) |
| if (strstr(arg, con->quote_prefix[i]) == arg |
return CFG_ERROR_INTERNAL; |
| && (p_prefix == NULL || (p_prefix != NULL |
|
| && strlen(con->quote_prefix[i]) > strlen(p_prefix))) |
prefix_len = strlen(prefix); |
| && strlen(con->quote_prefix[i]) + strlen(con->quote_postfix[i]) |
postfix_len = strlen(postfix); |
| <= arg_len) { |
|
| p_prefix = con->quote_prefix[i]; |
memmove(p_quote, p_quote + prefix_len, |
| p_postfix = con->quote_postfix[i]; |
strlen(p_quote + prefix_len) + 1); |
| |
|
| |
end_ptr = strstr(p_quote, postfix); |
| |
|
| |
if (end_ptr == NULL) { |
| |
return CFG_ERROR_BADQUOTE; |
| |
} |
| |
|
| |
memmove(end_ptr, end_ptr + postfix_len, |
| |
strlen(end_ptr + postfix_len) + 1); |
| |
|
| |
arg = end_ptr; |
| } |
} |
| |
/* Separator processing. */ |
| |
else if ((p_sep != NULL && p_quote == NULL) |
| |
|| (p_sep != NULL && p_quote != NULL && p_sep <= p_quote)) { |
| |
|
| |
register char c; |
| |
|
| |
c = *p_sep; |
| |
*p_sep = '\0'; |
| |
#if DEBUG |
| |
//printf("adding <%s>, sep_char = '%c', sep_size = %d\n", arg_base, c, sep_size); |
| |
#endif |
| |
*ar = strdyn_add_va(*ar, arg_base, NULL); |
| |
|
| if (p_prefix != NULL && p_postfix != NULL) { |
*p_sep = c; |
| register int p_prefix_len, p_postfix_len; |
|
| |
|
| p_prefix_len = strlen(p_prefix); |
if (*ar == NULL) |
| p_postfix_len = strlen(p_postfix); |
return CFG_ERROR_NOMEM; |
| |
|
| if (strcmp(arg + strlen(arg) - p_postfix_len, p_postfix)) |
arg_base = arg = (p_sep + sep_size); |
| return CFG_ERROR_BADQUOTE; |
} |
| |
|
| memmove(arg, arg + p_prefix_len, |
} while (p_quote != NULL || p_sep != NULL); |
| arg_len - (p_prefix_len + p_postfix_len)); |
|
| arg[arg_len - (p_prefix_len + p_postfix_len)] = '\0'; |
if ((*ar = strdyn_add_va(*ar, arg_base, NULL)) == NULL) |
| } |
return CFG_ERROR_NOMEM; |
| |
|
| |
return CFG_OK; |
| |
} |
| |
|
| |
static int unquote_single_arg(const CFG_CONTEXT con, char *arg) |
| |
{ |
| return CFG_OK; |
return CFG_OK; |
| } |
} |
| |
|
| |
/* |
| |
static int unquote_single_arg(const CFG_CONTEXT con, char *arg) |
| |
{ |
| |
register int i, arg_len; |
| |
register char *p_prefix, *p_postfix; |
| |
|
| |
arg_len = strlen(arg); |
| |
|
| |
for (p_prefix = NULL, p_postfix = NULL, i = 0; |
| |
con->quote_prefix[i] != NULL |
| |
&& con->quote_postfix[i] != NULL; |
| |
i++) |
| |
if (strstr(arg, con->quote_prefix[i]) == arg |
| |
&& (p_prefix == NULL || (p_prefix != NULL |
| |
&& strlen(con->quote_prefix[i]) > strlen(p_prefix))) |
| |
&& strlen(con->quote_prefix[i]) + strlen(con->quote_postfix[i]) |
| |
<= arg_len) { |
| |
p_prefix = con->quote_prefix[i]; |
| |
p_postfix = con->quote_postfix[i]; |
| |
} |
| |
|
| |
if (p_prefix != NULL && p_postfix != NULL) { |
| |
register int p_prefix_len, p_postfix_len; |
| |
|
| |
p_prefix_len = strlen(p_prefix); |
| |
p_postfix_len = strlen(p_postfix); |
| |
|
| |
if (strcmp(arg + strlen(arg) - p_postfix_len, p_postfix)) |
| |
return CFG_ERROR_BADQUOTE; |
| |
|
| |
memmove(arg, arg + p_prefix_len, |
| |
arg_len - (p_prefix_len + p_postfix_len)); |
| |
arg[arg_len - (p_prefix_len + p_postfix_len)] = '\0'; |
| |
} |
| |
|
| |
return CFG_OK; |
| |
} |
| */ |
*/ |