7 gpointer parse(FILE *input, const char *name,
8 GList **data, GList **code);
10 int main(int argc, char **argv)
12 const char *name = "stdin";
14 char *option_output = NULL;
15 GOptionEntry entries[] = {
16 {"output", 'o', 0, G_OPTION_ARG_STRING, &option_output,
20 GOptionContext *context = g_option_context_new("[template]");
21 g_option_context_add_main_entries(context, entries, NULL);
22 g_option_context_parse(context, &argc, &argv, NULL);
24 /* Handle input and output */
26 if (argv[1] && !g_str_equal(input, "-")) {
28 input = fopen(argv[1], "r");
31 g_error("invalid input file");
33 FILE *output = stdout;
34 if (option_output && !g_str_equal(option_output, "-"))
35 output = fopen(option_output, "w");
36 else if (input != stdin && option_output == NULL) {
37 char *outf = g_strdup(argv[1]);
38 outf[strlen(outf)-1] = '\0';
39 output = fopen(outf, "w");
43 g_error("invalid output file");
48 parse(input, name, &data, &code);
49 data = g_list_reverse(data);
50 code = g_list_reverse(code);
52 fprintf(output, "#include <stdio.h>\n");
53 fprintf(output, "\n");
54 for (GList *cur = data; cur; cur = cur->next)
55 fprintf(output, "%s", (gchar *)cur->data);
56 fprintf(output, "\n");
57 for (GList *cur = code; cur; cur = cur->next)
58 fprintf(output, "%s", (gchar *)cur->data);