From 625915288ccfb19576d62d2bd52bbd1cd22ca038 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 25 Jun 2001 23:38:32 +0000 Subject: [PATCH] hopefully make line directives work --- tools/qfcc/source/qc-lex.l | 23 ++++++++++++++++++----- tools/qfcc/source/qc-parse.y | 4 ++-- tools/qfcc/source/qfcc.c | 3 +-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index 6b6bea7c4..7cfd3aa9f 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -7,9 +7,7 @@ #define YY_NO_UNPUT -int lineno; - -void error (char*s){fprintf(stderr,"%d: %s\n",lineno,s);} +void error (char*s){fprintf(stderr,"%d: %s\n",pr_source_line,s);} int type_or_name (char *token); @@ -45,7 +43,7 @@ m ([\-+]?) if (c == EOF) error ("EOF in comment"); if (c == '\n') - lineno++; + pr_source_line++; } while (c != '/' && c != EOF); } @@ -83,6 +81,21 @@ m ([\-+]?) } ^#{s}+{DIGIT}+{s}+\"(\.|[^"])*\".*$ { + char *p; + int line; + + pr_file_p = yytext + 1; + line = strtol (pr_file_p, &p, 10); + pr_file_p = p; + while (isspace (*pr_file_p)) + pr_file_p++; + if (!*pr_file_p) + PR_ParseError ("Unexpected end of file"); + PR_LexString (); // grab the filename + while (*pr_file_p && *pr_file_p != '\n') // ignore flags + pr_file_p++; + pr_source_line = line - 1; + s_file = ReuseString (pr_immediate_string); } "!"|"("|")"|"{"|"}"|"."|"*"|"/"|"&"|"|"|"+"|"-"|"="|"["|"]"|";"|","|"#" return yytext[0]; @@ -111,7 +124,7 @@ m ([\-+]?) [^\n]* /* skip */ <*>\n { - lineno++; + pr_source_line++; BEGIN (INITIAL); } diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index f69c08a0a..9e67a7ac9 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -6,12 +6,12 @@ #define YYERROR_VERBOSE 1 extern char *yytext; -extern int lineno; +extern int pr_source_line; void yyerror (const char *s) { - fprintf (stderr, "%d, %s %s\n", lineno, yytext, s); + fprintf (stderr, "%d, %s %s\n", pr_source_line, yytext, s); } int yylex (void); diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 6d803129f..ff571ebfd 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -906,7 +906,6 @@ Options: \n\ #ifdef NEW_PARSER extern FILE *yyin; int yyparse(void); - extern int lineno; extern void clear_frame_macros (void); //extern int yydebug; //yydebug = 1; @@ -916,7 +915,7 @@ Options: \n\ yyin = fopen (filename, "rt"); s_file = ReuseString (filename); - lineno = 1; + pr_source_line = 1; clear_frame_macros (); if (yyparse ()) { printf ("%s\n", filename);