Make much more usage of dynamic strings (StrBufs) instead of char* and
friends. Since names and other strings are now StrBufs in many places, code for output had to be changed. Added support for string literals to StrBuf. git-svn-id: svn://svn.cc65.org/cc65/trunk@3825 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -6,10 +6,10 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2003 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* (C) 2003-2008, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1999-2005 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstrasse 52 */
|
||||
/* (C) 1999-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
@@ -62,9 +62,9 @@
|
||||
|
||||
|
||||
struct BinDesc {
|
||||
unsigned Undef; /* Count of undefined externals */
|
||||
FILE* F; /* Output file */
|
||||
const char* Filename; /* Name of output file */
|
||||
unsigned Undef; /* Count of undefined externals */
|
||||
FILE* F; /* Output file */
|
||||
const char* Filename; /* Name of output file */
|
||||
};
|
||||
|
||||
|
||||
@@ -148,9 +148,9 @@ static void BinWriteMem (BinDesc* D, Memory* M)
|
||||
Print (stdout, 1, " Writing `%s'\n", GetString (S->Name));
|
||||
|
||||
/* Writes do only occur in the load area and not for BSS segments */
|
||||
DoWrite = (S->Flags & SF_BSS) == 0 && /* No BSS segment */
|
||||
S->Load == M && /* LOAD segment */
|
||||
S->Seg->Dumped == 0; /* Not already written */
|
||||
DoWrite = (S->Flags & SF_BSS) == 0 && /* No BSS segment */
|
||||
S->Load == M && /* LOAD segment */
|
||||
S->Seg->Dumped == 0; /* Not already written */
|
||||
|
||||
/* Output debugging stuff */
|
||||
PrintBoolVal ("bss", S->Flags & SF_BSS);
|
||||
@@ -315,3 +315,4 @@ void BinWriteTarget (BinDesc* D, struct File* F)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2005, Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstrasse 52 */
|
||||
/* (C) 2005-2008, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
@@ -91,7 +91,7 @@ static void CE_Done (CfgExpr* E)
|
||||
{
|
||||
/* If the type is a string, we must delete the string buffer */
|
||||
if (E->Type == ceString) {
|
||||
DoneStrBuf (&E->SVal);
|
||||
SB_Done (&E->SVal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2000-2003 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstrasse 52 */
|
||||
/* (C) 2000-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
@@ -112,7 +112,7 @@ static int ConDesCompare (void* Data, const void* E1, const void* E2)
|
||||
Cmp = 1;
|
||||
} else {
|
||||
/* Use the name in this case */
|
||||
Cmp = strcmp (GetString (Exp1->Name), GetString (Exp2->Name));
|
||||
Cmp = SB_Compare (GetStrBuf (Exp1->Name), GetStrBuf (Exp2->Name));
|
||||
}
|
||||
|
||||
/* Reverse the result for decreasing order */
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2005 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstrasse 52 */
|
||||
/* (C) 1998-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
@@ -203,7 +203,7 @@ static Memory* CfgFindMemory (unsigned Name)
|
||||
static Memory* CfgGetMemory (unsigned Name)
|
||||
/* Find the memory are with the given name. Print an error on an invalid name */
|
||||
{
|
||||
Memory* M = CfgFindMemory (Name);
|
||||
Memory* M = CfgFindMemory (Name);
|
||||
if (M == 0) {
|
||||
CfgError ("Invalid memory area `%s'", GetString (Name));
|
||||
}
|
||||
@@ -1557,13 +1557,14 @@ void CfgRead (void)
|
||||
static void CreateRunDefines (SegDesc* S, unsigned long SegAddr)
|
||||
/* Create the defines for a RUN segment */
|
||||
{
|
||||
char Buf [256];
|
||||
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
|
||||
|
||||
xsprintf (Buf, sizeof (Buf), "__%s_RUN__", GetString (S->Name));
|
||||
CreateMemoryExport (GetStringId (Buf), S->Run, SegAddr - S->Run->Start);
|
||||
xsprintf (Buf, sizeof (Buf), "__%s_SIZE__", GetString (S->Name));
|
||||
CreateConstExport (GetStringId (Buf), S->Seg->Size);
|
||||
SB_Printf (&Buf, "__%s_RUN__", GetString (S->Name));
|
||||
CreateMemoryExport (GetStrBufId (&Buf), S->Run, SegAddr - S->Run->Start);
|
||||
SB_Printf (&Buf, "__%s_SIZE__", GetString (S->Name));
|
||||
CreateConstExport (GetStrBufId (&Buf), S->Seg->Size);
|
||||
S->Flags |= SF_RUN_DEF;
|
||||
SB_Done (&Buf);
|
||||
}
|
||||
|
||||
|
||||
@@ -1571,11 +1572,12 @@ static void CreateRunDefines (SegDesc* S, unsigned long SegAddr)
|
||||
static void CreateLoadDefines (SegDesc* S, unsigned long SegAddr)
|
||||
/* Create the defines for a LOAD segment */
|
||||
{
|
||||
char Buf [256];
|
||||
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
|
||||
|
||||
xsprintf (Buf, sizeof (Buf), "__%s_LOAD__", GetString (S->Name));
|
||||
CreateMemoryExport (GetStringId (Buf), S->Load, SegAddr - S->Load->Start);
|
||||
SB_Printf (&Buf, "__%s_LOAD__", GetString (S->Name));
|
||||
CreateMemoryExport (GetStrBufId (&Buf), S->Load, SegAddr - S->Load->Start);
|
||||
S->Flags |= SF_LOAD_DEF;
|
||||
SB_Done (&Buf);
|
||||
}
|
||||
|
||||
|
||||
@@ -1697,13 +1699,14 @@ unsigned CfgAssignSegments (void)
|
||||
|
||||
/* If requested, define symbols for start and size of the memory area */
|
||||
if (M->Flags & MF_DEFINE) {
|
||||
char Buf [256];
|
||||
sprintf (Buf, "__%s_START__", GetString (M->Name));
|
||||
CreateMemoryExport (GetStringId (Buf), M, 0);
|
||||
sprintf (Buf, "__%s_SIZE__", GetString (M->Name));
|
||||
CreateConstExport (GetStringId (Buf), M->Size);
|
||||
sprintf (Buf, "__%s_LAST__", GetString (M->Name));
|
||||
CreateMemoryExport (GetStringId (Buf), M, M->FillLevel);
|
||||
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
|
||||
SB_Printf (&Buf, "__%s_START__", GetString (M->Name));
|
||||
CreateMemoryExport (GetStrBufId (&Buf), M, 0);
|
||||
SB_Printf (&Buf, "__%s_SIZE__", GetString (M->Name));
|
||||
CreateConstExport (GetStrBufId (&Buf), M->Size);
|
||||
SB_Printf (&Buf, "__%s_LAST__", GetString (M->Name));
|
||||
CreateMemoryExport (GetStrBufId (&Buf), M, M->FillLevel);
|
||||
SB_Done (&Buf);
|
||||
}
|
||||
|
||||
/* Next memory area */
|
||||
@@ -1728,7 +1731,7 @@ void CfgWriteTarget (void)
|
||||
if (F->MemList) {
|
||||
|
||||
/* Is there an output file? */
|
||||
if (strlen (GetString (F->Name)) > 0) {
|
||||
if (SB_GetLen (GetStrBuf (F->Name)) > 0) {
|
||||
|
||||
/* Assign a proper binary format */
|
||||
if (F->Format == BINFMT_DEFAULT) {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2001-2003 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstra<EFBFBD>e 52 */
|
||||
/* (C) 2001-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstra<EFBFBD>e 52 */
|
||||
/* (C) 1998-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstrasse 52 */
|
||||
/* (C) 1998-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
@@ -36,9 +36,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/* common */
|
||||
#include "cmdline.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
/* ld65 */
|
||||
#include "error.h"
|
||||
@@ -54,12 +55,17 @@
|
||||
void Warning (const char* Format, ...)
|
||||
/* Print a warning message */
|
||||
{
|
||||
StrBuf S = STATIC_STRBUF_INITIALIZER;
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, Format);
|
||||
fprintf (stderr, "%s: Warning: ", ProgName);
|
||||
vfprintf (stderr, Format, ap);
|
||||
putc ('\n', stderr);
|
||||
SB_VPrintf (&S, Format, ap);
|
||||
va_end (ap);
|
||||
SB_Terminate (&S);
|
||||
|
||||
fprintf (stderr, "%s: Warning: %s\n", ProgName, SB_GetConstBuf (&S));
|
||||
|
||||
SB_Done (&S);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,12 +73,18 @@ void Warning (const char* Format, ...)
|
||||
void Error (const char* Format, ...)
|
||||
/* Print an error message and die */
|
||||
{
|
||||
StrBuf S = STATIC_STRBUF_INITIALIZER;
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, Format);
|
||||
fprintf (stderr, "%s: Error: ", ProgName);
|
||||
vfprintf (stderr, Format, ap);
|
||||
putc ('\n', stderr);
|
||||
SB_VPrintf (&S, Format, ap);
|
||||
va_end (ap);
|
||||
SB_Terminate (&S);
|
||||
|
||||
fprintf (stderr, "%s: Error: %s\n", ProgName, SB_GetConstBuf (&S));
|
||||
|
||||
SB_Done (&S);
|
||||
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -81,14 +93,20 @@ void Error (const char* Format, ...)
|
||||
void Internal (const char* Format, ...)
|
||||
/* Print an internal error message and die */
|
||||
{
|
||||
StrBuf S = STATIC_STRBUF_INITIALIZER;
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, Format);
|
||||
fprintf (stderr, "%s: Internal error: ", ProgName);
|
||||
vfprintf (stderr, Format, ap);
|
||||
putc ('\n', stderr);
|
||||
SB_VPrintf (&S, Format, ap);
|
||||
va_end (ap);
|
||||
SB_Terminate (&S);
|
||||
|
||||
fprintf (stderr, "%s: Internal Error: %s\n", ProgName, SB_GetConstBuf (&S));
|
||||
|
||||
SB_Done (&S);
|
||||
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2005 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstra<EFBFBD>e 52 */
|
||||
/* (C) 1998-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
@@ -620,7 +620,7 @@ static void PrintUnresolved (ExpCheckFunc F, void* Data)
|
||||
/* Unresolved external */
|
||||
Import* Imp = E->ImpList;
|
||||
fprintf (stderr,
|
||||
"Unresolved external `%s' referenced in:\n",
|
||||
"Unresolved external `%s' referenced in:\n",
|
||||
GetString (E->Name));
|
||||
while (Imp) {
|
||||
const char* Name = GetSourceFileName (Imp->Obj, Imp->Pos.Name);
|
||||
@@ -636,8 +636,8 @@ static void PrintUnresolved (ExpCheckFunc F, void* Data)
|
||||
static int CmpExpName (const void* K1, const void* K2)
|
||||
/* Compare function for qsort */
|
||||
{
|
||||
return strcmp (GetString ((*(Export**)K1)->Name),
|
||||
GetString ((*(Export**)K2)->Name));
|
||||
return SB_Compare (GetStrBuf ((*(Export**)K1)->Name),
|
||||
GetStrBuf ((*(Export**)K2)->Name));
|
||||
}
|
||||
|
||||
|
||||
@@ -728,7 +728,7 @@ void PrintExportMap (FILE* F)
|
||||
/* Print unreferenced symbols only if explictly requested */
|
||||
if (VerboseMap || E->ImpCount > 0 || IS_EXP_CONDES (E->Type)) {
|
||||
fprintf (F,
|
||||
"%-25s %06lX %c%c%c%c ",
|
||||
"%-25s %06lX %c%c%c%c ",
|
||||
GetString (E->Name),
|
||||
GetExportVal (E),
|
||||
E->ImpCount? 'R' : ' ',
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1999-2003 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstrasse 52 */
|
||||
/* (C) 1999-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstrasse 52 */
|
||||
/* (C) 1998-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
@@ -283,34 +283,23 @@ unsigned ReadStr (FILE* F)
|
||||
*/
|
||||
{
|
||||
unsigned Id;
|
||||
char* B;
|
||||
char Buf[256];
|
||||
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
|
||||
|
||||
/* Read the length */
|
||||
unsigned Len = ReadVar (F);
|
||||
|
||||
/* If the string is short enough, use our buffer on the stack, otherwise
|
||||
* allocate space on the heap.
|
||||
*/
|
||||
if (Len < sizeof (Buf)) {
|
||||
B = Buf;
|
||||
} else {
|
||||
B = xmalloc (Len + 1);
|
||||
}
|
||||
/* Expand the string buffer memory */
|
||||
SB_Realloc (&Buf, Len);
|
||||
|
||||
/* Read the string */
|
||||
ReadData (F, B, Len);
|
||||
|
||||
/* Terminate the string */
|
||||
B[Len] = '\0';
|
||||
ReadData (F, SB_GetBuf (&Buf), Len);
|
||||
Buf.Len = Len;
|
||||
|
||||
/* Insert it into the string pool and remember the id */
|
||||
Id = GetStringId (B);
|
||||
Id = GetStrBufId (&Buf);
|
||||
|
||||
/* If we had allocated memory before, free it now */
|
||||
if (B != Buf) {
|
||||
xfree (B);
|
||||
}
|
||||
/* Free the memory buffer */
|
||||
SB_Done (&Buf);
|
||||
|
||||
/* Return the string id */
|
||||
return Id;
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2000 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* EMail: uz@musoftware.de */
|
||||
/* (C) 1998-2008, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
@@ -95,7 +95,7 @@ void CfgWarning (const char* Format, ...)
|
||||
va_end (ap);
|
||||
|
||||
Warning ("%s(%u): %s", CfgGetName(), CfgErrorLine, SB_GetConstBuf (&Buf));
|
||||
DoneStrBuf (&Buf);
|
||||
SB_Done (&Buf);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ void CfgError (const char* Format, ...)
|
||||
va_end (ap);
|
||||
|
||||
Error ("%s(%u): %s", CfgGetName(), CfgErrorLine, SB_GetConstBuf (&Buf));
|
||||
DoneStrBuf (&Buf);
|
||||
SB_Done (&Buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -57,12 +57,12 @@ StringPool StrPool = STATIC_STRINGPOOL_INITIALIZER;
|
||||
void InitStrPool (void)
|
||||
/* Initialize the string pool */
|
||||
{
|
||||
/* We insert a first string here, which will have id zero. This means
|
||||
/* We insert a first string here, which will have id zero. This means
|
||||
* that we can treat index zero later as invalid.
|
||||
*/
|
||||
SP_Add (&StrPool, "<invalid message #0>");
|
||||
*/
|
||||
SP_AddStr (&StrPool, "<invalid message #0>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2003 Ullrich von Bassewitz */
|
||||
/* R<EFBFBD>merstrasse 52 */
|
||||
/* (C) 2003-2008 Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
@@ -64,8 +64,8 @@ extern StringPool StrPool;
|
||||
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned GetStringId (const char* S)
|
||||
/* Return the id of the given string */
|
||||
INLINE unsigned GetStrBufId (const StrBuf* S)
|
||||
/* Return the id of the given string buffer */
|
||||
{
|
||||
return SP_Add (&StrPool, S);
|
||||
}
|
||||
@@ -74,13 +74,33 @@ INLINE unsigned GetStringId (const char* S)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE const char* GetString (unsigned Index)
|
||||
INLINE unsigned GetStringId (const char* S)
|
||||
/* Return the id of the given string */
|
||||
{
|
||||
return SP_AddStr (&StrPool, S);
|
||||
}
|
||||
#else
|
||||
# define GetStringId(S) SP_Add (&StrPool, (S))
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE const StrBuf* GetStrBuf (unsigned Index)
|
||||
/* Convert a string index into a string */
|
||||
{
|
||||
return SP_Get (&StrPool, Index);
|
||||
}
|
||||
#else
|
||||
# define GetString(Index) SP_Get (&StrPool, (Index))
|
||||
# define GetStrBuf(Index) SP_Get (&StrPool, (Index))
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE const char* GetString (unsigned Index)
|
||||
/* Convert a string index into a string */
|
||||
{
|
||||
return SB_GetConstBuf (SP_Get (&StrPool, Index));
|
||||
}
|
||||
#else
|
||||
# define GetString(Index) SB_GetConstBuf (SP_Get (&StrPool, (Index)))
|
||||
#endif
|
||||
|
||||
void InitStrPool (void);
|
||||
|
||||
Reference in New Issue
Block a user