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 "hist.h"
24 #include "parser.h"
25 #include "telescope.h"
27 void
28 erase_buffer(struct buffer *buffer)
29 {
30 return;
31 }
33 int
34 main(void)
35 {
36 FILE *fp;
37 struct tab tab;
38 ssize_t r;
39 size_t blen;
40 char buf[BUFSIZ], *b;
42 memset(&tab, 0, sizeof(tab));
43 if ((tab.hist = hist_new(HIST_LINEAR)) == NULL)
44 err(1, "hist_new");
45 if (hist_push(tab.hist, "dummy://address") == -1)
46 err(1, "hist_push");
48 parser_init(&tab, gophermap_initparser);
49 for (;;) {
50 if ((r = read(0, buf, sizeof(buf))) == -1)
51 err(1, "read");
52 if (r == 0)
53 break;
54 if (!parser_parse(&tab, buf, r))
55 err(1, "parser_parse");
56 }
58 if (!parser_free(&tab))
59 err(1, "parser_free");
61 if ((fp = open_memstream(&b, &blen)) == NULL)
62 err(1, "open_memstream");
64 if (parser_serialize(&tab, fp) == -1)
65 err(1, "parser_serialize");
67 fclose(fp);
68 write(1, b, blen);
70 return 0;
71 }