| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.603 2020/10/30 16:48:58 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.604 2020/10/30 16:54:38 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.603 2020/10/30 16:48:58 rillig Exp $"); | | 132 | MAKE_RCSID("$NetBSD: var.c,v 1.604 2020/10/30 16:54:38 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 | */ |
| @@ -268,30 +268,30 @@ typedef enum VarExportFlags { | | | @@ -268,30 +268,30 @@ typedef enum VarExportFlags { |
268 | /* | | 268 | /* |
269 | * We pass this to Var_Export when doing the initial export | | 269 | * We pass this to Var_Export when doing the initial export |
270 | * or after updating an exported var. | | 270 | * or after updating an exported var. |
271 | */ | | 271 | */ |
272 | VAR_EXPORT_PARENT = 0x01, | | 272 | VAR_EXPORT_PARENT = 0x01, |
273 | /* | | 273 | /* |
274 | * We pass this to Var_Export1 to tell it to leave the value alone. | | 274 | * We pass this to Var_Export1 to tell it to leave the value alone. |
275 | */ | | 275 | */ |
276 | VAR_EXPORT_LITERAL = 0x02 | | 276 | VAR_EXPORT_LITERAL = 0x02 |
277 | } VarExportFlags; | | 277 | } VarExportFlags; |
278 | | | 278 | |
279 | /* Flags for pattern matching in the :S and :C modifiers */ | | 279 | /* Flags for pattern matching in the :S and :C modifiers */ |
280 | typedef enum VarPatternFlags { | | 280 | typedef enum VarPatternFlags { |
281 | VARP_SUB_GLOBAL = 0x01, /* Apply substitution globally */ | | 281 | VARP_SUB_GLOBAL = 0x01, /* Replace as often as possible ('g') */ |
282 | VARP_SUB_ONE = 0x02, /* Apply substitution to one word */ | | 282 | VARP_SUB_ONE = 0x02, /* Replace only once ('1') */ |
283 | VARP_ANCHOR_START = 0x04, /* Match at start of word */ | | 283 | VARP_ANCHOR_START = 0x04, /* Match at start of word ('^') */ |
284 | VARP_ANCHOR_END = 0x08 /* Match at end of word */ | | 284 | VARP_ANCHOR_END = 0x08 /* Match at end of word ('$') */ |
285 | } VarPatternFlags; | | 285 | } VarPatternFlags; |
286 | | | 286 | |
287 | static Var * | | 287 | static Var * |
288 | VarNew(const char *name, void *name_freeIt, const char *value, VarFlags flags) | | 288 | VarNew(const char *name, void *name_freeIt, const char *value, VarFlags flags) |
289 | { | | 289 | { |
290 | size_t value_len = strlen(value); | | 290 | size_t value_len = strlen(value); |
291 | Var *var = bmake_malloc(sizeof *var); | | 291 | Var *var = bmake_malloc(sizeof *var); |
292 | var->name = name; | | 292 | var->name = name; |
293 | var->name_freeIt = name_freeIt; | | 293 | var->name_freeIt = name_freeIt; |
294 | Buf_Init(&var->val, value_len + 1); | | 294 | Buf_Init(&var->val, value_len + 1); |
295 | Buf_AddBytes(&var->val, value, value_len); | | 295 | Buf_AddBytes(&var->val, value, value_len); |
296 | var->flags = flags; | | 296 | var->flags = flags; |
297 | return var; | | 297 | return var; |