summaryrefslogtreecommitdiff
path: root/read.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2012-03-04 16:53:50 +0000
committerPaul Smith <psmith@gnu.org>2012-03-04 16:53:50 +0000
commitcf1c79c9a331896d5bc2e68a1ea8206105a53eaa (patch)
treea7f622393478929ecbf44027d94e5ee576ae637b /read.c
parent76827d7c10c2708a3147171b02bfe3981492a38f (diff)
downloadgunmake-cf1c79c9a331896d5bc2e68a1ea8206105a53eaa.tar.gz
Improve handling for escaped colons in prerequisite lists.
Fixes Savannah bug #12126 and bug #16545
Diffstat (limited to 'read.c')
-rw-r--r--read.c77
1 files changed, 61 insertions, 16 deletions
diff --git a/read.c b/read.c
index 51e345b..d7b357b 100644
--- a/read.c
+++ b/read.c
@@ -156,6 +156,7 @@ static enum make_word_type get_next_mword (char *buffer, char *delim,
static void remove_comments (char *line);
static char *find_char_unquote (char *string, int stop1, int stop2,
int blank, int ignorevars);
+static char *unescape_char (char *string, int c);
/* Compare a word, both length and contents.
@@ -1872,24 +1873,28 @@ record_files (struct nameseq *filenames, const char *pattern,
expansion: if so, snap_deps() will do it. */
if (depstr == 0)
deps = 0;
- else if (second_expansion && strchr (depstr, '$'))
- {
- deps = alloc_dep ();
- deps->name = depstr;
- deps->need_2nd_expansion = 1;
- deps->staticpattern = pattern != 0;
- }
else
{
- deps = split_prereqs (depstr);
- free (depstr);
-
- /* We'll enter static pattern prereqs later when we have the stem. We
- don't want to enter pattern rules at all so that we don't think that
- they ought to exist (make manual "Implicit Rule Search Algorithm",
- item 5c). */
- if (! pattern && ! implicit_percent)
- deps = enter_prereqs (deps, NULL);
+ depstr = unescape_char (depstr, ':');
+ if (second_expansion && strchr (depstr, '$'))
+ {
+ deps = alloc_dep ();
+ deps->name = depstr;
+ deps->need_2nd_expansion = 1;
+ deps->staticpattern = pattern != 0;
+ }
+ else
+ {
+ deps = split_prereqs (depstr);
+ free (depstr);
+
+ /* We'll enter static pattern prereqs later when we have the stem.
+ We don't want to enter pattern rules at all so that we don't
+ think that they ought to exist (make manual "Implicit Rule Search
+ Algorithm", item 5c). */
+ if (! pattern && ! implicit_percent)
+ deps = enter_prereqs (deps, NULL);
+ }
}
/* For implicit rules, _all_ the targets must have a pattern. That means we
@@ -2211,6 +2216,46 @@ find_char_unquote (char *string, int stop1, int stop2, int blank,
return 0;
}
+/* Unescape a character in a string. The string is compressed onto itself. */
+
+static char *
+unescape_char (char *string, int c)
+{
+ char *p = string;
+ char *s = string;
+
+ while (*s != '\0')
+ {
+ if (*s == '\\')
+ {
+ char *e = s;
+ int l;
+
+ /* We found a backslash. See if it's escaping our character. */
+ while (*e == '\\')
+ ++e;
+ l = e - s;
+
+ if (*e != c || l%2 == 0)
+ /* It's not; just take it all without unescaping. */
+ memcpy (p, s, l);
+ else if (l > 1)
+ {
+ /* It is, and there's >1 backslash. Take half of them. */
+ l /= 2;
+ memcpy (p, s, l);
+ p += l;
+ }
+ s = e;
+ }
+
+ *(p++) = *(s++);
+ }
+
+ *p = '\0';
+ return string;
+}
+
/* Search PATTERN for an unquoted % and handle quoting. */
char *