ed

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

commit 9fc0b5d959a1830d83e0226e9ecd1c0fe9f72653
parent f2593570542c7916d04f30e54f685eeb92cf5b90
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 12 Dec 2015 12:48:30 +0100

Accept number of re in s commands

POSIX accepts like a flag a digit that indicate what occurrence
of the regular expression is substitued.

Diffstat:
Med.c | 25++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/ed.c b/ed.c @@ -841,6 +841,8 @@ getrhs(int delim) } repl = addchar(c, repl, &siz, &cap); } + if (c == EOF) + error("invalid pattern delimiter"); back(c); repl = addchar('\0', repl, &siz, &cap); @@ -859,24 +861,25 @@ subs(void) { int c, delim; - if ((delim = input()) == '\n') { if (!rhs || !lhs) error("no previous substitution"); + back('\n'); } else { - gsub = 0; getlhs(delim); getrhs(delim); - - if (c == delim) { - if ((c = input()) == 'g') - gsub = 1; - else - back(c); - } else { + if ((c = input()) == '\n') pflag = 'p'; - back(c); - } + back('\n'); + } + + if ((c = input()) == 'g') { + gsub = -1; + } else if (isdigit(c)) { + gsub = c - '0'; + } else { + gsub = 1; + back(c); } }