Changeset 503 for trunk/src/gmake/variable.c
- Timestamp:
- Sep 15, 2006, 7:09:38 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/variable.c
r431 r503 1 1 /* Internals of variables for GNU Make. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 3 2002 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. 4 5 This file is part of GNU Make. 5 6 6 GNU Make is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Make is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Make; see the file COPYING. If not, write to 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 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. */ 20 18 21 19 #include "make.h" 20 21 #include <assert.h> 22 22 23 #include "dep.h" 23 24 #include "filedef.h" … … 618 619 initialize_file_variables (struct file *file, int reading) 619 620 { 620 registerstruct variable_set_list *l = file->variables;621 struct variable_set_list *l = file->variables; 621 622 622 623 if (l == 0) … … 714 715 and free all its storage. */ 715 716 716 static void717 free_variable_name_and_value (const void *item)718 {719 struct variable *v = (struct variable *) item;720 free (v->name);721 free (v->value);722 }723 724 void725 pop_variable_scope (void)726 {727 struct variable_set_list *setlist = current_variable_set_list;728 struct variable_set *set = setlist->set;729 730 current_variable_set_list = setlist->next;731 free ((char *) setlist);732 733 hash_map (&set->table, free_variable_name_and_value);734 hash_free (&set->table, 1);735 736 free ((char *) set);737 }738 739 717 struct variable_set_list * 740 718 create_new_variable_set (void) … … 755 733 } 756 734 757 /* Create a new variable set and push it on the current setlist. */ 735 static void 736 free_variable_name_and_value (const void *item) 737 { 738 struct variable *v = (struct variable *) item; 739 free (v->name); 740 free (v->value); 741 } 742 743 void 744 free_variable_set (struct variable_set_list *list) 745 { 746 hash_map (&list->set->table, free_variable_name_and_value); 747 hash_free (&list->set->table, 1); 748 free ((char *) list->set); 749 free ((char *) list); 750 } 751 752 /* Create a new variable set and push it on the current setlist. 753 If we're pushing a global scope (that is, the current scope is the global 754 scope) then we need to "push" it the other way: file variable sets point 755 directly to the global_setlist so we need to replace that with the new one. 756 */ 758 757 759 758 struct variable_set_list * 760 759 push_new_variable_scope (void) 761 760 { 762 return (current_variable_set_list = create_new_variable_set()); 761 current_variable_set_list = create_new_variable_set(); 762 if (current_variable_set_list->next == &global_setlist) 763 { 764 /* It was the global, so instead of new -> &global we want to replace 765 &global with the new one and have &global -> new, with current still 766 pointing to &global */ 767 struct variable_set *set = current_variable_set_list->set; 768 current_variable_set_list->set = global_setlist.set; 769 global_setlist.set = set; 770 current_variable_set_list->next = global_setlist.next; 771 global_setlist.next = current_variable_set_list; 772 current_variable_set_list = &global_setlist; 773 } 774 return (current_variable_set_list); 775 } 776 777 void 778 pop_variable_scope (void) 779 { 780 struct variable_set_list *setlist; 781 struct variable_set *set; 782 783 /* Can't call this if there's no scope to pop! */ 784 assert(current_variable_set_list->next != NULL); 785 786 if (current_variable_set_list != &global_setlist) 787 { 788 /* We're not pointing to the global setlist, so pop this one. */ 789 setlist = current_variable_set_list; 790 set = setlist->set; 791 current_variable_set_list = setlist->next; 792 } 793 else 794 { 795 /* This set is the one in the global_setlist, but there is another global 796 set beyond that. We want to copy that set to global_setlist, then 797 delete what used to be in global_setlist. */ 798 setlist = global_setlist.next; 799 set = global_setlist.set; 800 global_setlist.set = setlist->set; 801 global_setlist.next = setlist->next; 802 } 803 804 /* Free the one we no longer need. */ 805 free ((char *) setlist); 806 hash_map (&set->table, free_variable_name_and_value); 807 hash_free (&set->table, 1); 808 free ((char *) set); 763 809 } 764 810 … … 796 842 struct variable_set_list *setlist1) 797 843 { 798 register struct variable_set_list *list0= *setlist0;844 struct variable_set_list *to = *setlist0; 799 845 struct variable_set_list *last0 = 0; 800 846 801 while (setlist1 != 0 && list0 != 0) 802 { 803 struct variable_set_list *next = setlist1; 804 setlist1 = setlist1->next; 805 806 merge_variable_sets (list0->set, next->set); 807 808 last0 = list0; 809 list0 = list0->next; 810 } 811 812 if (setlist1 != 0) 847 /* If there's nothing to merge, stop now. */ 848 if (!setlist1) 849 return; 850 851 /* This loop relies on the fact that all setlists terminate with the global 852 setlist (before NULL). If that's not true, arguably we SHOULD die. */ 853 if (to) 854 while (setlist1 != &global_setlist && to != &global_setlist) 855 { 856 struct variable_set_list *from = setlist1; 857 setlist1 = setlist1->next; 858 859 merge_variable_sets (to->set, from->set); 860 861 last0 = to; 862 to = to->next; 863 } 864 865 if (setlist1 != &global_setlist) 813 866 { 814 867 if (last0 == 0) … … 1310 1363 #endif /* __MSDOS__ */ 1311 1364 #ifdef WINDOWS32 1312 if ((origin == o_file || origin == o_override) && streq (varname, "SHELL")) 1365 if ((origin == o_file || origin == o_override || origin == o_command) 1366 && streq (varname, "SHELL")) 1313 1367 { 1314 1368 extern char *default_shell;
Note:
See TracChangeset
for help on using the changeset viewer.