1
0
mirror of https://github.com/cc65/cc65.git synced 2024-09-28 10:55:43 +00:00

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
This commit is contained in:
cuz 2001-05-23 21:32:57 +00:00
parent bfbedfa54b
commit 275da22a66
9 changed files with 181 additions and 12 deletions

79
src/ld65/fileinfo.c Normal file
View File

@ -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;
}

82
src/ld65/fileinfo.h Normal file
View File

@ -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 <stdio.h>
/* 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

View File

@ -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;
}

View File

@ -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 */
};

View File

@ -27,6 +27,7 @@ OBJS = bin.o \
exports.o \
expr.o \
extsyms.o \
fileinfo.o \
fileio.o \
fragment.o \
global.o \

View File

@ -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 \

View File

@ -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;
}
}

View File

@ -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 */

View File

@ -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) {