summaryrefslogtreecommitdiff
path: root/tar/subst.c
diff options
context:
space:
mode:
Diffstat (limited to 'tar/subst.c')
-rw-r--r--tar/subst.c106
1 files changed, 54 insertions, 52 deletions
diff --git a/tar/subst.c b/tar/subst.c
index fd6f8e22..4710e06a 100644
--- a/tar/subst.c
+++ b/tar/subst.c
@@ -236,64 +236,66 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result,
continue;
}
- if (regexec(&rule->re, name, 10, matches, 0))
- continue;
-
- got_match = 1;
- print_match |= rule->print;
- realloc_strncat(result, name, matches[0].rm_so);
-
- for (i = 0, j = 0; rule->result[i] != '\0'; ++i) {
- if (rule->result[i] == '~') {
- realloc_strncat(result, rule->result + j, i - j);
- realloc_strncat(result,
- name + matches[0].rm_so,
- matches[0].rm_eo - matches[0].rm_so);
- j = i + 1;
- continue;
- }
- if (rule->result[i] != '\\')
- continue;
-
- ++i;
- c = rule->result[i];
- switch (c) {
- case '~':
- case '\\':
- realloc_strncat(result, rule->result + j, i - j - 1);
- j = i;
+ while (1) {
+ if (regexec(&rule->re, name, 10, matches, 0))
break;
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- realloc_strncat(result, rule->result + j, i - j - 1);
- if ((size_t)(c - '0') > (size_t)(rule->re.re_nsub)) {
- free(*result);
- *result = NULL;
- return -1;
+
+ got_match = 1;
+ print_match |= rule->print;
+ realloc_strncat(result, name, matches[0].rm_so);
+
+ for (i = 0, j = 0; rule->result[i] != '\0'; ++i) {
+ if (rule->result[i] == '~') {
+ realloc_strncat(result, rule->result + j, i - j);
+ realloc_strncat(result,
+ name + matches[0].rm_so,
+ matches[0].rm_eo - matches[0].rm_so);
+ j = i + 1;
+ continue;
+ }
+ if (rule->result[i] != '\\')
+ continue;
+
+ ++i;
+ c = rule->result[i];
+ switch (c) {
+ case '~':
+ case '\\':
+ realloc_strncat(result, rule->result + j, i - j - 1);
+ j = i;
+ break;
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ realloc_strncat(result, rule->result + j, i - j - 1);
+ if ((size_t)(c - '0') > (size_t)(rule->re.re_nsub)) {
+ free(*result);
+ *result = NULL;
+ return -1;
+ }
+ realloc_strncat(result, name + matches[c - '0'].rm_so, matches[c - '0'].rm_eo - matches[c - '0'].rm_so);
+ j = i + 1;
+ break;
+ default:
+ /* Just continue; */
+ break;
}
- realloc_strncat(result, name + matches[c - '0'].rm_so, matches[c - '0'].rm_eo - matches[c - '0'].rm_so);
- j = i + 1;
- break;
- default:
- /* Just continue; */
- break;
- }
- }
+ }
- realloc_strcat(result, rule->result + j);
+ realloc_strcat(result, rule->result + j);
- name += matches[0].rm_eo;
+ name += matches[0].rm_eo;
- if (!rule->global)
- break;
+ if (!rule->global)
+ break;
+ }
}
if (got_match)