| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.627 2020/10/31 18:05:16 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.628 2020/10/31 18:14:59 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.627 2020/10/31 18:05:16 rillig Exp $"); | | 132 | MAKE_RCSID("$NetBSD: var.c,v 1.628 2020/10/31 18:14:59 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 | */ |
| @@ -1626,48 +1626,45 @@ VarUniq(const char *str) | | | @@ -1626,48 +1626,45 @@ VarUniq(const char *str) |
1626 | words.words[j] = words.words[i]; | | 1626 | words.words[j] = words.words[i]; |
1627 | words.len = j + 1; | | 1627 | words.len = j + 1; |
1628 | } | | 1628 | } |
1629 | | | 1629 | |
1630 | return Words_JoinFree(words); | | 1630 | return Words_JoinFree(words); |
1631 | } | | 1631 | } |
1632 | | | 1632 | |
1633 | | | 1633 | |
1634 | /* Quote shell meta-characters and space characters in the string. | | 1634 | /* Quote shell meta-characters and space characters in the string. |
1635 | * If quoteDollar is set, also quote and double any '$' characters. */ | | 1635 | * If quoteDollar is set, also quote and double any '$' characters. */ |
1636 | static char * | | 1636 | static char * |
1637 | VarQuote(const char *str, Boolean quoteDollar) | | 1637 | VarQuote(const char *str, Boolean quoteDollar) |
1638 | { | | 1638 | { |
1639 | char *res; | | | |
1640 | Buffer buf; | | 1639 | Buffer buf; |
1641 | Buf_Init(&buf, 0); | | 1640 | Buf_Init(&buf, 0); |
1642 | | | 1641 | |
1643 | for (; *str != '\0'; str++) { | | 1642 | for (; *str != '\0'; str++) { |
1644 | if (*str == '\n') { | | 1643 | if (*str == '\n') { |
1645 | const char *newline = Shell_GetNewline(); | | 1644 | const char *newline = Shell_GetNewline(); |
1646 | if (newline == NULL) | | 1645 | if (newline == NULL) |
1647 | newline = "\\\n"; | | 1646 | newline = "\\\n"; |
1648 | Buf_AddStr(&buf, newline); | | 1647 | Buf_AddStr(&buf, newline); |
1649 | continue; | | 1648 | continue; |
1650 | } | | 1649 | } |
1651 | if (ch_isspace(*str) || ismeta((unsigned char)*str)) | | 1650 | if (ch_isspace(*str) || ismeta((unsigned char)*str)) |
1652 | Buf_AddByte(&buf, '\\'); | | 1651 | Buf_AddByte(&buf, '\\'); |
1653 | Buf_AddByte(&buf, *str); | | 1652 | Buf_AddByte(&buf, *str); |
1654 | if (quoteDollar && *str == '$') | | 1653 | if (quoteDollar && *str == '$') |
1655 | Buf_AddStr(&buf, "\\$"); | | 1654 | Buf_AddStr(&buf, "\\$"); |
1656 | } | | 1655 | } |
1657 | | | 1656 | |
1658 | res = Buf_Destroy(&buf, FALSE); | | 1657 | return Buf_Destroy(&buf, FALSE); |
1659 | VAR_DEBUG1("QuoteMeta: [%s]\n", res); | | | |
1660 | return res; | | | |
1661 | } | | 1658 | } |
1662 | | | 1659 | |
1663 | /* 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 |
1664 | * 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. */ |
1665 | static char * | | 1662 | static char * |
1666 | VarHash(const char *str) | | 1663 | VarHash(const char *str) |
1667 | { | | 1664 | { |
1668 | static const char hexdigits[16] = "0123456789abcdef"; | | 1665 | static const char hexdigits[16] = "0123456789abcdef"; |
1669 | const unsigned char *ustr = (const unsigned char *)str; | | 1666 | const unsigned char *ustr = (const unsigned char *)str; |
1670 | | | 1667 | |
1671 | uint32_t h = 0x971e137bU; | | 1668 | uint32_t h = 0x971e137bU; |
1672 | uint32_t c1 = 0x95543787U; | | 1669 | uint32_t c1 = 0x95543787U; |
1673 | uint32_t c2 = 0x2ad7eb25U; | | 1670 | uint32_t c2 = 0x2ad7eb25U; |