From 2a19f6b700646be5158f4eefbd0edf60c340b7c7 Mon Sep 17 00:00:00 2001 From: cuz Date: Wed, 31 Aug 2005 21:29:11 +0000 Subject: [PATCH] Fixed minor and rather obscure problem: When including files, the line after the .include statement went into the listing file, before the contents of the include file. The problem was caused by the several levels of lookahead in the scanner, and the only way to avoid it was to remove the calls to NextTok () in relevant places - and add compensation for it in others. git-svn-id: svn://svn.cc65.org/cc65/trunk@3609 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/pseudo.c | 9 +-------- src/ca65/scanner.c | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index cfd5592e9..cca2fbe69 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1106,15 +1106,11 @@ Done: static void DoInclude (void) /* Include another file */ { - char Name [MAX_STR_LEN+1]; - /* Name must follow */ if (Tok != TOK_STRCON) { ErrorSkip ("String constant expected"); } else { - strcpy (Name, SVal); - NextTok (); - NewInputFile (Name); + NewInputFile (SVal); } } @@ -1222,9 +1218,6 @@ static void DoMacPack (void) return; } - /* Skip the package name */ - NextTok (); - /* Insert the package */ MacPackInsert (Package); } diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 5f64c2ade..9c3790931 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -364,8 +364,12 @@ void NewInputFile (const char* Name) IFile = I; ++ICount; - /* Prime the pump */ - NextChar (); + /* Setup the next token and character so it will be skipped on the + * next call to NextRawTok(). + */ + C = ' '; + Tok = TOK_SEP; + } } @@ -409,8 +413,11 @@ void NewInputData (char* Data, int Malloced) I->Next = IData; IData = I; - /* Prime the pump */ - NextChar (); + /* Setup the next token and character so it will be skipped on the + * next call to NextRawTok(). + */ + C = ' '; + Tok = TOK_SEP; } @@ -457,8 +464,8 @@ static void NextChar (void) C = *IData->Pos++; if (C == '\0') { - /* End of input data, will set to last file char */ - DoneInputData (); + /* End of input data */ + C = EOF; } } else { @@ -1198,11 +1205,21 @@ CharAgain: /* Check if we have any open token lists in this file */ CheckInputStack (); - /* If this was an include file, then close it and handle like a - * separator. Do not close the main file, but return EOF. + /* If this was an include file, then close it and read the next + * token. When an include file is opened, the last token of the + * old file is not skipped, to prevent the lookahead to read + * the next line of the old input file. So we do effectively + * skip the last token in the old file (the file name of the + * include statement). + * In case of the main file, do not close it, but return EOF. */ - if (ICount > 1) { + if (IData) { + /* Input came from internal data */ + DoneInputData (); + goto Again; + } else if (ICount > 1) { DoneInputFile (); + goto Again; } else { Tok = TOK_EOF; }