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