X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2FCLIShell_src%2Fmain.c;h=89bfe0d1af7428b0118c369f32857bd37d5f8d2a;hb=4d45d15216040b78b91af7469a796797b6b03c4f;hp=1f381e26120fab2fb7f8e046d5af9fa4d9e2f91c;hpb=243bdab4e7acc8516d9b1c138f45dc1195f97767;p=tpg%2Facess2.git diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 1f381e26..89bfe0d1 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -1,12 +1,17 @@ /* * AcessOS Shell Version 3 */ +#define USE_READLINE 1 #include #include #include #include #include "header.h" +#if USE_READLINE +# include "readline.h" +#endif + #define _stdin 0 #define _stdout 1 #define _stderr 2 @@ -44,14 +49,18 @@ char **gasCommandHistory; int giCommandSpace = 0; // ==== CODE ==== -int main(int argc, char *argv[], char *envp[]) +int main(int argc, char *argv[], char **envp) { char *sCommandStr; char *saArgs[32] = {0}; int length = 0; int i; int iArgCount = 0; + #if !USE_READLINE int bCached = 1; + #else + tReadline *readline_state = Readline_Init(1); + #endif gasEnvironment = envp; @@ -68,23 +77,28 @@ int main(int argc, char *argv[], char *envp[]) } } - write(_stdout, 22, "Acess Shell Version 3\n"); - write(_stdout, 2, "\n"); + printf("Acess Shell Version 3\n\n"); for(;;) { // Free last command & arguments if(saArgs[0]) free(saArgs); + #if !USE_READLINE if(!bCached) free(sCommandStr); bCached = 0; + #endif - write(_stdout, strlen(gsCurrentDirectory), gsCurrentDirectory); - write(_stdout, 2, "$ "); + printf("%s$ ", gsCurrentDirectory); // Read Command line + #if USE_READLINE + sCommandStr = Readline( readline_state ); + printf("\n"); + length = strlen(sCommandStr); + #else sCommandStr = ReadCommandLine( &length ); if(!sCommandStr) { - write(_stdout, 25, "PANIC: Out of heap space\n"); + printf("PANIC: Out of heap space\n"); return -1; } @@ -99,6 +113,7 @@ int main(int argc, char *argv[], char *envp[]) gasCommandHistory[ giLastCommand ] = sCommandStr; bCached = 1; } + #endif // Parse Command Line into arguments Parse_Args(sCommandStr, saArgs); @@ -123,9 +138,14 @@ int main(int argc, char *argv[], char *envp[]) // Shall we? CallCommand( &saArgs[1] ); + + #if USE_READLINE + free( sCommandStr ); + #endif } } +#if !USE_READLINE /** * \fn char *ReadCommandLine(int *Length) * \brief Read from the command line @@ -146,21 +166,20 @@ char *ReadCommandLine(int *Length) // Read In Command Line do { - read(_stdin, 1, &ch); // Read Character from stdin (read is a blocking call) - + ch = getchar(); // Read Character from stdin (read is a blocking call) if(ch == '\n') break; switch(ch) { // Control characters case '\x1B': - read(_stdin, 1, &ch); // Read control character + ch = getchar(); // Read control character switch(ch) { //case 'D': if(pos) pos--; break; //case 'C': if(pos