Author: cwittich
Date: Thu Jan 31 20:59:02 2008
New Revision: 32068
URL:
http://svn.reactos.org/svn/reactos?rev=32068&view=rev
Log:
support else
handle negative values in special envvars
stdin,out,err can't be redirected for windows gui apps
Modified:
trunk/reactos/base/shell/cmd/batch.c
trunk/reactos/base/shell/cmd/cmd.c
Modified: trunk/reactos/base/shell/cmd/batch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/batch.c?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/batch.c (original)
+++ trunk/reactos/base/shell/cmd/batch.c Thu Jan 31 20:59:02 2008
@@ -458,10 +458,21 @@
{
if (*first == _T(')'))
{
- bc->bCmdBlock--;
+ 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--;
+ }
continue;
}
- if ((bc->bCmdBlock >= 0) && (bc->bCmdBlock < MAX_PATH))
+ if (bc->bCmdBlock < MAX_PATH)
if (!bc->bExecuteBlock[bc->bCmdBlock])
{
/* increase the bCmdBlock count when there is another conditon which opens a new
bracket */
Modified: trunk/reactos/base/shell/cmd/cmd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=3…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.c (original)
+++ trunk/reactos/base/shell/cmd/cmd.c Thu Jan 31 20:59:02 2008
@@ -811,9 +811,18 @@
FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
- LoadString(CMD_ModuleHandle, STRING_CMD_ERROR1, szMsg, RC_STRING_MAX_SIZE);
- ConErrPrintf(szMsg, in);
- return;
+ 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);
+ ConErrPrintf(szMsg, in);
+ return;
+ }
}
if (!SetStdHandle (STD_INPUT_HANDLE, hFile))
@@ -892,7 +901,7 @@
/* Now set up the end conditions... */
/* redirect STDOUT */
- if (out[0])
+ if ((bc) && (bc->hBatchFile != INVALID_HANDLE_VALUE) && (out[0]))
{
/* Final output to here */
HANDLE hFile;
@@ -959,7 +968,7 @@
}
/* redirect STDERR */
- if (err[0])
+ if ((bc) && (bc->hBatchFile != INVALID_HANDLE_VALUE) && (err[0]))
{
/* Final output to here */
HANDLE hFile;
@@ -1165,15 +1174,23 @@
if (position)
{
position += 2;
- Token = _tcstok(position, _T(","));
- while ((Token != NULL) && (i < 2))
+ if (_tcschr(position, _T(',')) != NULL)
{
- StringPart[i] = _ttoi(Token);
- i++;
- Token = _tcstok (NULL, _T(","));
+ Token = _tcstok(position, _T(","));
+ while ((Token != NULL) && (i < 2))
+ {
+ StringPart[i] = _ttoi(Token);
+ i++;
+ 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]);
+ _tcscpy(ret, ReturnValue);
+ }
}
- _tcsncpy(ReturnValue, ret + StringPart[0], StringPart[1]);
- _tcscpy(ret, ReturnValue);
return ret;
}
else