[hackers] [PATCH 15/17] Use nextln() in scroll()

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

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

---
 ed.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/ed.c b/ed.c
index 1e814e9..dbdfe60 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -841,14 +841,20 @@ join(void)
 static void
 scroll(int num)
 {
-	int i;
+	int max, ln, cnt;
 
 	if (!line1 || line1 == lastln)
 		error("incorrect address");
 
-	for (i = line1; i <= line1 + num && i <= lastln; ++i)
-		fputs(gettxt(i), stdout);
-	curln = i;
+	ln = line1;
+	max = line1 + num;
+	if (max > lastln)
+		max = lastln;
+	for (cnt = line1; cnt < max; cnt++) {
+		fputs(gettxt(ln), stdout);
+		ln = nextln(ln);
+	}
+	curln = ln;
 }
 
 static void
-- 
2.14.2
Received on Tue Mar 06 2018 - 12:58:07 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 06 2018 - 13:03:30 CET