mirror of
https://github.com/reactos/reactos.git
synced 2025-04-25 16:10:29 +00:00
- Allow running a batch file from inside a FOR
- A little cleanup svn path=/trunk/; revision=40038
This commit is contained in:
parent
c116a4507a
commit
341c5b2e5f
4 changed files with 36 additions and 47 deletions
|
@ -88,7 +88,7 @@ LPTSTR FindArg(TCHAR Char, BOOL *IsParam0)
|
|||
|
||||
TRACE ("FindArg: (%d)\n", n);
|
||||
|
||||
if (bc == NULL || n < 0 || n > 9)
|
||||
if (n < 0 || n > 9)
|
||||
return NULL;
|
||||
|
||||
n += bc->shiftlevel;
|
||||
|
@ -167,38 +167,32 @@ LPTSTR BatchParams (LPTSTR s1, LPTSTR s2)
|
|||
* message
|
||||
*/
|
||||
|
||||
VOID ExitBatch (LPTSTR msg)
|
||||
VOID ExitBatch()
|
||||
{
|
||||
TRACE ("ExitBatch: (\'%s\')\n", debugstr_aw(msg));
|
||||
TRACE ("ExitBatch\n");
|
||||
|
||||
if (bc != NULL)
|
||||
if (bc->hBatchFile)
|
||||
{
|
||||
if (bc->hBatchFile)
|
||||
{
|
||||
CloseHandle (bc->hBatchFile);
|
||||
bc->hBatchFile = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
if (bc->raw_params)
|
||||
cmd_free(bc->raw_params);
|
||||
|
||||
if (bc->params)
|
||||
cmd_free(bc->params);
|
||||
|
||||
UndoRedirection(bc->RedirList, NULL);
|
||||
FreeRedirection(bc->RedirList);
|
||||
|
||||
/* Preserve echo state across batch calls */
|
||||
bEcho = bc->bEcho;
|
||||
|
||||
while (bc->setlocal)
|
||||
cmd_endlocal(_T(""));
|
||||
|
||||
bc = bc->prev;
|
||||
CloseHandle (bc->hBatchFile);
|
||||
bc->hBatchFile = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
if (msg && *msg)
|
||||
ConOutPrintf (_T("%s\n"), msg);
|
||||
if (bc->raw_params)
|
||||
cmd_free(bc->raw_params);
|
||||
|
||||
if (bc->params)
|
||||
cmd_free(bc->params);
|
||||
|
||||
UndoRedirection(bc->RedirList, NULL);
|
||||
FreeRedirection(bc->RedirList);
|
||||
|
||||
/* Preserve echo state across batch calls */
|
||||
bEcho = bc->bEcho;
|
||||
|
||||
while (bc->setlocal)
|
||||
cmd_endlocal(_T(""));
|
||||
|
||||
bc = bc->prev;
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,6 +206,7 @@ VOID ExitBatch (LPTSTR msg)
|
|||
BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
|
||||
{
|
||||
BATCH_CONTEXT new;
|
||||
LPFOR_CONTEXT saved_fc;
|
||||
|
||||
HANDLE hFile;
|
||||
SetLastError(0);
|
||||
|
@ -228,9 +223,6 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/* Kill any and all FOR contexts */
|
||||
fc = NULL;
|
||||
|
||||
if (bc != NULL && Cmd == bc->current)
|
||||
{
|
||||
/* Then we are transferring to another batch */
|
||||
|
@ -252,7 +244,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd
|
|||
/* Get its SETLOCAL stack so it can be migrated to the new context */
|
||||
setlocal = bc->setlocal;
|
||||
bc->setlocal = NULL;
|
||||
ExitBatch(NULL);
|
||||
ExitBatch();
|
||||
}
|
||||
|
||||
/* Create a new context. This function will not
|
||||
|
@ -285,6 +277,10 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd
|
|||
if (*firstword == _T(':'))
|
||||
cmd_goto(firstword);
|
||||
|
||||
/* If we are calling from inside a FOR, hide the FOR variables */
|
||||
saved_fc = fc;
|
||||
fc = NULL;
|
||||
|
||||
/* If we have created a new context, don't return
|
||||
* until this batch file has completed. */
|
||||
while (bc == &new && !bExit)
|
||||
|
@ -310,6 +306,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd
|
|||
|
||||
TRACE ("Batch: returns TRUE\n");
|
||||
|
||||
fc = saved_fc;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -317,9 +314,6 @@ VOID AddBatchRedirection(REDIRECTION **RedirList)
|
|||
{
|
||||
REDIRECTION **ListEnd;
|
||||
|
||||
if(!bc)
|
||||
return;
|
||||
|
||||
/* Prepend the list to the batch context's list */
|
||||
ListEnd = RedirList;
|
||||
while (*ListEnd)
|
||||
|
@ -343,17 +337,13 @@ VOID AddBatchRedirection(REDIRECTION **RedirList)
|
|||
|
||||
LPTSTR ReadBatchLine ()
|
||||
{
|
||||
/* No batch */
|
||||
if (bc == NULL)
|
||||
return NULL;
|
||||
|
||||
TRACE ("ReadBatchLine ()\n");
|
||||
|
||||
/* User halt */
|
||||
if (CheckCtrlBreak (BREAK_BATCHFILE))
|
||||
{
|
||||
while (bc)
|
||||
ExitBatch (NULL);
|
||||
ExitBatch();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -361,7 +351,7 @@ LPTSTR ReadBatchLine ()
|
|||
{
|
||||
TRACE ("ReadBatchLine(): Reached EOF!\n");
|
||||
/* End of file.... */
|
||||
ExitBatch (NULL);
|
||||
ExitBatch();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ extern TCHAR textline[BATCH_BUFFSIZE]; /* Buffer for reading Batch file lines */
|
|||
|
||||
LPTSTR FindArg (TCHAR, BOOL *);
|
||||
LPTSTR BatchParams (LPTSTR, LPTSTR);
|
||||
VOID ExitBatch (LPTSTR);
|
||||
VOID ExitBatch ();
|
||||
BOOL Batch (LPTSTR, LPTSTR, LPTSTR, PARSED_COMMAND *);
|
||||
LPTSTR ReadBatchLine();
|
||||
VOID AddBatchRedirection(REDIRECTION **);
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
|
||||
INT cmd_goto (LPTSTR param)
|
||||
{
|
||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||
LPTSTR tmp, tmp2;
|
||||
LONG lNewPosHigh = 0;
|
||||
|
||||
|
@ -58,8 +57,8 @@ INT cmd_goto (LPTSTR param)
|
|||
|
||||
if (*param == _T('\0'))
|
||||
{
|
||||
LoadString(CMD_ModuleHandle, STRING_GOTO_ERROR1, szMsg, RC_STRING_MAX_SIZE);
|
||||
ExitBatch(szMsg);
|
||||
ConErrResPrintf(STRING_GOTO_ERROR1);
|
||||
ExitBatch();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -117,7 +116,7 @@ INT cmd_goto (LPTSTR param)
|
|||
}
|
||||
|
||||
ConErrResPrintf(STRING_GOTO_ERROR2, param);
|
||||
ExitBatch(NULL);
|
||||
ExitBatch();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -665,7 +665,7 @@ INT CommandExit (LPTSTR param)
|
|||
param++;
|
||||
if (_istdigit(*param))
|
||||
nErrorLevel = _ttoi(param);
|
||||
ExitBatch (NULL);
|
||||
ExitBatch();
|
||||
}
|
||||
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue