mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 17:14:41 +00:00
Fixed bugs and added DIRS command.
svn path=/trunk/; revision=723
This commit is contained in:
parent
583a7209da
commit
36f33622cc
10 changed files with 223 additions and 86 deletions
|
@ -217,6 +217,9 @@ VOID InitializeAlias (VOID)
|
|||
|
||||
VOID DestroyAlias (VOID)
|
||||
{
|
||||
if (lpFirst == NULL)
|
||||
return;
|
||||
|
||||
while (lpFirst->next != NULL)
|
||||
{
|
||||
lpLast = lpFirst;
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -888,9 +888,6 @@ Initialize (int argc, char *argv[])
|
|||
TCHAR commandline[CMDLINE_LENGTH];
|
||||
INT i;
|
||||
|
||||
/* Added by Rob Lake 06/16/98. This enables the command.com
|
||||
* to run the autoexec.bat at startup */
|
||||
|
||||
#ifdef _DEBUG
|
||||
INT x;
|
||||
|
||||
|
@ -916,16 +913,18 @@ Initialize (int argc, char *argv[])
|
|||
|
||||
if (argc >= 2 && !_tcsncmp (argv[1], _T("/?"), 2))
|
||||
{
|
||||
ConOutPuts (_T("Starts a new instance of the ReactOS command line interpreter\n\n"
|
||||
"CMD [/P][/C]...\n\n"
|
||||
" /P ...\n"
|
||||
" /C ..."));
|
||||
ConOutPuts (_T("Starts a new instance of the ReactOS command line interpreter.\n"
|
||||
"\n"
|
||||
"CMD [/[C|K] command][/P][/Q][/T:bf]\n"
|
||||
"\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);
|
||||
}
|
||||
|
||||
ShortVersion ();
|
||||
ShowCommands ();
|
||||
|
||||
#ifdef INCLUDE_CMD_CHDIR
|
||||
InitLastPath ();
|
||||
#endif
|
||||
|
@ -957,7 +956,7 @@ Initialize (int argc, char *argv[])
|
|||
}
|
||||
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;
|
||||
_tcscpy (commandline, argv[i]);
|
||||
while (argv[++i])
|
||||
|
@ -969,7 +968,19 @@ Initialize (int argc, char *argv[])
|
|||
ParseCommandLine(commandline);
|
||||
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
|
||||
else if (!_tcsnicmp (argv[i], _T("/t:"), 3))
|
||||
{
|
||||
|
@ -982,6 +993,9 @@ Initialize (int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
ShortVersion ();
|
||||
ShowCommands ();
|
||||
|
||||
/* run cmdstart.bat */
|
||||
if (IsValidFileName (_T("cmdstart.bat")))
|
||||
{
|
||||
|
|
|
@ -172,7 +172,7 @@ INT cmd_date (LPTSTR, LPTSTR);
|
|||
|
||||
|
||||
/* Prototypes for DEL.C */
|
||||
INT cmd_del (LPTSTR, LPTSTR);
|
||||
INT CommandDelete (LPTSTR, LPTSTR);
|
||||
|
||||
|
||||
/* Prototypes for DELAY.C */
|
||||
|
@ -190,6 +190,7 @@ VOID DestroyDirectoryStack (VOID);
|
|||
INT GetDirectoryStackDepth (VOID);
|
||||
INT CommandPushd (LPTSTR, LPTSTR);
|
||||
INT CommandPopd (LPTSTR, LPTSTR);
|
||||
INT CommandDirs (LPTSTR, LPTSTR);
|
||||
|
||||
|
||||
/* Prototypes for ECHO.C */
|
||||
|
|
|
@ -48,10 +48,6 @@ COMMAND cmds[] =
|
|||
{_T("beep"), 0, cmd_beep},
|
||||
#endif
|
||||
|
||||
/*
|
||||
{_T("break"), 0, cmd_break},
|
||||
*/
|
||||
|
||||
{_T("call"), CMD_BATCHONLY, cmd_call},
|
||||
|
||||
#ifdef INCLUDE_CMD_CHDIR
|
||||
|
@ -80,19 +76,13 @@ COMMAND cmds[] =
|
|||
{_T("copy"), 0, cmd_copy},
|
||||
#endif
|
||||
|
||||
/*
|
||||
#define INCLUDE_CMD_CTTY
|
||||
{_T("ctty"), 0, cmd_ctty},
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifdef INCLUDE_CMD_DATE
|
||||
{_T("date"), 0, cmd_date},
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_DEL
|
||||
{_T("del"), 0, cmd_del},
|
||||
{_T("delete"), 0, cmd_del},
|
||||
{_T("del"), 0, CommandDelete},
|
||||
{_T("delete"), 0, CommandDelete},
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_DELAY
|
||||
|
@ -103,13 +93,17 @@ COMMAND cmds[] =
|
|||
{_T("dir"), CMD_SPECIAL, cmd_dir},
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_DIRECTORY_STACK
|
||||
{_T("dirs"), 0, CommandDirs},
|
||||
#endif
|
||||
|
||||
{_T("echo"), 0, CommandEcho},
|
||||
{_T("echos"), 0, CommandEchos},
|
||||
{_T("echoerr"), 0, CommandEchoerr},
|
||||
{_T("echoserr"), 0, CommandEchoserr},
|
||||
|
||||
#ifdef INCLUDE_CMD_DEL
|
||||
{_T("erase"), 0, cmd_del},
|
||||
{_T("erase"), 0, CommandDelete},
|
||||
#endif
|
||||
|
||||
{_T("exit"), 0, CommandExit},
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#endif /* __REACTOS__ */
|
||||
|
||||
|
||||
/* JPP 20 Jul 1998 - define _DEBUG to add debugging code */
|
||||
/* Define to enable debugging code */
|
||||
/* #define _DEBUG */
|
||||
|
||||
|
||||
|
@ -61,14 +61,12 @@
|
|||
#define INCLUDE_CMD_ACTIVATE
|
||||
#endif
|
||||
#define INCLUDE_CMD_ATTRIB
|
||||
/*#define INCLUDE_CMD_BREAK*/
|
||||
#define INCLUDE_CMD_CHCP
|
||||
#define INCLUDE_CMD_CHDIR
|
||||
#define INCLUDE_CMD_CHOICE
|
||||
#define INCLUDE_CMD_CLS
|
||||
#define INCLUDE_CMD_COLOR
|
||||
#define INCLUDE_CMD_COPY
|
||||
/*#define INCLUDE_CMD_CTTY*/
|
||||
#define INCLUDE_CMD_DATE
|
||||
#define INCLUDE_CMD_DEL
|
||||
#define INCLUDE_CMD_DELAY
|
||||
|
@ -115,6 +113,4 @@ shift
|
|||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#endif /* _CONFIG_H_INCLUDED_ */
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -34,7 +34,7 @@ VOID DebugPrintf (LPTSTR szFormat, ...)
|
|||
_vstprintf (szOut, szFormat, arg_ptr);
|
||||
va_end (arg_ptr);
|
||||
|
||||
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE),
|
||||
WriteFile (GetStdHandle (STD_ERROR_HANDLE),
|
||||
szOut,
|
||||
_tcslen(szOut) * sizeof(TCHAR),
|
||||
&dwWritten,
|
||||
|
|
|
@ -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;
|
||||
INT args;
|
||||
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"
|
||||
" /Q Quiet.\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;
|
||||
}
|
||||
|
@ -250,7 +251,17 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
|
|||
ConErrPrintf (_T("Wildcards!\n\n"));
|
||||
#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)
|
||||
{
|
||||
error_file_not_found ();
|
||||
|
@ -265,13 +276,19 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
|
|||
!_tcscmp (f.cFileName, _T("..")))
|
||||
continue;
|
||||
|
||||
_tcscpy (pFilePart, f.cFileName);
|
||||
|
||||
#ifdef _DEBUG
|
||||
ConErrPrintf (_T("Full filename: %s\n"), szFullPath);
|
||||
#endif
|
||||
|
||||
if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL))
|
||||
ConErrPrintf (_T("Deleting: %s\n"), f.cFileName);
|
||||
ConErrPrintf (_T("Deleting: %s\n"), szFullPath);
|
||||
|
||||
/* delete the file */
|
||||
if (!(dwFlags & DEL_NOTHING))
|
||||
{
|
||||
if (RemoveFile (f.cFileName, dwFlags))
|
||||
if (RemoveFile (szFullPath, dwFlags))
|
||||
{
|
||||
dwFiles++;
|
||||
}
|
||||
|
@ -279,9 +296,9 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
|
|||
{
|
||||
if (dwFlags & DEL_ZAP)
|
||||
{
|
||||
if (SetFileAttributes (arg[i], 0))
|
||||
if (SetFileAttributes (szFullPath, 0))
|
||||
{
|
||||
if (RemoveFile (arg[i], dwFlags))
|
||||
if (RemoveFile (szFullPath, dwFlags))
|
||||
{
|
||||
dwFiles++;
|
||||
}
|
||||
|
@ -301,8 +318,6 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
while (FindNextFile (hFile, &f));
|
||||
FindClose (hFile);
|
||||
|
@ -310,17 +325,22 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
|
|||
else
|
||||
{
|
||||
/* no wildcards in filespec */
|
||||
|
||||
#ifdef _DEBUG
|
||||
ConErrPrintf (_T("No Wildcards!\n"));
|
||||
#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))
|
||||
ConOutPrintf (_T("Deleting %s\n"), arg[i]);
|
||||
ConOutPrintf (_T("Deleting %s\n"), szFullPath);
|
||||
|
||||
if (!(dwFlags & DEL_NOTHING))
|
||||
{
|
||||
if (RemoveFile (arg[i], dwFlags))
|
||||
if (RemoveFile (szFullPath, dwFlags))
|
||||
{
|
||||
dwFiles++;
|
||||
}
|
||||
|
@ -328,9 +348,9 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
|
|||
{
|
||||
if (dwFlags & DEL_ZAP)
|
||||
{
|
||||
if (SetFileAttributes (arg[i], 0))
|
||||
if (SetFileAttributes (szFullPath, 0))
|
||||
{
|
||||
if (RemoveFile (arg[i], dwFlags))
|
||||
if (RemoveFile (szFullPath, dwFlags))
|
||||
{
|
||||
dwFiles++;
|
||||
}
|
||||
|
@ -364,14 +384,14 @@ INT cmd_del (LPTSTR cmd, LPTSTR param)
|
|||
|
||||
freep (arg);
|
||||
|
||||
|
||||
if (!(dwFlags & DEL_QUIET))
|
||||
{
|
||||
if (dwFiles == 0)
|
||||
ConOutPrintf (_T(" 0 files deleted\n"));
|
||||
else
|
||||
ConOutPrintf (_T(" %lu file%s deleted\n"),
|
||||
dwFiles, (dwFiles == 1) ? "s" : "");
|
||||
dwFiles,
|
||||
(dwFiles == 1) ? "s" : "");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
*
|
||||
* 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
||||
* Unicode and redirection safe!
|
||||
*
|
||||
* 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
||||
* Added DIRS command.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
@ -25,6 +28,7 @@
|
|||
|
||||
typedef struct tagDIRENTRY
|
||||
{
|
||||
struct tagDIRENTRY *prev;
|
||||
struct tagDIRENTRY *next;
|
||||
LPTSTR pszPath;
|
||||
} DIRENTRY, *LPDIRENTRY;
|
||||
|
@ -32,6 +36,7 @@ typedef struct tagDIRENTRY
|
|||
|
||||
static INT nStackDepth;
|
||||
static LPDIRENTRY lpStackTop;
|
||||
static LPDIRENTRY lpStackBottom;
|
||||
|
||||
|
||||
static INT
|
||||
|
@ -46,7 +51,17 @@ PushDirectory (LPTSTR pszPath)
|
|||
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;
|
||||
|
||||
lpDir->pszPath = (LPTSTR)malloc ((_tcslen(pszPath)+1)*sizeof(TCHAR));
|
||||
|
@ -75,6 +90,11 @@ PopDirectory (VOID)
|
|||
|
||||
lpDir = lpStackTop;
|
||||
lpStackTop = lpDir->next;
|
||||
if (lpStackTop != NULL)
|
||||
lpStackTop->prev = NULL;
|
||||
else
|
||||
lpStackBottom = NULL;
|
||||
|
||||
free (lpDir->pszPath);
|
||||
free (lpDir);
|
||||
|
||||
|
@ -99,6 +119,7 @@ VOID InitDirectoryStack (VOID)
|
|||
{
|
||||
nStackDepth = 0;
|
||||
lpStackTop = NULL;
|
||||
lpStackBottom = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -178,4 +199,39 @@ INT CommandPopd (LPTSTR first, LPTSTR rest)
|
|||
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 */
|
|
@ -10,7 +10,6 @@ Sorting in DIR command ("dir /o...").
|
|||
^S and ^Q to pause/resume displays.
|
||||
|
||||
Improve DEL, COPY and MOVE commands.
|
||||
BREAK command on command-line.
|
||||
|
||||
Add wildcard support to REN.
|
||||
|
||||
|
|
|
@ -97,6 +97,63 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
|
|||
INT n;
|
||||
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 */
|
||||
pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
|
||||
|
@ -106,9 +163,6 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
|
|||
GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer * sizeof (TCHAR));
|
||||
}
|
||||
|
||||
/* initialize full name buffer */
|
||||
*pFullName = _T('\0');
|
||||
|
||||
if (!(p = _tcsrchr (pFileName, _T('.'))) ||
|
||||
_tcschr (p + 1, _T('\\')))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue