mirror of
https://github.com/reactos/reactos.git
synced 2024-09-30 22:47:28 +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
|
@ -88,7 +88,7 @@ LPTSTR FindArg(TCHAR Char, BOOL *IsParam0)
|
||||||
|
|
||||||
TRACE ("FindArg: (%d)\n", n);
|
TRACE ("FindArg: (%d)\n", n);
|
||||||
|
|
||||||
if (bc == NULL || n < 0 || n > 9)
|
if (n < 0 || n > 9)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
n += bc->shiftlevel;
|
n += bc->shiftlevel;
|
||||||
|
@ -167,38 +167,32 @@ LPTSTR BatchParams (LPTSTR s1, LPTSTR s2)
|
||||||
* message
|
* 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;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg && *msg)
|
if (bc->raw_params)
|
||||||
ConOutPrintf (_T("%s\n"), msg);
|
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)
|
BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
|
||||||
{
|
{
|
||||||
BATCH_CONTEXT new;
|
BATCH_CONTEXT new;
|
||||||
|
LPFOR_CONTEXT saved_fc;
|
||||||
|
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
SetLastError(0);
|
SetLastError(0);
|
||||||
|
@ -228,9 +223,6 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Kill any and all FOR contexts */
|
|
||||||
fc = NULL;
|
|
||||||
|
|
||||||
if (bc != NULL && Cmd == bc->current)
|
if (bc != NULL && Cmd == bc->current)
|
||||||
{
|
{
|
||||||
/* Then we are transferring to another batch */
|
/* 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 */
|
/* Get its SETLOCAL stack so it can be migrated to the new context */
|
||||||
setlocal = bc->setlocal;
|
setlocal = bc->setlocal;
|
||||||
bc->setlocal = NULL;
|
bc->setlocal = NULL;
|
||||||
ExitBatch(NULL);
|
ExitBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new context. This function will not
|
/* 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(':'))
|
if (*firstword == _T(':'))
|
||||||
cmd_goto(firstword);
|
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
|
/* If we have created a new context, don't return
|
||||||
* until this batch file has completed. */
|
* until this batch file has completed. */
|
||||||
while (bc == &new && !bExit)
|
while (bc == &new && !bExit)
|
||||||
|
@ -310,6 +306,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd
|
||||||
|
|
||||||
TRACE ("Batch: returns TRUE\n");
|
TRACE ("Batch: returns TRUE\n");
|
||||||
|
|
||||||
|
fc = saved_fc;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,9 +314,6 @@ VOID AddBatchRedirection(REDIRECTION **RedirList)
|
||||||
{
|
{
|
||||||
REDIRECTION **ListEnd;
|
REDIRECTION **ListEnd;
|
||||||
|
|
||||||
if(!bc)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Prepend the list to the batch context's list */
|
/* Prepend the list to the batch context's list */
|
||||||
ListEnd = RedirList;
|
ListEnd = RedirList;
|
||||||
while (*ListEnd)
|
while (*ListEnd)
|
||||||
|
@ -343,17 +337,13 @@ VOID AddBatchRedirection(REDIRECTION **RedirList)
|
||||||
|
|
||||||
LPTSTR ReadBatchLine ()
|
LPTSTR ReadBatchLine ()
|
||||||
{
|
{
|
||||||
/* No batch */
|
|
||||||
if (bc == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
TRACE ("ReadBatchLine ()\n");
|
TRACE ("ReadBatchLine ()\n");
|
||||||
|
|
||||||
/* User halt */
|
/* User halt */
|
||||||
if (CheckCtrlBreak (BREAK_BATCHFILE))
|
if (CheckCtrlBreak (BREAK_BATCHFILE))
|
||||||
{
|
{
|
||||||
while (bc)
|
while (bc)
|
||||||
ExitBatch (NULL);
|
ExitBatch();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +351,7 @@ LPTSTR ReadBatchLine ()
|
||||||
{
|
{
|
||||||
TRACE ("ReadBatchLine(): Reached EOF!\n");
|
TRACE ("ReadBatchLine(): Reached EOF!\n");
|
||||||
/* End of file.... */
|
/* End of file.... */
|
||||||
ExitBatch (NULL);
|
ExitBatch();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ extern TCHAR textline[BATCH_BUFFSIZE]; /* Buffer for reading Batch file lines */
|
||||||
|
|
||||||
LPTSTR FindArg (TCHAR, BOOL *);
|
LPTSTR FindArg (TCHAR, BOOL *);
|
||||||
LPTSTR BatchParams (LPTSTR, LPTSTR);
|
LPTSTR BatchParams (LPTSTR, LPTSTR);
|
||||||
VOID ExitBatch (LPTSTR);
|
VOID ExitBatch ();
|
||||||
BOOL Batch (LPTSTR, LPTSTR, LPTSTR, PARSED_COMMAND *);
|
BOOL Batch (LPTSTR, LPTSTR, LPTSTR, PARSED_COMMAND *);
|
||||||
LPTSTR ReadBatchLine();
|
LPTSTR ReadBatchLine();
|
||||||
VOID AddBatchRedirection(REDIRECTION **);
|
VOID AddBatchRedirection(REDIRECTION **);
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
|
|
||||||
INT cmd_goto (LPTSTR param)
|
INT cmd_goto (LPTSTR param)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
||||||
LPTSTR tmp, tmp2;
|
LPTSTR tmp, tmp2;
|
||||||
LONG lNewPosHigh = 0;
|
LONG lNewPosHigh = 0;
|
||||||
|
|
||||||
|
@ -58,8 +57,8 @@ INT cmd_goto (LPTSTR param)
|
||||||
|
|
||||||
if (*param == _T('\0'))
|
if (*param == _T('\0'))
|
||||||
{
|
{
|
||||||
LoadString(CMD_ModuleHandle, STRING_GOTO_ERROR1, szMsg, RC_STRING_MAX_SIZE);
|
ConErrResPrintf(STRING_GOTO_ERROR1);
|
||||||
ExitBatch(szMsg);
|
ExitBatch();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +116,7 @@ INT cmd_goto (LPTSTR param)
|
||||||
}
|
}
|
||||||
|
|
||||||
ConErrResPrintf(STRING_GOTO_ERROR2, param);
|
ConErrResPrintf(STRING_GOTO_ERROR2, param);
|
||||||
ExitBatch(NULL);
|
ExitBatch();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -665,7 +665,7 @@ INT CommandExit (LPTSTR param)
|
||||||
param++;
|
param++;
|
||||||
if (_istdigit(*param))
|
if (_istdigit(*param))
|
||||||
nErrorLevel = _ttoi(param);
|
nErrorLevel = _ttoi(param);
|
||||||
ExitBatch (NULL);
|
ExitBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue