--- var.c 2002/03/06 10:05:10 1.80
+++ var.c 2002/03/06 10:18:19 1.81
@@ -152,6 +152,24 @@
return;
}
+static int
+tokenbuf_isundef(
+ tokenbuf_t *buf)
+{
+ if (buf->begin == NULL && buf->end == NULL)
+ return 1;
+ return 0;
+}
+
+static int
+tokenbuf_isempty(
+ tokenbuf_t *buf)
+{
+ if (buf->begin == buf->end)
+ return 1;
+ return 0;
+}
+
static void
tokenbuf_set(
tokenbuf_t *buf, const char *begin, const char *end, size_t buffer_size)
@@ -1252,7 +1270,9 @@
goto error_return;
}
p += rc;
- if (data->begin != NULL && data->begin == data->end) {
+ if (tokenbuf_isundef(data))
+ tokenbuf_move(&tmptokbuf, data);
+ else if (tokenbuf_isempty(data)) {
tokenbuf_free(data);
tokenbuf_move(&tmptokbuf, data);
}
@@ -1823,12 +1843,8 @@
rc = lookup_value(var, ctx,
name.begin, name.end-name.begin, idx,
&data, &len, &buffer_size);
- if (rc == VAR_ERR_UNDEFINED_VARIABLE) {
- if (ctx->force_expand)
- goto error_return;
- tokenbuf_set(result, begin - 1, p, 0);
- failed = 1;
- }
+ if (rc == VAR_ERR_UNDEFINED_VARIABLE)
+ tokenbuf_init(result); /* delayed handling of undefined variable */
else if (rc < 0)
goto error_return;
else
@@ -1841,6 +1857,7 @@
goahead:
if (p[-1] == ':') {
tokenbuf_free(&tmp);
+ tokenbuf_init(&tmp);
p--;
while (p != end && *p == ':') {
p++;
@@ -1863,6 +1880,16 @@
result->end++;
}
+ /* lazy handling of undefined variable */
+ if (!failed && tokenbuf_isundef(result)) {
+ if (ctx->force_expand) {
+ rc = VAR_ERR_UNDEFINED_VARIABLE;
+ goto error_return;
+ }
+ else
+ tokenbuf_set(result, begin - 1, p, 0);
+ }
+
/* return successfully */
tokenbuf_free(&name);
tokenbuf_free(&tmp);
|