X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Finput.c;h=0f254f4921bb6034ad7ec79a62425aae5c46fae6;hb=aef8789873bd008d42aa50330ca98488fad91b31;hp=307d3557ed533f7419961633e52479449a6ccc36;hpb=0e80187cec763daaf02a3dae725233c6885cf41a;p=cc65 diff --git a/src/cc65/input.c b/src/cc65/input.c index 307d3557e..0f254f492 100644 --- a/src/cc65/input.c +++ b/src/cc65/input.c @@ -36,14 +36,18 @@ #include #include #include +#include +#include /* common */ #include "check.h" #include "coll.h" +#include "print.h" #include "xmalloc.h" /* cc65 */ #include "asmcode.h" +#include "codegen.h" #include "error.h" #include "incpath.h" #include "lineinfo.h" @@ -86,7 +90,7 @@ static Collection AFiles = STATIC_COLLECTION_INITIALIZER; /*****************************************************************************/ -/* struct IFile */ +/* struct IFile */ /*****************************************************************************/ @@ -103,6 +107,8 @@ static IFile* NewIFile (const char* Name) /* Initialize the fields */ IF->Index = CollCount (&IFiles) + 1; IF->Usage = 0; + IF->Size = 0; + IF->MTime = 0; memcpy (IF->Name, Name, Len+1); /* Insert the new structure into the IFile collection */ @@ -131,8 +137,24 @@ static AFile* NewAFile (IFile* IF, FILE* F) AF->F = F; AF->Input = IF; - /* Increment the usage counter of the corresponding IFile */ - ++IF->Usage; + /* Increment the usage counter of the corresponding IFile. If this + * is the first use, set the file data and output debug info if + * requested. + */ + if (IF->Usage++ == 0) { + + /* Get file size and modification time */ + struct stat Buf; + if (fstat (fileno (F), &Buf) != 0) { + /* Error */ + Fatal ("Cannot stat `%s': %s", IF->Name, strerror (errno)); + } + IF->Size = (unsigned long) Buf.st_size; + IF->MTime = (unsigned long) Buf.st_mtime; + + /* Set the debug data */ + g_fileinfo (IF->Name, IF->Size, IF->MTime); + } /* Insert the new structure into the AFile collection */ CollAppend (&AFiles, AF); @@ -238,6 +260,9 @@ void OpenIncludeFile (const char* Name, unsigned DirSpec) return; } + /* Debugging output */ + Print (stdout, 1, "Opened include file `%s'\n", IF->Name); + /* Allocate a new AFile structure */ (void) NewAFile (IF, F); } @@ -362,11 +387,14 @@ int NextLine (void) /* We got a new line */ ++Input->Line; - /* Remove the trailing newline if we have one */ + /* Remove the trailing cr/lf if we have one. We will ignore both, cr + * and lf on all systems since this enables us to compile DOS/Windows + * stuff also on unix systems (where fgets does not remove the cr). + */ Part = strlen (line + Len); Start = Len; Len += Part; - while (Len > 0 && line [Len-1] == '\n') { + while (Len > 0 && (line[Len-1] == '\n' || line[Len-1] == '\r')) { --Len; } line [Len] = '\0';