Use reference to clean up CON_QSPRINTF

git-svn-id: https://svn.eduke32.com/eduke32@7260 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-12-15 01:37:44 +00:00
parent 76edec81ac
commit 0bbde29c85

View file

@ -4751,12 +4751,16 @@ badindex:
continue; continue;
} }
int32_t arg[32]; auto &inBuf = apStrings[inputQuote];
int const quoteLen = Bstrlen(apStrings[inputQuote]);
int inputPos = 0; int32_t arg[32];
char outBuf[MAXQUOTELEN]; char outBuf[MAXQUOTELEN];
int outBufPos = 0;
int argIdx = 0; int const quoteLen = Bstrlen(inBuf);
int inputPos = 0;
int outputPos = 0;
int argIdx = 0;
while ((*insptr & VM_INSTMASK) != CON_NULLOP && argIdx < 32) while ((*insptr & VM_INSTMASK) != CON_NULLOP && argIdx < 32)
arg[argIdx++] = Gv_GetVarX(*insptr++); arg[argIdx++] = Gv_GetVarX(*insptr++);
@ -4769,20 +4773,20 @@ badindex:
do do
{ {
while (inputPos < quoteLen && outBufPos < MAXQUOTELEN && apStrings[inputQuote][inputPos] != '%') while (inputPos < quoteLen && outputPos < MAXQUOTELEN && inBuf[inputPos] != '%')
outBuf[outBufPos++] = apStrings[inputQuote][inputPos++]; outBuf[outputPos++] = inBuf[inputPos++];
if (apStrings[inputQuote][inputPos] == '%') if (inBuf[inputPos] == '%')
{ {
inputPos++; inputPos++;
switch (apStrings[inputQuote][inputPos]) switch (inBuf[inputPos])
{ {
case 'l': case 'l':
if (apStrings[inputQuote][inputPos + 1] != 'd') if (inBuf[inputPos + 1] != 'd')
{ {
// write the % and l // write the % and l
outBuf[outBufPos++] = apStrings[inputQuote][inputPos - 1]; outBuf[outputPos++] = inBuf[inputPos - 1];
outBuf[outBufPos++] = apStrings[inputQuote][inputPos++]; outBuf[outputPos++] = inBuf[inputPos++];
break; break;
} }
inputPos++; inputPos++;
@ -4796,8 +4800,8 @@ badindex:
Bsprintf(buf, "%d", arg[argIdx++]); Bsprintf(buf, "%d", arg[argIdx++]);
int const bufLen = Bstrlen(buf); int const bufLen = Bstrlen(buf);
Bmemcpy(&outBuf[outBufPos], buf, bufLen); Bmemcpy(&outBuf[outputPos], buf, bufLen);
outBufPos += bufLen; outputPos += bufLen;
inputPos++; inputPos++;
} }
break; break;
@ -4809,19 +4813,19 @@ badindex:
int const argLen = Bstrlen(apStrings[arg[argIdx]]); int const argLen = Bstrlen(apStrings[arg[argIdx]]);
Bmemcpy(&outBuf[outBufPos], apStrings[arg[argIdx]], argLen); Bmemcpy(&outBuf[outputPos], apStrings[arg[argIdx]], argLen);
outBufPos += argLen; outputPos += argLen;
argIdx++; argIdx++;
inputPos++; inputPos++;
} }
break; break;
default: outBuf[outBufPos++] = apStrings[inputQuote][inputPos - 1]; break; default: outBuf[outputPos++] = inBuf[inputPos - 1]; break;
} }
} }
} while (inputPos < quoteLen && outBufPos < MAXQUOTELEN); } while (inputPos < quoteLen && outputPos < MAXQUOTELEN);
finish_qsprintf: finish_qsprintf:
outBuf[outBufPos] = '\0'; outBuf[outputPos] = '\0';
Bstrncpyz(apStrings[outputQuote], outBuf, MAXQUOTELEN); Bstrncpyz(apStrings[outputQuote], outBuf, MAXQUOTELEN);
continue; continue;
} }