| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.602 2020/10/30 16:45:37 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.603 2020/10/30 16:48:58 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | | 4 | * Copyright (c) 1988, 1989, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -119,27 +119,27 @@ | | | @@ -119,27 +119,27 @@ |
119 | #include <sys/types.h> | | 119 | #include <sys/types.h> |
120 | #include <regex.h> | | 120 | #include <regex.h> |
121 | #endif | | 121 | #endif |
122 | #include <inttypes.h> | | 122 | #include <inttypes.h> |
123 | #include <limits.h> | | 123 | #include <limits.h> |
124 | #include <time.h> | | 124 | #include <time.h> |
125 | | | 125 | |
126 | #include "make.h" | | 126 | #include "make.h" |
127 | #include "dir.h" | | 127 | #include "dir.h" |
128 | #include "job.h" | | 128 | #include "job.h" |
129 | #include "metachar.h" | | 129 | #include "metachar.h" |
130 | | | 130 | |
131 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ | | 131 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ |
132 | MAKE_RCSID("$NetBSD: var.c,v 1.602 2020/10/30 16:45:37 rillig Exp $"); | | 132 | MAKE_RCSID("$NetBSD: var.c,v 1.603 2020/10/30 16:48:58 rillig Exp $"); |
133 | | | 133 | |
134 | #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) | | 134 | #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) |
135 | #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) | | 135 | #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) |
136 | #define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) | | 136 | #define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) |
137 | #define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) | | 137 | #define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) |
138 | | | 138 | |
139 | ENUM_FLAGS_RTTI_3(VarEvalFlags, | | 139 | ENUM_FLAGS_RTTI_3(VarEvalFlags, |
140 | VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); | | 140 | VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); |
141 | | | 141 | |
142 | /* | | 142 | /* |
143 | * This lets us tell if we have replaced the original environ | | 143 | * This lets us tell if we have replaced the original environ |
144 | * (which we cannot free). | | 144 | * (which we cannot free). |
145 | */ | | 145 | */ |
| @@ -592,32 +592,31 @@ Var_ExportVars(void) | | | @@ -592,32 +592,31 @@ Var_ExportVars(void) |
592 | * recursion - but each uses a different name. | | 592 | * recursion - but each uses a different name. |
593 | * We allow the makefiles to update MAKELEVEL and ensure | | 593 | * We allow the makefiles to update MAKELEVEL and ensure |
594 | * children see a correctly incremented value. | | 594 | * children see a correctly incremented value. |
595 | */ | | 595 | */ |
596 | char tmp[BUFSIZ]; | | 596 | char tmp[BUFSIZ]; |
597 | snprintf(tmp, sizeof(tmp), "%d", makelevel + 1); | | 597 | snprintf(tmp, sizeof(tmp), "%d", makelevel + 1); |
598 | setenv(MAKE_LEVEL_ENV, tmp, 1); | | 598 | setenv(MAKE_LEVEL_ENV, tmp, 1); |
599 | | | 599 | |
600 | if (var_exportedVars == VAR_EXPORTED_NONE) | | 600 | if (var_exportedVars == VAR_EXPORTED_NONE) |
601 | return; | | 601 | return; |
602 | | | 602 | |
603 | if (var_exportedVars == VAR_EXPORTED_ALL) { | | 603 | if (var_exportedVars == VAR_EXPORTED_ALL) { |
604 | HashIter hi; | | 604 | HashIter hi; |
605 | HashEntry *he; | | | |
606 | | | 605 | |
607 | /* Ouch! Exporting all variables at once is crazy... */ | | 606 | /* Ouch! Exporting all variables at once is crazy... */ |
608 | HashIter_Init(&hi, &VAR_GLOBAL->context); | | 607 | HashIter_Init(&hi, &VAR_GLOBAL->context); |
609 | while ((he = HashIter_Next(&hi)) != NULL) { | | 608 | while (HashIter_Next(&hi) != NULL) { |
610 | Var *var = HashEntry_Get(he); | | 609 | Var *var = hi.entry->value; |
611 | Var_Export1(var->name, 0); | | 610 | Var_Export1(var->name, 0); |
612 | } | | 611 | } |
613 | return; | | 612 | return; |
614 | } | | 613 | } |
615 | | | 614 | |
616 | (void)Var_Subst("${" MAKE_EXPORTED ":O:u}", VAR_GLOBAL, VARE_WANTRES, &val); | | 615 | (void)Var_Subst("${" MAKE_EXPORTED ":O:u}", VAR_GLOBAL, VARE_WANTRES, &val); |
617 | /* TODO: handle errors */ | | 616 | /* TODO: handle errors */ |
618 | if (*val) { | | 617 | if (*val) { |
619 | Words words = Str_Words(val, FALSE); | | 618 | Words words = Str_Words(val, FALSE); |
620 | size_t i; | | 619 | size_t i; |
621 | | | 620 | |
622 | for (i = 0; i < words.len; i++) | | 621 | for (i = 0; i < words.len; i++) |
623 | Var_Export1(words.words[i], 0); | | 622 | Var_Export1(words.words[i], 0); |
| @@ -3883,34 +3882,33 @@ Var_End(void) | | | @@ -3883,34 +3882,33 @@ Var_End(void) |
3883 | | | 3882 | |
3884 | void | | 3883 | void |
3885 | Var_Stats(void) | | 3884 | Var_Stats(void) |
3886 | { | | 3885 | { |
3887 | HashTable_DebugStats(&VAR_GLOBAL->context, "VAR_GLOBAL"); | | 3886 | HashTable_DebugStats(&VAR_GLOBAL->context, "VAR_GLOBAL"); |
3888 | } | | 3887 | } |
3889 | | | 3888 | |
3890 | /* Print all variables in a context, sorted by name. */ | | 3889 | /* Print all variables in a context, sorted by name. */ |
3891 | void | | 3890 | void |
3892 | Var_Dump(GNode *ctxt) | | 3891 | Var_Dump(GNode *ctxt) |
3893 | { | | 3892 | { |
3894 | Vector /* of const char * */ vec; | | 3893 | Vector /* of const char * */ vec; |
3895 | HashIter hi; | | 3894 | HashIter hi; |
3896 | HashEntry *he; | | | |
3897 | size_t i; | | 3895 | size_t i; |
3898 | const char **varnames; | | 3896 | const char **varnames; |
3899 | | | 3897 | |
3900 | Vector_Init(&vec, sizeof(const char *)); | | 3898 | Vector_Init(&vec, sizeof(const char *)); |
3901 | | | 3899 | |
3902 | HashIter_Init(&hi, &ctxt->context); | | 3900 | HashIter_Init(&hi, &ctxt->context); |
3903 | while ((he = HashIter_Next(&hi)) != NULL) | | 3901 | while (HashIter_Next(&hi) != NULL) |
3904 | *(const char **)Vector_Push(&vec) = he->key; | | 3902 | *(const char **)Vector_Push(&vec) = hi.entry->key; |
3905 | varnames = vec.items; | | 3903 | varnames = vec.items; |
3906 | | | 3904 | |
3907 | qsort(varnames, vec.len, sizeof varnames[0], str_cmp_asc); | | 3905 | qsort(varnames, vec.len, sizeof varnames[0], str_cmp_asc); |
3908 | | | 3906 | |
3909 | for (i = 0; i < vec.len; i++) { | | 3907 | for (i = 0; i < vec.len; i++) { |
3910 | const char *varname = varnames[i]; | | 3908 | const char *varname = varnames[i]; |
3911 | Var *var = HashTable_FindValue(&ctxt->context, varname); | | 3909 | Var *var = HashTable_FindValue(&ctxt->context, varname); |
3912 | debug_printf("%-16s = %s\n", varname, Buf_GetAll(&var->val, NULL)); | | 3910 | debug_printf("%-16s = %s\n", varname, Buf_GetAll(&var->val, NULL)); |
3913 | } | | 3911 | } |
3914 | | | 3912 | |
3915 | Vector_Done(&vec); | | 3913 | Vector_Done(&vec); |
3916 | } | | 3914 | } |