From 0806a403d65ef6a7f16e2c17aa8286100ebad5d7 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Wed, 15 Feb 2006 23:54:42 +0000 Subject: Fix Savannah bug #106: keep separate track of which variable we are expanding, and use that info when generating error messages instead of the file info, where appropriate. --- expand.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'expand.c') diff --git a/expand.c b/expand.c index 82e12f7..d25afef 100644 --- a/expand.c +++ b/expand.c @@ -26,6 +26,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "variable.h" #include "rule.h" +/* Initially, any errors reported when expanding strings will be reported + against the file where the error appears. */ +const struct floc **expanding_var = &reading_file; + /* The next two describe the variable output buffer. This buffer is used to hold the variable-expansion of a line of the makefile. It is made bigger with realloc whenever it is too small. @@ -95,14 +99,25 @@ char * recursively_expand_for_file (struct variable *v, struct file *file) { char *value; - struct variable_set_list *save = 0; + const struct floc *this_var; + const struct floc **saved_varp; + struct variable_set_list *save; int set_reading = 0; + /* Don't install a new location if this location is empty. + This can happen for command-line variables, builtin variables, etc. */ + saved_varp = expanding_var; + if (v->fileinfo.filenm) + { + this_var = &v->fileinfo; + expanding_var = &this_var; + } + if (v->expanding) { if (!v->exp_count) /* Expanding V causes infinite recursion. Lose. */ - fatal (reading_file, + fatal (this_var, _("Recursive variable `%s' references itself (eventually)"), v->name); --v->exp_count; @@ -118,7 +133,7 @@ recursively_expand_for_file (struct variable *v, struct file *file) if (!reading_file) { set_reading = 1; - reading_file = &v->fileinfo; + reading_file = this_var; } v->expanding = 1; @@ -130,9 +145,12 @@ recursively_expand_for_file (struct variable *v, struct file *file) if (set_reading) reading_file = 0; + if (file) current_variable_set_list = save; + expanding_var = saved_varp; + return value; } @@ -245,7 +263,7 @@ variable_expand_string (char *line, char *string, long length) end = strchr (beg, closeparen); if (end == 0) /* Unterminated variable reference. */ - fatal (reading_file, _("unterminated variable reference")); + fatal (*expanding_var, _("unterminated variable reference")); p1 = lindex (beg, end, '$'); if (p1 != 0) { @@ -371,19 +389,7 @@ variable_expand_string (char *line, char *string, long length) /* A $ followed by a random char is a variable reference: $a is equivalent to $(a). */ - { - /* We could do the expanding here, but this way - avoids code repetition at a small performance cost. */ - char name[5]; - name[0] = '$'; - name[1] = '('; - name[2] = *p; - name[3] = ')'; - name[4] = '\0'; - p1 = allocated_variable_expand (name); - o = variable_buffer_output (o, p1, strlen (p1)); - free (p1); - } + o = reference_variable (o, p, 1); break; } -- cgit v1.2.3