Added some more commands. Thanks to Dr. Faustus.

Some more cleanup.

svn path=/trunk/; revision=659
This commit is contained in:
Eric Kohl 1999-09-12 18:23:31 +00:00
parent 5249698af3
commit 0c91339480
25 changed files with 987 additions and 665 deletions

View file

@ -105,7 +105,7 @@ DeleteAlias (LPTSTR pszName)
}
static INT
static VOID
AddAlias (LPTSTR name, LPTSTR subst)
{
LPALIAS ptr = lpFirst;
@ -120,20 +120,20 @@ AddAlias (LPTSTR name, LPTSTR subst)
if (!s)
{
error_out_of_memory ();
return 1;
return;
}
free (ptr->lpSubst);
ptr->lpSubst = s;
_tcscpy (ptr->lpSubst, subst);
return 0;
return;
}
ptr = ptr->next;
}
ptr = (LPALIAS)malloc (sizeof (ALIAS));
if (!ptr)
return 1;
return;
ptr->next = 0;
@ -142,7 +142,7 @@ AddAlias (LPTSTR name, LPTSTR subst)
{
error_out_of_memory ();
free (ptr);
return 1;
return;
}
_tcscpy (ptr->lpName, name);
@ -152,7 +152,7 @@ AddAlias (LPTSTR name, LPTSTR subst)
error_out_of_memory ();
free (ptr->lpName);
free (ptr);
return 1;
return;
}
_tcscpy (ptr->lpSubst, subst);
@ -189,7 +189,7 @@ AddAlias (LPTSTR name, LPTSTR subst)
ptr->next = entry;
lpFirst = ptr;
}
return 0;
return;
}
prev = entry;
entry = entry->next;
@ -204,7 +204,7 @@ AddAlias (LPTSTR name, LPTSTR subst)
lpLast->next = ptr;
lpLast = ptr;
return 0;
return;
}
@ -275,20 +275,19 @@ VOID ExpandAlias (LPTSTR cmd, INT maxlen)
}
INT cmd_alias (LPTSTR cmd, LPTSTR param)
VOID CommandAlias (LPTSTR cmd, LPTSTR param)
{
LPTSTR ptr;
INT n = 0;
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("Sets, removes or shows aliases.\n"
"\n"
"ALIAS [alias=[command]]\n"
"\n"
" alias Name for an alias.\n"
" command Text to be substituted for an alias.\n"
"\n"
"\n"
"ALIAS [alias=[command]]\n"
"\n"
" alias Name for an alias.\n"
" command Text to be substituted for an alias.\n"
"\n"
// "For example:\n"
"To list all aliases:\n"
" ALIAS\n\n"
@ -298,18 +297,18 @@ INT cmd_alias (LPTSTR cmd, LPTSTR param)
" ALIAS da="
// "Type ALIAS without a parameter to display the alias list.\n"
));
return 0;
return;
}
if (param[0] == _T('\0'))
{
PrintAlias ();
return 0;
return;
}
/* error if no '=' found */
if ((ptr = _tcschr (param, _T('='))) == 0)
return -1;
return;
/* Split rest into name and substitute */
*ptr++ = _T('\0');
@ -319,8 +318,8 @@ INT cmd_alias (LPTSTR cmd, LPTSTR param)
if (ptr[0] == _T('\0'))
DeleteAlias (param);
else
n = AddAlias (param, ptr);
AddAlias (param, ptr);
return n;
return;
}
#endif

View file

@ -19,10 +19,9 @@
#include <string.h>
#include "cmd.h"
#include "chcp.h"
INT CommandChcp (LPTSTR cmd, LPTSTR param)
VOID CommandChcp (LPTSTR cmd, LPTSTR param)
{
LPTSTR *arg;
INT args;
@ -31,10 +30,10 @@ INT CommandChcp (LPTSTR cmd, LPTSTR param)
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("Displays or sets the active code page number.\n\n"
"CHCP [nnn]\n\n"
" nnn Specifies the active code page number.\n\n"
"Type CHCP without a parameter to display the active code page number."));
return 0;
"CHCP [nnn]\n\n"
" nnn Specifies the active code page number.\n\n"
"Type CHCP without a parameter to display the active code page number."));
return;
}
/* get parameters */
@ -83,7 +82,7 @@ INT CommandChcp (LPTSTR cmd, LPTSTR param)
freep (arg);
return 0;
return;
}
#endif /* INCLUDE_CMD_CHCP */

View file

