ed

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

commit 5896396de8e35ebc1cc2049a715567d791998b11
parent 6be8562ba50a4c27de57fb1114cb2ab26e03ef71
Author: FRIGN <dev@frign.de>
Date:   Tue,  1 Dec 2015 17:37:58 +0100

Some style changes

Diffstat:
Med.c | 68++++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/ed.c b/ed.c @@ -121,9 +121,9 @@ getindex(int line) struct hline *lp; int n; - for (n = 0, lp = zero; n != line; ++n) { - lp = &zero[lp->next]; - } + for (n = 0, lp = zero; n != line; ++n) + lp = zero + lp->next; + return lp - zero; } @@ -137,12 +137,12 @@ gettxt(int line) ssize_t n; char *p; - lp = &zero[getindex(line)]; + lp = zero + getindex(line); off = lp->seek; sizetxt = 0; repeat: - if (csize == 0 || off < lasto || off - lasto >= csize) { + if (!csize || off < lasto || off - lasto >= csize) { block = off & ~(CACHESIZ-1); fprintf(stderr, "getting a new cache at %ld\n", block); if (lseek(scratch, block, SEEK_SET) < 0 || @@ -152,11 +152,11 @@ repeat: csize = n; lasto = block; } - for (p = &buf[off - lasto]; p < &buf[csize] && *p != '\n'; ++p) { + for (p = buf + off - lasto; p < buf + csize && *p != '\n'; ++p) { ++off; addchar(*p); } - if (csize != 0 && p == &buf[csize]) + if (csize && p == buf + csize) goto repeat; add_newline: @@ -169,7 +169,7 @@ static void setglobal(int i, int dir) { int lnk = getindex(i); - int m = regexec(pattern, gettxt(i), 0, NULL, 0) == 0; + int m = !regexec(pattern, gettxt(i), 0, NULL, 0); zero[lnk].global = (m == dir && i >= line1 && i <= line2); } @@ -220,7 +220,7 @@ setscratch() mode_t mode = S_IRUSR | S_IWUSR; clearbuf(); - if ((scratch = open("ed.tmp", flags, mode)) < 0 || + if ((scratch = open("ed.tmp", flags, mode)) < 0 || (k = makeline("", NULL))) { error("input/output error in scratch file"); } @@ -240,13 +240,13 @@ compile() if (c == '\n' || c == delim) break; } - if ((len = cmdp - bp) == 0) { - if (pattern == NULL) + if (!(len = cmdp - bp)) { + if (!pattern) error("no previous pattern"); return; } if (!pattern) { - if ((pattern = malloc(sizeof(*pattern))) == NULL) + if (!(pattern = malloc(sizeof(*pattern)))) error("no memory"); } memcpy(buff, bp, len); @@ -263,7 +263,7 @@ match(int way) i = curln; do { i = (way == '/') ? nextln(i) : prevln(i); - if (regexec(pattern, gettxt(i), 0, NULL, 0) == 0) + if (!regexec(pattern, gettxt(i), 0, NULL, 0)) return i; } while (i != curln); @@ -296,7 +296,7 @@ getnum(int *line) skipblank(); if (!isalpha(c = *cmdp)) error("invalid mark character"); - if ((ln = marks[c]) == 0) + if (!(ln = marks[c])) error("invalid address"); break; case '$': @@ -395,7 +395,7 @@ getlst() static void deflines(int def1, int def2) { - if (nlines == 0) { + if (!nlines) { line1 = def1; line2 = def2; } @@ -412,7 +412,7 @@ setfname(char *fname) if (fname == savfname) return; len = strlen(fname); - if ((s = malloc(len + 1)) == NULL) + if (!(s = malloc(len + 1))) error("out of memory"); memcpy(s, fname, len+1); free(savfname); @@ -426,7 +426,7 @@ dowrite(char *fname, int trunc) char *s; int i; - if ((fp = fopen(fname, (trunc) ? "w" : "a")) == NULL) + if (!(fp = fopen(fname, (trunc) ? "w" : "a"))) error("input/output error"); for (i = line1; i <= line2; ++i) { @@ -450,15 +450,15 @@ doread(char *fname) if (!savfname) setfname(fname); - if ((fp = fopen(fname, "r")) == NULL) + if (!(fp = fopen(fname, "r"))) error("input/output error"); curln = line2; for (cnt = 0; getline(&s, &len, fp) > 0; ++cnt) { - if ((n = strlen(s)) == 0) + if (!(n = strlen(s))) break; if (s[n-1] != '\n') { if (n == len) { - if ((p = realloc(s, len+1)) == NULL) + if (!(p = realloc(s, len + 1))) error("out of memory"); ++len; s = p; @@ -590,7 +590,7 @@ delete(int from, int to) { int lto, lfrom; - if (from == 0) + if (!from) error("incorrect address"); lfrom = getindex(prevln(from)); @@ -605,7 +605,7 @@ move(int where) { int before, after, lto, lfrom; - if (line1 == 0 || where >= line1 && where <= line2) + if (!line1 || where >= line1 && where <= line2) error("incorrect address"); before = getindex(prevln(line1)); @@ -648,7 +648,7 @@ scroll(int num) int i, last; char *s; - if (line1 == 0 || line1 == lastln) + if (!line1 || line1 == lastln) error("incorrect address"); last = (line1 + num > lastln) ? lastln - line1 : num; @@ -663,7 +663,7 @@ copy(int where) int i, ind; char *s; - if (line1 == 0 || where >= line1 && where <= line2) + if (!line1 || where >= line1 && where <= line2) error("incorrect address"); curln = where; @@ -686,7 +686,7 @@ execsh(void) skipblank(); if (*cmdp != '!') { free(cmd); - if ((cmd = strdup(cmdp)) == NULL) + if (!(cmd = strdup(cmdp))) error("out of memory"); } system(cmd); @@ -756,7 +756,7 @@ docmd() goto bad_address; chkprint(1); deflines(curln, curln); - if (line1 == 0) + if (!line1) goto bad_address; append(prevln(line1)); break; @@ -790,7 +790,7 @@ docmd() case 'j': chkprint(1); deflines(curln, curln+1); - if (line1 == 0) + if (!line1) goto bad_address; join(); break; @@ -900,7 +900,7 @@ chkglobal(void) if (uflag) chkprint(0); - for (i = line1; i <= line2; i = i+1) + for (i = line1; i <= line2; i++) setglobal(i, nmatch); return 1; @@ -925,11 +925,11 @@ readcmd(int isglobal) for (s = buf;; *s++ = c) { if (optprompt) fputs(prompt, stdout); - if (!buf || s == &buf[size-2]) { - if ((p = realloc(buf, size+CMDSIZE)) == NULL) + if (!buf || s == buf + size - 2) { + if (!(p = realloc(buf, size+CMDSIZE))) error("out of memory"); buf = p; - s = (size == 0) ? p : &p[size-2]; + s = !size ? p : p + size - 2; size = size+CMDSIZE; } if ((c = getchar()) == EOF || c == '\n') @@ -949,7 +949,7 @@ doglobal(void) char *s; s = cmdp; - for (i = 1; i <= lastln; i = i+1) { + for (i = 1; i <= lastln; i++) { k = getindex(i); if (!zero[k].global) continue; @@ -981,13 +981,13 @@ main(int argc, char *argv[]) while (*++argv) { if (argv[0][0] != '-') break; - for (p = &argv[0][1]; *p; ++p) { + for (p = argv[0] + 1; *p; ++p) { switch (*p) { case 's': optdiag = 0; break; case 'p': - if (*++argv == NULL) + if (!*++argv) usage(); prompt = *argv; break;