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