summary refs log tree commit diff
path: root/parse.c
diff options
context:
space:
mode:
authorwrmr2024-11-03 12:12:20 -0500
committerwrmr2024-11-03 12:12:20 -0500
commitce088cbf9c3a73e9f9ed3012d31dd6e989d86052 (patch)
tree2fdc9ca366f8a42f919ca8e3577c8079dd102965 /parse.c
parent3e9c75318b0eb1114fb7361dbc467990674804b6 (diff)
file:// plaintext reading complete, add nav_next/nav_prev
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/parse.c b/parse.c
new file mode 100644
index 0000000..a1a68d8
--- /dev/null
+++ b/parse.c
@@ -0,0 +1,23 @@
+#include "parse.h"
+
+int parse_doc(enum doc_type type, struct doc *d, const buf_t *b) {
+	switch (type) {
+	case DOC_PLAIN:
+		doc_init(d);
+		for (size_t i = 0; i < b->sz; i++) {
+			char c = b->buf[i];
+			if (c == '\n') {
+				doc_new_line(d);
+			} else {
+				doc_add_textn(d, &c, 1);
+			}
+		}
+		goto ok;
+	default:
+		goto err;
+	}
+ok:
+	return 0;
+err:
+	return -1;
+}