]> Pileus Git - ~andy/ct/blob - ct.c
Add escaping printf specifier
[~andy/ct] / ct.c
1 #include <stdio.h>
2 #include <glib.h>
3
4 #include "parse.h"
5
6 gpointer parse(FILE *input, GList **data, GList **code);
7
8 int main(int argc, char **argv)
9 {
10         /* Parse arguments */
11         int option_log_level = 7;
12         GOptionEntry entries[] = {
13                 {"debug", 'd', 0, G_OPTION_ARG_INT,  &option_log_level,
14                         "Change default log level", "[1-7]"},
15                 {NULL}
16         };
17         GOptionContext *context = g_option_context_new("infile");
18         g_option_context_add_main_entries(context, entries, NULL);
19         g_option_context_parse(context, &argc, &argv, NULL);
20
21         FILE *input = stdin;
22         for (int i = 1; i < argc; i++)
23                 if (g_str_has_suffix(argv[i], ".ct"))
24                         input = fopen(argv[i], "r");
25
26         /* Start compiling */
27         GList *data = NULL;
28         GList *code = NULL;
29         parse(input, &data, &code);
30         data = g_list_reverse(data);
31         code = g_list_reverse(code);
32
33         g_print("#include <stdio.h>\n");
34         g_print("\n");
35         for (GList *cur = data; cur; cur = cur->next)
36                 g_print("%s", (gchar *)cur->data);
37         g_print("\n");
38         for (GList *cur = code; cur; cur = cur->next)
39                 g_print("%s", (gchar *)cur->data);
40 }