@ -4,8 +4,11 @@
*
* History:
*
* 12 Aug 1999 (Eric Kohl)
* started.
* 12-Aug-1999 (Eric Kohl)
* Started.
*
* 01 Sep 1999 (Eric Kohl)
* Fixed help text.
*/
#include "config.h"
@ -25,219 +28,221 @@
static INT
IsKeyInString (LPTSTR lpString, TCHAR cKey, BOOL bCaseSensitive)
{
PTCHAR p = lpString;
INT val = 0;
LPTSTR p = lpString;
INT val = 0;
while (*p)
{
if (bCaseSensitive)
{
if (*p == cKey)
return val;
}
else
{
if (_totlower (*p) == _totlower (cKey))
return val;
}
while (*p)
{
if (bCaseSensitive)
{
if (*p == cKey)
return val;
}
else
{
if (_totlower (*p) == _totlower (cKey))
return val;
}
val++;
p++;
}
val++;
p++;
}
return -1;
return -1;
}
INT
CommandChoice (LPTSTR cmd, LPTSTR param)
{
LPTSTR lpOptions = "YN";
LPTSTR lpText = NULL;
BOOL bNoPrompt = FALSE;
BOOL bCaseSensitive = FALSE;
BOOL bTimeout = FALSE;
INT nTimeout = 0;
TCHAR cDefault = _T('\0');
INPUT_RECORD ir;
LPTSTR p, np;
LPTSTR lpOptions = "YN";
LPTSTR lpText = NULL;
BOOL bNoPrompt = FALSE;
BOOL bCaseSensitive = FALSE;
BOOL bTimeout = FALSE;
INT nTimeout = 0;
TCHAR cDefault = _T('\0');
INPUT_RECORD ir;
LPTSTR p, np;
LPTSTR *arg;
INT argc;
INT i;
INT val;
INT val;
if (_tcsncmp (param, _T("/?"), 2) == 0)
{
ConOutPuts (_T("Prompts the user to select an option.\n"
"\n"
"CHOICE [/C[:]options][/N][/S][/T[:]c,nn][text]\n"
"\n"
" /C[:]options Allowed option characters. Default is YN.\n"
" /N The option characters and the question mark will\n"
" not be appended.\n"
" /S Input is case sensitive.\n"
" /T[:]c,nn Default to c after nn seconds.\n"
" text Displayed prompt.\n"
"\n"
"ERRORLEVEL ...\n"));
ConOutPuts (_T("Waits for the user to choose one of a set of choices.\n"
"\n"
"CHOICE [/C[:]choices][/N][/S][/T[:]c,nn][text]\n"
"\n"
" /C[:]choices Specifies allowable keys. Default is YN.\n"
" /N Do not display choices and ? at the end of the prompt string.\n"
" /S Treat choice keys as case sensitive.\n"
" /T[:]c,nn Default choice to c after nn seconds.\n"
" text Prompt string to display.\n"
"\n"
"ERRORLEVEL is set to offset of key user presses in choices."));
return 0;
}
/* retrieve text */
p = param;
/* retrieve text */
p = param;
while (TRUE)
{
if (*p == _T('\0'))
break;
if (*p != _T('/'))
{
lpText = p;
break;
}
np = _tcschr (p, _T(' '));
if (!np)
break;
p = np + 1;
}
while (TRUE)
{
if (*p == _T('\0'))
break;
if (*p != _T('/'))
{
lpText = p;
break;
}
np = _tcschr (p, _T(' '));
if (!np)
break;
p = np + 1;
}
/* build parameter array */
arg = split (param, &argc);
/* evaluate arguments */
if (argc > 0)
{
for (i = 0; i < argc; i++)
{
if (_tcsnicmp (arg[i], _T("/c"), 2) == 0)
{
if (arg[i][2] == _T(':'))
lpOptions = &arg[i][3];
else
lpOptions = &arg[i][2];
/* evaluate arguments */
if (argc > 0)
{
for (i = 0; i < argc; i++)
{
if (_tcsnicmp (arg[i], _T("/c"), 2) == 0)
{
if (arg[i][2] == _T(':'))
lpOptions = &arg[i][3];
else
lpOptions = &arg[i][2];
if (_tcslen (lpOptions) == 0)
{
ConErrPuts (_T("CHOICE: Error!!"));
freep (arg);
return 1;
}
}
else if (_tcsnicmp (arg[i], _T("/n"), 2) == 0)
{
bNoPrompt = TRUE;
}
else if (_tcsnicmp (arg[i], _T("/s"), 2) == 0)
{
bCaseSensitive = TRUE;
}
else if (_tcsnicmp (arg[i], _T("/t"), 2) == 0)
{
LPTSTR s;
if (_tcslen (lpOptions) == 0)
{
ConErrPuts (_T("Invalid choise switch syntax. Expected format: /C[:]choices\n"));
freep (arg);
return 1;
}
}
else if (_tcsnicmp (arg[i], _T("/n"), 2) == 0)
{
bNoPrompt = TRUE;
}
else if (_tcsnicmp (arg[i], _T("/s"), 2) == 0)
{
bCaseSensitive = TRUE;
}
else if (_tcsnicmp (arg[i], _T("/t"), 2) == 0)
{
LPTSTR s;
if (arg[i][2] == _T(':'))
{
cDefault = arg[i][3];
s = & arg[i][4];
}
else
{
cDefault = arg[i][2];
s = & arg[i][3];
}
if (arg[i][2] == _T(':'))
{
cDefault = arg[i][3];
s = & arg[i][4];
}
else
{
cDefault = arg[i][2];
s = & arg[i][3];
}
if (*s != _T(','))
{
ConErrPrintf (_T("Format Error: /T!!\n"));
freep (arg);
return 1;
}
if (*s != _T(','))
{
ConErrPrintf (_T("Invalid timeout syntax. Expected format: /T[:]c,nn\n"));
freep (arg);
return 1;
}
s++;
nTimeout = _ttoi(s);
bTimeout = TRUE;
}
else if (arg[i][0] == _T('/'))
{
ConErrPrintf (_T("Illegal Option: %s"), arg[i]);
freep (arg);
return 1;
}
}
}
s++;
nTimeout = _ttoi(s);
bTimeout = TRUE;
}
else if (arg[i][0] == _T('/'))
{
ConErrPrintf (_T("Invalid switch on command line. Expected format:\n"
" CHOICE [/C[:]choices][/N][/S][/T[:]c,nn][text]\n"));
freep (arg);
return 1;
}
}
}
/* print text */
if (lpText)
ConOutPrintf (_T("%s"), lpText);
/* print text */
if (lpText)
ConOutPrintf (_T("%s"), lpText);
/* print options */
if (bNoPrompt == FALSE)
{
ConOutPrintf (_T("[%c"), lpOptions[0]);
/* print options */
if (bNoPrompt == FALSE)
{
ConOutPrintf (_T("[%c"), lpOptions[0]);
for (i = 1; i < _tcslen (lpOptions); i++)
ConOutPrintf (_T(",%c"), lpOptions[i]);
for (i = 1; i < _tcslen (lpOptions); i++)
ConOutPrintf (_T(",%c"), lpOptions[i]);
ConOutPrintf (_T("]?"));
}
ConOutPrintf (_T("]?"));
}
ConInFlush ();
ConInFlush ();
if (bTimeout)
{
if (WaitForSingleObject (GetStdHandle(STD_INPUT_HANDLE),
nTimeout * 1000) == WAIT_TIMEOUT)
{
val = IsKeyInString (lpOptions,
cDefault,
bCaseSensitive);
if (bTimeout)
{
if (WaitForSingleObject (GetStdHandle(STD_INPUT_HANDLE),
nTimeout * 1000) == WAIT_TIMEOUT)
{
val = IsKeyInString (lpOptions,
cDefault,
bCaseSensitive);
if (val >= 0)
{
ConOutPrintf (_T("%c\n"), lpOptions[val]);
if (val >= 0)
{
ConOutPrintf (_T("%c\n"), lpOptions[val]);
nErrorLevel = val + 1;
nErrorLevel = val + 1;
freep (arg);
freep (arg);
#ifdef DEBUG
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel);
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel);
#endif /* DEBUG */
return 0;
}
return 0;
}
}
}
}
}
while (TRUE)
{
ConInKey (&ir);
while (TRUE)
{
ConInKey (&ir);
val = IsKeyInString (lpOptions,
val = IsKeyInString (lpOptions,
#ifdef _UNICODE
ir.Event.KeyEvent.uChar.UnicodeChar,
ir.Event.KeyEvent.uChar.UnicodeChar,
#else
ir.Event.KeyEvent.uChar.AsciiChar,
ir.Event.KeyEvent.uChar.AsciiChar,
#endif /* _UNICODE */
bCaseSensitive);
bCaseSensitive);
if (val >= 0)
{
ConOutPrintf (_T("%c\n"), lpOptions[val]);
if (val >= 0)
{
ConOutPrintf (_T("%c\n"), lpOptions[val]);
nErrorLevel = val + 1;
nErrorLevel = val + 1;
break;
}
break;
}
Beep (440, 50);
}
Beep (440, 50);
}
freep (arg);
freep (arg);
#ifdef DEBUG
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel);
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel);
#endif /* DEBUG */
return 0;

View file

@ -221,10 +221,10 @@ Execute (LPTSTR first, LPTSTR rest)
#ifndef __REACTOS__
if (CreateProcess (NULL, szFullCmdLine, NULL, NULL, FALSE,
0, NULL, NULL, &stui, &prci))
0, NULL, NULL, &stui, &prci))
#else
if (CreateProcess (szFullName, rest, NULL, NULL, FALSE,
0, NULL, NULL, &stui, &prci))
if (CreateProcess (szFullName, rest, NULL, NULL, FALSE,
0, NULL, NULL, &stui, &prci))
#endif
{
DWORD dwExitCode;
@ -237,7 +237,7 @@ Execute (LPTSTR first, LPTSTR rest)
else
{
ErrorMessage (GetLastError (),
"Error executing CreateProcess()!!\n");
"Error executing CreateProcess()!!\n");
}
}
}
@ -706,7 +706,7 @@ ProcessInput (BOOL bFlag)
break;
case _T('?'):
cp += _stprintf (cp, _T("%u"), nErrorLevel);
cp += _stprintf (cp, _T("%u"), nErrorLevel);
ip++;
break;
@ -824,7 +824,7 @@ ShowCommands (VOID)
#ifdef FEATURE_REDIRECTION
ConOutPuts (" [redirections and piping]");
#endif
ConOutChar ('\n');
ConOutChar ('\n');
}
@ -854,10 +854,10 @@ static VOID Initialize (int argc, char *argv[])
#endif
/* get version information */
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx (&osvi);
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx (&osvi);
InitLocale ();
InitLocale ();
/* get default input and output console handles */
hOut = GetStdHandle (STD_OUTPUT_HANDLE);
@ -867,14 +867,14 @@ static VOID Initialize (int argc, char *argv[])
InitLastPath ();
#endif
if (argc >= 2)
if (argc >= 2)
{
if (!_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 ..."));
"CMD [/P][/C]...\n\n"
" /P ...\n"
" /C ..."));
ExitProcess (0);
}
else
@ -941,23 +941,10 @@ static VOID Initialize (int argc, char *argv[])
/* Set COMSPEC environment variable */
#ifndef __REACTOS__
if (argv)
SetEnvironmentVariable (_T("COMSPEC"), argv[0]);
if (argv)
SetEnvironmentVariable (_T("COMSPEC"), argv[0]);
#endif
#if 0
/* Experimental ReactOS code */
ConOutPrintf("argc: %d\n", argc);
if (!argv)
{
ConOutPrintf("argc is NULL\n");
}
else
{
}
#endif /* 0 */
/* add ctrl handler */
#if 0
SetConsoleCtrlHandler (NULL, TRUE);
@ -979,7 +966,7 @@ static VOID Cleanup (VOID)
/* remove ctrl handler */
#if 0
SetConsoleCtrlHandler ((PHANDLER_ROUTINE)&BreakHandler, FALSE);
SetConsoleCtrlHandler ((PHANDLER_ROUTINE)&BreakHandler, FALSE);
#endif
}
@ -993,22 +980,22 @@ int main (int argc, char *argv[])
AllocConsole ();
#ifndef __REACTOS__
SetFileApisToOEM ();
SetFileApisToOEM ();
#endif
#ifdef __REACTOS__
SetCurrentDirectory (_T("C:\\"));
SetCurrentDirectory (_T("C:\\"));
#endif
/* check switches on command-line */
Initialize (argc, argv);
/* call prompt routine */
nExitCode = ProcessInput (FALSE);
nExitCode = ProcessInput (FALSE);
/* do the cleanup */
Cleanup ();
FreeConsole ();
Cleanup ();
FreeConsole ();
return nExitCode;
return nExitCode;
}

