[hackers] [PATCH 12/17] Allow overlapping transfer

From: quinq <quinq_AT_fifth.space>
Date: Tue, 6 Mar 2018 12:58:04 +0100

From: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>

---
 ed.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/ed.c b/ed.c
index 58bdb45..70dd2a5 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -19,6 +19,8 @@
 #define LINESIZE    80
 #define NUMLINES    32
 #define CACHESIZ  4096
+#define AFTER     0
+#define BEFORE    1
 
 typedef struct {
 	char *str;
_AT_@ -308,11 +310,11 @@ undo(void)
 }
 
 static void
-inject(char *s, int j)
+inject(char *s, int where)
 {
 	int off, k, begin, end;
 
-	if (j) {
+	if (where == BEFORE) {
 		begin = getindex(curln-1);
 		end = getindex(nextln(curln-1));
 	} else {
_AT_@ -649,7 +651,7 @@ doread(const char *fname)
 			s[n-1] = '\n';
 			s[n] = '\0';
 		}
-		inject(s, 0);
+		inject(s, AFTER);
 	}
 	if (optdiag)
 		printf("%zu\n", cnt);
_AT_@ -767,7 +769,7 @@ append(int num)
 	while (getline(&s, &len, stdin) > 0) {
 		if (*s == '.' && s[1] == '\n')
 			break;
-		inject(s, 0);
+		inject(s, AFTER);
 	}
 	free(s);
 }
_AT_@ -832,7 +834,7 @@ join(void)
 	addchar('\n', &s);
 	addchar('\0', &s);
 	delete(line1, line2);
-	inject(s.str, 1);
+	inject(s.str, BEFORE);
 	free(s.str);
 }
 
_AT_@ -854,12 +856,12 @@ copy(int where)
 {
 	int i;
 
-	if (!line1 || (where >= line1 && where <= line2))
+	if (!line1)
 		error("incorrect address");
 	curln = where;
 
 	for (i = line1; i <= line2; ++i)
-		inject(gettxt(i), 0);
+		inject(gettxt(i), AFTER);
 }
 
 static void
_AT_@ -1031,7 +1033,7 @@ subline(int num, int nth)
 	addpost(&s);
 	delete(num, num);
 	curln = prevln(num);
-	inject(s.str, 0);
+	inject(s.str, AFTER);
 }
 
 static void
-- 
2.14.2
Received on Tue Mar 06 2018 - 12:58:04 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 06 2018 - 13:02:58 CET