]> git.xonotic.org Git - xonotic/gmqcc.git/blob - main.c
Merge branch 'master' of github.com:graphitemaster/gmqcc
[xonotic/gmqcc.git] / main.c
1 /*
2  * Copyright (C) 2012
3  *     Dale Weiler
4  *     Wolfgang Bumiller
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of
7  * this software and associated documentation files (the "Software"), to deal in
8  * the Software without restriction, including without limitation the rights to
9  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is furnished to do
11  * so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "gmqcc.h"
25 #include "lexer.h"
26
27 /* TODO: cleanup this whole file .. it's a fuckign mess */
28
29 /* set by the standard */
30 const oper_info *operators      = NULL;
31 size_t           operator_count = 0;
32 static bool      opts_output_wasset = false;
33
34 typedef struct { char *filename; int   type;  } argitem;
35 typedef struct { char *name;     char *value; } ppitem;
36 static argitem *items = NULL;
37 static ppitem  *ppems = NULL;
38
39 #define TYPE_QC  0
40 #define TYPE_ASM 1
41 #define TYPE_SRC 2
42
43 static const char *app_name;
44
45 static void version() {
46     con_out("GMQCC %d.%d.%d Built %s %s\n",
47         GMQCC_VERSION_MAJOR,
48         GMQCC_VERSION_MINOR,
49         GMQCC_VERSION_PATCH,
50         __DATE__,
51         __TIME__
52     );
53 }
54
55 static int usage() {
56     con_out("usage: %s [options] [files...]", app_name);
57     con_out("options:\n"
58             "  -h, --help             show this help message\n"
59             "  -debug                 turns on compiler debug messages\n"
60             "  -memchk                turns on compiler memory leak check\n");
61     con_out("  -o, --output=file      output file, defaults to progs.dat\n"
62             "  -s filename            add a progs.src file to be used\n");
63     con_out("  -E                     stop after preprocessing\n");
64     con_out("  -config file           use the specified ini file\n");
65     con_out("  -std=standard          select one of the following standards\n"
66             "       -std=qcc          original QuakeC\n"
67             "       -std=fteqcc       fteqcc QuakeC\n"
68             "       -std=gmqcc        this compiler (default)\n");
69     con_out("  -f<flag>               enable a flag\n"
70             "  -fno-<flag>            disable a flag\n"
71             "  -fhelp                 list possible flags\n");
72     con_out("  -W<warning>            enable a warning\n"
73             "  -Wno-<warning>         disable a warning\n"
74             "  -Wall                  enable all warnings\n");
75     con_out("  -Werror                treat warnings as errors\n"
76             "  -Werror-<warning>      treat a warning as error\n"
77             "  -Wno-error-<warning>   opposite of the above\n");
78     con_out("  -Whelp                 list possible warnings\n");
79     con_out("  -O<number>             optimization level\n"
80             "  -O<name>               enable specific optimization\n"
81             "  -Ono-<name>            disable specific optimization\n"
82             "  -Ohelp                 list optimizations\n");
83     con_out("  -force-crc=num         force a specific checksum into the header\n");
84     return -1;
85 }
86
87 /* command line parsing */
88 static bool options_witharg(int *argc_, char ***argv_, char **out) {
89     int  argc   = *argc_;
90     char **argv = *argv_;
91
92     if (argv[0][2]) {
93         *out = argv[0]+2;
94         return true;
95     }
96     /* eat up the next */
97     if (argc < 2) /* no parameter was provided */
98         return false;
99
100     *out = argv[1];
101     --*argc_;
102     ++*argv_;
103     return true;
104 }
105
106 static bool options_long_witharg_all(const char *optname, int *argc_, char ***argv_, char **out, int ds, bool split) {
107     int  argc   = *argc_;
108     char **argv = *argv_;
109
110     size_t len = strlen(optname);
111
112     if (strncmp(argv[0]+ds, optname, len))
113         return false;
114
115     /* it's --optname, check how the parameter is supplied */
116     if (argv[0][ds+len] == '=') {
117         /* using --opt=param */
118         *out = argv[0]+ds+len+1;
119         return true;
120     }
121
122     if (!split || argc < ds) /* no parameter was provided, or only single-arg form accepted */
123         return false;
124
125     /* using --opt param */
126     *out = argv[1];
127     --*argc_;
128     ++*argv_;
129     return true;
130 }
131 static bool options_long_witharg(const char *optname, int *argc_, char ***argv_, char **out) {
132     return options_long_witharg_all(optname, argc_, argv_, out, 2, true);
133 }
134 static bool options_long_gcc(const char *optname, int *argc_, char ***argv_, char **out) {
135     return options_long_witharg_all(optname, argc_, argv_, out, 1, false);
136 }
137
138 static bool options_parse(int argc, char **argv) {
139     bool argend = false;
140     size_t itr;
141     char  buffer[1024];
142     char *redirout = NULL;
143     char *redirerr = NULL;
144     char *config   = NULL;
145
146     while (!argend && argc > 1) {
147         char *argarg;
148         argitem item;
149         ppitem  macro;
150
151         ++argv;
152         --argc;
153
154         if (argv[0][0] == '-') {
155             /* All gcc-type long options */
156             if (options_long_gcc("std", &argc, &argv, &argarg)) {
157                 if (!strcmp(argarg, "gmqcc") || !strcmp(argarg, "default")) {
158
159                     opts_set(opts.flags, ADJUST_VECTOR_FIELDS,  true);
160                     opts.standard = COMPILER_GMQCC;
161
162                 } else if (!strcmp(argarg, "qcc")) {
163
164                     opts_set(opts.flags, ADJUST_VECTOR_FIELDS,  false);
165                     opts_set(opts.flags, ASSIGN_FUNCTION_TYPES, true);
166                     opts.standard = COMPILER_QCC;
167
168                 } else if (!strcmp(argarg, "fte") || !strcmp(argarg, "fteqcc")) {
169
170                     opts_set(opts.flags, FTEPP,                    true);
171                     opts_set(opts.flags, TRANSLATABLE_STRINGS,     true);
172                     opts_set(opts.flags, ADJUST_VECTOR_FIELDS,     false);
173                     opts_set(opts.flags, ASSIGN_FUNCTION_TYPES,    true);
174                     opts_set(opts.warn, WARN_TERNARY_PRECEDENCE,   true);
175                     opts_set(opts.flags, CORRECT_TERNARY,          false);
176                     opts.standard = COMPILER_FTEQCC;
177
178                 } else if (!strcmp(argarg, "qccx")) {
179
180                     opts_set(opts.flags, ADJUST_VECTOR_FIELDS,  false);
181                     opts.standard = COMPILER_QCCX;
182
183                 } else {
184                     con_out("Unknown standard: %s\n", argarg);
185                     return false;
186                 }
187                 continue;
188             }
189             if (options_long_gcc("force-crc", &argc, &argv, &argarg)) {
190                 opts.forcecrc   = true;
191                 opts.forced_crc = strtol(argarg, NULL, 0);
192                 continue;
193             }
194             if (options_long_gcc("redirout", &argc, &argv, &redirout)) {
195                 con_change(redirout, redirerr);
196                 continue;
197             }
198             if (options_long_gcc("redirerr", &argc, &argv, &redirerr)) {
199                 con_change(redirout, redirerr);
200                 continue;
201             }
202             if (options_long_gcc("config", &argc, &argv, &argarg)) {
203                 config = argarg;
204                 continue;
205             }
206
207             /* show defaults (like pathscale) */
208             if (!strcmp(argv[0]+1, "show-defaults")) {
209                 for (itr = 0; itr < COUNT_FLAGS; ++itr) {
210                     if (!OPTS_FLAG(itr))
211                         continue;
212
213                     memset(buffer, 0, sizeof(buffer));
214                     util_strtononcmd(opts_flag_list[itr].name, buffer, strlen(opts_flag_list[itr].name) + 1);
215
216                     con_out("-f%s ", buffer);
217                 }
218                 for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
219                     if (!OPTS_WARN(itr))
220                         continue;
221
222                     memset(buffer, 0, sizeof(buffer));
223                     util_strtononcmd(opts_warn_list[itr].name, buffer, strlen(opts_warn_list[itr].name) + 1);
224                     con_out("-W%s ", buffer);
225                 }
226                 con_out("\n");
227                 exit(0);
228             }
229
230             if (!strcmp(argv[0]+1, "debug")) {
231                 opts.debug = true;
232                 continue;
233             }
234             if (!strcmp(argv[0]+1, "dump")) {
235                 opts.dump = true;
236                 continue;
237             }
238             if (!strcmp(argv[0]+1, "dumpfin")) {
239                 opts.dumpfin = true;
240                 continue;
241             }
242             if (!strcmp(argv[0]+1, "memchk")) {
243                 opts.memchk = true;
244                 continue;
245             }
246             if (!strcmp(argv[0]+1, "nocolor")) {
247                 con_color(0);
248                 continue;
249             }
250
251             switch (argv[0][1]) {
252                 /* -h, show usage but exit with 0 */
253                 case 'h':
254                     usage();
255                     exit(0);
256                     /* break; never reached because of exit(0) */
257
258                 case 'v':
259                     version();
260                     exit(0);
261
262                 case 'E':
263                     opts.pp_only = true;
264                     break;
265
266                 /* debug turns on -flno */
267                 case 'g':
268                     opts_setflag("LNO", true);
269                     opts.g = true;
270                     break;
271
272                 case 'D':
273                     if (!strlen(argv[0]+2)) {
274                         con_err("expected name after -D\n");
275                         exit(0);
276                     }
277
278                     if (!(argarg = strchr(argv[0] + 2, '='))) {
279                         macro.name  = util_strdup(argv[0]+2);
280                         macro.value = NULL;
281                     } else {
282                         *argarg='\0'; /* terminate for name */
283                         macro.name  = util_strdup(argv[0]+2);
284                         macro.value = util_strdup(argarg+1);
285                     }
286                     vec_push(ppems, macro);
287                     break;
288
289                 /* handle all -fflags */
290                 case 'f':
291                     util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
292                     if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
293                         con_out("Possible flags:\n");
294                         for (itr = 0; itr < COUNT_FLAGS; ++itr) {
295                             util_strtononcmd(opts_flag_list[itr].name, buffer, sizeof(buffer));
296                             con_out(" -f%s\n", buffer);
297                         }
298                         exit(0);
299                     }
300                     else if (!strncmp(argv[0]+2, "NO_", 3)) {
301                         if (!opts_setflag(argv[0]+5, false)) {
302                             con_out("unknown flag: %s\n", argv[0]+2);
303                             return false;
304                         }
305                     }
306                     else if (!opts_setflag(argv[0]+2, true)) {
307                         con_out("unknown flag: %s\n", argv[0]+2);
308                         return false;
309                     }
310                     break;
311                 case 'W':
312                     util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
313                     if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
314                         con_out("Possible warnings:\n");
315                         for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
316                             util_strtononcmd(opts_warn_list[itr].name, buffer, sizeof(buffer));
317                             con_out(" -W%s\n", buffer);
318                         }
319                         exit(0);
320                     }
321                     else if (!strcmp(argv[0]+2, "NO_ERROR") ||
322                              !strcmp(argv[0]+2, "NO_ERROR_ALL"))
323                     {
324                         for (itr = 0; itr < sizeof(opts.werror)/sizeof(opts.werror[0]); ++itr)
325                             opts.werror[itr] = 0;
326                         break;
327                     }
328                     else if (!strcmp(argv[0]+2, "ERROR") ||
329                              !strcmp(argv[0]+2, "ERROR_ALL"))
330                     {
331                         for (itr = 0; itr < sizeof(opts.werror)/sizeof(opts.werror[0]); ++itr)
332                             opts.werror[itr] = 0xFFFFFFFFL;
333                         break;
334                     }
335                     else if (!strcmp(argv[0]+2, "NONE")) {
336                         for (itr = 0; itr < sizeof(opts.warn)/sizeof(opts.warn[0]); ++itr)
337                             opts.warn[itr] = 0;
338                         break;
339                     }
340                     else if (!strcmp(argv[0]+2, "ALL")) {
341                         for (itr = 0; itr < sizeof(opts.warn)/sizeof(opts.warn[0]); ++itr)
342                             opts.warn[itr] = 0xFFFFFFFFL;
343                         break;
344                     }
345                     else if (!strncmp(argv[0]+2, "ERROR_", 6)) {
346                         if (!opts_setwerror(argv[0]+8, true)) {
347                             con_out("unknown warning: %s\n", argv[0]+2);
348                             return false;
349                         }
350                     }
351                     else if (!strncmp(argv[0]+2, "NO_ERROR_", 9)) {
352                         if (!opts_setwerror(argv[0]+11, false)) {
353                             con_out("unknown warning: %s\n", argv[0]+2);
354                             return false;
355                         }
356                     }
357                     else if (!strncmp(argv[0]+2, "NO_", 3)) {
358                         if (!opts_setwarn(argv[0]+5, false)) {
359                             con_out("unknown warning: %s\n", argv[0]+2);
360                             return false;
361                         }
362                     }
363                     else if (!opts_setwarn(argv[0]+2, true)) {
364                         con_out("unknown warning: %s\n", argv[0]+2);
365                         return false;
366                     }
367                     break;
368
369                 case 'O':
370                     if (!options_witharg(&argc, &argv, &argarg)) {
371                         con_out("option -O requires a numerical argument, or optimization name with an optional 'no-' prefix\n");
372                         return false;
373                     }
374                     if (isdigit(argarg[0])) {
375                         opts.O = atoi(argarg);
376                         opts_setoptimlevel(opts.O);
377                     } else {
378                         util_strtocmd(argarg, argarg, strlen(argarg)+1);
379                         if (!strcmp(argarg, "HELP")) {
380                             con_out("Possible optimizations:\n");
381                             for (itr = 0; itr < COUNT_OPTIMIZATIONS; ++itr) {
382                                 util_strtononcmd(opts_opt_list[itr].name, buffer, sizeof(buffer));
383                                 con_out(" -O%-20s (-O%u)\n", buffer, opts_opt_oflag[itr]);
384                             }
385                             exit(0);
386                         }
387                         else if (!strcmp(argarg, "ALL"))
388                             opts_setoptimlevel(opts.O = 9999);
389                         else if (!strncmp(argarg, "NO_", 3)) {
390                             if (!opts_setoptim(argarg+3, false)) {
391                                 con_out("unknown optimization: %s\n", argarg+3);
392                                 return false;
393                             }
394                         }
395                         else {
396                             if (!opts_setoptim(argarg, true)) {
397                                 con_out("unknown optimization: %s\n", argarg);
398                                 return false;
399                             }
400                         }
401                     }
402                     break;
403
404                 case 'o':
405                     if (!options_witharg(&argc, &argv, &argarg)) {
406                         con_out("option -o requires an argument: the output file name\n");
407                         return false;
408                     }
409                     opts.output = argarg;
410                     opts_output_wasset = true;
411                     break;
412
413                 case 'a':
414                 case 's':
415                     item.type = argv[0][1] == 'a' ? TYPE_ASM : TYPE_SRC;
416                     if (!options_witharg(&argc, &argv, &argarg)) {
417                         con_out("option -a requires a filename %s\n",
418                                 (argv[0][1] == 'a' ? "containing QC-asm" : "containing a progs.src formatted list"));
419                         return false;
420                     }
421                     item.filename = argarg;
422                     vec_push(items, item);
423                     break;
424
425                 case '-':
426                     if (!argv[0][2]) {
427                         /* anything following -- is considered a non-option argument */
428                         argend = true;
429                         break;
430                     }
431             /* All long options without arguments */
432                     else if (!strcmp(argv[0]+2, "help")) {
433                         usage();
434                         exit(0);
435                     }
436                     else if (!strcmp(argv[0]+2, "version")) {
437                         version();
438                         exit(0);
439                     }
440                     else {
441             /* All long options with arguments */
442                         if (options_long_witharg("output", &argc, &argv, &argarg)) {
443                             opts.output = argarg;
444                             opts_output_wasset = true;
445                         } else {
446                             con_out("Unknown parameter: %s\n", argv[0]);
447                             return false;
448                         }
449                     }
450                     break;
451
452                 default:
453                     con_out("Unknown parameter: %s\n", argv[0]);
454                     return false;
455             }
456         }
457         else
458         {
459             /* it's a QC filename */
460             item.filename = argv[0];
461             item.type     = TYPE_QC;
462             vec_push(items, item);
463         }
464     }
465     opts_ini_init(config);
466     return true;
467 }
468
469 /* returns the line number, or -1 on error */
470 static bool progs_nextline(char **out, size_t *alen,FILE *src) {
471     int    len;
472     char  *line;
473     char  *start;
474     char  *end;
475
476     line = *out;
477     len  = file_getline(&line, alen, src);
478     if (len == -1)
479         return false;
480
481     /* start at first non-blank */
482     for (start = line; isspace(*start); ++start) {}
483     /* end at the first non-blank */
484     for (end = start;  *end && !isspace(*end);  ++end)   {}
485
486     *out = line;
487     /* move the actual filename to the beginning */
488     while (start != end) {
489         *line++ = *start++;
490     }
491     *line = 0;
492     return true;
493 }
494
495 int main(int argc, char **argv) {
496     size_t itr;
497     int    retval           = 0;
498     bool   opts_output_free = false;
499     bool   operators_free   = false;
500     bool   progs_src        = false;
501     FILE  *outfile          = NULL;
502
503     app_name = argv[0];
504     con_init ();
505     opts_init("progs.dat", COMPILER_GMQCC, (1024 << 3));
506
507     if (!options_parse(argc, argv)) {
508         return usage();
509     }
510
511     if (OPTS_FLAG(TRUE_EMPTY_STRINGS) && OPTS_FLAG(FALSE_EMPTY_STRINGS)) {
512         con_err("-ftrue-empty-strings and -ffalse-empty-strings are mutually exclusive");
513         exit(1);
514     }
515
516     /* the standard decides which set of operators to use */
517     if (opts.standard == COMPILER_GMQCC) {
518         operators      = c_operators;
519         operator_count = c_operator_count;
520     } else if (opts.standard == COMPILER_FTEQCC) {
521         operators      = fte_operators;
522         operator_count = fte_operator_count;
523     } else {
524         operators      = qcc_operators;
525         operator_count = qcc_operator_count;
526     }
527
528     if (operators == fte_operators) {
529         /* fix ternary? */
530         if (OPTS_FLAG(CORRECT_TERNARY)) {
531             oper_info *newops;
532             if (operators[operator_count-2].id != opid1(',') ||
533                 operators[operator_count-1].id != opid2(':','?'))
534             {
535                 con_err("internal error: operator precedence table wasn't updated correctly!\n");
536                 exit(1);
537             }
538             operators_free = true;
539             newops = mem_a(sizeof(operators[0]) * operator_count);
540             memcpy(newops, operators, sizeof(operators[0]) * operator_count);
541             memcpy(&newops[operator_count-2], &operators[operator_count-1], sizeof(newops[0]));
542             memcpy(&newops[operator_count-1], &operators[operator_count-2], sizeof(newops[0]));
543             newops[operator_count-2].prec = newops[operator_count-1].prec+1;
544             operators = newops;
545         }
546     }
547
548     if (opts.dump) {
549         for (itr = 0; itr < COUNT_FLAGS; ++itr)
550             con_out("Flag %s = %i\n",    opts_flag_list[itr].name, OPTS_FLAG(itr));
551         for (itr = 0; itr < COUNT_WARNINGS; ++itr)
552             con_out("Warning %s = %i\n", opts_warn_list[itr].name, OPTS_WARN(itr));
553         
554         con_out("output             = %s\n", opts.output);
555         con_out("optimization level = %d\n", opts.O);
556         con_out("standard           = %i\n", opts.standard);
557     }
558
559     if (opts.pp_only) {
560         if (opts_output_wasset) {
561             outfile = file_open(opts.output, "wb");
562             if (!outfile) {
563                 con_err("failed to open `%s` for writing\n", opts.output);
564                 retval = 1;
565                 goto cleanup;
566             }
567         }
568         else {
569          /* TODO: stdout without stdout .. */
570         }
571     }
572
573     if (!opts.pp_only) {
574         if (!parser_init()) {
575             con_err("failed to initialize parser\n");
576             retval = 1;
577             goto cleanup;
578         }
579     }
580
581     if (opts.pp_only || OPTS_FLAG(FTEPP)) {
582         if (!ftepp_init()) {
583             con_err("failed to initialize parser\n");
584             retval = 1;
585             goto cleanup;
586         }
587     }
588
589     if (OPTS_FLAG(TRUE_EMPTY_STRINGS))
590         type_not_instr[TYPE_STRING] = INSTR_NOT_F;
591
592     util_debug("COM", "starting ...\n");
593
594     /* add macros */
595     if (opts.pp_only || OPTS_FLAG(FTEPP)) {
596         for (itr = 0; itr < vec_size(ppems); itr++) {
597             ftepp_add_macro(ppems[itr].name, ppems[itr].value);
598             mem_d(ppems[itr].name);
599
600             /* can be null */
601             if (ppems[itr].value)
602                 mem_d(ppems[itr].value);
603         }
604     }
605
606     if (!vec_size(items)) {
607         FILE *src;
608         char *line;
609         size_t linelen = 0;
610
611         progs_src = true;
612
613         src = file_open("progs.src", "rb");
614         if (!src) {
615             con_err("failed to open `progs.src` for reading\n");
616             retval = 1;
617             goto cleanup;
618         }
619
620         line = NULL;
621         if (!progs_nextline(&line, &linelen, src) || !line[0]) {
622             con_err("illformatted progs.src file: expected output filename in first line\n");
623             retval = 1;
624             goto srcdone;
625         }
626
627         if (!opts_output_wasset) {
628             opts.output = util_strdup(line);
629             opts_output_free = true;
630         }
631
632         while (progs_nextline(&line, &linelen, src)) {
633             argitem item;
634             if (!line[0] || (line[0] == '/' && line[1] == '/'))
635                 continue;
636             item.filename = util_strdup(line);
637             item.type     = TYPE_QC;
638             vec_push(items, item);
639         }
640
641 srcdone:
642         file_close(src);
643         mem_d(line);
644     }
645
646     if (retval)
647         goto cleanup;
648
649     if (vec_size(items)) {
650         if (!opts.pp_only) {
651             con_out("Mode: %s\n", (progs_src ? "progs.src" : "manual"));
652             con_out("There are %lu items to compile:\n", (unsigned long)vec_size(items));
653         }
654         for (itr = 0; itr < vec_size(items); ++itr) {
655             if (!opts.pp_only) {
656                 con_out("  item: %s (%s)\n",
657                        items[itr].filename,
658                        ( (items[itr].type == TYPE_QC ? "qc" :
659                          (items[itr].type == TYPE_ASM ? "asm" :
660                          (items[itr].type == TYPE_SRC ? "progs.src" :
661                          ("unknown"))))));
662             }
663
664             if (opts.pp_only) {
665                 const char *out;
666                 if (!ftepp_preprocess_file(items[itr].filename)) {
667                     retval = 1;
668                     goto cleanup;
669                 }
670                 out = ftepp_get();
671                 if (out)
672                     file_printf(outfile, "%s", out);
673                 ftepp_flush();
674             }
675             else {
676                 if (OPTS_FLAG(FTEPP)) {
677                     const char *data;
678                     if (!ftepp_preprocess_file(items[itr].filename)) {
679                         retval = 1;
680                         goto cleanup;
681                     }
682                     data = ftepp_get();
683                     if (vec_size(data)) {
684                         if (!parser_compile_string_len(items[itr].filename, data, vec_size(data))) {
685                             retval = 1;
686                             goto cleanup;
687                         }
688                     }
689                     ftepp_flush();
690                 }
691                 else {
692                     if (!parser_compile_file(items[itr].filename)) {
693                         retval = 1;
694                         goto cleanup;
695                     }
696                 }
697             }
698
699             if (progs_src) {
700                 mem_d(items[itr].filename);
701                 items[itr].filename = NULL;
702             }
703         }
704
705         ftepp_finish();
706         if (!opts.pp_only) {
707             if (!parser_finish(opts.output)) {
708                 retval = 1;
709                 goto cleanup;
710             }
711         }
712     }
713
714     /* stuff */
715     if (!opts.pp_only) {
716         for (itr = 0; itr < COUNT_OPTIMIZATIONS; ++itr) {
717             if (opts_optimizationcount[itr]) {
718                 con_out("%s: %u\n", opts_opt_list[itr].name, (unsigned int)opts_optimizationcount[itr]);
719             }
720         }
721     }
722
723 cleanup:
724     util_debug("COM", "cleaning ...\n");
725     ftepp_finish();
726     con_close();
727     vec_free(items);
728     vec_free(ppems);
729
730     if (!opts.pp_only)
731         parser_cleanup();
732     if (opts_output_free)
733         mem_d((char*)opts.output);
734     if (operators_free)
735         mem_d((void*)operators);
736
737     lex_cleanup();
738     util_meminfo();
739     return retval;
740 }