View file

@ -79,7 +79,6 @@ extern SHORT maxy;
extern OSVERSIONINFO osvi;
// VOID Execute (char *, char *);
void command(char *);
VOID ParseCommandLine (LPTSTR);
int c_brk(void);
@ -89,7 +88,7 @@ int c_brk(void);
/* Prototypes for ALIAS.C */
VOID ExpandAlias (LPTSTR, INT);
INT cmd_alias (LPTSTR, LPTSTR);
VOID CommandAlias (LPTSTR, LPTSTR);
/* Prototypes for ATTRIB.C */
@ -104,6 +103,10 @@ INT cmd_beep (LPTSTR, LPTSTR);
INT cmd_call (LPTSTR, LPTSTR);
/* Prototypes for CHCP.C */
VOID CommandChcp (LPTSTR, LPTSTR);
/* Prototypes for CHOICE.C */
INT CommandChoice (LPTSTR, LPTSTR);
@ -173,6 +176,10 @@ INT cmd_date (LPTSTR, LPTSTR);
INT cmd_del (LPTSTR, LPTSTR);
/* Prototypes for DELAY.C */
INT CommandDelay (LPTSTR, LPTSTR);
/* Prototypes for DIR.C */
//int incline(int *line, unsigned flags);
INT cmd_dir (LPTSTR, LPTSTR);
@ -182,7 +189,7 @@ INT cmd_dir (LPTSTR, LPTSTR);
VOID InitDirectoryStack (VOID);
VOID DestroyDirectoryStack (VOID);
INT GetDirectoryStackDepth (VOID);
INT cmd_pushd (LPTSTR, LPTSTR);
VOID CommandPushd (LPTSTR, LPTSTR);
INT cmd_popd (LPTSTR, LPTSTR);
@ -222,6 +229,10 @@ INT ShowCompletionMatches (LPTSTR, INT);
INT cmd_for (LPTSTR, LPTSTR);
/* Prototypes for FREE.C */
INT CommandFree (LPTSTR, LPTSTR);
/* Prototypes for GOTO.C */
INT cmd_goto (LPTSTR, LPTSTR);
@ -239,8 +250,8 @@ INT cmd_chdir (LPTSTR, LPTSTR);
INT cmd_mkdir (LPTSTR, LPTSTR);
INT cmd_rmdir (LPTSTR, LPTSTR);
INT internal_exit (LPTSTR, LPTSTR);
INT cmd_rem (LPTSTR, LPTSTR);
INT cmd_showcommands (LPTSTR, LPTSTR);
VOID CommandRem (LPTSTR, LPTSTR);
VOID CommandShowCommands (LPTSTR, LPTSTR);
/* Prototypes for LABEL.C */
@ -262,6 +273,10 @@ VOID PrintDate (VOID);
VOID PrintTime (VOID);
/* Prototypes for MEMORY.C */
INT CommandMemory (LPTSTR, LPTSTR);
/* Prototypes for MISC.C */
TCHAR cgetchar (VOID);
BOOL CheckCtrlBreak (INT);
@ -304,6 +319,10 @@ INT GetRedirection (LPTSTR, LPTSTR, LPTSTR, LPTSTR, LPINT);
INT cmd_rename (LPTSTR, LPTSTR);
/* Prototypes for SCREEN.C */
INT CommandScreen (LPTSTR, LPTSTR);
/* Prototypes for SET.C */
INT cmd_set (LPTSTR, LPTSTR);

View file

