forked from pool/makedepend
Egbert Eich
33e03cb157
- u_Escape-special-characters-in-paths.patch Make gets confused by certain special characters in Makefiles. Escape them. This is a problem particularly with ':' in OBS paths. OBS-URL: https://build.opensuse.org/request/show/380100 OBS-URL: https://build.opensuse.org/package/show/X11:XOrg/makedepend?expand=0&rev=6
103 lines
2.8 KiB
Diff
103 lines
2.8 KiB
Diff
From: Egbert Eich <eich@suse.de>
|
|
Date: Fri Mar 18 06:42:20 2016 +0100
|
|
Subject: [PATCH]Escape special characters in paths.
|
|
Patch-mainline: to be upstreamed
|
|
Git-repo: git://anongit.freedesktop.org/git/xorg/util/makedepend
|
|
Git-commit: 6ba62c8f0236a97eaef4377a1cbca58da2d6a8c0
|
|
References:
|
|
Signed-off-by: Egbert Eich <eich@suse.com>
|
|
|
|
Make cannot handle certain special characters in make targets.
|
|
|
|
Signed-off-by: Egbert Eich <eich@suse.de>
|
|
---
|
|
pr.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
|
|
1 file changed, 56 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/pr.c b/pr.c
|
|
index 04abef9..e3a59e5 100644
|
|
--- a/pr.c
|
|
+++ b/pr.c
|
|
@@ -63,6 +63,56 @@ add_include(struct filepointer *filep, struct inclist *file,
|
|
}
|
|
}
|
|
|
|
+/**
|
|
+ * Replaces all occurrences of special characters in @p input with
|
|
+ * "\<special_character>" using @p outputbuffer (of size @p bufsize)
|
|
+ * possibly to hold the result. @p returns the string with quoted colons
|
|
+ */
|
|
+static const char *quoteSpecial(const char *input, char *outputbuffer, int bufsize)
|
|
+{
|
|
+#define min(a, b) ((a < b) ? a : b)
|
|
+ const char *tmp=input;
|
|
+ const char *loc;
|
|
+ const char *ret=input;
|
|
+#if !defined(WIN32) && !defined(__CYGWIN__)
|
|
+ const char special[] = {'$', ':', '#', '|', '?', '*', ' ', '\\', '\0'};
|
|
+ const char quotes[] = {'$', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\0'};
|
|
+#else
|
|
+ const char special[] = {'$', '\0'};
|
|
+ const char quotes[] = {'$', '\0'};
|
|
+#endif
|
|
+ int i;
|
|
+
|
|
+ for (i = 0; i < strlen(special); i++) {
|
|
+ char buf[bufsize];
|
|
+ int size=bufsize;
|
|
+ char *buf_p = buf;
|
|
+ loc = strchr(ret, special[i]);
|
|
+ if (loc == NULL)
|
|
+ continue;
|
|
+ tmp=ret;
|
|
+ while (loc != NULL) {
|
|
+ if (size > loc-tmp+2 ) {
|
|
+ memcpy(buf_p, tmp, loc-tmp);
|
|
+ buf_p+=loc-tmp;
|
|
+ *(buf_p++)=quotes[i];
|
|
+ *(buf_p++)=special[i];
|
|
+ size-=loc-tmp+2;
|
|
+ tmp=loc+1;
|
|
+ loc = strchr(tmp, special[i]);
|
|
+ } else {
|
|
+ size = min (size, loc - tmp + 1);
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ strncpy(buf_p, tmp, size);
|
|
+ buf_p[size - 1] = '\0';
|
|
+ strcpy(outputbuffer, buf);
|
|
+ ret = outputbuffer;
|
|
+ }
|
|
+ return ret;
|
|
+}
|
|
+
|
|
static void
|
|
pr(struct inclist *ip, const char *file, const char *base)
|
|
{
|
|
@@ -70,18 +120,21 @@ pr(struct inclist *ip, const char *file, const char *base)
|
|
static int current_len;
|
|
register int len, i;
|
|
char buf[ BUFSIZ ];
|
|
+ char quotebuf[ BUFSIZ ];
|
|
+ const char *result;
|
|
|
|
printed = TRUE;
|
|
- len = strlen(ip->i_file)+1;
|
|
+ result = quoteSpecial(ip->i_file, quotebuf, sizeof(quotebuf));
|
|
+ len = strlen(result)+1;
|
|
if (current_len + len > width || file != lastfile) {
|
|
lastfile = file;
|
|
snprintf(buf, sizeof(buf), "\n%s%s%s: %s",
|
|
- objprefix, base, objsuffix, ip->i_file);
|
|
+ objprefix, base, objsuffix, result);
|
|
len = current_len = strlen(buf);
|
|
}
|
|
else {
|
|
buf[0] = ' ';
|
|
- strcpy(buf+1, ip->i_file);
|
|
+ strcpy(buf+1, result);
|
|
current_len += len;
|
|
}
|
|
fwrite(buf, len, 1, stdout);
|