support else

handle negative values in special envvars
stdin,out,err can't be redirected for windows gui apps

svn path=/trunk/; revision=32068
This commit is contained in:
Christoph von Wittich 2008-01-31 17:59:02 +00:00
parent 00e33fbce3
commit 11ca34b0e3
2 changed files with 42 additions and 14 deletions

View file

@ -457,11 +457,22 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
if (bc->bCmdBlock >= 0) if (bc->bCmdBlock >= 0)
{ {
if (*first == _T(')')) if (*first == _T(')'))
{
first++;
/* Strip leading spaces and trailing space/control chars */
while(_istspace (*first))
first++;
if ((_tcsncicmp (first, _T("else"), 4) == 0) && (_tcschr(first, _T('('))))
{
bc->bExecuteBlock[bc->bCmdBlock] = !bc->bExecuteBlock[bc->bCmdBlock];
}
else
{ {
bc->bCmdBlock--; bc->bCmdBlock--;
}
continue; continue;
} }
if ((bc->bCmdBlock >= 0) && (bc->bCmdBlock < MAX_PATH)) if (bc->bCmdBlock < MAX_PATH)
if (!bc->bExecuteBlock[bc->bCmdBlock]) if (!bc->bExecuteBlock[bc->bCmdBlock])
{ {
/* increase the bCmdBlock count when there is another conditon which opens a new bracket */ /* increase the bCmdBlock count when there is another conditon which opens a new bracket */

View file

@ -810,11 +810,20 @@ VOID ParseCommandLine (LPTSTR cmd)
hFile = CreateFile (in, GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING, hFile = CreateFile (in, GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
{
if (bc)
{
/* will fail for windows gui apps */
num = 0;
bc->hBatchFile = INVALID_HANDLE_VALUE;
}
else
{ {
LoadString(CMD_ModuleHandle, STRING_CMD_ERROR1, szMsg, RC_STRING_MAX_SIZE); LoadString(CMD_ModuleHandle, STRING_CMD_ERROR1, szMsg, RC_STRING_MAX_SIZE);
ConErrPrintf(szMsg, in); ConErrPrintf(szMsg, in);
return; return;
} }
}
if (!SetStdHandle (STD_INPUT_HANDLE, hFile)) if (!SetStdHandle (STD_INPUT_HANDLE, hFile))
{ {
@ -892,7 +901,7 @@ VOID ParseCommandLine (LPTSTR cmd)
/* Now set up the end conditions... */ /* Now set up the end conditions... */
/* redirect STDOUT */ /* redirect STDOUT */
if (out[0]) if ((bc) && (bc->hBatchFile != INVALID_HANDLE_VALUE) && (out[0]))
{ {
/* Final output to here */ /* Final output to here */
HANDLE hFile; HANDLE hFile;
@ -959,7 +968,7 @@ VOID ParseCommandLine (LPTSTR cmd)
} }
/* redirect STDERR */ /* redirect STDERR */
if (err[0]) if ((bc) && (bc->hBatchFile != INVALID_HANDLE_VALUE) && (err[0]))
{ {
/* Final output to here */ /* Final output to here */
HANDLE hFile; HANDLE hFile;
@ -1165,6 +1174,8 @@ GetEnvVarOrSpecial ( LPCTSTR varName )
if (position) if (position)
{ {
position += 2; position += 2;
if (_tcschr(position, _T(',')) != NULL)
{
Token = _tcstok(position, _T(",")); Token = _tcstok(position, _T(","));
while ((Token != NULL) && (i < 2)) while ((Token != NULL) && (i < 2))
{ {
@ -1172,8 +1183,14 @@ GetEnvVarOrSpecial ( LPCTSTR varName )
i++; i++;
Token = _tcstok (NULL, _T(",")); Token = _tcstok (NULL, _T(","));
} }
if (i > 0)
{
if (StringPart[1] < 0)
StringPart[1] = _tcslen(ret + StringPart[0]) + StringPart[1];
_tcsncpy(ReturnValue, ret + StringPart[0], StringPart[1]); _tcsncpy(ReturnValue, ret + StringPart[0], StringPart[1]);
_tcscpy(ret, ReturnValue); _tcscpy(ret, ReturnValue);
}
}
return ret; return ret;
} }
else else