@ -365,7 +365,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
if ((ch >= 32 && ch <= 255) && (charcount != (maxlen - 2)))
#else
ch = ir.Event.KeyEvent.uChar.AsciiChar;
if (ch >= 32 && (charcount != (maxlen - 2)))
if (ch >= 32 && (charcount != (maxlen - 2)))
#endif /* _UNICODE */
{
/* insert character into string... */

View file

@ -24,25 +24,16 @@
#include "cmd.h"
#include "chcp.h"
/* a list of all the internal commands, associating their command names */
/* to the functions to process them */
/* Lines marked
*
* $$ are external commands
* !! internal commands which are not yet implemented
* ** special FREEDOS specific implementation
*/
COMMAND cmds[] =
{
{_T("?"), 0, cmd_showcommands},
{_T("?"), 0, CommandShowCommands},
#ifdef FEATURE_ALIASES
{_T("alias"), 0, cmd_alias},
{_T("alias"), 0, CommandAlias},
#endif
#ifdef INCLUDE_CMD_ATTRIB
@ -65,16 +56,16 @@ COMMAND cmds[] =
#endif
#ifdef INCLUDE_CMD_CHCP
{_T("chcp"), 0, CommandChcp},
{_T("chcp"), 0, CommandChcp},
#endif
#ifdef INCLUDE_CMD_CHOICE
{_T("choice"), 0, CommandChoice},
{_T("choice"), 0, CommandChoice},
#endif
#ifdef INCLUDE_CMD_CLS
{_T("cls"), 0, cmd_cls},
{_T("cls"), 0, cmd_cls},
#endif
#ifdef INCLUDE_CMD_COLOR
@ -100,20 +91,28 @@ COMMAND cmds[] =
{_T("delete"), 0, cmd_del},
#endif
#ifdef INCLUDE_CMD_DELAY
{_T("delay"), 0, CommandDelay},
#endif
#ifdef INCLUDE_CMD_DIR
{_T("dir"), CMD_SPECIAL, cmd_dir},
#endif
{_T("echo"), 0, cmd_echo},
{_T("echo"), 0, cmd_echo},
#ifdef INCLUDE_CMD_DEL
{_T("erase"), 0, cmd_del},
{_T("erase"), 0, cmd_del},
#endif
{_T("exit"), 0, internal_exit},
{_T("for"), 0, cmd_for},
#ifdef INCLUDE_CMD_FREE
{_T("free"), 0, CommandFree},
#endif
{_T("goto"), CMD_BATCHONLY, cmd_goto},
{_T("if"), 0, cmd_if},
@ -122,18 +121,21 @@ COMMAND cmds[] =
{_T("label"), 0, cmd_label},
#endif
#ifdef INCLUDE_CMD_MEMORY
{_T("memory"), 0, CommandMemory},
#endif
#ifdef INCLUDE_CMD_MKDIR
{_T("md"), CMD_SPECIAL, cmd_mkdir},
{_T("mkdir"), CMD_SPECIAL, cmd_mkdir},
#endif
#ifdef INCLUDE_CMD_MOVE
{_T("move"), 0, cmd_move},
{_T("move"), 0, cmd_move},
#endif
#ifdef INCLUDE_CMD_MSGBOX
{_T("msgbox"), 0, CommandMsgbox},
{_T("msgbox"), 0, CommandMsgbox},
#endif
#ifdef INCLUDE_CMD_PATH
@ -145,7 +147,7 @@ COMMAND cmds[] =
#endif
#ifdef FEATURE_DIRECTORY_STACK
{_T("popd"), 0, cmd_popd},
{_T("popd"), 0, cmd_popd},
#endif
#ifdef INCLUDE_CMD_PROMPT
@ -153,7 +155,7 @@ COMMAND cmds[] =
#endif
#ifdef FEATURE_DIRECTORY_STACK
{_T("pushd"), 0, cmd_pushd},
{_T("pushd"), 0, CommandPushd},
#endif
#ifdef INCLUDE_CMD_RMDIR
@ -161,7 +163,7 @@ COMMAND cmds[] =
#endif
#ifdef INCLUDE_CMD_REM
{_T("rem"), 0, cmd_rem},
{_T("rem"), 0, CommandRem},
#endif
#ifdef INCLUDE_CMD_RENAME
@ -173,6 +175,10 @@ COMMAND cmds[] =
{_T("rmdir"), CMD_SPECIAL, cmd_rmdir},
#endif
#ifdef INCLUDE_CMD_SCREEN
{_T("screen"), 0, CommandScreen},
#endif
#ifdef INCLUDE_CMD_SET
{_T("set"), 0, cmd_set},
#endif
@ -188,7 +194,7 @@ COMMAND cmds[] =
#endif
#ifdef INCLUDE_CMD_TIMER
{_T("timer"), 0, CommandTimer},
{_T("timer"), 0, CommandTimer},
#endif
#ifdef INCLUDE_CMD_TITLE
@ -214,48 +220,4 @@ COMMAND cmds[] =
{NULL, 0, NULL}
};
/* append, $$ */
/* assign, $$ */
/* attrib, ** */
/* backup, $$ */
/* chkdsk, $$ */
/* comp, $$ */
/* debug, $$ */
/* diskcomp, $$ */
/* diskcopy, $$ */
/* doskey, ** */
/* dosshell, $$ */
/* edit, $$ */
/* edlin, $$ */
/* emm386, $$ */
/* exe2bin, $$ */
/* expand, $$ */
/* fastopen, $$ */
/* fc, $$ */
/* fdisk, $$ */
/* find, $$ */
/* format, $$ */
/* graftabl, $$ */
/* graphics, $$ */
/* help, $$ */
/* join, $$ */
/* keyb, $$ */
/* mem, $$ */
/* mirror, $$ */
/* mode, $$ */
/* more, $$ */
/* nlsfunc, $$ */
/* print, $$ */
/* qbasic, $$ */
/* recover, $$ */
/* replace, $$ */
/* restore, $$ */
/* setver, $$ */
/* share, $$ */
/* sort, $$ */
/* subst, $$ */
/* sys, $$ */
/* tree, $$ */
/* undelete, $$ */
/* unformat, $$ */
/* xcopy, $$ */
/* EOF */

View file

@ -10,7 +10,7 @@
*/
/* undefine only if used under ReactOS */
#define __REACTOS__
//#define __REACTOS__
#ifndef _CONFIG_H_INCLUDED_
#define _CONFIG_H_INCLUDED_
@ -47,8 +47,8 @@
/* Define one of these to select the used locale. */
/* (date and time formats etc.) used in DATE, TIME */
/* DIR and PROMPT. */
/* (date and time formats etc.) used in DATE, TIME, */
/* DIR, PROMPT etc. */
#ifdef __REACTOS__
#define LOCALE_DEFAULT
#else
@ -68,8 +68,11 @@
/*#define INCLUDE_CMD_CTTY*/
#define INCLUDE_CMD_DATE
#define INCLUDE_CMD_DEL
#define INCLUDE_CMD_DELAY
#define INCLUDE_CMD_DIR
#define INCLUDE_CMD_FREE
#define INCLUDE_CMD_LABEL
#define INCLUDE_CMD_MEMORY
#define INCLUDE_CMD_MKDIR
#define INCLUDE_CMD_MOVE
#ifndef __REACTOS__
@ -79,6 +82,7 @@
#define INCLUDE_CMD_PROMPT
#define INCLUDE_CMD_RMDIR
#define INCLUDE_CMD_RENAME
#define INCLUDE_CMD_SCREEN
#define INCLUDE_CMD_SET
#define INCLUDE_CMD_START
#define INCLUDE_CMD_TIME

58
rosapps/cmd/delay.c Normal file
View file

@ -0,0 +1,58 @@
/*
* DELAY.C - internal command.
*
* clone from 4nt delay command
*
* 30 Aug 1999
* started - Dr.F <dfaustus@freemail.it>
*
*
*/
#include "config.h"
#ifdef INCLUDE_CMD_DELAY
#include <tchar.h>
#include <windows.h>
#include <stdlib.h>
#include "cmd.h"
INT CommandDelay (LPTSTR cmd, LPTSTR param)
{
DWORD val;
DWORD mul=1000;
if (_tcsncmp (param, _T("/?"), 2) == 0)
{
ConOutPuts(_T(
"pause for n seconds or milliseconds"
"\n"
"DELAY [/m]n\n"
"\n"
" /m specifiy than n are milliseconds\n"
" otherwise n are seconds"));
return 0;
}
if (*param==0)
{
error_req_param_missing ();
return 1;
}
if (_tcsnicmp(param,"/m",2) == 0)
{
mul = 1;
param += 2;
}
val = atoi(param);
Sleep(val*mul);
return 0;
}
#endif /* INCLUDE_CMD_DELAY */

View file

@ -121,7 +121,7 @@ INT GetDirectoryStackDepth (VOID)
/*
* pushd command
*/
INT cmd_pushd (LPTSTR first, LPTSTR rest)
VOID CommandPushd (LPTSTR first, LPTSTR rest)
{
TCHAR curPath[MAX_PATH];
TCHAR newPath[MAX_PATH];
@ -133,7 +133,7 @@ INT cmd_pushd (LPTSTR first, LPTSTR rest)
"changes to the specified directory.\n\n"
"PUSHD [path | ..]\n\n"
" path Specifies the directory to make the current directory"));
return 0;
return;
}
if (rest[0] != _T('\0'))
@ -144,12 +144,12 @@ INT cmd_pushd (LPTSTR first, LPTSTR rest)
GetCurrentDirectory (MAX_PATH, curPath);
if (PushDirectory (curPath))
return -1;
return;
if (bChangePath)
SetCurrentDirectory (newPath);
return 0;
return;
}

View file

@ -35,12 +35,14 @@ echo.c Implements echo command
error.c Error Message Routines
filecomp.c Filename completion functions
for.c Implements for command
free.c Implements free command
goto.c Implements goto command
history.c Command-line history handling
if.c Implements if command
internal.c Internal commands (DIR, RD, etc)
label.c Implements label command
locale.c Locale handling code
memory.c Implements memory command
misc.c Misc. Functions
msgbox.c Implements msgbox command
move.c Implements move command

View file

@ -4,20 +4,23 @@
*
* History:
*
* 16 Jul 1998 (Hans B Pufal)
* started.
* 16-Jul-1998 (Hans B Pufal)
* Started.
*
* 16 Jul 1998 (John P Price)
* 16-Jul-1998 (John P Price)
* Seperated commands into individual files.
*
* 19 Jul 1998 (Hans B Pufal) [HBP_001]
* Implementation of FOR
* 19-Jul-1998 (Hans B Pufal)
* Implementation of FOR.
*
* 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
* added config.h include
* Added config.h include.
*
* 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* 20-Jan-1999 (Eric Kohl)
* Unicode and redirection safe!
*
* 01-Sep-1999 (Eric Kohl)
* Added help text.
*/
#include "config.h"
@ -58,14 +61,24 @@ INT cmd_for (LPTSTR cmd, LPTSTR param)
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts ("FOR :");
ConOutPuts (_T("Runs a specified command for each file in a set of files\n"
"\n"
"FOR %variable IN (set) DO command [parameters]\n"
"\n"
" %variable Specifies a replaceable parameter.\n"
" (set) Specifies a set of one or more files. Wildcards may be used.\n"
" command Specifies the command to carry out for each file.\n"
" parameters Specifies parameters or switches for the specified command.\n"
"\n"
"To user the FOR comamnd in a batch program, specify %%variable instead of\n"
"%variable."));
return 0;
}
/* Check that first element is % then an alpha char followed by space */
if ((*param != _T('%')) || !_istalpha (*(param + 1)) || !_istspace (*(param + 2)))
{
error_syntax (_T("bad varable specification."));
error_syntax (_T("bad variable specification."));
return 1;
}
@ -132,3 +145,5 @@ INT cmd_for (LPTSTR cmd, LPTSTR param)
return 0;
}
/* EOF */

165
rosapps/cmd/free.c Normal file
View file

@ -0,0 +1,165 @@
/*
* FREE.C - internal command.
*
*
* History:
*
* 01-Sep-1999 (Eric Kohl)
* Started.
*/
#include "config.h"
#ifdef INCLUDE_CMD_FREE
#include <windows.h>
#include <tchar.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "cmd.h"
/*
* convert
*
* insert commas into a number
*/
static INT
ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len)
{
TCHAR temp[32];
INT c = 0;
INT n = 0;
if (num.QuadPart == 0)
{
des[0] = _T('0');
des[1] = _T('\0');
n = 1;
}
else
{
temp[31] = 0;
while (num.QuadPart > 0)
{
if (((c + 1) % (nNumberGroups + 1)) == 0)
temp[30 - c++] = cThousandSeparator;
temp[30 - c++] = (TCHAR)(num.QuadPart % 10) + _T('0');
num.QuadPart /= 10;
}
for (n = 0; n <= c; n++)
des[n] = temp[31 - c + n];
}
return n;
}
static VOID
PrintDiskInfo (LPTSTR szDisk)
{
TCHAR szRootPath[4] = "A:\\";
TCHAR szDrive[2] = "A";
TCHAR szVolume[64];
TCHAR szSerial[10];
TCHAR szTotal[40];
TCHAR szUsed[40];
TCHAR szFree[40];
DWORD dwSerial;
ULARGE_INTEGER uliSize;
DWORD dwSecPerCl;
DWORD dwBytPerSec;
DWORD dwFreeCl;
DWORD dwTotCl;
if (_tcslen (szDisk) < 2 || szDisk[1] != _T(':'))
{
ConErrPrintf (_T("Invalid drive %s\n"), szDisk);
return;
}
szRootPath[0] = szDisk[0];
szDrive[0] = _totupper (szRootPath[0]);
if (!GetVolumeInformation (szRootPath, szVolume, 64, &dwSerial,
NULL, NULL, NULL, 0))
{
ConErrPrintf (_T("Invalid drive %s:\n"), szDrive);
return;
}
if (szVolume[0] == _T('\0'))
_tcscpy (szVolume, _T("unlabeled"));
_stprintf (szSerial,
_T("%04X-%04X"),
HIWORD(dwSerial),
LOWORD(dwSerial));
if (!GetDiskFreeSpace (szRootPath, &dwSecPerCl,
&dwBytPerSec, &dwFreeCl, &dwTotCl))
{
ConErrPrintf (_T("Invalid drive %s:\n"), szDrive);
return;
}
uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwTotCl;
ConvertULargeInteger (uliSize, szTotal, 40);
uliSize.QuadPart = dwSecPerCl * dwBytPerSec * (dwTotCl - dwFreeCl);
ConvertULargeInteger (uliSize, szUsed, 40);
uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwFreeCl;
ConvertULargeInteger (uliSize, szFree, 40);
ConOutPrintf (_T("\n"
" Volume in drive %s is %-11s Serial number is %s\n"
" %16s bytes total disk space\n"
" %16s bytes used\n"
" %16s bytes free\n"),
szDrive, szVolume, szSerial,
szTotal, szUsed, szFree);
}
INT CommandFree (LPTSTR cmd, LPTSTR param)
{
LPTSTR szParam;
TCHAR szDefPath[MAX_PATH];
INT argc, i;
LPTSTR *arg;
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("Displays drive information.\n"
"\n"
"FREE [drive: ...]"));
return 0;
}
if (!param || *param == _T('\0'))
{
GetCurrentDirectory (MAX_PATH, szDefPath);
szDefPath[2] = _T('\0');
szParam = szDefPath;
}
else
szParam = param;
arg = split (szParam, &argc);
for (i = 0; i < argc; i++)
PrintDiskInfo (arg[i]);
freep (arg);
return 0;
}
#endif /* INCLUDE_CMD_FREE */
/* EOF */

View file

@ -344,14 +344,15 @@ o Added CHCP command.
o Fixed keyboard input bug.
o Rewrote DEL and MOVE commands.
29-Aug-1999 ReactOS CMD version 0.1 pre 6 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
01-Sep-1999 ReactOS CMD version 0.1 pre 7 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
o Cleaned up DIR command.
o Searching for executables in the right order.
o Fixed some little but nasty bugs.
o Added TITLE command. Thanks to Emanuele Aliberti!
o Added "/Q", "/W" and "/Z" options to DEL command.
o Added CHOICE command.
o Added TIMER command.
o Added CHOICE, TIMER, FREE and MEMORY commands.
o Added MSGBOX command (not available under ReactOS).
o Added and fixed missing help texts.
o Fixed bugs in MD and RD that crashed cmd when no directory was specified.

View file

@ -18,6 +18,9 @@
*
* 21-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Unicode and redirection ready!
*
* 01-Sep-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Fixed help text.
*/
#include "config.h"
@ -46,7 +49,20 @@ INT cmd_if (LPTSTR cmd, LPTSTR param)
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("IF :"));
ConOutPuts (_T("Performs conditional processing in batch programs.\n"
"\n"
" IF [NOT] ERRORLEVEL number command\n"
" IF [NOT] string1==string2 command\n"
" IF [NOT] EXIST filename command\n"
"\n"
"NOT Specifies that CMD should carry out the command only if\n"
" the condition is false\n"
"ERRORLEVEL number Specifies a true condition if the last program run returned\n"
" an exit code equal or greater than the number specified.\n"
"command Specifies the command to carry out if the condition is met.\n"
"string1==string2 Specifies a true condition if the specified text strings\n"
" match.\n"
"EXIST filename Specifies a true condition if the specified filename exists."));
return 0;
}

View file

@ -338,6 +338,12 @@ INT cmd_mkdir (LPTSTR cmd, LPTSTR param)
dir = p[0];
}
if (!dir)
{
ConErrPrintf (_T("Required parameter missing\n"));
return 1;
}
/* remove trailing \ if any, but ONLY if dir is not the root dir */
if (_tcslen (dir) >= 2 && dir[_tcslen (dir) - 1] == _T('\\'))
dir[_tcslen(dir) - 1] = _T('\0');
@ -405,6 +411,12 @@ INT cmd_rmdir (LPTSTR cmd, LPTSTR param)
dir = p[0];
}
if (!dir)
{
ConErrPrintf (_T("Required parameter missing\n"));
return 1;
}
/* remove trailing \ if any, but ONLY if dir is not the root dir */
if (_tcslen (dir) >= 2 && dir[_tcslen (dir) - 1] == _T('\\'))
dir[_tcslen(dir) - 1] = _T('\0');
@ -448,20 +460,20 @@ INT internal_exit (LPTSTR cmd, LPTSTR param)
* does nothing
*
*/
INT cmd_rem (LPTSTR cmd, LPTSTR param)
VOID CommandRem (LPTSTR cmd, LPTSTR param)
{
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("Starts a comment line in a batch file.\n\n"
"REM [Comment]"));
"REM [Comment]"));
}
return 0;
return;
}
#endif
#endif /* INCLUDE_CMD_REM */
INT cmd_showcommands (LPTSTR cmd, LPTSTR param)
VOID CommandShowCommands (LPTSTR cmd, LPTSTR param)
{
LPCOMMAND cmdptr;
INT y;
@ -484,5 +496,7 @@ INT cmd_showcommands (LPTSTR cmd, LPTSTR param)
if (y != 0)
ConOutChar (_T('\n'));
return 0;
return;
}
/* EOF */

View file

@ -2,16 +2,25 @@
# ReactOS makefile for CMD
#
all: cmd.exe
TARGET=cmd.exe
all: $(TARGET)
OBJECTS = cmd.o attrib.o alias.o batch.o beep.o call.o chcp.o choice.o \
cls.o cmdinput.o cmdtable.o color.o console.o copy.o date.o del.o \
dir.o dirstack.o echo.o error.o filecomp.o for.o goto.o history.o \
if.o internal.o label.o locale.o misc.o move.o msgbox.o path.o \
pause.o prompt.o redir.o ren.o set.o shift.o start.o time.o \
timer.o title.o type.o ver.o verify.o vol.o where.o cmd.coff
delay.o dir.o dirstack.o echo.o error.o filecomp.o for.o free.o \
goto.o history.o if.o internal.o label.o locale.o memory.o misc.o \
move.o msgbox.o path.o pause.o prompt.o redir.o ren.o screen.o \
set.o shift.o start.o time.o timer.o title.o type.o ver.o \
verify.o vol.o where.o cmd.coff
CLEAN_FILES = *.o cmd.exe cmd.sym cmd.coff
cmd.exe: $(OBJECTS)
$(CC) $(OBJECTS) -lkernel32 -lcrtdll -luser32 -o cmd.exe
$(NM) --numeric-sort cmd.exe > cmd.sym
CLEAN_FILES = *.o cmd.exe cmd.sym
clean: $(CLEAN_FILES:%=%_clean)
@ -20,8 +29,24 @@ $(CLEAN_FILES:%=%_clean): %_clean:
.phony: clean $(CLEAN_FILES:%=%_clean)
cmd.exe: $(OBJECTS)
$(CC) $(OBJECTS) -lkernel32 -lcrtdll -luser32 -o cmd.exe
$(NM) --numeric-sort cmd.exe > cmd.sym
floppy: $(TARGET:%=$(FLOPPY_DIR)/apps/%)
$(TARGET:%=$(FLOPPY_DIR)/apps/%): $(FLOPPY_DIR)/apps/%: %
ifeq ($(DOSCLI),yes)
$(CP) $* $(FLOPPY_DIR)\apps\$*
else
$(CP) $* $(FLOPPY_DIR)/apps/$*
endif
dist: $(TARGET:%=../$(DIST_DIR)/apps/%)
$(TARGET:%=../$(DIST_DIR)/apps/%): ../$(DIST_DIR)/apps/%: %
ifeq ($(DOSCLI),yes)
$(CP) $* ..\$(DIST_DIR)\apps\$*
else
$(CP) $* ../$(DIST_DIR)/apps/$*
endif
include ../rules.mak

