diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-09-24 19:42:12 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-09-24 19:42:12 +0200 |
commit | 942288dfb98a1762220da96d6a4b899d0651c6f8 (patch) | |
tree | 04319e58972f2253dfe6f622bb0df182e1037c1b /xe.c | |
parent | c188e1313bb9808bab82e0a11b358bb1ec781049 (diff) | |
download | xe-942288dfb98a1762220da96d6a4b899d0651c6f8.tar.gz xe-942288dfb98a1762220da96d6a4b899d0651c6f8.tar.xz xe-942288dfb98a1762220da96d6a4b899d0651c6f8.zip |
percent patterns without / match against basenames only
Diffstat (limited to 'xe.c')
-rw-r--r-- | xe.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/xe.c b/xe.c index 1888775..19c1a26 100644 --- a/xe.c +++ b/xe.c @@ -362,6 +362,12 @@ parse_jobs(char *s) int perc_match(char *pat, char *arg) { + if (!strchr(pat, '/')) { + char *d = strrchr(arg, '/'); + if (d) + arg = d + 1; + } + char *s = strchr(pat, '%'); if (!s) @@ -382,6 +388,14 @@ perc_subst(char *pat, char *base, char *arg) { static char buf[2048]; size_t l; + char *dir = base; + + if (!strchr(pat, '/')) { + char *d = strrchr(base, '/'); + if (d) + base = d + 1; + } + char *s = strchr(pat, '%'); char *t = strchr(arg, '%'); @@ -389,7 +403,10 @@ perc_subst(char *pat, char *base, char *arg) return arg; if (s) - l = snprintf(buf, sizeof buf, "%.*s%.*s%.*s", + l = snprintf(buf, sizeof buf, "%.*s%.*s%.*s%.*s", + (int)(base - dir), + dir, + (int)(t - arg), arg, @@ -399,7 +416,10 @@ perc_subst(char *pat, char *base, char *arg) (int)(arg + strlen(arg) - t), t+1); else - l = snprintf(buf, sizeof buf, "%.*s%s%.*s", + l = snprintf(buf, sizeof buf, "%.*s%.*s%s%.*s", + (int)(base - dir), + dir, + (int)(t - arg), arg, |