Fixed bugs and added DIRS command.

svn path=/trunk/; revision=723
This commit is contained in:
Eric Kohl 1999-10-23 18:17:37 +00:00
parent 583a7209da
commit 36f33622cc
10 changed files with 223 additions and 86 deletions

View file

@ -217,6 +217,9 @@ VOID InitializeAlias (VOID)
VOID DestroyAlias (VOID) VOID DestroyAlias (VOID)
{ {
if (lpFirst == NULL)
return;
while (lpFirst->next != NULL) while (lpFirst->next != NULL)
{ {
lpLast = lpFirst; lpLast = lpFirst;

View file

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.12 1999/10/22 20:35:02 ekohl Exp $ /* $Id: cmd.c,v 1.13 1999/10/23 18:17:37 ekohl Exp $
* *
* CMD.C - command-line interface. * CMD.C - command-line interface.
* *
@ -888,9 +888,6 @@ Initialize (int argc, char *argv[])
TCHAR commandline[CMDLINE_LENGTH]; TCHAR commandline[CMDLINE_LENGTH];
INT i; INT i;
/* Added by Rob Lake 06/16/98. This enables the command.com
* to run the autoexec.bat at startup */
#ifdef _DEBUG #ifdef _DEBUG
INT x; INT x;
@ -916,16 +913,18 @@ Initialize (int argc, char *argv[])
if (argc >= 2 && !_tcsncmp (argv[1], _T("/?"), 2)) if (argc >= 2 && !_tcsncmp (argv[1], _T("/?"), 2))
{ {
ConOutPuts (_T("Starts a new instance of the ReactOS command line interpreter\n\n" ConOutPuts (_T("Starts a new instance of the ReactOS command line interpreter.\n"
"CMD [/P][/C]...\n\n" "\n"
" /P ...\n" "CMD [/[C|K] command][/P][/Q][/T:bf]\n"
" /C ...")); "\n"
" /C command Runs the specified command and terminates.\n"
" /K command Runs the specified command and remains.\n"
" /P CMD becomes permanent and runs autoexec.bat\n"
" (cannot be terminated).\n"
" /T:bf Sets the background/foreground color (see COLOR command)."));
ExitProcess (0); ExitProcess (0);
} }
ShortVersion ();
ShowCommands ();
#ifdef INCLUDE_CMD_CHDIR #ifdef INCLUDE_CMD_CHDIR
InitLastPath (); InitLastPath ();
#endif #endif
@ -957,7 +956,7 @@ Initialize (int argc, char *argv[])
} }
else if (!_tcsicmp (argv[i], _T("/c"))) else if (!_tcsicmp (argv[i], _T("/c")))
{ {
/* This just runs a program and exits, RL: 06/16,21/98 */ /* This just runs a program and exits */
++i; ++i;
_tcscpy (commandline, argv[i]); _tcscpy (commandline, argv[i]);
while (argv[++i]) while (argv[++i])
@ -969,7 +968,19 @@ Initialize (int argc, char *argv[])
ParseCommandLine(commandline); ParseCommandLine(commandline);
ExitProcess (ProcessInput (TRUE)); ExitProcess (ProcessInput (TRUE));
} }
else if (!_tcsicmp (argv[i], _T("/k")))
{
/* This just runs a program and remains */
++i;
_tcscpy (commandline, argv[i]);
while (argv[++i])
{
_tcscat (commandline, " ");
_tcscat (commandline, argv[i]);
}
ParseCommandLine(commandline);
}
#ifdef INCLUDE_CMD_COLOR #ifdef INCLUDE_CMD_COLOR
else if (!_tcsnicmp (argv[i], _T("/t:"), 3)) else if (!_tcsnicmp (argv[i], _T("/t:"), 3))
{ {
@ -982,6 +993,9 @@ Initialize (int argc, char *argv[])
} }
} }
ShortVersion ();
ShowCommands ();
/* run cmdstart.bat */ /* run cmdstart.bat */
if (IsValidFileName (_T("cmdstart.bat"))) if (IsValidFileName (_T("cmdstart.bat")))
{ {

View file

@ -172,7 +172,7 @@ INT cmd_date (LPTSTR, LPTSTR);
/* Prototypes for DEL.C */ /* Prototypes for DEL.C */
INT cmd_del (LPTSTR, LPTSTR); INT CommandDelete (LPTSTR, LPTSTR);
/* Prototypes for DELAY.C */ /* Prototypes for DELAY.C */
@ -190,6 +190,7 @@ VOID DestroyDirectoryStack (VOID);
INT GetDirectoryStackDepth (VOID); INT GetDirectoryStackDepth (VOID);
INT CommandPushd (LPTSTR, LPTSTR); INT CommandPushd (LPTSTR, LPTSTR);
INT CommandPopd (LPTSTR, LPTSTR); INT CommandPopd (LPTSTR, LPTSTR);
INT CommandDirs (LPTSTR, LPTSTR);
/* Prototypes for ECHO.C */ /* Prototypes for ECHO.C */

View file

@ -48,10 +48,6 @@ COMMAND cmds[] =
{_T("beep"), 0, cmd_beep}, {_T("beep"), 0, cmd_beep},
#endif #endif
/*
{_T("break"), 0, cmd_break},
*/
{_T("call"), CMD_BATCHONLY, cmd_call}, {_T("call"), CMD_BATCHONLY, cmd_call},
#ifdef INCLUDE_CMD_CHDIR #ifdef INCLUDE_CMD_CHDIR
@ -80,19 +76,13 @@ COMMAND cmds[] =
{_T("copy"), 0, cmd_copy}, {_T("copy"), 0, cmd_copy},
#endif #endif
/*
#define INCLUDE_CMD_CTTY
{_T("ctty"), 0, cmd_ctty},
#endif
*/
#ifdef INCLUDE_CMD_DATE #ifdef INCLUDE_CMD_DATE
{_T("date"), 0, cmd_date}, {_T("date"), 0, cmd_date},
#endif #endif
#ifdef INCLUDE_CMD_DEL #ifdef INCLUDE_CMD_DEL
{_T("del"), 0, cmd_del}, {_T("del"), 0, CommandDelete},
{_T("delete"), 0, cmd_del}, {_T("delete"), 0, CommandDelete},
#endif #endif
#ifdef INCLUDE_CMD_DELAY #ifdef INCLUDE_CMD_DELAY
@ -103,13 +93,17 @@ COMMAND cmds[] =
{_T("dir"), CMD_SPECIAL, cmd_dir}, {_T("dir"), CMD_SPECIAL, cmd_dir},
#endif #endif
#ifdef FEATURE_DIRECTORY_STACK
{_T("dirs"), 0, CommandDirs},
#endif
{_T("echo"), 0, CommandEcho}, {_T("echo"), 0, CommandEcho},
{_T("echos"), 0, CommandEchos}, {_T("echos"), 0, CommandEchos},
{_T("echoerr"), 0, CommandEchoerr}, {_T("echoerr"), 0, CommandEchoerr},
{_T("echoserr"), 0, CommandEchoserr}, {_T("echoserr"), 0, CommandEchoserr},
#ifdef INCLUDE_CMD_DEL #ifdef INCLUDE_CMD_DEL
{_T("erase"), 0, cmd_del}, {_T("erase"), 0, CommandDelete},
#endif #endif
{_T("exit"), 0, CommandExit}, {_T("exit"), 0, CommandExit},

View file

@ -21,7 +21,7 @@
#endif /* __REACTOS__ */ #endif /* __REACTOS__ */
/* JPP 20 Jul 1998 - define _DEBUG to add debugging code */ /* Define to enable debugging code */
/* #define _DEBUG */ /* #define _DEBUG */
@ -61,14 +61,12 @@
#define INCLUDE_CMD_ACTIVATE #define INCLUDE_CMD_ACTIVATE
#endif #endif
#define INCLUDE_CMD_ATTRIB #define INCLUDE_CMD_ATTRIB
/*#define INCLUDE_CMD_BREAK*/
#define INCLUDE_CMD_CHCP #define INCLUDE_CMD_CHCP
#define INCLUDE_CMD_CHDIR #define INCLUDE_CMD_CHDIR
#define INCLUDE_CMD_CHOICE #define INCLUDE_CMD_CHOICE
#define INCLUDE_CMD_CLS #define INCLUDE_CMD_CLS
#define INCLUDE_CMD_COLOR #define INCLUDE_CMD_COLOR
#define INCLUDE_CMD_COPY #define INCLUDE_CMD_COPY
/*#define INCLUDE_CMD_CTTY*/
#define INCLUDE_CMD_DATE #define INCLUDE_CMD_DATE
#define INCLUDE_CMD_DEL #define INCLUDE_CMD_DEL
#define INCLUDE_CMD_DELAY #define INCLUDE_CMD_DELAY
@ -115,6 +113,4 @@ shift
*/ */
#endif /* _CONFIG_H_INCLUDED_ */ #endif /* _CONFIG_H_INCLUDED_ */

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.11 1999/10/22 20:35:02 ekohl Exp $ /* $Id: console.c,v 1.12 1999/10/23 18:17:37 ekohl Exp $
* *
* CONSOLE.C - console input/output functions. * CONSOLE.C - console input/output functions.
* *
@ -34,7 +34,7 @@ VOID DebugPrintf (LPTSTR szFormat, ...)
_vstprintf (szOut, szFormat, arg_ptr); _vstprintf (szOut, szFormat, arg_ptr);
va_end (arg_ptr); va_end (arg_ptr);
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), WriteFile (GetStdHandle (STD_ERROR_HANDLE),
szOut, szOut,
_tcslen(szOut) * sizeof(TCHAR), _tcslen(szOut) * sizeof(TCHAR),
&dwWritten, &dwWritten,

View file

@ -136,8 +136,10 @@ RemoveFile (LPTSTR lpFileName, DWORD dwFlags)
} }
INT cmd_del (LPTSTR cmd, LPTSTR param) INT CommandDelete (LPTSTR cmd, LPTSTR param)
{ {
TCHAR szFullPath[MAX_PATH];
LPTSTR pFilePart;
LPTSTR *arg = NULL; LPTSTR *arg = NULL;
INT args; INT args;
INT i; INT i;
@ -164,8 +166,7 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
" /T Display total number of deleted files and freed disk space.\n" " /T Display total number of deleted files and freed disk space.\n"
" /Q Quiet.\n" " /Q Quiet.\n"
" /W Wipe. Overwrite the file with zeros before deleting it.\n" " /W Wipe. Overwrite the file with zeros before deleting it.\n"
" /Z Zap (delete hidden, read-only and system files).\n" " /Z Zap (delete hidden, read-only and system files).\n"));
));
return 0; return 0;
} }
@ -250,7 +251,17 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
ConErrPrintf (_T("Wildcards!\n\n")); ConErrPrintf (_T("Wildcards!\n\n"));
#endif #endif
hFile = FindFirstFile (arg[i], &f); GetFullPathName (arg[i],
MAX_PATH,
szFullPath,
&pFilePart);
#ifdef _DEBUG
ConErrPrintf (_T("Full path: %s\n"), szFullPath);
ConErrPrintf (_T("File part: %s\n"), pFilePart);
#endif
hFile = FindFirstFile (szFullPath, &f);
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
{ {
error_file_not_found (); error_file_not_found ();
@ -265,13 +276,19 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
!_tcscmp (f.cFileName, _T(".."))) !_tcscmp (f.cFileName, _T("..")))
continue; continue;
_tcscpy (pFilePart, f.cFileName);
#ifdef _DEBUG
ConErrPrintf (_T("Full filename: %s\n"), szFullPath);
#endif
if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL)) if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL))
ConErrPrintf (_T("Deleting: %s\n"), f.cFileName); ConErrPrintf (_T("Deleting: %s\n"), szFullPath);
/* delete the file */ /* delete the file */
if (!(dwFlags & DEL_NOTHING)) if (!(dwFlags & DEL_NOTHING))
{ {
if (RemoveFile (f.cFileName, dwFlags)) if (RemoveFile (szFullPath, dwFlags))
{ {
dwFiles++; dwFiles++;
} }
@ -279,9 +296,9 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
{ {
if (dwFlags & DEL_ZAP) if (dwFlags & DEL_ZAP)
{ {
if (SetFileAttributes (arg[i], 0)) if (SetFileAttributes (szFullPath, 0))
{ {
if (RemoveFile (arg[i], dwFlags)) if (RemoveFile (szFullPath, dwFlags))
{ {
dwFiles++; dwFiles++;
} }
@ -301,8 +318,6 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
} }
} }
} }
} }
while (FindNextFile (hFile, &f)); while (FindNextFile (hFile, &f));
FindClose (hFile); FindClose (hFile);
@ -310,17 +325,22 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
else else
{ {
/* no wildcards in filespec */ /* no wildcards in filespec */
#ifdef _DEBUG #ifdef _DEBUG
ConErrPrintf (_T("No Wildcards!\n")); ConErrPrintf (_T("No Wildcards!\n"));
#endif #endif
GetFullPathName (arg[i],
MAX_PATH,
szFullPath,
&pFilePart);
#ifdef _DEBUG
ConErrPrintf (_T("Full path: %s\n"), szFullPath);
#endif
if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL)) if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL))
ConOutPrintf (_T("Deleting %s\n"), arg[i]); ConOutPrintf (_T("Deleting %s\n"), szFullPath);
if (!(dwFlags & DEL_NOTHING)) if (!(dwFlags & DEL_NOTHING))
{ {
if (RemoveFile (arg[i], dwFlags)) if (RemoveFile (szFullPath, dwFlags))
{ {
dwFiles++; dwFiles++;
} }
@ -328,9 +348,9 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
{ {
if (dwFlags & DEL_ZAP) if (dwFlags & DEL_ZAP)
{ {
if (SetFileAttributes (arg[i], 0)) if (SetFileAttributes (szFullPath, 0))
{ {
if (RemoveFile (arg[i], dwFlags)) if (RemoveFile (szFullPath, dwFlags))
{ {
dwFiles++; dwFiles++;
} }
@ -364,14 +384,14 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
freep (arg); freep (arg);
if (!(dwFlags & DEL_QUIET)) if (!(dwFlags & DEL_QUIET))
{ {
if (dwFiles == 0) if (dwFiles == 0)
ConOutPrintf (_T(" 0 files deleted\n")); ConOutPrintf (_T(" 0 files deleted\n"));
else else
ConOutPrintf (_T(" %lu file%s deleted\n"), ConOutPrintf (_T(" %lu file%s deleted\n"),
dwFiles, (dwFiles == 1) ? "s" : ""); dwFiles,
(dwFiles == 1) ? "s" : "");
} }
return 0; return 0;

View file

@ -9,6 +9,9 @@
* *
* 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>) * 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Unicode and redirection safe! * Unicode and redirection safe!
*
* 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Added DIRS command.
*/ */
#include "config.h" #include "config.h"
@ -25,6 +28,7 @@
typedef struct tagDIRENTRY typedef struct tagDIRENTRY
{ {
struct tagDIRENTRY *prev;
struct tagDIRENTRY *next; struct tagDIRENTRY *next;
LPTSTR pszPath; LPTSTR pszPath;
} DIRENTRY, *LPDIRENTRY; } DIRENTRY, *LPDIRENTRY;
@ -32,6 +36,7 @@ typedef struct tagDIRENTRY
static INT nStackDepth; static INT nStackDepth;
static LPDIRENTRY lpStackTop; static LPDIRENTRY lpStackTop;
static LPDIRENTRY lpStackBottom;
static INT static INT
@ -46,7 +51,17 @@ PushDirectory (LPTSTR pszPath)
return -1; return -1;
} }
lpDir->next = (lpStackTop) ? lpStackTop : NULL; lpDir->prev = NULL;
if (lpStackTop == NULL)
{
lpDir->next = NULL;
lpStackBottom = lpDir;
}
else
{
lpDir->next = lpStackTop;
lpStackTop->prev = lpDir;
}
lpStackTop = lpDir; lpStackTop = lpDir;
lpDir->pszPath = (LPTSTR)malloc ((_tcslen(pszPath)+1)*sizeof(TCHAR)); lpDir->pszPath = (LPTSTR)malloc ((_tcslen(pszPath)+1)*sizeof(TCHAR));
@ -75,6 +90,11 @@ PopDirectory (VOID)
lpDir = lpStackTop; lpDir = lpStackTop;
lpStackTop = lpDir->next; lpStackTop = lpDir->next;
if (lpStackTop != NULL)
lpStackTop->prev = NULL;
else
lpStackBottom = NULL;
free (lpDir->pszPath); free (lpDir->pszPath);
free (lpDir); free (lpDir);
@ -99,6 +119,7 @@ VOID InitDirectoryStack (VOID)
{ {
nStackDepth = 0; nStackDepth = 0;
lpStackTop = NULL; lpStackTop = NULL;
lpStackBottom = NULL;
} }
@ -178,4 +199,39 @@ INT CommandPopd (LPTSTR first, LPTSTR rest)
return 0; return 0;
} }
/*
* dirs command
*/
INT CommandDirs (LPTSTR first, LPTSTR rest)
{
LPDIRENTRY lpDir;
if (!_tcsncmp(rest, _T("/?"), 2))
{
ConOutPuts (_T("Prints the contents of the directory stack.\n"
"\n"
"DIRS"));
return 0;
}
lpDir = lpStackBottom;
if (lpDir == NULL)
{
ConOutPuts (_T("Directory stack empty"));
return 0;
}
while (lpDir != NULL)
{
ConOutPuts (lpDir->pszPath);
lpDir = lpDir->prev;
}
return 0;
}
#endif /* FEATURE_DIRECTORY_STACK */ #endif /* FEATURE_DIRECTORY_STACK */

View file

@ -10,7 +10,6 @@ Sorting in DIR command ("dir /o...").
^S and ^Q to pause/resume displays. ^S and ^Q to pause/resume displays.
Improve DEL, COPY and MOVE commands. Improve DEL, COPY and MOVE commands.
BREAK command on command-line.
Add wildcard support to REN. Add wildcard support to REN.

View file

@ -97,6 +97,63 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
INT n; INT n;
LPTSTR p,s,f; LPTSTR p,s,f;
/* initialize full name buffer */
*pFullName = _T('\0');
#ifdef _DEBUG
DebugPrintf (_T("SearchForExecutable: \'%s\'\n"), pFileName);
#endif
if (_tcschr (pFileName, _T('\\')) != NULL)
{
LPTSTR pFilePart;
#ifdef _DEBUG
DebugPrintf (_T("Absolute or relative path is given.\n"));
#endif
GetFullPathName (pFileName,
MAX_PATH,
szPathBuffer,
&pFilePart);
if (_tcschr (pFilePart, _T('.')) != NULL)
{
#ifdef _DEBUG
DebugPrintf (_T("Filename extension!\n"));
#endif
_tcscpy (pFullName, szPathBuffer);
return TRUE;
}
else
{
#ifdef _DEBUG
DebugPrintf (_T("No filename extension!\n"));
#endif
p = szPathBuffer + _tcslen (szPathBuffer);
for (n = 0; n < nExtCount; n++)
{
_tcscpy (p, ext[n]);
#ifdef _DEBUG
DebugPrintf (_T("Testing: \'%s\'\n"), szPathBuffer);
#endif
if (IsValidFileName (szPathBuffer))
{
#ifdef _DEBUG
DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer);
#endif
_tcscpy (pFullName, szPathBuffer);
return TRUE;
}
}
return FALSE;
}
}
/* load environment varable PATH into buffer */ /* load environment varable PATH into buffer */
pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR)); pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE); dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
@ -106,9 +163,6 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer * sizeof (TCHAR)); GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer * sizeof (TCHAR));
} }
/* initialize full name buffer */
*pFullName = _T('\0');
if (!(p = _tcsrchr (pFileName, _T('.'))) || if (!(p = _tcsrchr (pFileName, _T('.'))) ||
_tcschr (p + 1, _T('\\'))) _tcschr (p + 1, _T('\\')))
{ {