View file

@ -4,7 +4,7 @@
# 19990128 Eric Kohl <ekohl@abo.rhein-zeitung.de>
# Modified for cmd 0.0.4pre3.
#
# ReactOS : http://www.sid-dis.com/reactos/
# ReactOS : http://www.reactos.com
# Lcc-Win32: http://www.cs.virginia.edu/*lcc-win32
#
TARGET=cmd
@ -18,6 +18,7 @@ OBJS=alias.obj \
beep.obj \
call.obj \
chcp.obj \
choice.obj \
cls.obj \
cmd.obj \
cmdinput.obj \
@ -27,28 +28,36 @@ OBJS=alias.obj \
copy.obj \
date.obj \
del.obj \
delay.obj \
dir.obj \
dirstack.obj \
echo.obj \
error.obj \
filecomp.obj \
for.obj \
free.obj \
goto.obj \
history.obj \
if.obj \
internal.obj \
label.obj \
locale.obj \
memory.obj \
misc.obj \
move.obj \
msgbox.obj \
path.obj \
pause.obj \
prompt.obj \
redir.obj \
ren.obj \
screen.obj \
set.obj \
shift.obj \
start.obj \
time.obj \
timer.obj \
title.obj \
type.obj \
ver.obj \
verify.obj \
@ -57,138 +66,11 @@ OBJS=alias.obj \
# MAIN
# What about this implicid rule?
# It should compile all c files.
# (To test this, uncomment the following two lines.) EK
.c.obj:
$(CC) $(CFLAGS) $<
$(TARGET).exe: $(OBJS)
$(LD) $(LFLAGS) $(OBJS)
# MODULES
alias.obj: alias.c
$(CC) $(CFLAGS) alias.c
attrib.obj: attrib.c
$(CC) $(CFLAGS) attrib.c
batch.obj: batch.c
$(CC) $(CFLAGS) batch.c
beep.obj: beep.c
$(CC) $(CFLAGS) beep.c
call.obj: call.c
$(CC) $(CFLAGS) call.c
cls.obj: cls.c
$(CC) $(CFLAGS) cls.c
cmd.obj: cmd.c
$(CC) $(CFLAGS) cmd.c
cmdinput.obj: cmdinput.c
$(CC) $(CFLAGS) cmdinput.c
cmdtable.obj: cmdtable.c
$(CC) $(CFLAGS) cmdtable.c
color.obj: color.c
$(CC) $(CFLAGS) color.c
console.obj: console.c
$(CC) $(CFLAGS) console.c
copy.obj: copy.c
$(CC) $(CFLAGS) copy.c
date.obj: date.c
$(CC) $(CFLAGS) date.c
del.obj: del.c
$(CC) $(CFLAGS) del.c
dir.obj: dir.c
$(CC) $(CFLAGS) dir.c
dirstack.obj: dirstack.c
$(CC) $(CFLAGS) dirstack.c
echo.obj: echo.c
$(CC) $(CFLAGS) echo.c
error.obj: error.c
$(CC) $(CFLAGS) error.c
filecomp.obj: filecomp.c
$(CC) $(CFLAGS) filecomp.c
for.obj: for.c
$(CC) $(CFLAGS) for.c
goto.obj: goto.c
$(CC) $(CFLAGS) goto.c
history.obj: history.c
$(CC) $(CFLAGS) history.c
if.obj: if.c
$(CC) $(CFLAGS) if.c
internal.obj: internal.c
$(CC) $(CFLAGS) internal.c
label.obj: label.c
$(CC) $(CFLAGS) label.c
locale.obj: locale.c
$(CC) $(CFLAGS) locale.c
misc.obj: misc.c
$(CC) $(CFLAGS) misc.c
move.obj: move.c
$(CC) $(CFLAGS) move.c
path.obj: path.c
$(CC) $(CFLAGS) path.c
pause.obj: pause.c
$(CC) $(CFLAGS) pause.c
prompt.obj: prompt.c
$(CC) $(CFLAGS) prompt.c
redir.obj: redir.c
$(CC) $(CFLAGS) redir.c
ren.obj: ren.c
$(CC) $(CFLAGS) ren.c
set.obj: set.c
$(CC) $(CFLAGS) set.c
shift.obj: shift.c
$(CC) $(CFLAGS) shift.c
time.obj: time.c
$(CC) $(CFLAGS) time.c
type.obj: type.c
$(CC) $(CFLAGS) type.c
ver.obj: ver.c
$(CC) $(CFLAGS) ver.c
verify.obj: verify.c
$(CC) $(CFLAGS) verify.c
vol.obj: vol.c
$(CC) $(CFLAGS) vol.c
where.obj: where.c
$(CC) $(CFLAGS) where.c
#EOF

110
rosapps/cmd/memory.c Normal file
View file

@ -0,0 +1,110 @@
/*
* MEMORY.C - internal command.
*
*
* History:
*
* 01-Sep-1999 (Eric Kohl)
* Started.
*/
#include "config.h"
#ifdef INCLUDE_CMD_MEMORY
#include <windows.h>
#include <tchar.h>
#include <string.h>
#include <ctype.h>
#include "cmd.h"
/*
* convert
*
* insert commas into a number
*/
static INT
ConvertDWord (DWORD num, LPTSTR des, INT len, BOOL bSeparator)
{
TCHAR temp[32];
INT c = 0;
INT n = 0;
if (num == 0)
{
des[0] = _T('0');
des[1] = _T('\0');
n = 1;
}
else
{
temp[31] = 0;
while (num > 0)
{
if (bSeparator && (((c + 1) % (nNumberGroups + 1)) == 0))
temp[30 - c++] = cThousandSeparator;
temp[30 - c++] = (TCHAR)(num % 10) + _T('0');
num /= 10;
}
for (n = 0; n <= c; n++)
des[n] = temp[31 - c + n];
}
return n;
}
INT CommandMemory (LPTSTR cmd, LPTSTR param)
{
MEMORYSTATUS ms;
TCHAR szMemoryLoad[20];
TCHAR szTotalPhys[20];
TCHAR szAvailPhys[20];
TCHAR szTotalPageFile[20];
TCHAR szAvailPageFile[20];
TCHAR szTotalVirtual[20];
TCHAR szAvailVirtual[20];
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("Displays the amount of system memory.\n"
"\n"
"MEMORY"));
return 0;
}
ms.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus (&ms);
ConvertDWord (ms.dwMemoryLoad, szMemoryLoad, 20, FALSE);
ConvertDWord (ms.dwTotalPhys, szTotalPhys, 20, TRUE);
ConvertDWord (ms.dwAvailPhys, szAvailPhys, 20, TRUE);
ConvertDWord (ms.dwTotalPageFile, szTotalPageFile, 20, TRUE);
ConvertDWord (ms.dwAvailPageFile, szAvailPageFile, 20, TRUE);
ConvertDWord (ms.dwTotalVirtual, szTotalVirtual, 20, TRUE);
ConvertDWord (ms.dwAvailVirtual, szAvailVirtual, 20, TRUE);
ConOutPrintf (_T("\n"
" %12s%% memory load.\n"
"\n"
" %13s bytes total physical RAM.\n"
" %13s bytes available physical RAM.\n"
"\n"
" %13s bytes total page file.\n"
" %13s bytes available page file.\n"
"\n"
" %13s bytes total virtual memory.\n"
" %13s bytes available virtual memory.\n"),
szMemoryLoad, szTotalPhys, szAvailPhys, szTotalPageFile,
szAvailPageFile, szTotalVirtual, szAvailVirtual);
return 0;
}
#endif /* INCLUDE_CMD_MEMORY */
/* EOF */

