Author: cwittich Date: Thu Jan 31 23:55:05 2008 New Revision: 32070
URL: http://svn.reactos.org/svn/reactos?rev=32070&view=rev Log: handle call :Label fix goto :Label
Modified: trunk/reactos/base/shell/cmd/batch.c trunk/reactos/base/shell/cmd/batch.h trunk/reactos/base/shell/cmd/call.c trunk/reactos/base/shell/cmd/goto.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 23:55:05 2008 @@ -273,6 +273,8 @@ bc->bEcho = bEcho; /* Preserve echo across batch calls */ bc->shiftlevel = 0; bc->bCmdBlock = -1; + bc->lCallPosition = 0; + bc->lCallPositionHigh = 0; bc->ffind = NULL; bc->forvar = _T('\0');
Modified: trunk/reactos/base/shell/cmd/batch.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/batch.h?rev=... ============================================================================== --- trunk/reactos/base/shell/cmd/batch.h (original) +++ trunk/reactos/base/shell/cmd/batch.h Thu Jan 31 23:55:05 2008 @@ -24,6 +24,8 @@ TCHAR forvar; INT bCmdBlock; BOOL bExecuteBlock[MAX_PATH]; + LONG lCallPosition; /* store position where to return to after Call :Label */ + LONG lCallPositionHigh; } BATCH_CONTEXT, *LPBATCH_CONTEXT;
Modified: trunk/reactos/base/shell/cmd/call.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/call.c?rev=3... ============================================================================== --- trunk/reactos/base/shell/cmd/call.c (original) +++ trunk/reactos/base/shell/cmd/call.c Thu Jan 31 23:55:05 2008 @@ -53,6 +53,13 @@ return 0; }
+ if (*param == _T(':') && (bc)) + { + bc->lCallPosition = SetFilePointer(bc->hBatchFile, 0, &bc->lCallPositionHigh, FILE_CURRENT); + cmd_goto(_T("goto"), param); + return 0; + } + nErrorLevel = 0;
n = (LPBATCH_CONTEXT)cmd_alloc (sizeof (BATCH_CONTEXT));
Modified: trunk/reactos/base/shell/cmd/goto.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/goto.c?rev=3... ============================================================================== --- trunk/reactos/base/shell/cmd/goto.c (original) +++ trunk/reactos/base/shell/cmd/goto.c Thu Jan 31 23:55:05 2008 @@ -40,7 +40,7 @@ { TCHAR szMsg[RC_STRING_MAX_SIZE]; LPTSTR tmp; - LONG lNewPosHigh; + LONG lNewPosHigh = 0;
#ifdef _DEBUG DebugPrintf (_T("cmd_goto ('%s', '%s'\n"), cmd, param); @@ -67,33 +67,40 @@
/* terminate label at first space char */ tmp = param+1; - while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':'))) - tmp++; + while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':'))) + tmp++; *(tmp) = _T('\0');
/* set file pointer to the beginning of the batch file */ lNewPosHigh = 0;
- /* jump to end of the file */ - if ( _tcsicmp( param, _T(":eof"))==0) - { - SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_END); - return 0; - } + /* jump to end of the file */ + if ( _tcsicmp( param, _T(":eof"))==0) + { + /* when lCallPosition != 0 we have to return to the caller */ + if (bc->lCallPosition == 0) + SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_END); + else + { + SetFilePointer (bc->hBatchFile, (LONG)bc->lCallPosition, &bc->lCallPositionHigh, FILE_BEGIN); + bc->lCallPosition = 0; + bc->lCallPositionHigh = 0; + } + return 0; + }
- /* jump to begin of the file */ - SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_BEGIN); + /* jump to begin of the file */ + SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_BEGIN);
while (FileGetString (bc->hBatchFile, textline, sizeof(textline) / sizeof(textline[0]))) { - int pos; - int size; + int pos; + int size;
/* Strip out any trailing spaces or control chars */ tmp = textline + _tcslen (textline) - 1;
- - while (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':'))) + while (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':'))) tmp--; *(tmp + 1) = _T('\0');
@@ -101,20 +108,21 @@ tmp = textline; while (_istspace (*tmp)) tmp++; - - /* All space after leading space terminate the string */ - size = _tcslen(tmp) -1; - pos=0; - while (tmp+pos < tmp+size) - { - if (_istspace(tmp[pos])) - tmp[pos]=_T('\0'); - pos++; - } + + /* All space after leading space terminate the string */ + size = _tcslen(tmp) -1; + pos=0; + while (tmp+pos < tmp+size) + { + if (_istspace(tmp[pos])) + tmp[pos]=_T('\0'); + pos++; + }
/* use whole label name */ - if ((*tmp == _T(':')) && (_tcsicmp (++tmp, param) == 0)) + if ((*tmp == _T(':')) && ((_tcsicmp (++tmp, param) == 0) || (_tcsicmp (tmp, ++param) == 0))) return 0; + }
LoadString(CMD_ModuleHandle, STRING_GOTO_ERROR2, szMsg, RC_STRING_MAX_SIZE);