From: cuz Date: Wed, 23 May 2001 21:32:57 +0000 (+0000) Subject: Use a separate structure for file infos instead of just the name. X-Git-Tag: V2.12.0~2815 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=275da22a66d69e2e5ecaa92766104833f0de767a;p=cc65 Use a separate structure for file infos instead of just the name. git-svn-id: svn://svn.cc65.org/cc65/trunk@749 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ld65/fileinfo.c b/src/ld65/fileinfo.c new file mode 100644 index 000000000..e8e31b4d2 --- /dev/null +++ b/src/ld65/fileinfo.c @@ -0,0 +1,79 @@ +/*****************************************************************************/ +/* */ +/* fileinfo.c */ +/* */ +/* sOURCE FILE INFO STRUCTURE */ +/* */ +/* */ +/* */ +/* (C) 2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +/* common */ +#include "xmalloc.h" + +/* ld65 */ +#include "fileio.h" +#include "fileinfo.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +static FileInfo* NewFileInfo (void) +/* Allocate and initialize a new FileInfo struct and return it */ +{ + /* Allocate memory */ + FileInfo* FI = xmalloc (sizeof (FileInfo)); + + /* Return the new struct */ + return FI; +} + + + +FileInfo* ReadFileInfo (FILE* F, ObjData* O) +/* Read a file info from a file and return it */ +{ + /* Allocate a new FileInfo structure */ + FileInfo* FI = NewFileInfo (); + + /* Read the fields from the file */ + FI->MTime = Read32 (F); + FI->Size = Read32 (F); + FI->Name = ReadStr (F); + + /* Return the new struct */ + return FI; +} + + + diff --git a/src/ld65/fileinfo.h b/src/ld65/fileinfo.h new file mode 100644 index 000000000..162e95d44 --- /dev/null +++ b/src/ld65/fileinfo.h @@ -0,0 +1,82 @@ +/*****************************************************************************/ +/* */ +/* fileinfo.h */ +/* */ +/* Source file info structure */ +/* */ +/* */ +/* */ +/* (C) 2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef FILEINFO_H +#define FILEINFO_H + + + +#include + +/* common */ +#include "coll.h" +#include "filepos.h" + +/* ld65 */ +#include "objdata.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +typedef struct FileInfo FileInfo; +struct FileInfo { + unsigned long MTime; /* Time of last modification */ + unsigned long Size; /* Size of the file */ + char* Name; /* File name */ +}; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +FileInfo* ReadFileInfo (FILE* F, ObjData* O); +/* Read a file info from a file and return it */ + + + +/* End of fileinfo.h */ +#endif + + + diff --git a/src/ld65/lineinfo.c b/src/ld65/lineinfo.c index 5cc2e19e1..1811e5a01 100644 --- a/src/ld65/lineinfo.c +++ b/src/ld65/lineinfo.c @@ -34,6 +34,7 @@ /* common */ +#include "check.h" #include "xmalloc.h" /* ld65 */ @@ -55,6 +56,7 @@ static LineInfo* NewLineInfo (void) LineInfo* LI = xmalloc (sizeof (LineInfo)); /* Initialize the fields */ + LI->File = 0; InitFilePos (&LI->Pos); InitCollection (&LI->Fragments); @@ -73,6 +75,10 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O) /* Read the file position */ ReadFilePos (F, &LI->Pos); + /* Resolve the file index to a pointer to FileInfo struct */ + CHECK (LI->Pos.Name < O->FileCount); + LI->File = O->Files[LI->Pos.Name]; + /* Return the new LineInfo */ return LI; } diff --git a/src/ld65/lineinfo.h b/src/ld65/lineinfo.h index 98138c47c..8a40126f3 100644 --- a/src/ld65/lineinfo.h +++ b/src/ld65/lineinfo.h @@ -55,8 +55,9 @@ typedef struct LineInfo LineInfo; struct LineInfo { - FilePos Pos; /* File position */ - Collection Fragments; /* Fragments for this line */ + struct FileInfo* File; /* File struct for this line */ + FilePos Pos; /* File position */ + Collection Fragments; /* Fragments for this line */ }; diff --git a/src/ld65/make/gcc.mak b/src/ld65/make/gcc.mak index f48fc8bc5..3dfdd2670 100644 --- a/src/ld65/make/gcc.mak +++ b/src/ld65/make/gcc.mak @@ -27,6 +27,7 @@ OBJS = bin.o \ exports.o \ expr.o \ extsyms.o \ + fileinfo.o \ fileio.o \ fragment.o \ global.o \ diff --git a/src/ld65/make/watcom.mak b/src/ld65/make/watcom.mak index 0a9c66585..ab731b54b 100644 --- a/src/ld65/make/watcom.mak +++ b/src/ld65/make/watcom.mak @@ -76,10 +76,12 @@ OBJS = bin.obj \ exports.obj \ expr.obj \ extsyms.obj \ + fileinfo.obj \ fileio.obj \ fragment.obj \ global.obj \ library.obj \ + lineinfo.obj \ main.obj \ mapfile.obj \ o65.obj \ diff --git a/src/ld65/objdata.c b/src/ld65/objdata.c index 8deecb0f7..5183c7d81 100644 --- a/src/ld65/objdata.c +++ b/src/ld65/objdata.c @@ -41,6 +41,7 @@ /* ld65 */ #include "error.h" +#include "fileinfo.h" #include "objdata.h" @@ -110,7 +111,7 @@ void FreeObjData (ObjData* O) xfree (O->Name); xfree (O->Imports); xfree (O->Exports); - xfree (O->DbgSyms); + xfree (O->DbgSyms); xfree (O->LineInfos); xfree (O); } @@ -144,7 +145,7 @@ const char* GetSourceFileName (const ObjData* O, unsigned Index) PRECONDITION (Index < O->FileCount); /* Return the name */ - return O->Files[Index]; + return O->Files[Index]->Name; } } diff --git a/src/ld65/objdata.h b/src/ld65/objdata.h index a6d39ace7..cca2f7a38 100644 --- a/src/ld65/objdata.h +++ b/src/ld65/objdata.h @@ -65,7 +65,7 @@ struct ObjData { unsigned long Start; /* Start offset of data in library */ unsigned Flags; unsigned FileCount; /* Input file count */ - char** Files; /* List of input files */ + struct FileInfo** Files; /* List of input files */ unsigned SectionCount; /* Count of sections in this object */ struct Section** Sections; /* List of all sections */ unsigned ExportCount; /* Count of exports */ diff --git a/src/ld65/objfile.c b/src/ld65/objfile.c index f08b14761..b11794236 100644 --- a/src/ld65/objfile.c +++ b/src/ld65/objfile.c @@ -46,6 +46,7 @@ #include "dbgsyms.h" #include "error.h" #include "exports.h" +#include "fileinfo.h" #include "fileio.h" #include "lineinfo.h" #include "objdata.h" @@ -112,13 +113,9 @@ void ObjReadFiles (FILE* F, ObjData* O) unsigned I; O->FileCount = ReadVar (F); - O->Files = xmalloc (O->FileCount * sizeof (char*)); + O->Files = xmalloc (O->FileCount * sizeof (FileInfo*)); for (I = 0; I < O->FileCount; ++I) { - /* Skip MTime and size */ - Read32 (F); - Read32 (F); - /* Read the filename */ - O->Files [I] = ReadStr (F); + O->Files[I] = ReadFileInfo (F, O); } } @@ -158,7 +155,7 @@ void ObjReadDbgSyms (FILE* F, ObjData* O) /* Read the debug symbols from a file at the current position */ { unsigned I; - + O->DbgSymCount = ReadVar (F); O->DbgSyms = xmalloc (O->DbgSymCount * sizeof (DbgSym*)); for (I = 0; I < O->DbgSymCount; ++I) {