Fixed a few bugs and enhanced performance

svn path=/trunk/; revision=1549
This commit is contained in:
Phillip Susi 2001-01-21 00:05:53 +00:00
parent 0f09a6d59c
commit b360ee177d

View file

@ -1,4 +1,4 @@
/* $Id: shell.c,v 1.1 2000/12/05 02:38:08 ekohl Exp $ /* $Id: shell.c,v 1.2 2001/01/21 00:05:53 phreak Exp $
* *
* PROJECT : ReactOS Operating System * PROJECT : ReactOS Operating System
* DESCRIPTION: ReactOS' Native Shell * DESCRIPTION: ReactOS' Native Shell
@ -133,7 +133,7 @@ int ExecuteProcess(char* name, char* cmdline, BOOL detached)
PROCESS_INFORMATION ProcessInformation; PROCESS_INFORMATION ProcessInformation;
STARTUPINFO StartupInfo; STARTUPINFO StartupInfo;
BOOL ret; BOOL ret;
CHAR fullname[MAX_PATH]; CHAR fullname[260];
PCHAR p; PCHAR p;
/* append '.exe' if needed */ /* append '.exe' if needed */
@ -148,8 +148,6 @@ int ExecuteProcess(char* name, char* cmdline, BOOL detached)
memset(&StartupInfo, 0, sizeof(StartupInfo)); memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof (STARTUPINFO); StartupInfo.cb = sizeof (STARTUPINFO);
StartupInfo.lpTitle = name; StartupInfo.lpTitle = name;
// set mode to default for new process
SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ), ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
ret = CreateProcessA(fullname, ret = CreateProcessA(fullname,
cmdline, cmdline,
NULL, NULL,
@ -198,8 +196,6 @@ int ExecuteProcess(char* name, char* cmdline, BOOL detached)
CloseHandle(ProcessInformation.hThread); CloseHandle(ProcessInformation.hThread);
} }
} }
// reset mode
SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ), 0 );
return(ret); return(ret);
} }
@ -413,42 +409,20 @@ void ReadLine(char* line)
{ {
DWORD Result; DWORD Result;
UCHAR CurrentDir[255]; UCHAR CurrentDir[255];
int length = 0;
int c;
GetCurrentDirectoryA(255,CurrentDir); GetCurrentDirectoryA(255,CurrentDir);
debug_printf("%s>", CurrentDir); debug_printf("%s>", CurrentDir);
if ( !ReadConsoleA(InputHandle, line, 252, &Result, NULL) )
do
{
if ( !ReadConsoleA(InputHandle, line, 255 - length, &Result, NULL) )
{ {
debug_printf("Failed to read from console\n"); debug_printf("Failed to read from console\n");
for(;;); for(;;);
} }
for( c = 0; c < Result; c++ ) // If the \n is in there, so is the \r so null it, otherwise, null the last char
switch ( line[c] ) if( line[Result-1] == '\n' )
{ line[Result-2] = 0;
case '\b': else {
if (length > 0) line[Result] = 0;
{
debug_printf("\b \b");
memmove( &line[c-1], &line[c], Result - c - 1 );
c-=2;
length--;
Result--;
} }
break;
case '\n':
line[c] = 0;
debug_printf( "\n" );
return;
default:
debug_printf( "%c", line[c] );
length++;
}
line += Result;
} while (1);
} }
void ParseCommandLine (void) void ParseCommandLine (void)
@ -466,15 +440,9 @@ void ParseCommandLine (void)
int main(void) int main(void)
{ {
static char line[255]; static char line[256];
AllocConsole(); AllocConsole();
// clear line buffered mode
if( !SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ), 0 ) )
{
debug_printf( "Error: could not set console mode, error: %d\n", GetLastError() );
return GetLastError();
}
InputHandle = GetStdHandle(STD_INPUT_HANDLE); InputHandle = GetStdHandle(STD_INPUT_HANDLE);
OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE); OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);