From c6dc756d4e6905df8498596f5bd0c5a6aa1c6d24 Mon Sep 17 00:00:00 2001 From: seyko Date: Fri, 15 Apr 2016 17:15:11 +0300 Subject: preprocessor oprtion -C (keep comments) This is done by impression of the pcc -C option. Usual execution path and speed are not changed. --- libtcc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libtcc.c') diff --git a/libtcc.c b/libtcc.c index 678ba23..d587179 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1604,6 +1604,21 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) { s->output_type = output_type; + if (s->output_type == TCC_OUTPUT_PREPROCESS) { + if (!s->outfile) { + s->ppfp = stdout; + } else { + s->ppfp = fopen(s->outfile, "w"); + if (!s->ppfp) + tcc_error("could not write '%s'", s->outfile); + } + s->dffp = s->ppfp; + if (s->dflag == 'M') + s->ppfp = NULL; + } + if (s->option_C && !s->ppfp) + s->option_C = 0; + if (!s->nostdinc) { /* default include paths */ /* -isystem paths have already been handled */ @@ -1946,6 +1961,7 @@ enum { TCC_OPTION_b, TCC_OPTION_g, TCC_OPTION_c, + TCC_OPTION_C, TCC_OPTION_dumpversion, TCC_OPTION_d, TCC_OPTION_float_abi, @@ -2003,6 +2019,7 @@ static const TCCOption tcc_options[] = { #endif { "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, { "c", TCC_OPTION_c, 0 }, + { "C", TCC_OPTION_C, 0 }, { "dumpversion", TCC_OPTION_dumpversion, 0}, { "d", TCC_OPTION_d, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, #ifdef TCC_TARGET_ARM @@ -2191,6 +2208,9 @@ ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv) tcc_warning("-c: some compiler action already specified (%d)", s->output_type); s->output_type = TCC_OUTPUT_OBJ; break; + case TCC_OPTION_C: + s->option_C = 1; + break; case TCC_OPTION_d: if (*optarg == 'D' || *optarg == 'M') s->dflag = *optarg; -- cgit v1.3.1