1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-10 03:30:05 +00:00

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:
cuz 2004-12-16 22:43:52 +00:00
parent 1727d49c8d
commit ae70828938
4 changed files with 28 additions and 32 deletions

View File

@ -42,7 +42,6 @@
#include "cpu.h"
#include "print.h"
#include "xmalloc.h"
#include "xsprintf.h"
/* cc65 */
#include "asmlabel.h"

View File

@ -42,9 +42,9 @@
#include "debugflag.h"
#include "global.h"
#include "hashstr.h"
#include "strbuf.h"
#include "strutil.h"
#include "xmalloc.h"
#include "xsprintf.h"
/* cc65 */
#include "asmlabel.h"
@ -506,11 +506,11 @@ void CS_AddVLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap)
char Token[IDENTSIZE+10];
/* Format the line */
char Buf [256];
xvsprintf (Buf, sizeof (Buf), Format, ap);
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
SB_VPrintf (&Buf, Format, ap);
/* Skip whitespace */
L = SkipSpace (Buf);
L = SkipSpace (SB_GetConstBuf (&Buf));
/* Check which type of instruction we have */
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) {
CS_AddEntry (S, E);
}
/* Cleanup the string buffer */
DoneStrBuf (&Buf);
}

View File

@ -271,9 +271,8 @@ static void Parse (void)
void Compile (const char* FileName)
/* Top level compile routine. Will setup things and call the parser. */
{
char Buf[20];
char DateStr[20];
char TimeStr[20];
char DateStr[32];
char TimeStr[32];
time_t Time;
struct tm* TM;
@ -300,23 +299,23 @@ void Compile (const char* FileName)
*/
if (IS_Get (&Optimize)) {
long CodeSize = IS_Get (&CodeSizeFactor);
DefineNumericMacro ("__OPT__", 1);
DefineNumericMacro ("__OPT__", 1);
if (CodeSize > 100) {
DefineNumericMacro ("__OPT_i__", CodeSize);
}
if (IS_Get (&EnableRegVars)) {
DefineNumericMacro ("__OPT_r__", 1);
}
DefineNumericMacro ("__OPT_i__", CodeSize);
}
if (IS_Get (&EnableRegVars)) {
DefineNumericMacro ("__OPT_r__", 1);
}
if (IS_Get (&InlineStdFuncs)) {
DefineNumericMacro ("__OPT_s__", 1);
}
DefineNumericMacro ("__OPT_s__", 1);
}
}
/* __TIME__ and __DATE__ macros */
Time = time (0);
TM = localtime (&Time);
strftime (Buf, sizeof (Buf), "%e %Y", TM);
xsprintf (DateStr, sizeof (DateStr), "\"%s %s\"", MonthNames[TM->tm_mon], Buf);
xsprintf (DateStr, sizeof (DateStr), "\"%s %2d %d\"",
MonthNames[TM->tm_mon], TM->tm_mday, TM->tm_year + 1900);
strftime (TimeStr, sizeof (TimeStr), "\"%H:%M:%S\"", TM);
DefineTextMacro ("__DATE__", DateStr);
DefineTextMacro ("__TIME__", TimeStr);

View File

@ -35,7 +35,7 @@
/* common */
#include "check.h"
#include "xsprintf.h"
#include "strbuf.h"
/* cc65 */
#include "asmlabel.h"
@ -73,7 +73,7 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
* call to the function.
*/
{
static char Buf[256];
static StrBuf Buf = STATIC_STRBUF_INITIALIZER;
/* Expr may have it's own offset, adjust Offs accordingly */
Offs += Expr->IVal;
@ -83,35 +83,30 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
case E_LOC_ABS:
/* Absolute: numeric address or const */
xsprintf (Buf, sizeof (Buf), "$%04X", (int)(Offs & 0xFFFF));
SB_Printf (&Buf, "$%04X", (int)(Offs & 0xFFFF));
break;
case E_LOC_GLOBAL:
case E_LOC_STATIC:
/* Global or static variable */
if (Offs) {
xsprintf (Buf, sizeof (Buf), "%s%+ld",
SymGetAsmName (Expr->Sym), Offs);
SB_Printf (&Buf, "%s%+ld", SymGetAsmName (Expr->Sym), Offs);
} else {
xsprintf (Buf, sizeof (Buf), "%s",
SymGetAsmName (Expr->Sym));
SB_Printf (&Buf, "%s", SymGetAsmName (Expr->Sym));
}
break;
case E_LOC_REGISTER:
/* Register variable */
xsprintf (Buf, sizeof (Buf), "regbank+%u",
(unsigned)((Offs + Expr->Name) & 0xFFFFU));
SB_Printf (&Buf, "regbank+%u", (unsigned)((Offs + Expr->Name) & 0xFFFFU));
break;
case E_LOC_LITERAL:
/* Literal in the literal pool */
if (Offs) {
xsprintf (Buf, sizeof (Buf), "%s%+ld",
LocalLabelName (Expr->Name), Offs);
SB_Printf (&Buf, "%s%+ld", LocalLabelName (Expr->Name), Offs);
} else {
xsprintf (Buf, sizeof (Buf), "%s",
LocalLabelName (Expr->Name));
SB_Printf (&Buf, "%s", LocalLabelName (Expr->Name));
}
break;
@ -120,7 +115,7 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
}
/* Return a pointer to the static buffer */
return Buf;
return SB_GetConstBuf (&Buf);
}