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 7c7d258a 2024-01-23 op #include "hist.h"
24 23a912c2 2022-01-20 op #include "parser.h"
25 23a912c2 2022-01-20 op #include "telescope.h"
28 23a912c2 2022-01-20 op erase_buffer(struct buffer *buffer)
37 23a912c2 2022-01-20 op struct tab tab;
40 0180fcdd 2022-05-19 op char buf[BUFSIZ], *b;
42 23a912c2 2022-01-20 op memset(&tab, 0, sizeof(tab));
43 7c7d258a 2024-01-23 op if ((tab.hist = hist_new(HIST_LINEAR)) == NULL)
44 7c7d258a 2024-01-23 op err(1, "hist_new");
45 7c7d258a 2024-01-23 op if (hist_push(tab.hist, "dummy://address") == -1)
46 7c7d258a 2024-01-23 op err(1, "hist_push");
48 23a912c2 2022-01-20 op parser_init(&tab, gophermap_initparser);
50 23a912c2 2022-01-20 op if ((r = read(0, buf, sizeof(buf))) == -1)
51 23a912c2 2022-01-20 op err(1, "read");
54 23a912c2 2022-01-20 op if (!parser_parse(&tab, buf, r))
55 23a912c2 2022-01-20 op err(1, "parser_parse");
58 23a912c2 2022-01-20 op if (!parser_free(&tab))
59 23a912c2 2022-01-20 op err(1, "parser_free");
61 0180fcdd 2022-05-19 op if ((fp = open_memstream(&b, &blen)) == NULL)
62 0180fcdd 2022-05-19 op err(1, "open_memstream");
64 0180fcdd 2022-05-19 op if (parser_serialize(&tab, fp) == -1)
65 23a912c2 2022-01-20 op err(1, "parser_serialize");
68 0180fcdd 2022-05-19 op write(1, b, blen);