mirror of
https://github.com/reactos/reactos.git
synced 2025-04-27 09:00:27 +00:00
[CMD] Do not use an intermediate buffer when reading lines from batch files
This is easier on the heap and improves cmd:batch winetest nicely
This commit is contained in:
parent
5ca83e516c
commit
aae161d061
1 changed files with 14 additions and 31 deletions
|
@ -75,7 +75,6 @@ BOOL bEcho = TRUE; /* The echo flag */
|
||||||
/* Buffer for reading Batch file lines */
|
/* Buffer for reading Batch file lines */
|
||||||
TCHAR textline[BATCH_BUFFSIZE];
|
TCHAR textline[BATCH_BUFFSIZE];
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns a pointer to the n'th parameter of the current batch file.
|
* Returns a pointer to the n'th parameter of the current batch file.
|
||||||
* If no such parameter exists returns pointer to empty string.
|
* If no such parameter exists returns pointer to empty string.
|
||||||
|
@ -527,47 +526,31 @@ VOID AddBatchRedirection(REDIRECTION **RedirList)
|
||||||
*/
|
*/
|
||||||
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength)
|
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength)
|
||||||
{
|
{
|
||||||
LPSTR lpString;
|
|
||||||
INT len = 0;
|
INT len = 0;
|
||||||
#ifdef _UNICODE
|
|
||||||
lpString = cmd_alloc(nBufferLength);
|
|
||||||
if (!lpString)
|
|
||||||
{
|
|
||||||
WARN("Cannot allocate memory for lpString\n");
|
|
||||||
error_out_of_memory();
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
lpString = lpBuffer;
|
|
||||||
#endif
|
|
||||||
/* read all chars from memory until a '\n' is encountered */
|
/* read all chars from memory until a '\n' is encountered */
|
||||||
if (bc->mem)
|
if (bc->mem)
|
||||||
{
|
{
|
||||||
for (; (bc->mempos < bc->memsize && len < (nBufferLength-1)); len++)
|
for (; ((bc->mempos + len) < bc->memsize && len < (nBufferLength-1)); len++)
|
||||||
{
|
{
|
||||||
lpString[len] = bc->mem[bc->mempos++];
|
#ifndef _UNICODE
|
||||||
if (lpString[len] == '\n' )
|
lpBuffer[len] = bc->mem[bc->mempos + len];
|
||||||
|
#endif
|
||||||
|
if (bc->mem[bc->mempos + len] == '\n')
|
||||||
{
|
{
|
||||||
len++;
|
len++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef _UNICODE
|
||||||
|
nBufferLength = MultiByteToWideChar(OutputCodePage, 0, &bc->mem[bc->mempos], len, lpBuffer, nBufferLength);
|
||||||
|
lpBuffer[nBufferLength] = L'\0';
|
||||||
|
lpBuffer[len] = '\0';
|
||||||
|
#endif
|
||||||
|
bc->mempos += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!len)
|
return len != 0;
|
||||||
{
|
|
||||||
#ifdef _UNICODE
|
|
||||||
cmd_free(lpString);
|
|
||||||
#endif
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
lpString[len++] = '\0';
|
|
||||||
#ifdef _UNICODE
|
|
||||||
MultiByteToWideChar(OutputCodePage, 0, lpString, -1, lpBuffer, len);
|
|
||||||
cmd_free(lpString);
|
|
||||||
#endif
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue