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 7c7d258a 2024-01-23 op #include "hist.h"
24 59b2344e 2022-05-19 op #include "parser.h"
25 59b2344e 2022-05-19 op #include "telescope.h"
26 67d252a0 2024-01-16 op #include "utf8.h"
28 59b2344e 2022-05-19 op /* XXX: needed just to please the linker */
29 59b2344e 2022-05-19 op int hide_pre_context;
30 59b2344e 2022-05-19 op int hide_pre_closing_line;
31 59b2344e 2022-05-19 op int hide_pre_blocks;
32 59b2344e 2022-05-19 op int emojify_link;
35 59b2344e 2022-05-19 op emojied_line(const char *s, const char **space_ret)
41 59b2344e 2022-05-19 op erase_buffer(struct buffer *buffer)
50 59b2344e 2022-05-19 op struct tab tab;
53 59b2344e 2022-05-19 op char buf[BUFSIZ], *b;
55 59b2344e 2022-05-19 op memset(&tab, 0, sizeof(tab));
56 7c7d258a 2024-01-23 op if ((tab.hist = hist_new(HIST_LINEAR)) == NULL)
57 7c7d258a 2024-01-23 op err(1, "hist_new");
58 7c7d258a 2024-01-23 op if (hist_push(tab.hist, "dummy://address") == -1)
59 7c7d258a 2024-01-23 op err(1, "hist_push");
61 59b2344e 2022-05-19 op parser_init(&tab, gemtext_initparser);
63 59b2344e 2022-05-19 op if ((r = read(0, buf, sizeof(buf))) == -1)
64 59b2344e 2022-05-19 op err(1, "read");
67 59b2344e 2022-05-19 op if (!parser_parse(&tab, buf, r))
68 59b2344e 2022-05-19 op err(1, "parser_parse");
71 59b2344e 2022-05-19 op if (!parser_free(&tab))
72 59b2344e 2022-05-19 op err(1, "parser_free");
74 59b2344e 2022-05-19 op if ((fp = open_memstream(&b, &blen)) == NULL)
75 59b2344e 2022-05-19 op err(1, "open_memstream");
77 59b2344e 2022-05-19 op if (parser_serialize(&tab, fp) == -1)
78 59b2344e 2022-05-19 op err(1, "parser_serialize");
81 59b2344e 2022-05-19 op write(1, b, blen);