handle call :Label

fix goto :Label

svn path=/trunk/; revision=32070
This commit is contained in:
Christoph von Wittich 2008-01-31 20:55:05 +00:00
parent 97b5e11eba
commit 76569bc213
4 changed files with 45 additions and 26 deletions

View file

@ -273,6 +273,8 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
bc->bEcho = bEcho; /* Preserve echo across batch calls */ bc->bEcho = bEcho; /* Preserve echo across batch calls */
bc->shiftlevel = 0; bc->shiftlevel = 0;
bc->bCmdBlock = -1; bc->bCmdBlock = -1;
bc->lCallPosition = 0;
bc->lCallPositionHigh = 0;
bc->ffind = NULL; bc->ffind = NULL;
bc->forvar = _T('\0'); bc->forvar = _T('\0');

View file

@ -24,6 +24,8 @@ typedef struct tagBATCHCONTEXT
TCHAR forvar; TCHAR forvar;
INT bCmdBlock; INT bCmdBlock;
BOOL bExecuteBlock[MAX_PATH]; BOOL bExecuteBlock[MAX_PATH];
LONG lCallPosition; /* store position where to return to after Call :Label */
LONG lCallPositionHigh;
} BATCH_CONTEXT, *LPBATCH_CONTEXT; } BATCH_CONTEXT, *LPBATCH_CONTEXT;

View file

@ -53,6 +53,13 @@ INT cmd_call (LPTSTR cmd, LPTSTR param)
return 0; 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; nErrorLevel = 0;
n = (LPBATCH_CONTEXT)cmd_alloc (sizeof (BATCH_CONTEXT)); n = (LPBATCH_CONTEXT)cmd_alloc (sizeof (BATCH_CONTEXT));

View file

@ -40,7 +40,7 @@ INT cmd_goto (LPTSTR cmd, LPTSTR param)
{ {
TCHAR szMsg[RC_STRING_MAX_SIZE]; TCHAR szMsg[RC_STRING_MAX_SIZE];
LPTSTR tmp; LPTSTR tmp;
LONG lNewPosHigh; LONG lNewPosHigh = 0;
#ifdef _DEBUG #ifdef _DEBUG
DebugPrintf (_T("cmd_goto (\'%s\', \'%s\'\n"), cmd, param); DebugPrintf (_T("cmd_goto (\'%s\', \'%s\'\n"), cmd, param);
@ -67,33 +67,40 @@ INT cmd_goto (LPTSTR cmd, LPTSTR param)
/* terminate label at first space char */ /* terminate label at first space char */
tmp = param+1; tmp = param+1;
while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':'))) while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':')))
tmp++; tmp++;
*(tmp) = _T('\0'); *(tmp) = _T('\0');
/* set file pointer to the beginning of the batch file */ /* set file pointer to the beginning of the batch file */
lNewPosHigh = 0; lNewPosHigh = 0;
/* jump to end of the file */ /* jump to end of the file */
if ( _tcsicmp( param, _T(":eof"))==0) if ( _tcsicmp( param, _T(":eof"))==0)
{ {
SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_END); /* when lCallPosition != 0 we have to return to the caller */
return 0; 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 */ /* jump to begin of the file */
SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_BEGIN); SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_BEGIN);
while (FileGetString (bc->hBatchFile, textline, sizeof(textline) / sizeof(textline[0]))) while (FileGetString (bc->hBatchFile, textline, sizeof(textline) / sizeof(textline[0])))
{ {
int pos; int pos;
int size; int size;
/* Strip out any trailing spaces or control chars */ /* Strip out any trailing spaces or control chars */
tmp = textline + _tcslen (textline) - 1; tmp = textline + _tcslen (textline) - 1;
while (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':')))
while (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':')))
tmp--; tmp--;
*(tmp + 1) = _T('\0'); *(tmp + 1) = _T('\0');
@ -101,20 +108,21 @@ INT cmd_goto (LPTSTR cmd, LPTSTR param)
tmp = textline; tmp = textline;
while (_istspace (*tmp)) while (_istspace (*tmp))
tmp++; tmp++;
/* All space after leading space terminate the string */ /* All space after leading space terminate the string */
size = _tcslen(tmp) -1; size = _tcslen(tmp) -1;
pos=0; pos=0;
while (tmp+pos < tmp+size) while (tmp+pos < tmp+size)
{ {
if (_istspace(tmp[pos])) if (_istspace(tmp[pos]))
tmp[pos]=_T('\0'); tmp[pos]=_T('\0');
pos++; pos++;
} }
/* use whole label name */ /* use whole label name */
if ((*tmp == _T(':')) && (_tcsicmp (++tmp, param) == 0)) if ((*tmp == _T(':')) && ((_tcsicmp (++tmp, param) == 0) || (_tcsicmp (tmp, ++param) == 0)))
return 0; return 0;
} }
LoadString(CMD_ModuleHandle, STRING_GOTO_ERROR2, szMsg, RC_STRING_MAX_SIZE); LoadString(CMD_ModuleHandle, STRING_GOTO_ERROR2, szMsg, RC_STRING_MAX_SIZE);