Blame


1 59b2344e 2022-05-19 op /*
2 59b2344e 2022-05-19 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
3 59b2344e 2022-05-19 op *
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.
7 59b2344e 2022-05-19 op *
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.
15 59b2344e 2022-05-19 op */
16 59b2344e 2022-05-19 op
17 59b2344e 2022-05-19 op #include "compat.h"
18 59b2344e 2022-05-19 op
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>
22 59b2344e 2022-05-19 op
23 59b2344e 2022-05-19 op #include "parser.h"
24 59b2344e 2022-05-19 op #include "telescope.h"
25 59b2344e 2022-05-19 op
26 59b2344e 2022-05-19 op /* XXX: needed just to please the linker */
27 59b2344e 2022-05-19 op int hide_pre_context;
28 59b2344e 2022-05-19 op int hide_pre_closing_line;
29 59b2344e 2022-05-19 op int hide_pre_blocks;
30 59b2344e 2022-05-19 op int emojify_link;
31 59b2344e 2022-05-19 op
32 59b2344e 2022-05-19 op int
33 59b2344e 2022-05-19 op emojied_line(const char *s, const char **space_ret)
34 59b2344e 2022-05-19 op {
35 59b2344e 2022-05-19 op return 0;
36 59b2344e 2022-05-19 op }
37 59b2344e 2022-05-19 op
38 59b2344e 2022-05-19 op void
39 59b2344e 2022-05-19 op erase_buffer(struct buffer *buffer)
40 59b2344e 2022-05-19 op {
41 59b2344e 2022-05-19 op return;
42 59b2344e 2022-05-19 op }
43 59b2344e 2022-05-19 op
44 59b2344e 2022-05-19 op int
45 59b2344e 2022-05-19 op main(void)
46 59b2344e 2022-05-19 op {
47 59b2344e 2022-05-19 op FILE *fp;
48 59b2344e 2022-05-19 op struct tab tab;
49 59b2344e 2022-05-19 op struct hist hist;
50 59b2344e 2022-05-19 op ssize_t r;
51 59b2344e 2022-05-19 op size_t blen;
52 59b2344e 2022-05-19 op char buf[BUFSIZ], *b;
53 59b2344e 2022-05-19 op
54 59b2344e 2022-05-19 op memset(&tab, 0, sizeof(tab));
55 59b2344e 2022-05-19 op memset(&hist, 0, sizeof(hist));
56 59b2344e 2022-05-19 op tab.hist_cur = &hist;
57 59b2344e 2022-05-19 op
58 59b2344e 2022-05-19 op parser_init(&tab, gemtext_initparser);
59 59b2344e 2022-05-19 op for (;;) {
60 59b2344e 2022-05-19 op if ((r = read(0, buf, sizeof(buf))) == -1)
61 59b2344e 2022-05-19 op err(1, "read");
62 59b2344e 2022-05-19 op if (r == 0)
63 59b2344e 2022-05-19 op break;
64 59b2344e 2022-05-19 op if (!parser_parse(&tab, buf, r))
65 59b2344e 2022-05-19 op err(1, "parser_parse");
66 59b2344e 2022-05-19 op }
67 59b2344e 2022-05-19 op
68 59b2344e 2022-05-19 op if (!parser_free(&tab))
69 59b2344e 2022-05-19 op err(1, "parser_free");
70 59b2344e 2022-05-19 op
71 59b2344e 2022-05-19 op if ((fp = open_memstream(&b, &blen)) == NULL)
72 59b2344e 2022-05-19 op err(1, "open_memstream");
73 59b2344e 2022-05-19 op
74 59b2344e 2022-05-19 op if (parser_serialize(&tab, fp) == -1)
75 59b2344e 2022-05-19 op err(1, "parser_serialize");
76 59b2344e 2022-05-19 op
77 59b2344e 2022-05-19 op fclose(fp);
78 59b2344e 2022-05-19 op write(1, b, blen);
79 59b2344e 2022-05-19 op
80 59b2344e 2022-05-19 op return 0;
81 59b2344e 2022-05-19 op }