#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
/* 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"
/*****************************************************************************/
-/* struct IFile */
+/* struct IFile */
/*****************************************************************************/
/* 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 */
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);
return;
}
+ /* Debugging output */
+ Print (stdout, 1, "Opened include file `%s'\n", IF->Name);
+
/* Allocate a new AFile structure */
(void) NewAFile (IF, F);
}
/* 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';