Allow overlapping transfer

This commit is contained in:
Roberto E. Vargas Caballero 2018-03-04 16:08:57 +01:00 committed by sin
parent d849e6d4aa
commit 504dde1373

18
ed.c
View File

@ -19,6 +19,8 @@
#define LINESIZE 80 #define LINESIZE 80
#define NUMLINES 32 #define NUMLINES 32
#define CACHESIZ 4096 #define CACHESIZ 4096
#define AFTER 0
#define BEFORE 1
typedef struct { typedef struct {
char *str; char *str;
@ -308,11 +310,11 @@ undo(void)
} }
static void static void
inject(char *s, int j) inject(char *s, int where)
{ {
int off, k, begin, end; int off, k, begin, end;
if (j) { if (where == BEFORE) {
begin = getindex(curln-1); begin = getindex(curln-1);
end = getindex(nextln(curln-1)); end = getindex(nextln(curln-1));
} else { } else {
@ -649,7 +651,7 @@ doread(const char *fname)
s[n-1] = '\n'; s[n-1] = '\n';
s[n] = '\0'; s[n] = '\0';
} }
inject(s, 0); inject(s, AFTER);
} }
if (optdiag) if (optdiag)
printf("%zu\n", cnt); printf("%zu\n", cnt);
@ -767,7 +769,7 @@ append(int num)
while (getline(&s, &len, stdin) > 0) { while (getline(&s, &len, stdin) > 0) {
if (*s == '.' && s[1] == '\n') if (*s == '.' && s[1] == '\n')
break; break;
inject(s, 0); inject(s, AFTER);
} }
free(s); free(s);
} }
@ -832,7 +834,7 @@ join(void)
addchar('\n', &s); addchar('\n', &s);
addchar('\0', &s); addchar('\0', &s);
delete(line1, line2); delete(line1, line2);
inject(s.str, 1); inject(s.str, BEFORE);
free(s.str); free(s.str);
} }
@ -854,12 +856,12 @@ copy(int where)
{ {
int i; int i;
if (!line1 || (where >= line1 && where <= line2)) if (!line1)
error("incorrect address"); error("incorrect address");
curln = where; curln = where;
for (i = line1; i <= line2; ++i) for (i = line1; i <= line2; ++i)
inject(gettxt(i), 0); inject(gettxt(i), AFTER);
} }
static void static void
@ -1031,7 +1033,7 @@ subline(int num, int nth)
addpost(&s); addpost(&s);
delete(num, num); delete(num, num);
curln = prevln(num); curln = prevln(num);
inject(s.str, 0); inject(s.str, AFTER);
} }
static void static void