Author: jmorlan
Date: Sun Mar 15 18:45:17 2009
New Revision: 40038
URL:
http://svn.reactos.org/svn/reactos?rev=40038&view=rev
Log:
- Allow running a batch file from inside a FOR
- A little cleanup
Modified:
trunk/reactos/base/shell/cmd/batch.c
trunk/reactos/base/shell/cmd/batch.h
trunk/reactos/base/shell/cmd/goto.c
trunk/reactos/base/shell/cmd/internal.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 [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/batch.c [iso-8859-1] Sun Mar 15 18:45:17 2009
@@ -88,7 +88,7 @@
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 @@
* message
*/
-VOID ExitBatch (LPTSTR msg)
-{
- TRACE ("ExitBatch: (\'%s\')\n", debugstr_aw(msg));
-
- if (bc != NULL)
- {
- 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;
- }
-
- if (msg && *msg)
- ConOutPrintf (_T("%s\n"), msg);
+VOID ExitBatch()
+{
+ TRACE ("ExitBatch\n");
+
+ 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;
}
@@ -212,6 +206,7 @@
BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
{
BATCH_CONTEXT new;
+ LPFOR_CONTEXT saved_fc;
HANDLE hFile;
SetLastError(0);
@@ -227,9 +222,6 @@
ConErrResPuts(STRING_BATCH_ERROR);
return FALSE;
}
-
- /* Kill any and all FOR contexts */
- fc = NULL;
if (bc != NULL && Cmd == bc->current)
{
@@ -252,7 +244,7 @@
/* 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 @@
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,15 +306,13 @@
TRACE ("Batch: returns TRUE\n");
+ fc = saved_fc;
return TRUE;
}
VOID AddBatchRedirection(REDIRECTION **RedirList)
{
REDIRECTION **ListEnd;
-
- if(!bc)
- return;
/* Prepend the list to the batch context's list */
ListEnd = RedirList;
@@ -343,17 +337,13 @@
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 @@
{
TRACE ("ReadBatchLine(): Reached EOF!\n");
/* End of file.... */
- ExitBatch (NULL);
+ ExitBatch();
return NULL;
}
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 [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/batch.h [iso-8859-1] Sun Mar 15 18:45:17 2009
@@ -46,7 +46,7 @@
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 **);
Modified: trunk/reactos/base/shell/cmd/goto.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/goto.c?rev=…
==============================================================================
--- trunk/reactos/base/shell/cmd/goto.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/goto.c [iso-8859-1] Sun Mar 15 18:45:17 2009
@@ -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 @@
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 @@
}
ConErrResPrintf(STRING_GOTO_ERROR2, param);
- ExitBatch(NULL);
+ ExitBatch();
return 1;
}
Modified: trunk/reactos/base/shell/cmd/internal.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/internal.c?…
==============================================================================
--- trunk/reactos/base/shell/cmd/internal.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/internal.c [iso-8859-1] Sun Mar 15 18:45:17 2009
@@ -665,7 +665,7 @@
param++;
if (_istdigit(*param))
nErrorLevel = _ttoi(param);
- ExitBatch (NULL);
+ ExitBatch();
}
else