/* */
/* */
/* */
-/* (C) 1998-2010 Ullrich von Bassewitz */
-/* Roemerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2010, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
#include <errno.h>
/* common */
-#include "check.h"
#include "bitops.h"
+#include "check.h"
+#include "coll.h"
#include "print.h"
#include "xmalloc.h"
#include "xsprintf.h"
/* File list */
-static File* FileList; /* Single linked list */
-static unsigned FileCount; /* Number of entries in the list */
-
-
+static Collection FileList = STATIC_COLLECTION_INITIALIZER;
/* Memory list */
-static Memory* MemoryList; /* Single linked list */
-static Memory* MemoryLast; /* Last element in list */
-static unsigned MemoryCount; /* Number of entries in the list */
+static Collection MemoryList = STATIC_COLLECTION_INITIALIZER;
/* Memory attributes */
#define MA_START 0x0001
static File* FindFile (unsigned Name)
/* Find a file with a given name. */
{
- File* F = FileList;
- while (F) {
- if (F->Name == Name) {
- return F;
- }
- F = F->Next;
+ unsigned I;
+ for (I = 0; I < CollCount (&FileList); ++I) {
+ File* F = CollAtUnchecked (&FileList, I);
+ if (F->Name == Name) {
+ return F;
+ }
}
return 0;
}
static Memory* CfgFindMemory (unsigned Name)
/* Find the memory are with the given name. Return NULL if not found */
{
- Memory* M = MemoryList;
- while (M) {
+ unsigned I;
+ for (I = 0; I < CollCount (&MemoryList); ++I) {
+ Memory* M = CollAt (&MemoryList, I);
if (M->Name == Name) {
return M;
}
- M = M->Next;
}
return 0;
}
F->MemLast = 0;
/* Insert the struct into the list */
- F->Next = FileList;
- FileList = F;
- ++FileCount;
+ CollAppend (&FileList, F);
/* ...and return it */
return F;
/* Initialize the fields */
M->Name = Name;
- M->Next = 0;
M->FNext = 0;
M->Attr = 0;
M->Flags = 0;
M->F = 0;
/* Insert the struct into the list */
- if (MemoryLast == 0) {
- /* First element */
- MemoryList = M;
- } else {
- MemoryLast->Next = M;
- }
- MemoryLast = M;
- ++MemoryCount;
+ CollAppend (&MemoryList, M);
/* ...and return it */
return M;
/* Search for the file, it must exist */
F = FindFile (GetStrBufId (&CfgSVal));
if (F == 0) {
- CfgError ("File `%s' not found in MEMORY section",
+ CfgError ("File `%s' not found in MEMORY section",
SB_GetConstBuf (&CfgSVal));
}
CfgSValId = GetStrBufId (&CfgSVal);
/* Check if the export symbol is also defined as an import. */
if (O65GetImport (O65FmtDesc, CfgSValId) != 0) {
- CfgError ("Exported symbol `%s' cannot be an import",
+ CfgError ("Exported symbol `%s' cannot be an import",
SB_GetConstBuf (&CfgSVal));
}
/* Check if we have this symbol defined already. The entry
* error message when checking it here.
*/
if (O65GetExport (O65FmtDesc, CfgSValId) != 0) {
- CfgError ("Duplicate exported symbol: `%s'",
+ CfgError ("Duplicate exported symbol: `%s'",
SB_GetConstBuf (&CfgSVal));
}
/* Insert the symbol into the table */
CfgSValId = GetStrBufId (&CfgSVal);
/* Check if the imported symbol is also defined as an export. */
if (O65GetExport (O65FmtDesc, CfgSValId) != 0) {
- CfgError ("Imported symbol `%s' cannot be an export",
+ CfgError ("Imported symbol `%s' cannot be an export",
SB_GetConstBuf (&CfgSVal));
}
/* Check if we have this symbol defined already. The entry
* error message when checking it here.
*/
if (O65GetImport (O65FmtDesc, CfgSValId) != 0) {
- CfgError ("Duplicate imported symbol: `%s'",
+ CfgError ("Duplicate imported symbol: `%s'",
SB_GetConstBuf (&CfgSVal));
}
/* Insert the symbol into the table */
CfgAssureIdent ();
/* Remember the value for later */
Count = GetStrBufId (&CfgSVal);
- break;
+ break;
case CFGTOK_TYPE:
/* Don't allow this twice */
* for an overflow of the section. Assign the start addresses of the
* segments while doing this.
*/
- Memory* M = MemoryList;
- while (M) {
+ unsigned I;
+ for (I = 0; I < CollCount (&MemoryList); ++I) {
MemListNode* N;
+ /* Get this entry */
+ Memory* M = CollAtUnchecked (&MemoryList, I);
+
/* Get the start address of this memory area */
unsigned long Addr = M->Start;
SB_Done (&Buf);
}
- /* Next memory area */
- M = M->Next;
}
/* Return the number of memory area overflows */
void CfgWriteTarget (void)
/* Write the target file(s) */
{
- Memory* M;
+ unsigned I;
/* Walk through the files list */
- File* F = FileList;
- while (F) {
- /* We don't need to look at files with no memory areas */
+ for (I = 0; I < CollCount (&FileList); ++I) {
+
+ /* Get this entry */
+ File* F = CollAtUnchecked (&FileList, I);
+
+ /* We don't need to look at files with no memory areas */
if (F->MemList) {
/* Is there an output file? */
/* No output file. Walk through the list and mark all segments
* loading into these memory areas in this file as dumped.
*/
- M = F->MemList;
+ Memory* M = F->MemList;
while (M) {
MemListNode* N;
}
}
}
-
- /* Next file */
- F = F->Next;
}
}
/* */
/* */
/* */
-/* (C) 1998-2005 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2010, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
typedef struct File File;
struct File {
unsigned Name; /* Name index of the file */
- File* Next; /* Pointer to next entry in list */
unsigned Flags;
unsigned Format; /* Output format */
struct Memory* MemList; /* List of memory areas in this file */
typedef struct Memory Memory;
struct Memory {
unsigned Name; /* Name index of the memory section */
- Memory* Next; /* Pointer to next entry in list */
Memory* FNext; /* Next in file list */
unsigned Attr; /* Which values are valid? */
unsigned Flags; /* Set of bitmapped flags */