From ea6cacb6edbed2fe44a370d9fbb1aca928f0bf60 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Wed, 28 Feb 2001 22:33:23 +0000 Subject: [PATCH] Various improvements by Carl Nettelblad. svn path=/trunk/; revision=1651 --- rosapps/cmd/batch.c | 14 +++++++++----- rosapps/cmd/batch.h | 5 ++--- rosapps/cmd/cmd.c | 14 ++++++++++---- rosapps/cmd/dir.c | 17 ++++++++++++++--- rosapps/cmd/for.c | 8 ++++++++ rosapps/cmd/internal.c | 3 +++ 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/rosapps/cmd/batch.c b/rosapps/cmd/batch.c index 4bac607da06..000e9f54a3a 100644 --- a/rosapps/cmd/batch.c +++ b/rosapps/cmd/batch.c @@ -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 ) * Replaced CRT io functions by Win32 io functions. * Unicode safe! + * + * 23-Feb-2001 (Carl Nettelblad ) + * 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) diff --git a/rosapps/cmd/batch.h b/rosapps/cmd/batch.h index cdc37f2a161..e7e6fb6c40f 100644 --- a/rosapps/cmd/batch.h +++ b/rosapps/cmd/batch.h @@ -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 diff --git a/rosapps/cmd/cmd.c b/rosapps/cmd/cmd.c index 9f2b3a143dc..7d5c8c68847 100644 --- a/rosapps/cmd/cmd.c +++ b/rosapps/cmd/cmd.c @@ -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 ) * Workaround because argc[0] is NULL under ReactOS + * + * 23-Feb-2001 (Carl Nettelblad ) + * %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'); diff --git a/rosapps/cmd/dir.c b/rosapps/cmd/dir.c index 0f75c1ce90e..678b49b854c 100644 --- a/rosapps/cmd/dir.c +++ b/rosapps/cmd/dir.c @@ -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 ) * Replaced all runtime io functions by their Win32 counterparts. + * + * 23-Feb-2001 (Carl Nettelblad ) + * 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; diff --git a/rosapps/cmd/for.c b/rosapps/cmd/for.c index 7c9d7f0946b..3e292a3ba1a 100644 --- a/rosapps/cmd/for.c +++ b/rosapps/cmd/for.c @@ -21,6 +21,10 @@ * * 01-Sep-1999 (Eric Kohl) * Added help text. + * + * 23-Feb-2001 (Carl Nettelblad ) + * 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; } diff --git a/rosapps/cmd/internal.c b/rosapps/cmd/internal.c index f7ea056fd46..1007f3a70d7 100644 --- a/rosapps/cmd/internal.c +++ b/rosapps/cmd/internal.c @@ -119,6 +119,9 @@ * 15-Mar-1999 (Eric Kohl ) * Fixed bug in "cd -" feature. If the previous directory was a root * directory, it was ignored. + * + * 23-Feb-2001 (Carl Nettelblad ) + * Improved chdir/cd command. */ #include "config.h" -- 2.17.1