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 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"
27 59b2344e 2022-05-19 op
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;
33 59b2344e 2022-05-19 op
34 59b2344e 2022-05-19 op int
35 59b2344e 2022-05-19 op emojied_line(const char *s, const char **space_ret)
36 59b2344e 2022-05-19 op {
37 59b2344e 2022-05-19 op return 0;
38 59b2344e 2022-05-19 op }
39 59b2344e 2022-05-19 op
40 59b2344e 2022-05-19 op void
41 59b2344e 2022-05-19 op erase_buffer(struct buffer *buffer)
42 59b2344e 2022-05-19 op {
43 59b2344e 2022-05-19 op return;
44 59b2344e 2022-05-19 op }
45 59b2344e 2022-05-19 op
46 59b2344e 2022-05-19 op int
47 59b2344e 2022-05-19 op main(void)
48 59b2344e 2022-05-19 op {
49 59b2344e 2022-05-19 op FILE *fp;
50 59b2344e 2022-05-19 op struct tab tab;
51 59b2344e 2022-05-19 op ssize_t r;
52 59b2344e 2022-05-19 op size_t blen;
53 59b2344e 2022-05-19 op char buf[BUFSIZ], *b;
54 59b2344e 2022-05-19 op
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");
60 59b2344e 2022-05-19 op
61 59b2344e 2022-05-19 op parser_init(&tab, gemtext_initparser);
62 59b2344e 2022-05-19 op for (;;) {
63 59b2344e 2022-05-19 op if ((r = read(0, buf, sizeof(buf))) == -1)
64 59b2344e 2022-05-19 op err(1, "read");
65 59b2344e 2022-05-19 op if (r == 0)
66 59b2344e 2022-05-19 op break;
67 59b2344e 2022-05-19 op if (!parser_parse(&tab, buf, r))
68 59b2344e 2022-05-19 op err(1, "parser_parse");
69 59b2344e 2022-05-19 op }
70 59b2344e 2022-05-19 op
71 59b2344e 2022-05-19 op if (!parser_free(&tab))
72 59b2344e 2022-05-19 op err(1, "parser_free");
73 59b2344e 2022-05-19 op
74 59b2344e 2022-05-19 op if ((fp = open_memstream(&b, &blen)) == NULL)
75 59b2344e 2022-05-19 op err(1, "open_memstream");
76 59b2344e 2022-05-19 op
77 59b2344e 2022-05-19 op if (parser_serialize(&tab, fp) == -1)
78 59b2344e 2022-05-19 op err(1, "parser_serialize");
79 59b2344e 2022-05-19 op
80 59b2344e 2022-05-19 op fclose(fp);
81 59b2344e 2022-05-19 op write(1, b, blen);
82 59b2344e 2022-05-19 op
83 59b2344e 2022-05-19 op return 0;
84 59b2344e 2022-05-19 op }