Blame


1 bff58270 2022-09-19 op /*
2 bff58270 2022-09-19 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
3 bff58270 2022-09-19 op *
4 bff58270 2022-09-19 op * Permission to use, copy, modify, and distribute this software for any
5 bff58270 2022-09-19 op * purpose with or without fee is hereby granted, provided that the above
6 bff58270 2022-09-19 op * copyright notice and this permission notice appear in all copies.
7 bff58270 2022-09-19 op *
8 bff58270 2022-09-19 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 bff58270 2022-09-19 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 bff58270 2022-09-19 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 bff58270 2022-09-19 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 bff58270 2022-09-19 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 bff58270 2022-09-19 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 bff58270 2022-09-19 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 bff58270 2022-09-19 op */
16 bff58270 2022-09-19 op
17 bff58270 2022-09-19 op #include <err.h>
18 bff58270 2022-09-19 op #include <stdio.h>
19 bff58270 2022-09-19 op #include <stdlib.h>
20 bff58270 2022-09-19 op #include <unistd.h>
21 bff58270 2022-09-19 op
22 bff58270 2022-09-19 op int parse(const char *);
23 bff58270 2022-09-19 op
24 bff58270 2022-09-19 op int nodebug;
25 bff58270 2022-09-19 op
26 bff58270 2022-09-19 op static void __dead
27 bff58270 2022-09-19 op usage(void)
28 bff58270 2022-09-19 op {
29 bff58270 2022-09-19 op fprintf(stderr, "usage: %s [file...]\n",
30 bff58270 2022-09-19 op getprogname());
31 bff58270 2022-09-19 op exit(1);
32 bff58270 2022-09-19 op }
33 bff58270 2022-09-19 op
34 bff58270 2022-09-19 op int
35 bff58270 2022-09-19 op main(int argc, char **argv)
36 bff58270 2022-09-19 op {
37 bff58270 2022-09-19 op int ch, i;
38 bff58270 2022-09-19 op
39 bff58270 2022-09-19 op if (pledge("stdio rpath", NULL) == -1)
40 bff58270 2022-09-19 op err(1, "pledge");
41 bff58270 2022-09-19 op
42 bff58270 2022-09-19 op while ((ch = getopt(argc, argv, "G")) != -1) {
43 bff58270 2022-09-19 op switch (ch) {
44 bff58270 2022-09-19 op case 'G':
45 bff58270 2022-09-19 op nodebug = 1;
46 bff58270 2022-09-19 op break;
47 bff58270 2022-09-19 op default:
48 bff58270 2022-09-19 op usage();
49 bff58270 2022-09-19 op }
50 bff58270 2022-09-19 op }
51 bff58270 2022-09-19 op argc -= optind;
52 bff58270 2022-09-19 op argv += optind;
53 bff58270 2022-09-19 op
54 bff58270 2022-09-19 op /* preamble */
55 bff58270 2022-09-19 op puts("#include \"tmpl.h\"");
56 bff58270 2022-09-19 op
57 bff58270 2022-09-19 op if (argc == 0) {
58 bff58270 2022-09-19 op parse("/dev/stdin");
59 bff58270 2022-09-19 op exit(0);
60 bff58270 2022-09-19 op }
61 bff58270 2022-09-19 op
62 bff58270 2022-09-19 op for (i = 0; i < argc; ++i)
63 bff58270 2022-09-19 op if (parse(argv[i]) == -1)
64 bff58270 2022-09-19 op return (1);
65 bff58270 2022-09-19 op
66 bff58270 2022-09-19 op return (0);
67 bff58270 2022-09-19 op }