2 23a912c2 2022-01-20 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
4 23a912c2 2022-01-20 op * Permission to use, copy, modify, and distribute this software for any
5 23a912c2 2022-01-20 op * purpose with or without fee is hereby granted, provided that the above
6 23a912c2 2022-01-20 op * copyright notice and this permission notice appear in all copies.
8 23a912c2 2022-01-20 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 23a912c2 2022-01-20 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 23a912c2 2022-01-20 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 23a912c2 2022-01-20 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 23a912c2 2022-01-20 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 23a912c2 2022-01-20 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 23a912c2 2022-01-20 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 23a912c2 2022-01-20 op #include "compat.h"
19 23a912c2 2022-01-20 op #include <stdio.h>
20 23a912c2 2022-01-20 op #include <string.h>
21 23a912c2 2022-01-20 op #include <unistd.h>
23 23a912c2 2022-01-20 op #include "parser.h"
24 23a912c2 2022-01-20 op #include "telescope.h"
27 23a912c2 2022-01-20 op erase_buffer(struct buffer *buffer)
36 23a912c2 2022-01-20 op struct tab tab;
37 23a912c2 2022-01-20 op struct hist hist;
40 0180fcdd 2022-05-19 op char buf[BUFSIZ], *b;
42 23a912c2 2022-01-20 op memset(&tab, 0, sizeof(tab));
43 23a912c2 2022-01-20 op memset(&hist, 0, sizeof(hist));
44 23a912c2 2022-01-20 op tab.hist_cur = &hist;
46 23a912c2 2022-01-20 op parser_init(&tab, gophermap_initparser);
48 23a912c2 2022-01-20 op if ((r = read(0, buf, sizeof(buf))) == -1)
49 23a912c2 2022-01-20 op err(1, "read");
52 23a912c2 2022-01-20 op if (!parser_parse(&tab, buf, r))
53 23a912c2 2022-01-20 op err(1, "parser_parse");
56 23a912c2 2022-01-20 op if (!parser_free(&tab))
57 23a912c2 2022-01-20 op err(1, "parser_free");
59 0180fcdd 2022-05-19 op if ((fp = open_memstream(&b, &blen)) == NULL)
60 0180fcdd 2022-05-19 op err(1, "open_memstream");
62 0180fcdd 2022-05-19 op if (parser_serialize(&tab, fp) == -1)
63 23a912c2 2022-01-20 op err(1, "parser_serialize");
66 0180fcdd 2022-05-19 op write(1, b, blen);