Changeset 1606 in kBuild
- Timestamp:
- May 8, 2008 2:44:58 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/expand.c
r1536 r1606 611 611 append_expanded_string_to_variable (struct variable *v, const char *value) 612 612 { 613 static char const empty_string[] = ""; 614 unsigned int original_value_length = v->value_length; 613 615 char *p; 614 616 615 /* switch the variable buffer to the variable value buffer. */617 /* Switch the variable buffer to the variable value buffer. */ 616 618 char *saved_buffer = variable_buffer; 617 619 unsigned int saved_buffer_length = variable_buffer_length; … … 619 621 variable_buffer_length = v->value_alloc_len; 620 622 621 /* skip the current value and start appending a space and the expanded string. */ 622 p = v->value + v->value_length; 623 if (v->value_length != 0) 623 /* Mark the variable as being expanding. */ 624 if (v->value_alloc_len == -42) 625 fatal (*expanding_var, _("var=%s"), v->name); 626 assert (v->value_alloc_len >= 0); 627 v->value_alloc_len = -42; 628 629 /* Skip the current value and start appending a '\0' / space before 630 expanding the string so recursive references are handled correctly. 631 Alternatively, if it's an empty value, replace the value with a fixed 632 empty string. */ 633 p = v->value + original_value_length; 634 if (original_value_length) 635 { 624 636 p = variable_buffer_output (p, " ", 1); 637 p[-1] = '\0'; 638 } 639 else 640 v->value = (char *)&empty_string[0]; 625 641 p = variable_expand_string (p, value, (long)-1); 626 642 627 /* update the variable. (The variable_expand_string return is annoying!) */ 643 /* Replace the '\0' with the space separator. */ 644 if (original_value_length) 645 { 646 assert (variable_buffer[original_value_length] == '\0'); 647 variable_buffer[original_value_length] = ' '; 648 } 649 else 650 { 651 assert (v->value == (char *)&empty_string[0]); 652 assert (empty_string[0] == '\0'); 653 } 654 655 /* Update the variable. (mind the variable_expand_string() return) */ 628 656 p = strchr (p, '\0'); 629 657 v->value = variable_buffer; … … 631 659 v->value_alloc_len = variable_buffer_length; 632 660 633 /* restore the variable buffer. */661 /* Restore the variable buffer. */ 634 662 variable_buffer = saved_buffer; 635 663 variable_buffer_length = saved_buffer_length;
Note:
See TracChangeset
for help on using the changeset viewer.