From 97d431d1f4ad404e282e3781bd195be3f053734d Mon Sep 17 00:00:00 2001 From: "Anthony J. Bentley" Date: Wed, 24 Sep 2014 00:52:00 -0600 Subject: [PATCH] rgbasm: Avoid unnecessary filename copying. --- include/asm/asm.h | 2 +- include/asm/fstack.h | 2 +- src/asm/fstack.c | 41 +++++++---------------------------------- 3 files changed, 9 insertions(+), 36 deletions(-) diff --git a/include/asm/asm.h b/include/asm/asm.h index bde48eb3..d6a08848 100644 --- a/include/asm/asm.h +++ b/include/asm/asm.h @@ -24,7 +24,7 @@ extern ULONG nTotalLines; extern ULONG nPC; extern ULONG nPass; extern ULONG nIFDepth; -extern char tzCurrentFileName[_MAX_PATH + 1]; +extern char *tzCurrentFileName; extern struct Section *pCurrentSection; extern struct sSymbol *tHashedSymbols[HASHSIZE]; extern struct sSymbol *pPCSymbol; diff --git a/include/asm/fstack.h b/include/asm/fstack.h index c3ca1ef0..92e4c101 100644 --- a/include/asm/fstack.h +++ b/include/asm/fstack.h @@ -19,7 +19,7 @@ struct sContext { YY_BUFFER_STATE FlexHandle; struct sSymbol *pMacro; struct sContext *pNext; - char tzFileName[_MAX_PATH + 1]; + char *tzFileName; char *tzMacroArgs[MAXMACROARGS + 1]; SLONG nLine; ULONG nStatus; diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 8fe3b1ee..a06f5afc 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -36,7 +36,7 @@ struct sSymbol *pCurrentMacro; YY_BUFFER_STATE CurrentFlexHandle; FILE *pCurrentFile; ULONG nCurrentStatus; -char tzCurrentFileName[_MAX_PATH + 1]; +char *tzCurrentFileName; char IncludePaths[MAXINCPATHS][_MAX_PATH + 1]; SLONG NextIncPath = 0; ULONG nMacroCount; @@ -75,8 +75,7 @@ pushcontext(void) (struct sContext *) malloc(sizeof(struct sContext))) != NULL) { (*ppFileStack)->FlexHandle = CurrentFlexHandle; (*ppFileStack)->pNext = NULL; - strcpy((char *) (*ppFileStack)->tzFileName, - (char *) tzCurrentFileName); + (*ppFileStack)->tzFileName = tzCurrentFileName; (*ppFileStack)->nLine = nLineNo; switch ((*ppFileStack)->nStatus = nCurrentStatus) { case STAT_isMacroArg: @@ -137,8 +136,7 @@ popcontext(void) nLineNo += 1; CurrentFlexHandle = pLastFile->FlexHandle; - strcpy((char *) tzCurrentFileName, - (char *) pLastFile->tzFileName); + tzCurrentFileName = pLastFile->tzFileName; switch (nCurrentStatus = pLastFile->nStatus) { case STAT_isMacroArg: case STAT_isMacro: @@ -256,7 +254,7 @@ fstk_RunInclude(char *tzFileName) pushcontext(); nLineNo = 1; nCurrentStatus = STAT_isInclude; - strcpy(tzCurrentFileName, tzFileName); + tzCurrentFileName = tzFileName; pCurrentFile = f; CurrentFlexHandle = yy_create_buffer(pCurrentFile); yy_switch_to_buffer(CurrentFlexHandle); @@ -284,7 +282,7 @@ fstk_RunMacro(char *s) nLineNo = -1; sym_UseNewMacroArgs(); nCurrentStatus = STAT_isMacro; - strcpy(tzCurrentFileName, s); + tzCurrentFileName = s; pCurrentMacro = sym; CurrentFlexHandle = yy_scan_bytes(pCurrentMacro->pMacro, @@ -294,32 +292,7 @@ fstk_RunMacro(char *s) } else return (0); } -/* - * RGBAsm - FSTACK.C (FileStack routines) - * - * Set up a macroargument for parsing - * - */ -void -fstk_RunMacroArg(SLONG s) -{ - char *sym; - - if (s == '@') - s = -1; - else - s -= '0'; - - if ((sym = sym_FindMacroArg(s)) != NULL) { - pushcontext(); - nCurrentStatus = STAT_isMacroArg; - sprintf(tzCurrentFileName, "%c", (UBYTE) s); - CurrentFlexHandle = yy_scan_bytes(sym, strlen(sym)); - yy_switch_to_buffer(CurrentFlexHandle); - } else - fatalerror("No such macroargument"); -} /* * RGBAsm - FSTACK.C (FileStack routines) * @@ -335,7 +308,7 @@ fstk_RunString(char *s) if ((pSym = sym_FindSymbol(s)) != NULL) { pushcontext(); nCurrentStatus = STAT_isMacroArg; - strcpy(tzCurrentFileName, s); + tzCurrentFileName = s; CurrentFlexHandle = yy_scan_bytes(pSym->pMacro, strlen(pSym->pMacro)); yy_switch_to_buffer(CurrentFlexHandle); @@ -392,7 +365,7 @@ fstk_Init(char *s) nMacroCount = 0; nCurrentStatus = STAT_isInclude; - strcpy(tzCurrentFileName, tzFileName); + tzCurrentFileName = tzFileName; CurrentFlexHandle = yy_create_buffer(pCurrentFile); yy_switch_to_buffer(CurrentFlexHandle); nLineNo = 1;