ed

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

commit 99e4f82543be7a4ebafa993e17acbf0ee3c90ec9
parent 9cf111abf80b34081313c84fa1330330d702ae59
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Tue,  1 Dec 2015 19:48:55 +0100

revert some regressions and cleanup parts from previous patches

- REG_BASIC must be set to 0 (portability).
- use cnt on same line of for loop.
- don't return in compile(), error() will handle the error flow.

Diffstat:
Med.c | 17+++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/ed.c b/ed.c @@ -230,7 +230,7 @@ setscratch() modflag = 0; } -static int +static void compile() { static char regerrbuf[BUFSIZ]; @@ -247,7 +247,7 @@ compile() if (bp >= cmdp) { if (!pattern) error("no previous pattern"); - return 0; + return; } if (!pattern && (!(pattern = malloc(sizeof(*pattern))))) error("no memory"); @@ -256,11 +256,10 @@ compile() error("regular expression too long"); memcpy(buff, bp, len); buff[len] = '\0'; - if ((ret = regcomp(pattern, buff, REG_BASIC))) { + if ((ret = regcomp(pattern, buff, 0))) { regerror(ret, pattern, regerrbuf, sizeof(regerrbuf)); error(regerrbuf); } - return !ret; } static int @@ -314,8 +313,8 @@ getnum(int *line) sign = -sign; case '/': c = *cmdp; - if (compile()) - ln = match(c); + compile(); + ln = match(c); break; default: if (isdigit(*cmdp)) { @@ -459,8 +458,7 @@ doread(char *fname) if (!(fp = fopen(fname, "r"))) error("input/output error"); curln = line2; - for (cnt = 0; (n = getline(&s, &len, fp)) > 0;) { - cnt += (size_t)n; + for (cnt = 0; (n = getline(&s, &len, fp)) > 0; cnt += (size_t)n) { if (s[n-1] != '\n') { if (len == SIZE_MAX || !(p = realloc(s, ++len))) @@ -897,7 +895,7 @@ chkglobal(void) return 0; } deflines(nextln(0), lastln); - compile(); /* TODO: check compile */ + compile(); ++cmdp; /* skip trailing '/' */ if (uflag) @@ -1001,7 +999,6 @@ main(int argc, char *argv[]) } } - if (!setjmp(savesp)) { setscratch(); if (*argv) {