1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-25 17:29:50 +00:00

Fixed a bug: Compiling an empty source file led to an internal error.

Changed the lineinfo module to take dynamically allocated string buffers
instead of char*.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3523 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2005-06-08 11:31:00 +00:00
parent 7579aba638
commit 0da97c6711
3 changed files with 40 additions and 24 deletions

View File

@ -205,6 +205,9 @@ static IFile* FindFile (const char* Name)
void OpenMainFile (const char* Name)
/* Open the main file. Will call Fatal() in case of failures. */
{
AFile* MainFile;
/* Setup a new IFile structure for the main file */
IFile* IF = NewIFile (Name);
@ -216,10 +219,15 @@ void OpenMainFile (const char* Name)
}
/* Allocate a new AFile structure for the file */
(void) NewAFile (IF, F);
MainFile = NewAFile (IF, F);
/* Allocate the input line buffer */
Line = NewStrBuf ();
/* Update the line infos, so we have a valid line info even at start of
* the main file before the first line is read.
*/
UpdateLineInfo (MainFile->Input, MainFile->Line, Line);
}
@ -340,7 +348,7 @@ static void GetInputChar (void)
void NextChar (void)
/* Skip the current input character and read the next one from the input
* stream. CurC and NextC are valid after the call. If end of line is
* stream. CurC and NextC are valid after the call. If end of line is
* reached, both are set to NUL, no more lines are read by this function.
*/
{
@ -478,7 +486,7 @@ int NextLine (void)
InitLine (Line);
/* Create line information for this line */
UpdateLineInfo (Input->Input, Input->Line, SB_GetConstBuf (Line));
UpdateLineInfo (Input->Input, Input->Line, Line);
/* Done */
return 1;

View File

@ -64,22 +64,25 @@ static LineInfo* CurLineInfo = 0;
static LineInfo* NewLineInfo (struct IFile* F, unsigned LineNum, const char* Line)
static LineInfo* NewLineInfo (struct IFile* F, unsigned LineNum, const StrBuf* Line)
/* Create and return a new line info. Ref count will be 1. */
{
unsigned Len;
LineInfo* LI;
char* T;
unsigned Len;
LineInfo* LI;
const char* S;
char* T;
/* Get the length of the line and a pointer to the line buffer */
Len = SB_GetLen (Line);
S = SB_GetConstBuf (Line);
/* Skip leading spaces in Line */
while (IsBlank (*Line)) {
++Line;
while (Len > 0 && IsBlank (*S)) {
++S;
--Len;
}
/* Calculate the length of the line */
Len = strlen (Line);
/* Allocate memory */
/* Allocate memory for the line info and the input line */
LI = xmalloc (sizeof (LineInfo) + Len);
/* Initialize the fields */
@ -93,13 +96,13 @@ static LineInfo* NewLineInfo (struct IFile* F, unsigned LineNum, const char* Lin
*/
T = LI->Line;
while (Len--) {
if (*Line == '\t') {
*T = ' ';
} else {
*T = *Line;
}
++Line;
++T;
if (*S == '\t') {
*T = ' ';
} else {
*T = *S;
}
++S;
++T;
}
/* Add the terminator */
@ -153,7 +156,7 @@ LineInfo* GetCurLineInfo (void)
void UpdateLineInfo (struct IFile* F, unsigned LineNum, const char* Line)
void UpdateLineInfo (struct IFile* F, unsigned LineNum, const StrBuf* Line)
/* Update the line info - called if a new line is read */
{
/* If a current line info exists, release it */
@ -165,7 +168,7 @@ void UpdateLineInfo (struct IFile* F, unsigned LineNum, const char* Line)
* of the supplied one to save some memory.
*/
if (!AddSource) {
Line = "";
Line = &EmptyStrBuf;
}
/* Create a new line info */

View File

@ -37,6 +37,11 @@
#define LINEINFO_H
/* common */
#include "strbuf.h"
/*****************************************************************************/
/* Forwards */
@ -45,7 +50,7 @@
/* Input file structure */
struct IFile;
struct IFile;
@ -87,7 +92,7 @@ LineInfo* GetCurLineInfo (void);
* increased, use UseLineInfo for that purpose.
*/
void UpdateLineInfo (struct IFile* F, unsigned LineNum, const char* Line);
void UpdateLineInfo (struct IFile* F, unsigned LineNum, const StrBuf* Line);
/* Update the line info - called if a new line is read */
const char* GetInputName (const LineInfo* LI);