diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2015-09-06 20:54:56 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2015-09-06 20:54:56 +0200 |
commit | 94cc057fa4ad9e6c0bbecb9c88e32937b0dc5a4c (patch) | |
tree | 9a5968f0a616b41882dc8c1ba7136f9712248408 | |
parent | 6c0164b8bf092bc0f48a3c07b6ea6fed1e3ceb1d (diff) | |
download | redo-c-94cc057fa4ad9e6c0bbecb9c88e32937b0dc5a4c.tar.gz redo-c-94cc057fa4ad9e6c0bbecb9c88e32937b0dc5a4c.tar.xz redo-c-94cc057fa4ad9e6c0bbecb9c88e32937b0dc5a4c.zip |
Fix $2 for default.EXT.do
-rw-r--r-- | redo.c | 36 |
1 files 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); |