From 94cc057fa4ad9e6c0bbecb9c88e32937b0dc5a4c Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Sun, 6 Sep 2015 20:54:56 +0200 Subject: Fix $2 for default.EXT.do --- redo.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/redo.c b/redo.c index 8edf657..8398962 100644 --- a/redo.c +++ b/redo.c @@ -538,6 +538,33 @@ new_waitjob(int fd, int implicit) return 0; } +// dofile doesn't contain / +// target can contain / +static char * +redo_basename(char *dofile, char *target) +{ + static char buf[PATH_MAX]; + int stripext = 1; + char *s; + + if (strncmp(dofile, "default.", 8) == 0) + for (stripext = -1, s = dofile; *s; s++) + if (*s == '.') + stripext++; + + strncpy(buf, target, sizeof buf); + while (stripext-- > 0) { + if (strchr(buf, '.')) { + char *e = strchr(buf, '\0'); + while (*--e != '.') + *e = 0; + *e = 0; + } + } + + return buf; +} + static void run_script(char *target, int implicit) { @@ -613,14 +640,7 @@ djb-style default.o.do: $2 all (!!) $3 whatever.tmp */ - int i; - - char *basename = strdup(rel_target); - if (strchr(basename, '.')) { - for (i = strlen(basename)-1; i && basename[i] != '.'; i--) - basename[i] = 0; - basename[i--] = 0; - } + char *basename = redo_basename(dofile, rel_target); if (old_dep_fd > 0) close(old_dep_fd); -- cgit 1.4.1