From: cuz Date: Thu, 16 Dec 2004 22:43:52 +0000 (+0000) Subject: Some improvements using the new SB_Printf for string buffers X-Git-Tag: V2.12.0~501 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ae708289384a8db26ed12168c00af697f1d0b78d;p=cc65 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 --- diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index fd909434d..e26e747f4 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -42,7 +42,6 @@ #include "cpu.h" #include "print.h" #include "xmalloc.h" -#include "xsprintf.h" /* cc65 */ #include "asmlabel.h" diff --git a/src/cc65/codeseg.c b/src/cc65/codeseg.c index 4ae945fd6..20c59df7b 100644 --- a/src/cc65/codeseg.c +++ b/src/cc65/codeseg.c @@ -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); } diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 8a9c7c3b5..bfec3eda5 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -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); diff --git a/src/cc65/exprdesc.c b/src/cc65/exprdesc.c index 4de2a6adf..285da06e0 100644 --- a/src/cc65/exprdesc.c +++ b/src/cc65/exprdesc.c @@ -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); }