View file

@ -26,75 +26,77 @@
//that will be replaced by default ones
#define _SYNTAX_CHECK
HWND GetConsoleWindow(VOID)
{
TCHAR original[256]; /*holds original title*/
TCHAR temp[256]; /*holds temp title*/
HWND h=0;
GetConsoleTitle(original,sizeof(original));
_tcscpy(temp,original);
_tcscat(temp,_T("-xxx "));
if( FindWindow(0,temp) == NULL )
{
SetConsoleTitle(temp);
h=FindWindow(0,temp);
SetConsoleTitle(original);
}
return h;
}
INT CommandMsgbox (LPTSTR cmd, LPTSTR param)
{
//used to parse command line
LPTSTR tmp;
#if 0
//command line parsing stuff
LPTSTR *p;
INT argc;
INT i;
#endif
//used to find window title (used as messagebox title)
//and to find window handle to pass to MessageBox
HWND hWnd;
TCHAR buff[2048];
TCHAR buff[128];
//these are MessabeBox() parameters
LPTSTR title, prompt="";
UINT uType=U_TYPE_INIT;
//set default title to window title
GetConsoleTitle(buff,2048);
GetConsoleTitle(buff,128);
title = buff;
if (_tcsncmp (param, _T("/?"), 2) == 0)
{
ConOutPuts(_T(
"display a message box and return user responce\n"
"\n"
"MSGBOX type [\"title\"] prompt\n"
"\n"
"type button displayed\n"
" possible values are: OK, OKCANCEL,\n"
" YESNO, YESNOCANCEL\n"
"title title of message box\n"
"prompt text displayed by the message box\n"
"\n"
"\n"
"ERRORLEVEL is set according the button pressed:\n"
"\n"
"YES : 10 | NO : 11\n"
"OK : 10 | CANCEL : 12\n"
));
ConOutPuts(_T(
"display a message box and return user responce\n"
"\n"
"MSGBOX type [\"title\"] prompt\n"
"\n"
"type button displayed\n"
" possible values are: OK, OKCANCEL,\n"
" YESNO, YESNOCANCEL\n"
"title title of message box\n"
"prompt text displayed by the message box\n"
"\n"
"\n"
"ERRORLEVEL is set according the button pressed:\n"
"\n"
"YES : 10 | NO : 11\n"
"OK : 10 | CANCEL : 12\n"));
return 0;
}
//yes here things are quite massed up :)
//skip spaces
while(_istspace(*param))
param++;
//serch for messagebox type (ok, okcancel, ...)
//search for type of messagebox (ok, okcancel, ...)
if (_tcsnicmp(param, _T("ok "),3 ) == 0)
{
uType |= MB_ICONEXCLAMATION | MB_OK;
@ -130,7 +132,7 @@ INT CommandMsgbox (LPTSTR cmd, LPTSTR param)
param++;
#ifdef _SYNTAX_CHECK
//if reache end of string
//if reached end of string
//it is an error becuase we do not yet have prompt
if ( *param == 0)
{
@ -139,7 +141,7 @@ INT CommandMsgbox (LPTSTR cmd, LPTSTR param)
}
#endif
//serche for "title"
//search for "title"
tmp = param;
if(*param == '"')
@ -152,9 +154,7 @@ INT CommandMsgbox (LPTSTR cmd, LPTSTR param)
tmp++;
param = tmp;
}
}
}
//skip spaces
while(_istspace(*param))
@ -168,68 +168,9 @@ INT CommandMsgbox (LPTSTR cmd, LPTSTR param)
}
#endif
prompt = param;
prompt = param;
#if 0
p=split(param,&argc);
for(i=0;i <argc;i++)
{
if (!(_tcsicmp(&p[i][0],"ok"))) //! for ok
{
uType |= MB_ICONEXCLAMATION | MB_OK;
continue;
}
if (!(_tcsicmp(&p[i][0],"okcancel"))) //? for all other
{
uType |= MB_ICONQUESTION | MB_OKCANCEL;
continue;
}
if (!(_tcsicmp(&p[i][0],"yesno")))
{
uType |= MB_ICONQUESTION | MB_YESNO;
continue;
}
if (!(_tcsicmp(&p[i][0],"yesnocancel")))
{
uType |= MB_ICONQUESTION | MB_YESNOCANCEL;
continue;
}
//quoted title
if (p[i][0] == '"')
{
//title will point to
//"title", but we need to remove the two "
title = &p[i][1];
title[_tcsclen(title)-1] = 0;
//not a grat piece of code
//but that's ok because p[i] will be deleted
//on the function exit
break;
}
}
//get prompt
#endif
hWnd=FindWindow(0,buff);
hWnd=GetConsoleWindow ();
//DebugPrintf("FindWindow hWnd = %d\n",hWnd);
switch (
@ -238,19 +179,19 @@ INT CommandMsgbox (LPTSTR cmd, LPTSTR param)
{
case IDYES:
case IDOK:
nErrorLevel = 10;
break;
nErrorLevel = 10;
break;
case IDNO:
nErrorLevel = 11;
break;
nErrorLevel = 11;
break;
case IDCANCEL:
nErrorLevel = 12;
break;
nErrorLevel = 12;
break;
}
return 0;
return 0;
}
#endif /* INCLUDE_CMD_MSGBOX */

111
rosapps/cmd/screen.c Normal file
View file

@ -0,0 +1,111 @@
/*
* SCREEN.C - screen internal command.
*
* clone from 4nt msgbox command
*
* 30 Aug 1999
* started - Dr.F <dfaustus@freemail.it>
*
*
*/
#include "config.h"
#ifdef INCLUDE_CMD_SCREEN
#include <tchar.h>
#include <windows.h>
#include <stdlib.h>
#include <ctype.h>
#include "cmd.h"
INT CommandScreen (LPTSTR cmd, LPTSTR param)
{
SHORT x,y;
BOOL bSkipText = FALSE;
if (_tcsncmp (param, _T("/?"), 2) == 0)
{
ConOutPuts(_T(
"move cursor and optionally print text\n"
"\n"
"SCREEN row col [text]\n"
"\n"
" row row to wich move the cursor\n"
" col column to wich move the cursor"));
return 0;
}
//get row
while(_istspace(*param))
param++;
if(!(*param))
{
error_req_param_missing ();
return 1;
}
y = atoi(param);
if (y<0 || y>(maxy-1))
{
ConOutPrintf("invalid value for row");
return 1;
}
//get col
if(!(param = _tcschr(param,_T(' '))))
{
error_req_param_missing ();
return 1;
}
while(_istspace(*param))
param++;
if(!(*param))
{
error_req_param_missing ();
return 1;
}
x = atoi(param);
if (x<0 || x>(maxx-1))
{
ConErrPuts(_T("invalid value for col"));
return 1;
}
//get text
if(!(param = _tcschr(param,_T(' '))))
{
bSkipText = TRUE;
}
else
{
while(_istspace(*param))
param++;
if(!(*param))
{
bSkipText = TRUE;
}
}
bIgnoreEcho = TRUE;
if(bSkipText)
x=0;
SetCursorXY(x,y);
if(!(bSkipText))
ConOutPuts(param);
return 0;
}
#endif /* INCLUDE_CMD_SCREEN */

View file

@ -143,11 +143,14 @@ INT cmd_time (LPTSTR cmd, LPTSTR param)
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("Displays or sets the system time.\n\n"
"TIME [/T][time]\n\n"
" /T display only\n\n"
"Type TIME with no parameters to display the current time setting and a prompt\n"
"for a new one. Press ENTER to keep the same time."));
ConOutPuts (_T("Displays or sets the system time.\n"
"\n"
"TIME [/T][time]\n"
"\n"
" /T display only\n"
"\n"
"Type TIME with no parameters to display the current time setting and a prompt\n"
"for a new one. Press ENTER to keep the same time."));
return 0;
}
@ -159,6 +162,7 @@ INT cmd_time (LPTSTR cmd, LPTSTR param)
{
if (_tcsicmp (arg[i], _T("/t")) == 0)
bPrompt = FALSE;
if ((*arg[i] != _T('/')) && (nTimeString == -1))
nTimeString = i;
}
@ -203,8 +207,8 @@ INT cmd_time (LPTSTR cmd, LPTSTR param)
return 0;
}
/* force input the next time around. */
nTimeString = -1;
/* force input the next time around. */
nTimeString = -1;
}
ConErrPuts (_T("Invalid time."));
}

