From 40418f87c7da9d3358363769fb13c558b43f2847 Mon Sep 17 00:00:00 2001 From: seyko Date: Tue, 3 Mar 2015 14:15:28 +0300 Subject: [PATCH] Move a line_ref variable from tcc_preprocess() function into struct BufferedFile. This id needed for a right ouput in other places, precisely to calculate a number of empty lines which are waiting to output. --- tcc.h | 1 + tccpp.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tcc.h b/tcc.h index 0a052329..e77a3fb0 100644 --- a/tcc.h +++ b/tcc.h @@ -500,6 +500,7 @@ typedef struct BufferedFile { int fd; struct BufferedFile *prev; int line_num; /* current line number - here to simplify code */ + int line_ref; /* moved from tcc_preprocess(), needed for a right ouput in other places */ int ifndef_macro; /* #ifndef macro / #endif search */ int ifndef_macro_saved; /* saved ifndef_macro */ int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */ diff --git a/tccpp.c b/tccpp.c index 405a5d67..ab70ba28 100644 --- a/tccpp.c +++ b/tccpp.c @@ -3139,7 +3139,7 @@ ST_FUNC int tcc_preprocess(TCCState *s1) Sym *define_start; BufferedFile *file_ref, **iptr, **iptr_new; - int token_seen, line_ref, d; + int token_seen, d; const char *s; preprocess_init(s1); @@ -3149,7 +3149,7 @@ ST_FUNC int tcc_preprocess(TCCState *s1) parse_flags = PARSE_FLAG_ASM_COMMENTS | PARSE_FLAG_PREPROCESS | PARSE_FLAG_LINEFEED | PARSE_FLAG_SPACES; token_seen = 0; - line_ref = 0; + file->line_ref = 0; file_ref = NULL; iptr = s1->include_stack_ptr; @@ -3162,10 +3162,10 @@ ST_FUNC int tcc_preprocess(TCCState *s1) } else if (tok == TOK_LINEFEED) { if (!token_seen) continue; - ++line_ref; + file->line_ref++; token_seen = 0; } else if (!token_seen) { - d = file->line_num - line_ref; + d = file->line_num - file->line_ref; if (file != file_ref || d < 0 || d >= 8) { print_line: iptr_new = s1->include_stack_ptr; @@ -3180,7 +3180,7 @@ print_line: while (d) fputs("\n", s1->ppfp), --d; } - line_ref = (file_ref = file)->line_num; + file->line_ref = (file_ref = file)->line_num; token_seen = tok != TOK_LINEFEED; if (!token_seen) continue;