2 59b2344e 2022-05-19 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
4 59b2344e 2022-05-19 op * Permission to use, copy, modify, and distribute this software for any
5 59b2344e 2022-05-19 op * purpose with or without fee is hereby granted, provided that the above
6 59b2344e 2022-05-19 op * copyright notice and this permission notice appear in all copies.
8 59b2344e 2022-05-19 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 59b2344e 2022-05-19 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 59b2344e 2022-05-19 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 59b2344e 2022-05-19 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 59b2344e 2022-05-19 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 59b2344e 2022-05-19 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 59b2344e 2022-05-19 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 59b2344e 2022-05-19 op #include "compat.h"
19 59b2344e 2022-05-19 op #include <stdio.h>
20 59b2344e 2022-05-19 op #include <string.h>
21 59b2344e 2022-05-19 op #include <unistd.h>
23 59b2344e 2022-05-19 op #include "parser.h"
24 59b2344e 2022-05-19 op #include "telescope.h"
25 67d252a0 2024-01-16 op #include "utf8.h"
27 59b2344e 2022-05-19 op /* XXX: needed just to please the linker */
28 59b2344e 2022-05-19 op int hide_pre_context;
29 59b2344e 2022-05-19 op int hide_pre_closing_line;
30 59b2344e 2022-05-19 op int hide_pre_blocks;
31 59b2344e 2022-05-19 op int emojify_link;
34 59b2344e 2022-05-19 op emojied_line(const char *s, const char **space_ret)
40 59b2344e 2022-05-19 op erase_buffer(struct buffer *buffer)
49 59b2344e 2022-05-19 op struct tab tab;
50 59b2344e 2022-05-19 op struct hist hist;
53 59b2344e 2022-05-19 op char buf[BUFSIZ], *b;
55 59b2344e 2022-05-19 op memset(&tab, 0, sizeof(tab));
56 59b2344e 2022-05-19 op memset(&hist, 0, sizeof(hist));
57 59b2344e 2022-05-19 op tab.hist_cur = &hist;
59 59b2344e 2022-05-19 op parser_init(&tab, gemtext_initparser);
61 59b2344e 2022-05-19 op if ((r = read(0, buf, sizeof(buf))) == -1)
62 59b2344e 2022-05-19 op err(1, "read");
65 59b2344e 2022-05-19 op if (!parser_parse(&tab, buf, r))
66 59b2344e 2022-05-19 op err(1, "parser_parse");
69 59b2344e 2022-05-19 op if (!parser_free(&tab))
70 59b2344e 2022-05-19 op err(1, "parser_free");
72 59b2344e 2022-05-19 op if ((fp = open_memstream(&b, &blen)) == NULL)
73 59b2344e 2022-05-19 op err(1, "open_memstream");
75 59b2344e 2022-05-19 op if (parser_serialize(&tab, fp) == -1)
76 59b2344e 2022-05-19 op err(1, "parser_serialize");
79 59b2344e 2022-05-19 op write(1, b, blen);