Blame


1 23a912c2 2022-01-20 op /*
2 23a912c2 2022-01-20 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
3 23a912c2 2022-01-20 op *
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.
7 23a912c2 2022-01-20 op *
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.
15 23a912c2 2022-01-20 op */
16 23a912c2 2022-01-20 op
17 23a912c2 2022-01-20 op #include "compat.h"
18 23a912c2 2022-01-20 op
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>
22 23a912c2 2022-01-20 op
23 23a912c2 2022-01-20 op #include "parser.h"
24 23a912c2 2022-01-20 op #include "telescope.h"
25 23a912c2 2022-01-20 op
26 23a912c2 2022-01-20 op void
27 23a912c2 2022-01-20 op erase_buffer(struct buffer *buffer)
28 23a912c2 2022-01-20 op {
29 23a912c2 2022-01-20 op return;
30 23a912c2 2022-01-20 op }
31 23a912c2 2022-01-20 op
32 23a912c2 2022-01-20 op int
33 23a912c2 2022-01-20 op main(void)
34 23a912c2 2022-01-20 op {
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;
38 23a912c2 2022-01-20 op ssize_t r;
39 23a912c2 2022-01-20 op char buf[BUFSIZ];
40 23a912c2 2022-01-20 op
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;
44 23a912c2 2022-01-20 op
45 23a912c2 2022-01-20 op parser_init(&tab, gophermap_initparser);
46 23a912c2 2022-01-20 op for (;;) {
47 23a912c2 2022-01-20 op if ((r = read(0, buf, sizeof(buf))) == -1)
48 23a912c2 2022-01-20 op err(1, "read");
49 23a912c2 2022-01-20 op if (r == 0)
50 23a912c2 2022-01-20 op break;
51 23a912c2 2022-01-20 op if (!parser_parse(&tab, buf, r))
52 23a912c2 2022-01-20 op err(1, "parser_parse");
53 23a912c2 2022-01-20 op }
54 23a912c2 2022-01-20 op
55 23a912c2 2022-01-20 op if (!parser_free(&tab))
56 23a912c2 2022-01-20 op err(1, "parser_free");
57 23a912c2 2022-01-20 op
58 23a912c2 2022-01-20 op if ((evb = evbuffer_new()) == NULL)
59 23a912c2 2022-01-20 op err(1, "evbuffer_new");
60 23a912c2 2022-01-20 op
61 23a912c2 2022-01-20 op if (parser_serialize(&tab, evb) == -1)
62 23a912c2 2022-01-20 op err(1, "parser_serialize");
63 23a912c2 2022-01-20 op
64 23a912c2 2022-01-20 op evbuffer_write(evb, 1);
65 23a912c2 2022-01-20 op
66 23a912c2 2022-01-20 op evbuffer_free(evb);
67 23a912c2 2022-01-20 op
68 23a912c2 2022-01-20 op return 0;
69 23a912c2 2022-01-20 op }