View file

@ -1,4 +1,4 @@
/*
/*
* TIMER.C - timer internal command.
*
* clone from 4nt timer command
@ -62,38 +62,38 @@ PrintElapsedTime (DWORD time,INT format)
time /=60;
m = time % 60;
h = time / 60;
ConOutPrintf("Elapsed %02d%c%02d%c%02d%c%02d\n",
h,cTimeSeparator,
m,cTimeSeparator,
s,cDecimalSeparator,ms/10);
break;
ConOutPrintf("Elapsed %02d%c%02d%c%02d%c%02d\n",
h,cTimeSeparator,
m,cTimeSeparator,
s,cDecimalSeparator,ms/10);
break;
}
}
INT CommandTimer (LPTSTR cmd, LPTSTR param)
{
//here are kept all timers
// all timers are kept
static DWORD clksT[10];
//timers status
//set all the clocks off by default
// timers status
// set all the clocks off by default
static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE};
//TRUE if /S in command line
// TRUE if /S in command line
BOOL bS = FALSE;
//avoid to set clk_n more than once
// avoid to set clk_n more than once
BOOL bCanNSet = TRUE;
INT NewClkStatus = NCS_NOT_SPECIFIED;
//the clock number specified on the command line
//1 by default
// the clock number specified on the command line
// 1 by default
INT clk_n=1;
// output format
// output format
INT iFormat=1;
@ -105,37 +105,37 @@ INT CommandTimer (LPTSTR cmd, LPTSTR param)
if (_tcsncmp (param, _T("/?"), 2) == 0)
{
ConOutPrintf(_T(
"allow the use of ten stopwaches.\n"
"\n"
"TIMER [ON|OFF] [/S] [/n] [/Fn]\n"
"\n"
" ON set stopwach ON\n"
" OFF set stopwach OFF\n"
" /S Split time. Return stopwach split\n"
" time without changing its value\n"
" /n Specifiy the stopwach number.\n"
" Stopwaches avaliable are 0 to 10\n"
" If it is not specified default is 1\n"
" /Fn Format for output\n"
" n can be:\n"
" 0 milliseconds\n"
" 1 hh%cmm%css%cdd\n"
"\n"),
cTimeSeparator,cTimeSeparator,cDecimalSeparator);
ConOutPrintf(_T(
"allow the use of ten stopwaches.\n"
"\n"
"TIMER [ON|OFF] [/S] [/n] [/Fn]\n"
"\n"
" ON set stopwach ON\n"
" OFF set stopwach OFF\n"
" /S Split time. Return stopwach split\n"
" time without changing its value\n"
" /n Specifiy the stopwach number.\n"
" Stopwaches avaliable are 0 to 10\n"
" If it is not specified default is 1\n"
" /Fn Format for output\n"
" n can be:\n"
" 0 milliseconds\n"
" 1 hh%cmm%css%cdd\n"
"\n"),
cTimeSeparator,cTimeSeparator,cDecimalSeparator);
ConOutPrintf(_T(
"if none of ON, OFF or /S is specified the command\n"
"will toggle stopwach state\n"
"\n"));
ConOutPrintf(_T(
"if none of ON, OFF or /S is specified the command\n"
"will toggle stopwach state\n"
"\n"));
return 0;
}
p = split (param,&argc);
p = split (param,&argc);
//read options
for (i = 0; i < argc; i++)
//read options
for (i = 0; i < argc; i++)
{
//set timer on
if (!(_tcsicmp(&p[i][0],"on")) && NewClkStatus == NCS_NOT_SPECIFIED)
@ -151,11 +151,11 @@ INT CommandTimer (LPTSTR cmd, LPTSTR param)
continue;
}
//other options
// other options
if (p[i][0] == _T('/'))
{
//set timer number
// set timer number
if (_istdigit(p[i][1]) && bCanNSet)
{
clk_n = p[i][1] - _T('0');
@ -163,31 +163,29 @@ INT CommandTimer (LPTSTR cmd, LPTSTR param)
continue;
}
//set s(plit) option
// set s(plit) option
if (_totupper(p[i][1]) == _T('S'))
{
bS = TRUE;
continue;
}
//specify format
// specify format
if(_totupper(p[i][1]) == _T('F'))
{
iFormat = p[i][2] - _T('0');
continue;
}
}
}
//do stuff (start/stop/read timer)
// do stuff (start/stop/read timer)
if(NewClkStatus == NCS_ON)
{
cT=GetTickCount();
cS=TRUE;
PS;
freep(p);
freep(p);
return 0;
}
@ -196,54 +194,53 @@ INT CommandTimer (LPTSTR cmd, LPTSTR param)
if(cS)
{
PS;
PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p);
PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p);
return 0;
}
cT=GetTickCount();
cS=TRUE;
PS;
freep(p);
return 0;
freep(p);
return 0;
}
if(NewClkStatus == NCS_NOT_SPECIFIED)
if(NewClkStatus == NCS_NOT_SPECIFIED)
{
if(cS){
cS=FALSE;
PS;
PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p);
PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p);
return 0;
}
cT=GetTickCount();
cS=TRUE;
PS;
freep(p);
freep(p);
return 0;
}
if(NewClkStatus == NCS_OFF)
if(NewClkStatus == NCS_OFF)
{
if(cS)
{
cS=FALSE;
PS;
PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p);
PrintElapsedTime(GetTickCount()-cT, iFormat);
freep(p);
return 0;
}
PS;
freep(p);
PS;
freep(p);
return 0;
}
freep(p);
return 0;
return 0;
}
#endif /* INCLUDE_CMD_TIMER */

View file

@ -14,6 +14,4 @@ BREAK command on command-line.
Add wildcard support to REN.
Add "/?" support to all batch commands.
And many, many more...

View file

@ -51,12 +51,24 @@ INT cmd_ver (LPTSTR cmd, LPTSTR param)
{
INT i;
if (_tcsstr (param, _T("/?")) != NULL)
{
ConOutPuts (_T("Displays shell version information\n"
"\n"
"VER [/C][/R][/W]\n"
"\n"
" /C Displays credits.\n"
" /R Displays redistribution information.\n"
" /W Displays warranty information."));
return 0;
}
ConOutPuts (_T("\n"
SHELLINFO "\n"
SHELLVER "\n"
"\n"
"Copyright (C) 1994-1998 Tim Norman and others."));
ConOutPuts (_T("Copyright (C) 1998,1999 Eric Kohl."));
ConOutPuts (_T("Copyright (C) 1998,1999 Eric Kohl and others."));
/* Basic copyright notice */
if (param[0] == _T('\0'))
@ -69,13 +81,6 @@ INT cmd_ver (LPTSTR cmd, LPTSTR param)
}
else
{
/* MS-DOS ver prints just help if /? is alone or not */
if (_tcsstr (param, _T("/?")) != NULL)
{
ConOutPuts (_T("\ndisplay shell version info\n\nVER [/C/R/W/?]"));
return 0;
}
for (i = 0; param[i]; i++)
{
/* skip spaces */
@ -112,15 +117,18 @@ INT cmd_ver (LPTSTR cmd, LPTSTR param)
else if (_totupper (param[i]) == _T('C'))
{
/* Developer listing */
ConOutPuts (_T("\nFreeDOS version written by:\n"
ConOutPuts (_T("\n"
"FreeDOS version written by:\n"
" Tim Norman Matt Rains\n"
" Evan Jeffrey Steffen Kaiser\n"
" Svante Frey Oliver Mueller\n"
" Aaron Kaufman Marc Desrochers\n"
" Rob Lake John P Price\n"
" Hans B Pufal\n"
"\nReactOS version written by:\n"
" Eric Kohl Emanuele Aliberti\n"));
"\n"
"ReactOS version written by:\n"
" Eric Kohl Emanuele Aliberti\n"
" Dr. Faustus\n"));
}
else
{
@ -130,9 +138,9 @@ INT cmd_ver (LPTSTR cmd, LPTSTR param)
}
}
ConOutPuts (_T("\nSend bug reports to <ekohl@abo.rhein-zeitung.de>.\n"
ConOutPuts (_T("\nSend bug reports to <ekohl@abo.rhein-zeitung.de>."
/*
"Updates are available at http://www.sid-dis.com/reactos"
"\nUpdates are available at http://www.reactos.com"
*/
));
return 0;