2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * A streaming text/plain "parser."
27 #include "telescope.h"
30 static int textplain_parse_line(struct buffer *, const char *, size_t);
32 const struct parser textplain_parser = {
34 .parseline = &textplain_parse_line,
38 emit_line(struct buffer *b, const char *line, size_t len)
42 l = xcalloc(1, sizeof(*l));
47 l->line = xcalloc(1, len + 1);
49 memcpy(l->line, line, len);
52 TAILQ_INSERT_TAIL(&b->head, l, lines);
58 textplain_parse_line(struct buffer *b, const char *line, size_t linelen)
60 return emit_line(b, line, linelen);