Changeset 503 for trunk/src/gmake/expand.c
- Timestamp:
- Sep 15, 2006, 7:09:38 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/expand.c
r281 r503 1 1 /* Variable expansion functions for GNU Make. 2 Copyright (C) 1988, 89, 91, 92, 93, 95 Free Software Foundation, Inc. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 4 Foundation, Inc. 3 5 This file is part of GNU Make. 4 6 5 GNU Make is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2, or (at your option) 8 any later version. 9 10 GNU Make is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with GNU Make; see the file COPYING. If not, write to 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 Boston, MA 02111-1307, USA. */ 7 GNU Make is free software; you can redistribute it and/or modify it under the 8 terms of the GNU General Public License as published by the Free Software 9 Foundation; either version 2, or (at your option) any later version. 10 11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 13 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along with 16 GNU Make; see the file COPYING. If not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 19 18 20 19 #include "make.h" … … 27 26 #include "variable.h" 28 27 #include "rule.h" 28 29 /* Initially, any errors reported when expanding strings will be reported 30 against the file where the error appears. */ 31 const struct floc **expanding_var = &reading_file; 29 32 30 33 /* The next two describe the variable output buffer. … … 98 101 { 99 102 char *value; 103 const struct floc *this_var; 104 const struct floc **saved_varp; 100 105 struct variable_set_list *save = 0; 101 106 int set_reading = 0; 102 107 108 /* Don't install a new location if this location is empty. 109 This can happen for command-line variables, builtin variables, etc. */ 110 saved_varp = expanding_var; 111 if (v->fileinfo.filenm) 112 { 113 this_var = &v->fileinfo; 114 expanding_var = &this_var; 115 } 116 117 /* If we have no other file-reading context, use the variable's context. */ 118 if (!reading_file) 119 { 120 set_reading = 1; 121 reading_file = &v->fileinfo; 122 } 123 103 124 if (v->expanding) 104 125 { 105 126 if (!v->exp_count) 106 127 /* Expanding V causes infinite recursion. Lose. */ 107 fatal ( reading_file,128 fatal (*expanding_var, 108 129 _("Recursive variable `%s' references itself (eventually)"), 109 130 v->name); … … 115 136 save = current_variable_set_list; 116 137 current_variable_set_list = file->variables; 117 }118 119 /* If we have no other file-reading context, use the variable's context. */120 if (!reading_file)121 {122 set_reading = 1;123 reading_file = &v->fileinfo;124 138 } 125 139 … … 133 147 if (set_reading) 134 148 reading_file = 0; 149 135 150 if (file) 136 151 current_variable_set_list = save; 152 153 expanding_var = saved_varp; 137 154 138 155 return value; … … 208 225 p1 = strchr (p, '$'); 209 226 210 o = variable_buffer_output (o, p, p1 != 0 ? p1 - p: strlen (p) + 1);227 o = variable_buffer_output (o, p, p1 != 0 ? (unsigned int)(p1 - p) : strlen (p) + 1); 211 228 212 229 if (p1 == 0) … … 249 266 if (end == 0) 250 267 /* Unterminated variable reference. */ 251 fatal ( reading_file, _("unterminated variable reference"));268 fatal (*expanding_var, _("unterminated variable reference")); 252 269 p1 = lindex (beg, end, '$'); 253 270 if (p1 != 0) … … 375 392 /* A $ followed by a random char is a variable reference: 376 393 $a is equivalent to $(a). */ 377 { 378 /* We could do the expanding here, but this way 379 avoids code repetition at a small performance cost. */ 380 char name[5]; 381 name[0] = '$'; 382 name[1] = '('; 383 name[2] = *p; 384 name[3] = ')'; 385 name[4] = '\0'; 386 p1 = allocated_variable_expand (name); 387 o = variable_buffer_output (o, p1, strlen (p1)); 388 free (p1); 389 } 394 o = reference_variable (o, p, 1); 390 395 391 396 break; … … 503 508 buf = variable_buffer_output (buf, " ", 1); 504 509 505 return variable_buffer_output (buf, v->value, strlen (v->value)); 510 /* Either expand it or copy it, depending. */ 511 if (! v->recursive) 512 return variable_buffer_output (buf, v->value, strlen (v->value)); 513 514 buf = variable_expand_string (buf, v->value, strlen (v->value)); 515 return (buf + strlen (buf)); 506 516 } 507 517 … … 510 520 allocated_variable_append (const struct variable *v) 511 521 { 512 char *val , *retval;522 char *val; 513 523 514 524 /* Construct the appended variable value. */ … … 526 536 variable_buffer_length = olen; 527 537 528 /* Now expand it and return that. */ 529 530 retval = allocated_variable_expand (val); 531 532 free (val); 533 return retval; 538 return val; 534 539 } 535 540
Note:
See TracChangeset
for help on using the changeset viewer.