[hackers] [PATCH 10/17] Move subline() to use String type

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

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

---
 ed.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/ed.c b/ed.c
index 0f86759..2a66184 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -970,26 +970,26 @@ getnth(void)
 }
 
 static void
-addpre(char **s, size_t *cap, size_t *siz)
+addpre(String *s)
 {
 	char *p;
 
 	for (p = lastmatch; p < lastmatch + matchs[0].rm_so; ++p)
-		*s = addchar(*p, *s, cap, siz);
+		addchar_(*p, s);
 }
 
 static void
-addpost(char **s, size_t *cap, size_t *siz)
+addpost(String *s)
 {
 	char c, *p;
 
 	for (p = lastmatch + matchs[0].rm_eo; (c = *p); ++p)
-		*s = addchar(c, *s, cap, siz);
-	*s = addchar('\0', *s, cap, siz);
+		addchar_(c, s);
+	addchar_('\0', s);
 }
 
 static int
-addsub(char **s, size_t *cap, size_t *siz, int nth, int nmatch)
+addsub(String *s, int nth, int nmatch)
 {
 	char *end, *q, *p, c;
 	int sub;
_AT_@ -998,7 +998,7 @@ addsub(char **s, size_t *cap, size_t *siz, int nth, int nmatch)
 		q   = lastmatch + matchs[0].rm_so;
 		end = lastmatch + matchs[0].rm_eo;
 		while (q < end)
-			*s = addchar(*q++, *s, cap, siz);
+			addchar_(*q++, s);
 		return 0;
 	}
 
_AT_@ -1017,11 +1017,11 @@ addsub(char **s, size_t *cap, size_t *siz, int nth, int nmatch)
 			q   = lastmatch + matchs[sub].rm_so;
 			end = lastmatch + matchs[sub].rm_eo;
 			while (q < end)
-				*s = addchar(*q++, *s, cap, siz);
+				addchar_(*q++, s);
 			break;
 		default:
 		copy_char:
-			*s = addchar(c, *s, cap, siz);
+			addchar_(c, s);
 			break;
 		}
 	}
_AT_@ -1032,22 +1032,21 @@ static void
 subline(int num, int nth)
 {
 	int i, m, changed;
-	static char *s;
-	static size_t siz, cap;
+	static String s;
 
-	i = changed = siz = 0;
+	i = changed = s.siz = 0;
 	for (m = match(num); m; m = rematch(num)) {
-		addpre(&s, &cap, &siz);
-		changed |= addsub(&s, &cap, &siz, nth, ++i);
+		addpre(&s);
+		changed |= addsub(&s, nth, ++i);
 		if (eol || bol)
 			break;
 	}
 	if (!changed)
 		return;
-	addpost(&s, &cap, &siz);
+	addpost(&s);
 	delete(num, num);
 	curln = prevln(num);
-	inject(s, 0);
+	inject(s.str, 0);
 }
 
 static void
-- 
2.14.2
Received on Tue Mar 06 2018 - 12:58:02 CET

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