added ver command

improved command line editing

svn path=/trunk/; revision=383
This commit is contained in:
Eric Kohl 1999-04-14 23:45:48 +00:00
parent 97c260445b
commit ebb6fcbc30

View file

@ -1,6 +1,9 @@
#include <ddk/ntddk.h> #include <windows.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <ctype.h>
HANDLE InputHandle, OutputHandle; HANDLE InputHandle, OutputHandle;
@ -8,15 +11,20 @@ void debug_printf(char* fmt, ...)
{ {
va_list args; va_list args;
char buffer[255]; char buffer[255];
va_start(args,fmt); va_start(args,fmt);
vsprintf(buffer,fmt,args); vsprintf(buffer,fmt,args);
WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL); WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
va_end(args); va_end(args);
} }
void ExecuteVer(void)
{
debug_printf("Reactos Simple Shell\n");
}
void ExecuteCd(char* cmdline) void ExecuteCd(char* cmdline)
{ {
if (!SetCurrentDirectoryA(cmdline)) if (!SetCurrentDirectoryA(cmdline))
{ {
debug_printf("Invalid directory\n"); debug_printf("Invalid directory\n");
@ -25,13 +33,13 @@ void ExecuteCd(char* cmdline)
void ExecuteDir(char* cmdline) void ExecuteDir(char* cmdline)
{ {
HANDLE shandle; HANDLE shandle;
WIN32_FIND_DATA FindData; WIN32_FIND_DATA FindData;
int nFile=0,nRep=0; int nFile=0, nRep=0;
TIME_FIELDS fTime; // TIME_FIELDS fTime;
shandle = FindFirstFile("*",&FindData);
shandle = FindFirstFile("*",&FindData);
if (shandle==INVALID_HANDLE_VALUE) if (shandle==INVALID_HANDLE_VALUE)
{ {
debug_printf("Invalid directory\n"); debug_printf("Invalid directory\n");
@ -41,7 +49,7 @@ void ExecuteDir(char* cmdline)
{ {
debug_printf("%-15.15s",FindData.cAlternateFileName); debug_printf("%-15.15s",FindData.cAlternateFileName);
if(FindData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY) if(FindData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
debug_printf("<REP> "),nRep++; debug_printf("<DIR> "),nRep++;
else else
debug_printf(" %10d ",FindData.nFileSizeLow),nFile++; debug_printf(" %10d ",FindData.nFileSizeLow),nFile++;
// RtlTimeToTimeFields(&FindData.ftLastWriteTime ,&fTime); // RtlTimeToTimeFields(&FindData.ftLastWriteTime ,&fTime);
@ -59,7 +67,7 @@ void ExecuteType(char* cmdline)
HANDLE FileHandle; HANDLE FileHandle;
char c; char c;
DWORD Result; DWORD Result;
FileHandle = CreateFile(cmdline, FileHandle = CreateFile(cmdline,
FILE_GENERIC_READ, FILE_GENERIC_READ,
0, 0,
@ -90,11 +98,11 @@ int ExecuteProcess(char* name, char* cmdline)
STARTUPINFO StartupInfo; STARTUPINFO StartupInfo;
char arguments; char arguments;
BOOL ret; BOOL ret;
memset(&StartupInfo,0,sizeof(StartupInfo)); memset(&StartupInfo,0,sizeof(StartupInfo));
StartupInfo.cb = sizeof(STARTUPINFO); StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.lpTitle = name; StartupInfo.lpTitle = name;
ret = CreateProcessA(name, ret = CreateProcessA(name,
cmdline, cmdline,
NULL, NULL,
@ -117,7 +125,7 @@ void ExecuteCommand(char* line)
{ {
char* cmd; char* cmd;
char* tail; char* tail;
if (isalpha(line[0]) && line[1] == ':' && line[2] == 0) if (isalpha(line[0]) && line[1] == ':' && line[2] == 0)
{ {
line[2] = '\\'; line[2] = '\\';
@ -125,7 +133,7 @@ void ExecuteCommand(char* line)
SetCurrentDirectoryA(line); SetCurrentDirectoryA(line);
return; return;
} }
tail = line; tail = line;
while ((*tail)!=' ' && (*tail)!=0) while ((*tail)!=' ' && (*tail)!=0)
{ {
@ -137,8 +145,8 @@ void ExecuteCommand(char* line)
tail++; tail++;
} }
cmd = line; cmd = line;
if (cmd==NULL) if (cmd==NULL)
{ {
return; return;
@ -158,6 +166,11 @@ void ExecuteCommand(char* line)
ExecuteType(tail); ExecuteType(tail);
return; return;
} }
if (strcmp(cmd,"ver")==0)
{
ExecuteVer();
return;
}
if (strcmp(cmd,"validate")==0) if (strcmp(cmd,"validate")==0)
{ {
debug_printf("Validating heap..."); debug_printf("Validating heap...");
@ -188,15 +201,16 @@ void ReadLine(char* line)
KEY_EVENT_RECORD KeyEvent; KEY_EVENT_RECORD KeyEvent;
DWORD Result; DWORD Result;
UCHAR CurrentDir[255]; UCHAR CurrentDir[255];
char ch; char ch;
int length = 0;
GetCurrentDirectoryA(255,CurrentDir); GetCurrentDirectoryA(255,CurrentDir);
debug_printf(CurrentDir); debug_printf("%s>", CurrentDir);
do do
{ {
if (!ReadConsoleA(InputHandle, if (!ReadConsoleA(InputHandle,
&ch, &ch,
1, 1,
&Result, &Result,
NULL)) NULL))
@ -204,9 +218,23 @@ void ReadLine(char* line)
debug_printf("Failed to read from console\n"); debug_printf("Failed to read from console\n");
for(;;); for(;;);
} }
debug_printf("%c", ch); switch (ch)
*line = ch; {
line++; case '\b':
if (length > 0)
{
debug_printf("\b \b");
line--;
length--;
}
break;
default:
debug_printf("%c", ch);
*line = ch;
line++;
length++;
}
} while (ch != '\n'); } while (ch != '\n');
line--; line--;
*line = 0; *line = 0;
@ -215,15 +243,15 @@ void ReadLine(char* line)
void main() void main()
{ {
static char line[255]; static char line[255];
AllocConsole(); AllocConsole();
InputHandle = GetStdHandle(STD_INPUT_HANDLE); InputHandle = GetStdHandle(STD_INPUT_HANDLE);
OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE); OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
debug_printf("Shell Starting...\n"); debug_printf("Shell Starting...\n");
SetCurrentDirectoryA("C:\\"); SetCurrentDirectoryA("C:\\");
for(;;) for(;;)
{ {
ReadLine(line); ReadLine(line);