diff --git a/tools/qfcc/include/rua-lang.h b/tools/qfcc/include/rua-lang.h index 6b35311aa..bb299fa7b 100644 --- a/tools/qfcc/include/rua-lang.h +++ b/tools/qfcc/include/rua-lang.h @@ -80,6 +80,7 @@ rua_macro_t *rua_macro_append (rua_macro_t *macro, rua_tok_t *token, void *scanner); void rua_macro_finish (rua_macro_t *macro, void *scanner); rua_macro_t *rua_macro_arg (rua_macro_t *arg, void *scanner); +void rua_start_pragma (void *scanner); void rua_start_text (void *scanner); void rua_start_expr (void *scanner); void rua_expand_on (void *scanner); diff --git a/tools/qfcc/source/pragma.c b/tools/qfcc/source/pragma.c index 4c2776d4a..82e0cd3cd 100644 --- a/tools/qfcc/source/pragma.c +++ b/tools/qfcc/source/pragma.c @@ -205,6 +205,9 @@ set_math (pragma_arg_t *args) void pragma_process () { + if (options.preprocess_only) { + return; + } if (!pragma_args) { warning (0, "empty pragma"); return; @@ -239,6 +242,10 @@ pragma_process () void pragma_add_arg (const char *id) { + if (options.preprocess_only) { + printf (" %s", id); + return; + } pragma_arg_t *arg; ALLOC (16, pragma_arg_t, pragma_args, arg); arg->arg = save_string (id); diff --git a/tools/qfcc/source/pre-parse.y b/tools/qfcc/source/pre-parse.y index 5d753f128..98eb226cd 100644 --- a/tools/qfcc/source/pre-parse.y +++ b/tools/qfcc/source/pre-parse.y @@ -167,7 +167,8 @@ directive | UNDEF ID extra_warn { rua_undefine ($2, scanner); } | ERROR text { error (0, "%s", $text->str); dstring_delete ($text); } | WARNING text { warning (0, "%s", $text->str); dstring_delete ($text); } - | PRAGMA expand pragma_params { pragma_process (); } + | PRAGMA expand { rua_start_pragma (scanner); } + pragma_params { pragma_process (); } | LINE expand expr QSTRING extra_warn | IF expand expr { rua_if (expr_long ($3), scanner); } | IFDEF ID extra_warn { rua_if (rua_defined ($2, scanner), scanner); } @@ -212,8 +213,8 @@ expand ; pragma_params - : ID { pragma_add_arg (pre_yytext); } - | pragma_params ID { pragma_add_arg (pre_yytext); } + : ID { pragma_add_arg ($1); } + | pragma_params ID { pragma_add_arg ($2); } ; string diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index 72b26c395..044763e4e 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -246,8 +246,6 @@ pp_vnumber '({s}*{m}?{pp_number}){2,4}{s}*'{ULFD}? ^#{s}+{D}+{s}+\"(\.|[^"\n])*\".*$ { line_info (yytext + 1); } ^#line{s}+{D}+{s}+\"(\.|[^"\n])*\".*$ { line_info (yytext + 5); } -^{s}*#{s}*pragma{s}+ { yy_push_state (PRAGMA, yyscanner); } - { {ID} | @{ID} { return -rua_id; } @@ -317,15 +315,13 @@ pp_vnumber '({s}*{m}?{pp_number}){2,4}{s}*'{ULFD}? write_frame_macros (s); BEGIN (GRAB_OTHER); // ignore rest of line } -{PRAGMAID} { pragma_add_arg (yytext); } -@{PRAGMAID} { pragma_add_arg (yytext); } +{PRAGMAID} | +@{PRAGMAID} { return PRE_ID; } +\r*\n { next_line (yylloc, yyscanner); return PRE_EOD; } <*>\\\r*\n { next_line (yylloc, yyscanner); }/*line continuation*/ \r*\n { next_line (yylloc, yyscanner); return -rua_space; } <*>\r*\n { - if (YY_START == PRAGMA) { - pragma_process (); - } next_line (yylloc, yyscanner); if (yyg->yy_start_stack_ptr) { yy_pop_state (yyscanner); @@ -1586,6 +1582,16 @@ rua_macro_arg (rua_macro_t *arg, void *scanner) return arg; } +void +rua_start_pragma (void *scanner) +{ + if (options.preprocess_only) { + printf ("#pragma"); + } + yy_pop_state (scanner); + yy_push_state (PRAGMA, scanner); +} + void rua_start_text (void *scanner) {