summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc.c16
-rw-r--r--doc.h3
-rw-r--r--nav.c2
-rw-r--r--parse.c2
-rw-r--r--strv.c4
-rw-r--r--strv.h1
6 files changed, 14 insertions, 14 deletions
diff --git a/doc.c b/doc.c
index 97d8b34..d43ff30 100644
--- a/doc.c
+++ b/doc.c
@@ -39,20 +39,16 @@ void doc_new_line(struct doc *d) {
 }
 
 void doc_add_line(struct doc *d, strv_t s) {
-	doc_add_textn(d, s.s, s.n);
+	doc_add_text(d, s);
 	doc_new_line(d);
 }
 
-void doc_add_text(struct doc *d, const char *s) {
-	doc_add_textn(d, s, strlen(s));
-}
-
-void doc_add_textn(struct doc *d, const char *s, size_t n) {
-	buf_grow(&d->txt, n);
-	memcpy(&d->txt.buf[d->txt.sz], s, n);
+void doc_add_text(struct doc *d, strv_t s) {
+	buf_grow(&d->txt, s.n);
+	memcpy(&d->txt.buf[d->txt.sz], s.s, s.n);
 	struct doc_line *dl = (struct doc_line *)&d->txt.buf[d->latest];
-	d->txt.sz += n;
-	dl->len += n;
+	d->txt.sz += s.n;
+	dl->len += s.n;
 }
 
 unsigned short doc_add_link(struct doc *d, const char *url) {
diff --git a/doc.h b/doc.h
index a71ca49..a0b1031 100644
--- a/doc.h
+++ b/doc.h
@@ -29,8 +29,7 @@ void doc_fini(struct doc *);
 
 void doc_new_line(struct doc *);
 void doc_add_line(struct doc *, strv_t);
-void doc_add_text(struct doc *, const char *);
-void doc_add_textn(struct doc *, const char *, size_t);
+void doc_add_text(struct doc *, strv_t);
 
 struct doc_line *doc_line_at(struct doc *d, size_t ofs);
 int doc_line_prevp(struct doc *d, size_t ofs);
diff --git a/nav.c b/nav.c
index 8456a76..5e5d8ea 100644
--- a/nav.c
+++ b/nav.c
@@ -12,7 +12,7 @@ void nav_init(struct nav_state *ns) {
 	memset(ns, 0, sizeof *ns);
 	ns->histc = 1;
 	doc_init(ns->histv);
-	doc_add_text(ns->histv, "Type ? for command help.");
+	doc_add_text(ns->histv, strv("Type ? for command help."));
 	ns->prot_default = PROT_GOPHER;
 }
 
diff --git a/parse.c b/parse.c
index ff0c973..b62ea8a 100644
--- a/parse.c
+++ b/parse.c
@@ -78,7 +78,7 @@ int parse_gophermap_line(struct doc *d, strv_t ln) {
 		url[urln] = 0;
 		doc_set_link(d, doc_add_link(d, url));
 	case 'i':
-		doc_add_textn(d, bits.dstr.s, bits.dstr.n);
+		doc_add_text(d, bits.dstr);
 		doc_new_line(d);
 		break;
 	}
diff --git a/strv.c b/strv.c
index 5da11f5..a3e9f6a 100644
--- a/strv.c
+++ b/strv.c
@@ -2,6 +2,10 @@
 
 #include "strv.h"
 
+strv_t strv(const char *s) {
+	return (strv_t) { s, strlen(s) };
+}
+
 strv_t strv_head(strv_t ss, int chr, size_t *i) {
 	size_t j = i ? *i : 0;
 	char *c = memchr(&ss.s[j], chr, ss.n - j);
diff --git a/strv.h b/strv.h
index 553a39c..03bbb8e 100644
--- a/strv.h
+++ b/strv.h
@@ -8,6 +8,7 @@ typedef struct {
 	size_t n;
 } strv_t;
 
+strv_t strv(const char *s);
 strv_t strv_head(strv_t ss, int chr, size_t *i);
 
 #endif