#include "parse.h" #include "err.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: perr("unsupported doctype"); goto err; } ok: return 0; err: return -1; }