Some improvements using the new SB_Printf for string buffers
git-svn-id: svn://svn.cc65.org/cc65/trunk@3335 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -42,7 +42,6 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
#include "xsprintf.h"
|
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "asmlabel.h"
|
#include "asmlabel.h"
|
||||||
|
|||||||
@@ -42,9 +42,9 @@
|
|||||||
#include "debugflag.h"
|
#include "debugflag.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "hashstr.h"
|
#include "hashstr.h"
|
||||||
|
#include "strbuf.h"
|
||||||
#include "strutil.h"
|
#include "strutil.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
#include "xsprintf.h"
|
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "asmlabel.h"
|
#include "asmlabel.h"
|
||||||
@@ -506,11 +506,11 @@ void CS_AddVLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap)
|
|||||||
char Token[IDENTSIZE+10];
|
char Token[IDENTSIZE+10];
|
||||||
|
|
||||||
/* Format the line */
|
/* Format the line */
|
||||||
char Buf [256];
|
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
|
||||||
xvsprintf (Buf, sizeof (Buf), Format, ap);
|
SB_VPrintf (&Buf, Format, ap);
|
||||||
|
|
||||||
/* Skip whitespace */
|
/* Skip whitespace */
|
||||||
L = SkipSpace (Buf);
|
L = SkipSpace (SB_GetConstBuf (&Buf));
|
||||||
|
|
||||||
/* Check which type of instruction we have */
|
/* Check which type of instruction we have */
|
||||||
E = 0; /* Assume no insn created */
|
E = 0; /* Assume no insn created */
|
||||||
@@ -539,6 +539,9 @@ void CS_AddVLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap)
|
|||||||
if (E) {
|
if (E) {
|
||||||
CS_AddEntry (S, E);
|
CS_AddEntry (S, E);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Cleanup the string buffer */
|
||||||
|
DoneStrBuf (&Buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -271,9 +271,8 @@ static void Parse (void)
|
|||||||
void Compile (const char* FileName)
|
void Compile (const char* FileName)
|
||||||
/* Top level compile routine. Will setup things and call the parser. */
|
/* Top level compile routine. Will setup things and call the parser. */
|
||||||
{
|
{
|
||||||
char Buf[20];
|
char DateStr[32];
|
||||||
char DateStr[20];
|
char TimeStr[32];
|
||||||
char TimeStr[20];
|
|
||||||
time_t Time;
|
time_t Time;
|
||||||
struct tm* TM;
|
struct tm* TM;
|
||||||
|
|
||||||
@@ -315,8 +314,8 @@ void Compile (const char* FileName)
|
|||||||
/* __TIME__ and __DATE__ macros */
|
/* __TIME__ and __DATE__ macros */
|
||||||
Time = time (0);
|
Time = time (0);
|
||||||
TM = localtime (&Time);
|
TM = localtime (&Time);
|
||||||
strftime (Buf, sizeof (Buf), "%e %Y", TM);
|
xsprintf (DateStr, sizeof (DateStr), "\"%s %2d %d\"",
|
||||||
xsprintf (DateStr, sizeof (DateStr), "\"%s %s\"", MonthNames[TM->tm_mon], Buf);
|
MonthNames[TM->tm_mon], TM->tm_mday, TM->tm_year + 1900);
|
||||||
strftime (TimeStr, sizeof (TimeStr), "\"%H:%M:%S\"", TM);
|
strftime (TimeStr, sizeof (TimeStr), "\"%H:%M:%S\"", TM);
|
||||||
DefineTextMacro ("__DATE__", DateStr);
|
DefineTextMacro ("__DATE__", DateStr);
|
||||||
DefineTextMacro ("__TIME__", TimeStr);
|
DefineTextMacro ("__TIME__", TimeStr);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "xsprintf.h"
|
#include "strbuf.h"
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "asmlabel.h"
|
#include "asmlabel.h"
|
||||||
@@ -73,7 +73,7 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
|
|||||||
* call to the function.
|
* call to the function.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
static char Buf[256];
|
static StrBuf Buf = STATIC_STRBUF_INITIALIZER;
|
||||||
|
|
||||||
/* Expr may have it's own offset, adjust Offs accordingly */
|
/* Expr may have it's own offset, adjust Offs accordingly */
|
||||||
Offs += Expr->IVal;
|
Offs += Expr->IVal;
|
||||||
@@ -83,35 +83,30 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
|
|||||||
|
|
||||||
case E_LOC_ABS:
|
case E_LOC_ABS:
|
||||||
/* Absolute: numeric address or const */
|
/* Absolute: numeric address or const */
|
||||||
xsprintf (Buf, sizeof (Buf), "$%04X", (int)(Offs & 0xFFFF));
|
SB_Printf (&Buf, "$%04X", (int)(Offs & 0xFFFF));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_GLOBAL:
|
case E_LOC_GLOBAL:
|
||||||
case E_LOC_STATIC:
|
case E_LOC_STATIC:
|
||||||
/* Global or static variable */
|
/* Global or static variable */
|
||||||
if (Offs) {
|
if (Offs) {
|
||||||
xsprintf (Buf, sizeof (Buf), "%s%+ld",
|
SB_Printf (&Buf, "%s%+ld", SymGetAsmName (Expr->Sym), Offs);
|
||||||
SymGetAsmName (Expr->Sym), Offs);
|
|
||||||
} else {
|
} else {
|
||||||
xsprintf (Buf, sizeof (Buf), "%s",
|
SB_Printf (&Buf, "%s", SymGetAsmName (Expr->Sym));
|
||||||
SymGetAsmName (Expr->Sym));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_REGISTER:
|
case E_LOC_REGISTER:
|
||||||
/* Register variable */
|
/* Register variable */
|
||||||
xsprintf (Buf, sizeof (Buf), "regbank+%u",
|
SB_Printf (&Buf, "regbank+%u", (unsigned)((Offs + Expr->Name) & 0xFFFFU));
|
||||||
(unsigned)((Offs + Expr->Name) & 0xFFFFU));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case E_LOC_LITERAL:
|
case E_LOC_LITERAL:
|
||||||
/* Literal in the literal pool */
|
/* Literal in the literal pool */
|
||||||
if (Offs) {
|
if (Offs) {
|
||||||
xsprintf (Buf, sizeof (Buf), "%s%+ld",
|
SB_Printf (&Buf, "%s%+ld", LocalLabelName (Expr->Name), Offs);
|
||||||
LocalLabelName (Expr->Name), Offs);
|
|
||||||
} else {
|
} else {
|
||||||
xsprintf (Buf, sizeof (Buf), "%s",
|
SB_Printf (&Buf, "%s", LocalLabelName (Expr->Name));
|
||||||
LocalLabelName (Expr->Name));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -120,7 +115,7 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Return a pointer to the static buffer */
|
/* Return a pointer to the static buffer */
|
||||||
return Buf;
|
return SB_GetConstBuf (&Buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user