--- ed.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/ed.c b/ed.c index 184ed30..2a1c0ba 100644 --- a/ed.c +++ b/ed.c _AT_@ -297,13 +297,17 @@ undo(void) } static void -inject(char *s) +inject(char *s, int join) { int off, k, begin, end; - begin = getindex(curln); - end = getindex(nextln(curln)); - + if (join) { + begin = getindex(curln-1); + end = getindex(nextln(curln-1)); + } else { + begin = getindex(curln); + end = getindex(nextln(curln)); + } while (*s) { k = makeline(s, &off); s += off; _AT_@ -634,7 +638,7 @@ doread(char *fname) s[n-1] = '\n'; s[n] = '\0'; } - inject(s); + inject(s, 0); } if (optdiag) printf("%zu\n", cnt); _AT_@ -751,7 +755,7 @@ append(int num) while (getline(&s, &len, stdin) > 0) { if (*s == '.' && s[1] == '\n') break; - inject(s); + inject(s, 0); } free(s); } _AT_@ -801,21 +805,22 @@ static void join(void) { int i; - char *t, c; - size_t len = 0, cap = 0; - static char *s; + char *t, c; + size_t len = 0, cap = 0; + static char *s; + + free(s); + for (s = NULL, i = line1; i <= line2; i = nextln(i)) { + for (t = gettxt(i); (c = *t) != '\n'; ++t) + s = addchar(*t, s, &cap, &len); + } + + s = addchar('\n', s, &cap, &len); + s = addchar('\0', s, &cap, &len); + delete(line1, line2); + inject(s); + free(s); - free(s); - for (s = NULL, i = line1; i <= line2; i = nextln(i)) { - for (t = gettxt(i); (c = *t) != '\n'; ++t) - s = addchar(*t, s, &cap, &len); - } - - s = addchar('\n', s, &cap, &len); - s = addchar('\0', s, &cap, &len); - delete(line1, line2); - inject(s); - free(s); } static void _AT_@ -841,7 +846,7 @@ copy(int where) curln = where; for (i = line1; i <= line2; ++i) - inject(gettxt(i)); + inject(gettxt(i), 0); } static void _AT_@ -1021,7 +1026,7 @@ subline(int num, int nth) addpost(&s, &cap, &siz); delete(num, num); curln = prevln(num); - inject(s); + inject(s, 0); } static void -- 2.10.0 --Multipart=_Thu__6_Oct_2016_11_04_17_+0000_25tL/22NlhexcG.a Content-Type: text/x-patch; name="0002-ed-if-only-one-address-is-given-to-j-do-nothing.patch" Content-Disposition: attachment; filename="0002-ed-if-only-one-address-is-given-to-j-do-nothing.patch" Content-Transfer-Encoding: 7bitReceived on Mon Sep 17 2001 - 00:00:00 CEST
This archive was generated by hypermail 2.3.0 : Fri Oct 07 2016 - 09:00:13 CEST