diff --git a/doc/agat.sgml b/doc/agat.sgml
index ca5338c5f..71d5b019f 100644
--- a/doc/agat.sgml
+++ b/doc/agat.sgml
@@ -38,7 +38,7 @@ The default load address is $1903.
Programs containing Agat-specific code may use the Usefull info
+Useful info
Emulation
diff --git a/doc/ca65.sgml b/doc/ca65.sgml
index 5e53fb002..9980e55c9 100644
--- a/doc/ca65.sgml
+++ b/doc/ca65.sgml
@@ -3192,7 +3192,7 @@ See: , when .
pc_assignment
@@ -3792,8 +3792,8 @@ See: ,.LOCAL
This command may only be used inside a macro definition. It declares a list
- of identifiers as local to the macro expansion. The identifers may be
- standard identifiers or cheap local identifiers depending on the planed use.
+ of identifiers as local to the macro expansion. The identifiers may be
+ standard identifiers or cheap local identifiers depending on the planned use.
A problem when using macros are labels: Since they don't change their name,
you get a "duplicate symbol" error if the macro is expanded the second time.
diff --git a/src/ca65/macro.c b/src/ca65/macro.c
index 260bbd866..6ea136c20 100644
--- a/src/ca65/macro.c
+++ b/src/ca65/macro.c
@@ -728,7 +728,7 @@ ExpandParam:
/* Use next macro token */
TokSet (Mac->Exp);
- if (ExpandMacros) {
+ if (ExpandMacros && SB_GetLen (&ListingName) > 0) {
if (new_expand_line) {
/* Suppress unneeded lines if short expansion
** the ExpandStart is used to ensure that
diff --git a/src/ca65/toklist.c b/src/ca65/toklist.c
index 7fd8cfcd3..5c8cadfcf 100644
--- a/src/ca65/toklist.c
+++ b/src/ca65/toklist.c
@@ -252,7 +252,7 @@ static int ReplayTokList (void* List)
/* see description in macro.c */
static int new_expand_line = 1;
- if (ExpandMacros) {
+ if (ExpandMacros && SB_GetLen (&ListingName) > 0) {
if (new_expand_line) {
if (LineLast->FragList == 0 && ExpandMacros==1) {
LineCur->Output--;
diff --git a/src/common/gentype.c b/src/common/gentype.c
index 1600a7c2f..81480000a 100644
--- a/src/common/gentype.c
+++ b/src/common/gentype.c
@@ -102,7 +102,7 @@ const char* GT_AsString (const StrBuf* Type, StrBuf* String)
** will be zero terminated and a pointer to the contents are returned.
*/
{
- static const char HexTab[16] = "0123456789ABCDEF";
+ static const char HexTab[] = "0123456789ABCDEF";
unsigned I;
/* Convert Type into readable hex. String will have twice then length
diff --git a/src/ld65/main.c b/src/ld65/main.c
index ab2106fdc..3b434f68d 100644
--- a/src/ld65/main.c
+++ b/src/ld65/main.c
@@ -88,16 +88,46 @@ static unsigned LibFiles = 0; /* Count of library files linked */
#define INPUT_FILES_SGROUP 3 /* Entry is 'StartGroup' */
#define INPUT_FILES_EGROUP 4 /* Entry is 'EndGroup' */
-#define MAX_INPUTFILES 256
-
/* Array of inputs (libraries and object files) */
-static struct InputFile {
- const char *FileName;
- unsigned Type;
-} *InputFiles;
-static unsigned InputFilesCount = 0;
-static const char *CmdlineCfgFile = NULL,
- *CmdlineTarget = NULL;
+struct InputFile {
+ unsigned char Type;
+ char FileName[1]; /* Dynamically allocated */
+};
+typedef struct InputFile InputFile;
+static Collection InputFiles = STATIC_COLLECTION_INITIALIZER;
+
+static const char* CmdlineCfgFile = NULL;
+static const char* CmdlineTarget = NULL;
+
+
+
+/*****************************************************************************/
+/* struct InputFile */
+/*****************************************************************************/
+
+
+
+static InputFile* NewInputFile (unsigned char Type, const char* FileName)
+/* Create a new InputFile struct and return it */
+{
+ unsigned Length = FileName? strlen (FileName) : 0;
+ InputFile* F = xmalloc (sizeof (InputFile) + Length);
+ F->Type = Type;
+ if (FileName) {
+ memcpy (F->FileName, FileName, Length + 1);
+ } else {
+ F->FileName[0] = '\0';
+ }
+ return F;
+}
+
+
+
+static void FreeInputFile (InputFile* F)
+/* Free an InputFile struct */
+{
+ xfree (F);
+}
@@ -434,10 +464,7 @@ static void OptLargeAlignment (const char* Opt attribute ((unused)),
static void OptLib (const char* Opt attribute ((unused)), const char* Arg)
/* Link a library */
{
- InputFiles[InputFilesCount].Type = INPUT_FILES_FILE_LIB;
- InputFiles[InputFilesCount].FileName = Arg;
- if (++InputFilesCount >= MAX_INPUTFILES)
- Error ("Too many input files");
+ CollAppend (&InputFiles, NewInputFile (INPUT_FILES_FILE_LIB, Arg));
}
@@ -485,10 +512,7 @@ static void OptNoUtf8 (const char* Opt attribute ((unused)),
static void OptObj (const char* Opt attribute ((unused)), const char* Arg)
/* Link an object file */
{
- InputFiles[InputFilesCount].Type = INPUT_FILES_FILE_OBJ;
- InputFiles[InputFilesCount].FileName = Arg;
- if (++InputFilesCount >= MAX_INPUTFILES)
- Error ("Too many input files");
+ CollAppend (&InputFiles, NewInputFile (INPUT_FILES_FILE_OBJ, Arg));
}
@@ -606,10 +630,7 @@ static void CmdlOptStartGroup (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Remember 'start group' occurrence in input files array */
{
- InputFiles[InputFilesCount].Type = INPUT_FILES_SGROUP;
- InputFiles[InputFilesCount].FileName = Arg; /* Unused */
- if (++InputFilesCount >= MAX_INPUTFILES)
- Error ("Too many input files");
+ CollAppend (&InputFiles, NewInputFile (INPUT_FILES_SGROUP, 0));
}
@@ -618,10 +639,7 @@ static void CmdlOptEndGroup (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Remember 'end group' occurrence in input files array */
{
- InputFiles[InputFilesCount].Type = INPUT_FILES_EGROUP;
- InputFiles[InputFilesCount].FileName = Arg; /* Unused */
- if (++InputFilesCount >= MAX_INPUTFILES)
- Error ("Too many input files");
+ CollAppend (&InputFiles, NewInputFile (INPUT_FILES_EGROUP, 0));
}
@@ -679,9 +697,6 @@ static void ParseCommandLine (void)
unsigned I;
unsigned LabelFileGiven = 0;
- /* Allocate memory for input file array */
- InputFiles = xmalloc (MAX_INPUTFILES * sizeof (struct InputFile));
-
/* Defer setting of config/target and input files until all options are parsed */
I = 1;
while (I < ArgCount) {
@@ -774,13 +789,8 @@ static void ParseCommandLine (void)
}
} else {
-
/* A filename */
- InputFiles[InputFilesCount].Type = INPUT_FILES_FILE;
- InputFiles[InputFilesCount].FileName = Arg;
- if (++InputFilesCount >= MAX_INPUTFILES)
- Error ("Too many input files");
-
+ CollAppend (&InputFiles, NewInputFile (INPUT_FILES_FILE, Arg));
}
/* Next argument */
@@ -793,17 +803,18 @@ static void ParseCommandLine (void)
OptConfig (NULL, CmdlineCfgFile);
}
- /* Process input files */
- for (I = 0; I < InputFilesCount; ++I) {
- switch (InputFiles[I].Type) {
+ /* Process input files and delete the entries while doing so */
+ for (I = 0; I < CollCount (&InputFiles); ++I) {
+ InputFile* F = CollAtUnchecked (&InputFiles, I);
+ switch (F->Type) {
case INPUT_FILES_FILE:
- LinkFile (InputFiles[I].FileName, FILETYPE_UNKNOWN);
+ LinkFile (F->FileName, FILETYPE_UNKNOWN);
break;
case INPUT_FILES_FILE_LIB:
- LinkFile (InputFiles[I].FileName, FILETYPE_LIB);
+ LinkFile (F->FileName, FILETYPE_LIB);
break;
case INPUT_FILES_FILE_OBJ:
- LinkFile (InputFiles[I].FileName, FILETYPE_OBJ);
+ LinkFile (F->FileName, FILETYPE_OBJ);
break;
case INPUT_FILES_SGROUP:
OptStartGroup (NULL, 0);
@@ -812,12 +823,14 @@ static void ParseCommandLine (void)
OptEndGroup (NULL, 0);
break;
default:
- abort ();
+ FAIL ("Unknown file type");
}
+ FreeInputFile (F);
}
/* Free memory used for input file array */
- xfree (InputFiles);
+ DoneCollection (&InputFiles);
+ InitCollection (&InputFiles); /* Don't leave dangling pointers */
}