X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=main.c;h=990acf2c1b51565ba2fe1fe3a9deb8edceb23e2b;hb=ed6189e65531819b21c12651e2eb8118bf3e0f17;hp=1301e7549b70da667312bf89e2e27f6acb0e5731;hpb=d1373af7fc9b4657b1fb663bf6ea03c73e9ab8c7;p=xonotic%2Fgmqcc.git diff --git a/main.c b/main.c index 1301e75..990acf2 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,7 @@ /* * Copyright (C) 2012 * Dale Weiler + * Wolfgang Bumiller * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -202,6 +203,7 @@ static bool options_parse(int argc, char **argv) { options_set(opts_flags, ADJUST_VECTOR_FIELDS, false); opts_standard = COMPILER_QCC; } else if (!strcmp(argarg, "fte") || !strcmp(argarg, "fteqcc")) { + options_set(opts_flags, FTEPP, true); options_set(opts_flags, ADJUST_VECTOR_FIELDS, false); opts_standard = COMPILER_FTEQCC; } else if (!strcmp(argarg, "qccx")) { @@ -416,6 +418,7 @@ int main(int argc, char **argv) { int retval = 0; bool opts_output_free = false; bool progs_src = false; + FILE *outfile = NULL; app_name = argv[0]; con_init(); @@ -440,6 +443,7 @@ int main(int argc, char **argv) { options_set(opts_warn, WARN_MULTIFILE_IF, true); options_set(opts_flags, ADJUST_VECTOR_FIELDS, true); + options_set(opts_flags, FTEPP, false); if (!options_parse(argc, argv)) { return usage(); @@ -466,6 +470,19 @@ int main(int argc, char **argv) { con_out("standard = %i\n", opts_standard); } + if (opts_pp_only) { + if (opts_output_wasset) { + outfile = util_fopen(opts_output, "wb"); + if (!outfile) { + con_err("failed to open `%s` for writing\n", opts_output); + retval = 1; + goto cleanup; + } + } + else + outfile = stdout; + } + if (!opts_pp_only) { if (!parser_init()) { con_err("failed to initialize parser\n"); @@ -473,17 +490,8 @@ int main(int argc, char **argv) { goto cleanup; } } - if (opts_pp_only || opts_standard == COMPILER_FTEQCC) { - FILE *out = NULL; - if (opts_output_wasset) { - out = util_fopen(opts_output, "wb"); - if (!out) { - con_err("failed to open `%s` for writing\n", opts_output); - retval = 1; - goto cleanup; - } - } - if (!ftepp_init(out)) { + if (opts_pp_only || OPTS_FLAG(FTEPP)) { + if (!ftepp_init()) { con_err("failed to initialize parser\n"); retval = 1; goto cleanup; @@ -555,10 +563,29 @@ srcdone: retval = 1; goto cleanup; } + fprintf(outfile, "%s", ftepp_get()); + ftepp_flush(); } - else if (!parser_compile_file(items[itr].filename)) { - retval = 1; - goto cleanup; + else { + if (OPTS_FLAG(FTEPP)) { + const char *data; + if (!ftepp_preprocess_file(items[itr].filename)) { + retval = 1; + goto cleanup; + } + data = ftepp_get(); + if (!parser_compile_string_len(items[itr].filename, data, vec_size(data)-1)) { + retval = 1; + goto cleanup; + } + ftepp_flush(); + } + else { + if (!parser_compile_file(items[itr].filename)) { + retval = 1; + goto cleanup; + } + } } if (progs_src) { @@ -584,7 +611,8 @@ cleanup: con_close(); vec_free(items); - parser_cleanup(); + if (!opts_pp_only) + parser_cleanup(); if (opts_output_free) mem_d((char*)opts_output);