| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.628 2020/10/31 18:14:59 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.629 2020/10/31 18:17:08 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.628 2020/10/31 18:14:59 rillig Exp $"); | | 132 | MAKE_RCSID("$NetBSD: var.c,v 1.629 2020/10/31 18:17:08 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 | */ |
| @@ -1637,27 +1637,27 @@ static char * | | | @@ -1637,27 +1637,27 @@ static char * |
1637 | VarQuote(const char *str, Boolean quoteDollar) | | 1637 | VarQuote(const char *str, Boolean quoteDollar) |
1638 | { | | 1638 | { |
1639 | Buffer buf; | | 1639 | Buffer buf; |
1640 | Buf_Init(&buf, 0); | | 1640 | Buf_Init(&buf, 0); |
1641 | | | 1641 | |
1642 | for (; *str != '\0'; str++) { | | 1642 | for (; *str != '\0'; str++) { |
1643 | if (*str == '\n') { | | 1643 | if (*str == '\n') { |
1644 | const char *newline = Shell_GetNewline(); | | 1644 | const char *newline = Shell_GetNewline(); |
1645 | if (newline == NULL) | | 1645 | if (newline == NULL) |
1646 | newline = "\\\n"; | | 1646 | newline = "\\\n"; |
1647 | Buf_AddStr(&buf, newline); | | 1647 | Buf_AddStr(&buf, newline); |
1648 | continue; | | 1648 | continue; |
1649 | } | | 1649 | } |
1650 | if (ch_isspace(*str) || ismeta((unsigned char)*str)) | | 1650 | if (ch_isspace(*str) || is_shell_metachar((unsigned char)*str)) |
1651 | Buf_AddByte(&buf, '\\'); | | 1651 | Buf_AddByte(&buf, '\\'); |
1652 | Buf_AddByte(&buf, *str); | | 1652 | Buf_AddByte(&buf, *str); |
1653 | if (quoteDollar && *str == '$') | | 1653 | if (quoteDollar && *str == '$') |
1654 | Buf_AddStr(&buf, "\\$"); | | 1654 | Buf_AddStr(&buf, "\\$"); |
1655 | } | | 1655 | } |
1656 | | | 1656 | |
1657 | return Buf_Destroy(&buf, FALSE); | | 1657 | return Buf_Destroy(&buf, FALSE); |
1658 | } | | 1658 | } |
1659 | | | 1659 | |
1660 | /* Compute the 32-bit hash of the given string, using the MurmurHash3 | | 1660 | /* Compute the 32-bit hash of the given string, using the MurmurHash3 |
1661 | * algorithm. Output is encoded as 8 hex digits, in Little Endian order. */ | | 1661 | * algorithm. Output is encoded as 8 hex digits, in Little Endian order. */ |
1662 | static char * | | 1662 | static char * |
1663 | VarHash(const char *str) | | 1663 | VarHash(const char *str) |