Various improvements by Carl Nettelblad.

svn path=/trunk/; revision=1651
This commit is contained in:
Eric Kohl 2001-02-28 22:33:23 +00:00
parent 80ec0821f8
commit ea6cacb6ed
6 changed files with 46 additions and 15 deletions

View file

@ -1,4 +1,4 @@
/* $Id: batch.c,v 1.3 1999/10/03 22:20:32 ekohl Exp $
/* $Id: batch.c,v 1.4 2001/02/28 22:33:23 ekohl Exp $
*
* BATCH.C - batch file processor for CMD.EXE.
*
@ -51,6 +51,9 @@
* 26-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Replaced CRT io functions by Win32 io functions.
* Unicode safe!
*
* 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.es>)
* Fixes made to get "for" working.
*/
#include "config.h"
@ -294,7 +297,6 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
{
HANDLE hFind = INVALID_HANDLE_VALUE;
LPTSTR first;
LPTSTR ip;
@ -346,7 +348,8 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
if (bc->ffind)
{
/* First already done so do next */
fv = FindNextFile (hFind, bc->ffind) ? bc->ffind->cFileName : NULL;
fv = FindNextFile (bc->hFind, bc->ffind) ? bc->ffind->cFileName : NULL;
}
else
{
@ -357,8 +360,9 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
return NULL;
}
hFind = FindFirstFile (fv, bc->ffind);
fv = !(hFind==INVALID_HANDLE_VALUE) ? bc->ffind->cFileName : NULL;
bc->hFind = FindFirstFile (fv, bc->ffind);
fv = !(bc->hFind==INVALID_HANDLE_VALUE) ? bc->ffind->cFileName : NULL;
}
if (fv == NULL)

View file

@ -16,12 +16,11 @@ typedef struct tagBATCHCONTEXT
LPTSTR forproto;
LPTSTR params;
INT shiftlevel;
BOOL bEcho; /* Preserve echo flag across batch calls [HBP_001] */
BOOL bEcho; /* Preserve echo flag across batch calls */
HANDLE hFind; /* Preserve find handle when doing a for */
TCHAR forvar;
} BATCH_CONTEXT, *LPBATCH_CONTEXT;
/* HBP_002 } */
/* The stack of current batch contexts.
* NULL when no batch is active

View file

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.23 2001/02/03 10:40:19 ekohl Exp $
/* $Id: cmd.c,v 1.24 2001/02/28 22:33:23 ekohl Exp $
*
* CMD.C - command-line interface.
*
@ -116,6 +116,9 @@
*
* 03-Feb-2001 (Eric Kohl <ekohl@rz-online.de>)
* Workaround because argc[0] is NULL under ReactOS
*
* 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
* %envvar% replacement conflicted with for.
*/
#include "config.h"
@ -797,7 +800,7 @@ ProcessInput (BOOL bFlag)
break;
default:
if ((tp = _tcschr (ip, _T('%'))))
if ((tp = _tcschr (ip, _T('%'))) && (tp<=(unsigned int)strchr(ip,_T(' '))-1))
{
char evar[512];
*tp = _T('\0');
@ -809,6 +812,10 @@ ProcessInput (BOOL bFlag)
ip = tp + 1;
}
else
{
*cp++ = _T('%');
}
break;
}
continue;
@ -822,8 +829,7 @@ ProcessInput (BOOL bFlag)
*cp = _T('\0');
/* strip trailing spaces */
while ((--cp >= commandline) && _istspace (*cp))
;
while ((--cp >= commandline) && _istspace (*cp));
*(cp + 1) = _T('\0');

View file

@ -1,4 +1,4 @@
/* $Id: dir.c,v 1.9 1999/12/15 00:50:41 ekohl Exp $
/* $Id: dir.c,v 1.10 2001/02/28 22:33:23 ekohl Exp $
*
* DIR.C - dir internal command.
*
@ -110,6 +110,9 @@
*
* 01-Mar-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Replaced all runtime io functions by their Win32 counterparts.
*
* 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
* dir /s now works in deeper trees
*/
#include "config.h"
@ -998,7 +1001,12 @@ DirRead (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags)
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (DirList (file.cFileName, szFilespec, pLine, dwFlags))
_tcscpy (szFullPath, szPath);
if (szFullPath[_tcslen (szFullPath) - 1] != _T('\\'))
_tcscat (szFullPath, _T("\\"));
_tcscat (szFullPath, file.cFileName);
if (DirList (szFullPath, szFilespec, pLine, dwFlags))
{
FindClose (hFile);
return 1;
@ -1009,9 +1017,12 @@ DirRead (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags)
ConOutPrintf ("\n");
if (IncLine (pLine, dwFlags) != 0)
return 1;
ConOutPrintf ("\n");
if (IncLine (pLine, dwFlags) != 0)
return 1;
}
if (DirRead (file.cFileName, szFilespec, pLine, dwFlags) == 1)
if (DirRead (szFullPath, szFilespec, pLine, dwFlags) == 1)
{
FindClose (hFile);
return 1;

View file

@ -21,6 +21,10 @@
*
* 01-Sep-1999 (Eric Kohl)
* Added help text.
*
* 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
* Implemented preservation of echo flag. Some other for related
* code in other files fixed, too.
*/
#include "config.h"
@ -142,6 +146,10 @@ INT cmd_for (LPTSTR cmd, LPTSTR param)
bc->shiftlevel = 0;
bc->forvar = var;
bc->forproto = _tcsdup (pp);
if (bc->prev)
bc->bEcho = bc->prev->bEcho;
else
bc->bEcho = bEcho;
return 0;
}

View file

@ -119,6 +119,9 @@
* 15-Mar-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Fixed bug in "cd -" feature. If the previous directory was a root
* directory, it was ignored.
*
* 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
* Improved chdir/cd command.
*/
#include "config.h"