| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.613 2020/10/31 09:27:19 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.614 2020/10/31 09:57:47 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.613 2020/10/31 09:27:19 rillig Exp $"); | | 132 | MAKE_RCSID("$NetBSD: var.c,v 1.614 2020/10/31 09:57:47 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 | */ |
| @@ -741,27 +741,27 @@ Var_UnExport(const char *str) | | | @@ -741,27 +741,27 @@ Var_UnExport(const char *str) |
741 | VAR_DEBUG1("Unexporting \"%s\"\n", varname); | | 741 | VAR_DEBUG1("Unexporting \"%s\"\n", varname); |
742 | if (!unexport_env && (v->flags & VAR_EXPORTED) && | | 742 | if (!unexport_env && (v->flags & VAR_EXPORTED) && |
743 | !(v->flags & VAR_REEXPORT)) | | 743 | !(v->flags & VAR_REEXPORT)) |
744 | unsetenv(v->name); | | 744 | unsetenv(v->name); |
745 | v->flags &= ~(unsigned)(VAR_EXPORTED | VAR_REEXPORT); | | 745 | v->flags &= ~(unsigned)(VAR_EXPORTED | VAR_REEXPORT); |
746 | | | 746 | |
747 | /* | | 747 | /* |
748 | * If we are unexporting a list, | | 748 | * If we are unexporting a list, |
749 | * remove each one from .MAKE.EXPORTED. | | 749 | * remove each one from .MAKE.EXPORTED. |
750 | * If we are removing them all, | | 750 | * If we are removing them all, |
751 | * just delete .MAKE.EXPORTED below. | | 751 | * just delete .MAKE.EXPORTED below. |
752 | */ | | 752 | */ |
753 | if (varnames == str) { | | 753 | if (varnames == str) { |
754 | /* XXX: v->name is injected without escaping it */ | | 754 | /* XXX: v->name is injected without escaping it */ |
755 | char *expr = str_concat3("${" MAKE_EXPORTED ":N", v->name, "}"); | | 755 | char *expr = str_concat3("${" MAKE_EXPORTED ":N", v->name, "}"); |
756 | char *cp; | | 756 | char *cp; |
757 | (void)Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES, &cp); | | 757 | (void)Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES, &cp); |
758 | /* TODO: handle errors */ | | 758 | /* TODO: handle errors */ |
759 | Var_Set(MAKE_EXPORTED, cp, VAR_GLOBAL); | | 759 | Var_Set(MAKE_EXPORTED, cp, VAR_GLOBAL); |
760 | free(cp); | | 760 | free(cp); |
761 | free(expr); | | 761 | free(expr); |
762 | } | | 762 | } |
763 | } | | 763 | } |
764 | Words_Free(words); | | 764 | Words_Free(words); |
765 | if (varnames != str) { | | 765 | if (varnames != str) { |
766 | Var_Delete(MAKE_EXPORTED, VAR_GLOBAL); | | 766 | Var_Delete(MAKE_EXPORTED, VAR_GLOBAL); |
767 | free(varnames_freeIt); | | 767 | free(varnames_freeIt); |
| @@ -937,27 +937,27 @@ Var_Append(const char *name, const char | | | @@ -937,27 +937,27 @@ Var_Append(const char *name, const char |
937 | "name expands to empty string - ignored\n", | | 937 | "name expands to empty string - ignored\n", |
938 | unexpanded_name, val); | | 938 | unexpanded_name, val); |
939 | free(name_freeIt); | | 939 | free(name_freeIt); |
940 | return; | | 940 | return; |
941 | } | | 941 | } |
942 | } | | 942 | } |
943 | | | 943 | |
944 | v = VarFind(name, ctxt, ctxt == VAR_GLOBAL); | | 944 | v = VarFind(name, ctxt, ctxt == VAR_GLOBAL); |
945 | | | 945 | |
946 | if (v == NULL) { | | 946 | if (v == NULL) { |
947 | /* XXX: name is expanded for the second time */ | | 947 | /* XXX: name is expanded for the second time */ |
948 | Var_Set(name, val, ctxt); | | 948 | Var_Set(name, val, ctxt); |
949 | } else if (v->flags & VAR_READONLY) { | | 949 | } else if (v->flags & VAR_READONLY) { |
950 | VAR_DEBUG1("Ignoring append to %s since it is read-only\n", name); | | 950 | VAR_DEBUG1("Ignoring append to %s since it is read-only\n", name); |
951 | } else if (ctxt == VAR_CMDLINE || !(v->flags & VAR_FROM_CMD)) { | | 951 | } else if (ctxt == VAR_CMDLINE || !(v->flags & VAR_FROM_CMD)) { |
952 | Buf_AddByte(&v->val, ' '); | | 952 | Buf_AddByte(&v->val, ' '); |
953 | Buf_AddStr(&v->val, val); | | 953 | Buf_AddStr(&v->val, val); |
954 | | | 954 | |
955 | VAR_DEBUG3("%s:%s = %s\n", | | 955 | VAR_DEBUG3("%s:%s = %s\n", |
956 | ctxt->name, name, Buf_GetAll(&v->val, NULL)); | | 956 | ctxt->name, name, Buf_GetAll(&v->val, NULL)); |
957 | | | 957 | |
958 | if (v->flags & VAR_FROM_ENV) { | | 958 | if (v->flags & VAR_FROM_ENV) { |
959 | HashEntry *h; | | 959 | HashEntry *h; |
960 | | | 960 | |
961 | /* | | 961 | /* |
962 | * If the original variable came from the environment, we | | 962 | * If the original variable came from the environment, we |
963 | * have to install it in the global context (we could place | | 963 | * have to install it in the global context (we could place |