From 858717085394bcbe543685556d90017bd405baab Mon Sep 17 00:00:00 2001 From: Rex Jolliff Date: Tue, 8 Dec 1998 04:31:41 +0000 Subject: [PATCH] didnt want to delete these svn path=/trunk/; revision=114 --- reactos/apps/utils/cmd/cmd.c | 158 ++++++++++++++++++++++++++++++++ reactos/apps/utils/cmd/makefile | 12 +++ rosapps/cmd/cmd.c | 158 ++++++++++++++++++++++++++++++++ rosapps/cmd/makefile | 12 +++ 4 files changed, 340 insertions(+) create mode 100644 reactos/apps/utils/cmd/cmd.c create mode 100644 reactos/apps/utils/cmd/makefile create mode 100644 rosapps/cmd/cmd.c create mode 100644 rosapps/cmd/makefile diff --git a/reactos/apps/utils/cmd/cmd.c b/reactos/apps/utils/cmd/cmd.c new file mode 100644 index 00000000000..22211f73308 --- /dev/null +++ b/reactos/apps/utils/cmd/cmd.c @@ -0,0 +1,158 @@ +#include +#include + +HANDLE stdin; +HANDLE stdout; + + +void Console_puts(char* str) +{ + ULONG nchar; + + WriteConsole(stdout, + str, + strlen(str), + &nchar, + NULL); +} + +void Console_printf(char* fmt, ...) +{ + char buffer[255]; + va_list vargs; + + va_start(vargs,fmt); + vsprintf(buffer,fmt,vargs); + Console_puts(buffer); + va_end(vargs); +} + +void Console_getline(PCH Prompt, PCH Output, DWORD OutputLength) +{ + char ch; + DWORD nbytes; + + Console_puts(Prompt); + + ReadConsole(stdin, + Output, + OutputLength, + &nbytes, + NULL); + Output[nbytes-2]=0; +} + +void func_cd(char* s) +{ + Console_printf("Changing directory to %s\n",s); + if (!SetCurrentDirectory(s)) + { + Console_puts("Failed to change to directory\n"); + } +} + +void func_dir(char* s) +{ + HANDLE shandle; + WIN32_FIND_DATA FindData; + + shandle = FindFirstFile("*.*",&FindData); + + if (shandle==INVALID_HANDLE_VALUE) + { + return; + } + do + { + Console_printf("Scanning %s\n",FindData.cFileName); + } while(FindNextFile(shandle,&FindData)); +} + +int is_builtin(char* name, char* args) +{ + if (strcmp(name,"dir")==0) + { + func_dir(args); + return(1); + } + if (strcmp(name,"cd")==0) + { + func_cd(args); + return(1); + } + return(0); +} + +int process_command(char* str) +{ + char* name; + char* args; + PROCESS_INFORMATION pi; + STARTUPINFO si; + char process_arg[255]; + + if (strcmp(str,"exit")==0) + { + return(1); + } + + name = strtok(str," \t"); + args = strtok(NULL,""); + + if (is_builtin(name,args)) + { + return(0); + } + memset(&si,0,sizeof(STARTUPINFO)); + si.cb=sizeof(STARTUPINFO); + si.lpTitle=strdup(name); + + strcpy(process_arg,name); + strcat(process_arg," "); + if(args!=NULL) + { + strcat(process_arg,args); + } + Console_printf("name '%s' process_arg '%s'\n",name,process_arg); + if (!CreateProcess(NULL,process_arg,NULL,NULL,FALSE, + CREATE_NEW_CONSOLE, + NULL,NULL,&si,&pi)) + { + Console_printf("Failed to execute process\n"); + } + return(0); +} + +void build_prompt(char* prompt) +{ + int len; + + len = GetCurrentDirectory(255,prompt); + strcat(prompt,">"); +} + +void command_loop() +{ + char line[255]; + char prompt[255]; + int do_exit = 0; + + while (!do_exit) + { + build_prompt(prompt); + Console_getline(prompt,line,255); + Console_printf("Processing command '%s'\n",line); + do_exit = process_command(line); + } +} + +int STDCALL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) +{ + AllocConsole(); + stdin = GetStdHandle(STD_INPUT_HANDLE); + stdout = GetStdHandle(STD_OUTPUT_HANDLE); + + command_loop(); + + return 0; +} diff --git a/reactos/apps/utils/cmd/makefile b/reactos/apps/utils/cmd/makefile new file mode 100644 index 00000000000..7e36f733496 --- /dev/null +++ b/reactos/apps/utils/cmd/makefile @@ -0,0 +1,12 @@ +all: cmd.bin + +OBJECTS = ../common/crt0.o cmd.o + +LIBS = ../../lib/mingw32/mingw32.a ../../lib/crtdll/crtdll.a \ + ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a + +cmd.bin: $(OBJECTS) + $(LD) -Ttext 0x10000 $(OBJECTS) $(LIBS) -o cmd.exe + $(OBJCOPY) -O binary cmd.exe cmd.bin + +include ../../rules.mak diff --git a/rosapps/cmd/cmd.c b/rosapps/cmd/cmd.c new file mode 100644 index 00000000000..22211f73308 --- /dev/null +++ b/rosapps/cmd/cmd.c @@ -0,0 +1,158 @@ +#include +#include + +HANDLE stdin; +HANDLE stdout; + + +void Console_puts(char* str) +{ + ULONG nchar; + + WriteConsole(stdout, + str, + strlen(str), + &nchar, + NULL); +} + +void Console_printf(char* fmt, ...) +{ + char buffer[255]; + va_list vargs; + + va_start(vargs,fmt); + vsprintf(buffer,fmt,vargs); + Console_puts(buffer); + va_end(vargs); +} + +void Console_getline(PCH Prompt, PCH Output, DWORD OutputLength) +{ + char ch; + DWORD nbytes; + + Console_puts(Prompt); + + ReadConsole(stdin, + Output, + OutputLength, + &nbytes, + NULL); + Output[nbytes-2]=0; +} + +void func_cd(char* s) +{ + Console_printf("Changing directory to %s\n",s); + if (!SetCurrentDirectory(s)) + { + Console_puts("Failed to change to directory\n"); + } +} + +void func_dir(char* s) +{ + HANDLE shandle; + WIN32_FIND_DATA FindData; + + shandle = FindFirstFile("*.*",&FindData); + + if (shandle==INVALID_HANDLE_VALUE) + { + return; + } + do + { + Console_printf("Scanning %s\n",FindData.cFileName); + } while(FindNextFile(shandle,&FindData)); +} + +int is_builtin(char* name, char* args) +{ + if (strcmp(name,"dir")==0) + { + func_dir(args); + return(1); + } + if (strcmp(name,"cd")==0) + { + func_cd(args); + return(1); + } + return(0); +} + +int process_command(char* str) +{ + char* name; + char* args; + PROCESS_INFORMATION pi; + STARTUPINFO si; + char process_arg[255]; + + if (strcmp(str,"exit")==0) + { + return(1); + } + + name = strtok(str," \t"); + args = strtok(NULL,""); + + if (is_builtin(name,args)) + { + return(0); + } + memset(&si,0,sizeof(STARTUPINFO)); + si.cb=sizeof(STARTUPINFO); + si.lpTitle=strdup(name); + + strcpy(process_arg,name); + strcat(process_arg," "); + if(args!=NULL) + { + strcat(process_arg,args); + } + Console_printf("name '%s' process_arg '%s'\n",name,process_arg); + if (!CreateProcess(NULL,process_arg,NULL,NULL,FALSE, + CREATE_NEW_CONSOLE, + NULL,NULL,&si,&pi)) + { + Console_printf("Failed to execute process\n"); + } + return(0); +} + +void build_prompt(char* prompt) +{ + int len; + + len = GetCurrentDirectory(255,prompt); + strcat(prompt,">"); +} + +void command_loop() +{ + char line[255]; + char prompt[255]; + int do_exit = 0; + + while (!do_exit) + { + build_prompt(prompt); + Console_getline(prompt,line,255); + Console_printf("Processing command '%s'\n",line); + do_exit = process_command(line); + } +} + +int STDCALL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) +{ + AllocConsole(); + stdin = GetStdHandle(STD_INPUT_HANDLE); + stdout = GetStdHandle(STD_OUTPUT_HANDLE); + + command_loop(); + + return 0; +} diff --git a/rosapps/cmd/makefile b/rosapps/cmd/makefile new file mode 100644 index 00000000000..7e36f733496 --- /dev/null +++ b/rosapps/cmd/makefile @@ -0,0 +1,12 @@ +all: cmd.bin + +OBJECTS = ../common/crt0.o cmd.o + +LIBS = ../../lib/mingw32/mingw32.a ../../lib/crtdll/crtdll.a \ + ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a + +cmd.bin: $(OBJECTS) + $(LD) -Ttext 0x10000 $(OBJECTS) $(LIBS) -o cmd.exe + $(OBJCOPY) -O binary cmd.exe cmd.bin + +include ../../rules.mak