| version 1.14, 2002/05/29 15:12:11 |
version 1.15, 2002/05/29 20:12:02 |
| Line 738 store_single_arg(type, arg, where) |
|
| Line 738 store_single_arg(type, arg, where) |
|
| return CFG_OK; |
return CFG_OK; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| |
/* |
| |
* split_multi_arg() |
| |
* |
| |
* Splits multi argument with separators with focusing on quotations. |
| |
* Returns cfg_error type and in ar store resulting array. |
| |
*/ |
| |
|
| static int |
static int |
| split_multi_arg(con, arg, ar) |
split_multi_arg(con, arg, ar) |
| const CFG_CONTEXT con; |
const CFG_CONTEXT con; |
| Line 752 split_multi_arg(con, arg, ar) |
|
| Line 759 split_multi_arg(con, arg, ar) |
|
| if ((*ar = strdyn_create()) == NULL) |
if ((*ar = strdyn_create()) == NULL) |
| return CFG_ERROR_NOMEM; |
return CFG_ERROR_NOMEM; |
| |
|
| sep_ar = con->type == CFG_LINE |
arg_base = arg; |
| |
sep_ar = con->type == CFG_LINE |
| ? con->line_multi_vals_separator |
? con->line_multi_vals_separator |
| : con->file_multi_vals_separator; |
: con->file_multi_vals_separator; |
| |
|
| arg_base = arg; |
|
| |
|
| do { |
do { |
| |
|
| p_quote = strdyn_str2(arg, con->quote_prefix, "e_prefix_idx); |
/* Searching first quotation string (p_quote) |
| |
and set quotation variables */ |
| |
p_quote = strdyn_str2(arg, con->quote_prefix, "e_prefix_idx); |
| |
p_sep = NULL; /* pointer to separator */ |
| |
sep_ar_idx = -1; /* index of separator */ |
| |
sep_size = 0; /* length of separator string */ |
| |
|
| for (p_sep = NULL, sep_ar_idx = -1, sep_size = 0, i = 0; |
/* Searching first separator string (p_sep) */ |
| sep_ar[i] != NULL; i++) |
for (i = 0; sep_ar[i] != NULL; i++) { |
| if ((tmp_s = str_white_str(arg, sep_ar[i], &tmp_sep_size)) != NULL |
if ((tmp_s = str_white_str(arg, sep_ar[i], &tmp_sep_size)) != NULL |
| && (p_sep == NULL || tmp_s < p_sep)) { |
&& (p_sep == NULL || tmp_s < p_sep)) { |
| p_sep = tmp_s; |
p_sep = tmp_s; |
| sep_ar_idx = i; |
sep_ar_idx = i; |
| sep_size = tmp_sep_size; |
sep_size = tmp_sep_size; |
| } |
} |
| |
} |
| |
|
| /* Quotations processing. */ |
/* Process quotation |
| |
if is is on lower position than separator */ |
| if ((p_quote != NULL && p_sep == NULL) |
if ((p_quote != NULL && p_sep == NULL) |
| || (p_quote != NULL && p_sep != NULL && p_quote < p_sep)) { |
|| (p_quote != NULL && p_sep != NULL && p_quote < p_sep)) { |
| |
|
| register char *end_ptr, *prefix, *postfix; |
register char *end_ptr, *prefix, *postfix; |
| register int prefix_len, postfix_len; |
register int prefix_len, postfix_len; |
| |
|
| prefix = con->quote_prefix[quote_prefix_idx]; |
prefix = con->quote_prefix[quote_prefix_idx]; |
| postfix = con->quote_postfix[quote_prefix_idx]; |
postfix = con->quote_postfix[quote_prefix_idx]; |
| |
|
| if (prefix == NULL || postfix == NULL) |
if (prefix == NULL || postfix == NULL) |
| return CFG_ERROR_INTERNAL; |
return CFG_ERROR_INTERNAL; |
| |
|
| prefix_len = strlen(prefix); |
prefix_len = strlen(prefix); |
| postfix_len = strlen(postfix); |
postfix_len = strlen(postfix); |
| |
|
| memmove(p_quote, p_quote + prefix_len, |
memmove(p_quote, p_quote + prefix_len, |
| Line 792 split_multi_arg(con, arg, ar) |
|
| Line 805 split_multi_arg(con, arg, ar) |
|
| |
|
| end_ptr = strstr(p_quote, postfix); |
end_ptr = strstr(p_quote, postfix); |
| |
|
| if (end_ptr == NULL) { |
if (end_ptr == NULL) |
| return CFG_ERROR_BADQUOTE; |
return CFG_ERROR_BADQUOTE; |
| } |
|
| |
|
| memmove(end_ptr, end_ptr + postfix_len, |
memmove(end_ptr, end_ptr + postfix_len, |
| strlen(end_ptr + postfix_len) + 1); |
strlen(end_ptr + postfix_len) + 1); |
| |
|
| arg = end_ptr; |
arg = end_ptr; |
| } |
} |
| /* Separator processing. */ |
/* Separator processing otherwise */ |
| else if ((p_sep != NULL && p_quote == NULL) |
else if ((p_sep != NULL && p_quote == NULL) |
| || (p_sep != NULL && p_quote != NULL && p_sep <= p_quote)) { |
|| (p_sep != NULL && p_quote != NULL && p_sep <= p_quote)) { |
| |
|
| register char c; |
register char c; |
| |
|
| c = *p_sep; |
c = *p_sep; |
| *p_sep = '\0'; |
*p_sep = '\0'; |
| #if DEBUG |
*ar = strdyn_add_va(*ar, arg_base, NULL); |
| printf("adding <%s>, sep_char = '%c', sep_size = %d\n", |
|
| arg_base, c, sep_size); |
|
| #endif |
|
| *ar = strdyn_add_va(*ar, arg_base, NULL); |
|
| |
|
| *p_sep = c; |
*p_sep = c; |
| |
arg = arg_base = p_sep + sep_size; |
| |
|
| if (*ar == NULL) |
if (*ar == NULL) |
| return CFG_ERROR_NOMEM; |
return CFG_ERROR_NOMEM; |
| |
|
| arg_base = arg = (p_sep + sep_size); |
|
| } |
} |
| |
|
| } while (p_quote != NULL || p_sep != NULL); |
} while (p_quote != NULL || p_sep != NULL); |
| Line 831 split_multi_arg(con, arg, ar) |
|
| Line 837 split_multi_arg(con, arg, ar) |
|
| return CFG_OK; |
return CFG_OK; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| |
/* |
| |
* unquote_single_arg() |
| |
* |
| |
* Unquotes signle argument passed by reference as arg parameter. |
| |
* Returns cfg_error type and modyfies arg parameter. |
| |
*/ |
| |
|
| static int |
static int |
| unquote_single_arg(con, arg) |
unquote_single_arg(con, arg) |
| const CFG_CONTEXT con; |
const CFG_CONTEXT con; |
| char *arg; |
char *arg; |
| { /* {{{ */ |
{ /* {{{ */ |
| return CFG_OK; |
register char *p_quote; |
| } /* }}} */ |
int quote_prefix_idx; |
| |
|
| #if 0 |
do { |
| |
p_quote = strdyn_str2(arg, con->quote_prefix, "e_prefix_idx); |
| |
|
| static int unquote_single_arg(const CFG_CONTEXT con, char *arg) |
/* If beginning of quotation was found */ |
| { |
if (p_quote != NULL) { |
| register int i, arg_len; |
register char *end_ptr, *prefix, *postfix; |
| register char *p_prefix, *p_postfix; |
register int prefix_len, postfix_len; |
| |
|
| 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; |
prefix = con->quote_prefix[quote_prefix_idx]; |
| } /* }}} */ |
postfix = con->quote_postfix[quote_prefix_idx]; |
| |
|
| |
if (prefix == NULL || postfix == NULL) |
| |
return CFG_ERROR_INTERNAL; |
| |
|
| |
prefix_len = strlen(prefix); |
| |
postfix_len = strlen(postfix); |
| |
|
| |
memmove(p_quote, p_quote + prefix_len, |
| |
strlen(p_quote + prefix_len) + 1); |
| |
|
| #endif |
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; |
| |
} |
| |
} while (p_quote != NULL); |
| |
|
| |
return CFG_OK; |
| |
} /* }}} */ |
| |
|
| /* Modeline for ViM {{{ |
/* Modeline for ViM {{{ |
| * vim:set ts=4: |
* vim:set ts=4: |