summaryrefslogtreecommitdiff
path: root/regsub.c
diff options
context:
space:
mode:
Diffstat (limited to 'regsub.c')
-rw-r--r--regsub.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/regsub.c b/regsub.c
index 26f62b4..2b114fd 100644
--- a/regsub.c
+++ b/regsub.c
@@ -196,10 +196,18 @@ void regsub(re, src, dst)
}
*dst = '\0';
- /* remember what text we inserted this time */
- if (previous)
- free(previous);
- previous = (char *)malloc((unsigned)(strlen(start) + 1));
- if (previous)
- strcpy(previous, start);
+#ifndef NO_MAGIC
+ /* Don't copy the pattern if it is '~'; leave previous copy alone */
+ if (! (*start == '~' && *o_magic))
+ {
+#endif
+ /* remember what text we inserted this time */
+ if (previous)
+ free(previous);
+ previous = (char *)malloc((unsigned)(strlen(start) + 1));
+ if (previous)
+ strcpy(previous, start);
+#ifndef NO_MAGIC
+ }
+#endif
}