ed

simple ed
git clone git://git.2f30.org/ed.git
Log | Files | Refs | LICENSE

commit 1438d2c20405a651964e0f454d2037db1c91a22f
parent 19b5ef27501528a6f1f9c5b9127ec41856afb7aa
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun Dec 13 13:04:12 +0100

Add support for backreferences in addsub()

This support is for substitution patterns like
a\1a.

Diffstat:
ed.c | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/ed.c b/ed.c @@ -885,16 +885,27 @@ static void addsub(char **s, size_t *cap, size_t *siz) { char *end, *q, *p, c; + int sub; for (p = rhs; c = *p; ++p) { switch (c) { case '&': - q = lastmatch + matchs[0].rm_so; - end = lastmatch + matchs[0].rm_eo; + sub = 0; + goto copy_match; + case '\\': + if ((c = *++p) == '\0') + return; + if (!isdigit(c)) + goto copy_char; + sub = c - '0'; + copy_match: + q = lastmatch + matchs[sub].rm_so; + end = lastmatch + matchs[sub].rm_eo; while (q < end) *s = addchar(*q++, *s, cap, siz); break; default: + copy_char: *s = addchar(c, *s, cap, siz); break; }