X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Finput.c;h=0f254f4921bb6034ad7ec79a62425aae5c46fae6;hb=aef8789873bd008d42aa50330ca98488fad91b31;hp=f650dac5e7eb41c2f750929179ab00e9146cdab6;hpb=bc8f4f3a1e7f1f599974239cc15f1cab6aca846b;p=cc65 diff --git a/src/cc65/input.c b/src/cc65/input.c index f650dac5e..0f254f492 100644 --- a/src/cc65/input.c +++ b/src/cc65/input.c @@ -42,10 +42,11 @@ /* common */ #include "check.h" #include "coll.h" +#include "print.h" #include "xmalloc.h" /* cc65 */ -#include "asmcode.h" +#include "asmcode.h" #include "codegen.h" #include "error.h" #include "incpath.h" @@ -89,53 +90,7 @@ static Collection AFiles = STATIC_COLLECTION_INITIALIZER; /*****************************************************************************/ -/* Helper functions */ -/*****************************************************************************/ - - - -static long GetFileSize (FILE* F) -/* Calculate the size of the file F, return -1 on error. */ -{ - long Size; - long CurPos = ftell (F); - if (CurPos < 0) { - /* Error */ - return -1; - } - if (fseek (F, 0, SEEK_END) != 0) { - /* Error */ - return -1; - } - Size = ftell (F); - if (Size < 0) { - /* Error */ - return -1; - } - if (fseek (F, CurPos, SEEK_SET) != 0) { - /* Error */ - return -1; - } - return Size; -} - - - -static long GetFileTime (const char* Name) -/* Get the time of last modification for the given file. Return -1 on errors. */ -{ - struct stat Buf; - if (stat (Name, &Buf) != 0) { - /* Error */ - return -1; - } - return (long) Buf.st_mtime; -} - - - -/*****************************************************************************/ -/* struct IFile */ +/* struct IFile */ /*****************************************************************************/ @@ -188,21 +143,14 @@ static AFile* NewAFile (IFile* IF, FILE* F) */ if (IF->Usage++ == 0) { - long Val; - - /* Get the file size */ - Val = GetFileSize (AF->F); - if (Val < 0) { - Fatal ("Cannot seek on `%s': %s", IF->Name, strerror (errno)); - } - IF->Size = Val; - - /* Get the file modification time */ - Val = GetFileTime (IF->Name); - if (Val < 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->MTime = Val; + 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); @@ -312,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); } @@ -436,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';