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)
35 23a912c2 2022-01-20 op struct tab tab;
36 23a912c2 2022-01-20 op struct hist hist;
37 23a912c2 2022-01-20 op struct evbuffer *evb;
39 23a912c2 2022-01-20 op char buf[BUFSIZ];
41 23a912c2 2022-01-20 op memset(&tab, 0, sizeof(tab));
42 23a912c2 2022-01-20 op memset(&hist, 0, sizeof(hist));
43 23a912c2 2022-01-20 op tab.hist_cur = &hist;
45 23a912c2 2022-01-20 op parser_init(&tab, gophermap_initparser);
47 23a912c2 2022-01-20 op if ((r = read(0, buf, sizeof(buf))) == -1)
48 23a912c2 2022-01-20 op err(1, "read");
51 23a912c2 2022-01-20 op if (!parser_parse(&tab, buf, r))
52 23a912c2 2022-01-20 op err(1, "parser_parse");
55 23a912c2 2022-01-20 op if (!parser_free(&tab))
56 23a912c2 2022-01-20 op err(1, "parser_free");
58 23a912c2 2022-01-20 op if ((evb = evbuffer_new()) == NULL)
59 23a912c2 2022-01-20 op err(1, "evbuffer_new");
61 23a912c2 2022-01-20 op if (parser_serialize(&tab, evb) == -1)
62 23a912c2 2022-01-20 op err(1, "parser_serialize");
64 23a912c2 2022-01-20 op evbuffer_write(evb, 1);
66 23a912c2 2022-01-20 op evbuffer_free(evb);