Implement complete support for FOR command (including /D, /F, /L, and /R switches). cmd is now close to being able to run RosBE 1.3's initialization without errors.

svn path=/trunk/; revision=39742
This commit is contained in:
Jeffrey Morlan 2009-02-24 20:29:18 +00:00
parent 93ce0dce1f
commit b18a547c1b
7 changed files with 574 additions and 156 deletions

View file

@ -188,12 +188,6 @@ VOID ExitBatch (LPTSTR msg)
if (bc->params)
cmd_free(bc->params);
if (bc->forproto)
cmd_free(bc->forproto);
if (bc->ffind)
cmd_free(bc->ffind);
UndoRedirection(bc->RedirList, NULL);
FreeRedirection(bc->RedirList);
@ -270,9 +264,8 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, BOOL forcenew)
bc->bEcho = bEcho; /* Preserve echo across batch calls */
bc->shiftlevel = 0;
bc->ffind = NULL;
bc->forvar = _T('\0');
bc->forproto = NULL;
bc->forvarcount = 0;
bc->params = BatchParams (firstword, param);
//
// Allocate enough memory to hold the params and copy them over without modifications
@ -351,76 +344,6 @@ LPTSTR ReadBatchLine ()
if (bc == NULL)
return NULL;
/* If its a FOR context... */
if (bc->forvar)
{
LPTSTR sp = bc->forproto; /* pointer to prototype command */
LPTSTR dp = textline; /* Place to expand protoype */
LPTSTR fv = FindArg (0); /* Next list element */
/* End of list so... */
if ((fv == NULL) || (*fv == _T('\0')))
{
/* just exit this context */
ExitBatch (NULL);
continue;
}
if (_tcscspn (fv, _T("?*")) == _tcslen (fv))
{
/* element is wild file */
bc->shiftlevel++; /* No use it and shift list */
}
else
{
/* Wild file spec, find first (or next) file name */
if (bc->ffind)
{
/* First already done so do next */
fv = FindNextFile (bc->hFind, bc->ffind) ? bc->ffind->cFileName : NULL;
}
else
{
/* For first find, allocate a find first block */
if ((bc->ffind = (LPWIN32_FIND_DATA)cmd_alloc (sizeof (WIN32_FIND_DATA))) == NULL)
{
error_out_of_memory();
return NULL;
}
bc->hFind = FindFirstFile (fv, bc->ffind);
fv = !(bc->hFind==INVALID_HANDLE_VALUE) ? bc->ffind->cFileName : NULL;
}
if (fv == NULL)
{
/* Null indicates no more files.. */
cmd_free (bc->ffind); /* free the buffer */
bc->ffind = NULL;
bc->shiftlevel++; /* On to next list element */
continue;
}
}
/* At this point, fv points to parameter string */
bc->forvalue = fv;
/* Double up % signs so they will get through the parser intact */
while (*sp)
{
if (*sp == _T('%'))
*dp++ = _T('%');
*dp++ = *sp++;
}
*dp++ = _T('\n');
*dp = _T('\0');
return textline;
}
if (!FileGetString (bc->hBatchFile, textline, sizeof (textline) / sizeof (textline[0]) - 1))
{
TRACE ("ReadBatchLine(): Reached EOF!\n");