Blob


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