Index: ossp-pkg/var/TODO RCS File: /v/ossp/cvs/ossp-pkg/var/Attic/TODO,v rcsdiff -q -kk '-r1.18' '-r1.19' -u '/v/ossp/cvs/ossp-pkg/var/Attic/TODO,v' 2>/dev/null --- TODO 2002/02/28 11:54:25 1.18 +++ TODO 2002/02/28 12:10:33 1.19 @@ -19,9 +19,6 @@ o document exception handling - o add internal library context and move initialization and configuration - into this context. - o additional feature: functions via callback. ${foo:F:F} calls callback for bar with result of foo expansion and then callback for quux with the result returned from Index: ossp-pkg/var/var.c RCS File: /v/ossp/cvs/ossp-pkg/var/var.c,v rcsdiff -q -kk '-r1.67' '-r1.68' -u '/v/ossp/cvs/ossp-pkg/var/var.c,v' 2>/dev/null --- var.c 2002/02/28 11:59:29 1.67 +++ var.c 2002/02/28 12:10:33 1.68 @@ -1952,51 +1952,6 @@ return rc; } -static var_rc_t internal_expand( - const char *input_buf, size_t input_len, - char **result, size_t *result_len, - var_cb_value_t lookup, void *lookup_context, - const var_syntax_t *config, char_class_t nameclass, int force_expand) -{ - var_rc_t rc; - tokenbuf_t output; - - /* Set the result pointer to the begining of the input buffer so - that it is correctly initialized in case we fail with an error. */ - *result = (char *)input_buf; - - /* Call the parser. */ - tokenbuf_init(&output); - rc = input(input_buf, input_buf + input_len, config, nameclass, - lookup, lookup_context, force_expand, &output, 0, 0, NULL); - - /* Post-process output */ - if (rc >= 0) { - /* always NUL-terminate output for convinience reasons */ - if (!tokenbuf_append(&output, "\0", 1)) { - tokenbuf_free(&output); - return VAR_ERR_OUT_OF_MEMORY; - } - output.end--; - - /* Provide results */ - *result = (char *)output.begin; - if (result_len != NULL) - *result_len = output.end - output.begin; - - /* canonify all positive answers */ - rc = VAR_OK; - } - else { - /* Provide error results */ - *result = (char *)input_buf; - if (result_len != NULL) - *result_len = output.end - output.begin; - } - - return VAR_RC(rc); -} - /* ------------------------------------------------------------------ */ var_rc_t @@ -2144,21 +2099,56 @@ char **dst_ptr, size_t *dst_len, int force_expand) { - /* var_expand_t ctx; */ + var_expand_t ctx; + tokenbuf_t output; var_rc_t rc; /* argument sanity checks */ if (var == NULL || src_ptr == NULL || src_len == 0 || dst_ptr == NULL) return VAR_RC(VAR_ERR_INVALID_ARGUMENT); - /* ctx.force_expand = force_expand; */ - rc = internal_expand(src_ptr, src_len, dst_ptr, dst_len, - var->cb_value_fct, var->cb_value_ctx, - &var->syntax, var->syntax_nameclass, force_expand); - return rc; + /* prepare internal expansion context */ + ctx.force_expand = force_expand; + + /* set the dst_ptr pointer to the src_ptr so that it is correctly + initialized in case we fail with an error later. */ + *dst_ptr = (char *)src_ptr; + + /* call the parsing */ + tokenbuf_init(&output); + rc = input(src_ptr, src_ptr + src_len, + &var->syntax, var->syntax_nameclass, + var->cb_value_fct, var->cb_value_ctx, + ctx.force_expand, &output, 0, 0, NULL); + + /* post-process output */ + if (rc >= 0) { + /* always NUL-terminate output for convinience reasons */ + if (!tokenbuf_append(&output, "\0", 1)) { + tokenbuf_free(&output); + return VAR_RC(VAR_ERR_OUT_OF_MEMORY); + } + output.end--; + + /* provide dst_ptrs */ + *dst_ptr = (char *)output.begin; + if (dst_len != NULL) + *dst_len = output.end - output.begin; + + /* canonify all positive answers */ + rc = VAR_OK; + } + else { + /* provide error dst_ptr */ + *dst_ptr = (char *)src_ptr; + if (dst_len != NULL) + *dst_len = output.end - output.begin; + } + + return VAR_RC(rc); } -static char *var_errors[] = { +static const char *var_errors[] = { "everything ok", /* VAR_OK = 0 */ "incomplete named character", /* VAR_ERR_INCOMPLETE_NAMED_CHARACTER */ "incomplete hexadecimal value", /* VAR_ERR_INCOMPLETE_HEX */ @@ -2212,7 +2202,7 @@ if (rc < 0 || rc >= sizeof(var_errors) / sizeof(char *)) *str = "unknown error"; else - *str = var_errors[rc]; + *str = (char *)var_errors[rc]; return VAR_OK; }