X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Usermode%2FApplications%2FCLIShell_src%2Fmain.c;h=ca06a0584deaab311dba073398690c34d689353c;hb=7a70e3527bc012c065959382187c2361624e1911;hp=7f4ba01ccfe5d91e1ba2ff7d06517cc60838eac2;hpb=f8168f419a5b83f6875fc0a3044ce8a8b1572b65;p=tpg%2Facess2.git diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 7f4ba01c..ca06a058 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -49,7 +49,6 @@ int main(int argc, char *argv[], char **envp) { char *sCommandStr; char *saArgs[32] = {0}; - int length = 0; int i; int iArgCount = 0; tReadline *readline_state = Readline_Init(1); @@ -76,11 +75,11 @@ int main(int argc, char *argv[], char **envp) if(saArgs[0]) free(saArgs[0]); printf("%s$ ", gsCurrentDirectory); + fflush(stdout); // Read Command line sCommandStr = Readline( readline_state ); printf("\n"); - length = strlen(sCommandStr); // Parse Command Line into arguments iArgCount = Parse_Args(sCommandStr, saArgs); @@ -167,15 +166,15 @@ void CallCommand(char **Args) { GeneratePath(exefile, gsCurrentDirectory, sTmpBuffer); // Check file existence - fd = open(sTmpBuffer, OPENFLAG_EXEC); + fd = _SysOpen(sTmpBuffer, OPENFLAG_EXEC); if(fd == -1) { printf("Unknown Command: `%s'\n", Args[0]); // Error Message return ; } // Get File info and close file - finfo( fd, &info, 0 ); - close( fd ); + _SysFInfo( fd, &info, 0 ); + _SysClose( fd ); // Check if the file is a directory if(info.flags & FILEFLAG_DIRECTORY) { @@ -191,10 +190,10 @@ void CallCommand(char **Args) for( i = 0; i < giNumPathDirs; i++ ) { GeneratePath(exefile, gasPathDirs[i], sTmpBuffer); - fd = open(sTmpBuffer, OPENFLAG_EXEC); + fd = _SysOpen(sTmpBuffer, OPENFLAG_EXEC); if(fd == -1) continue; - finfo( fd, &info, 0 ); - close( fd ); + _SysFInfo( fd, &info, 0 ); + _SysClose( fd ); if(info.flags & FILEFLAG_DIRECTORY) continue; // Woohoo! We found a valid command break; @@ -208,19 +207,14 @@ void CallCommand(char **Args) } // Create new process - pid = clone(CLONE_VM, 0); - // Start Task - if(pid == 0) { - execve(sTmpBuffer, Args, gasEnvironment); - printf("Execve returned, ... oops\n"); - exit(-1); - } + int fds[] = {0, 1, 2}; + pid = _SysSpawn(sTmpBuffer, (const char **)Args, (const char **)gasEnvironment, 3, fds, NULL); if(pid <= 0) { printf("Unable to create process: `%s'\n", sTmpBuffer); // Error Message } else { int status; - waittid(pid, &status); + _SysWaitTID(pid, &status); } } @@ -258,7 +252,7 @@ void Command_Help(int argc, char **argv) */ void Command_Clear(int argc, char **argv) { - write(_stdout, "\x1B[2J", 4); //Clear Screen + _SysWrite(_stdout, "\x1B[2J", 4); //Clear Screen } /** @@ -279,13 +273,13 @@ void Command_Cd(int argc, char **argv) GeneratePath(argv[1], gsCurrentDirectory, tmpPath); - fp = open(tmpPath, 0); + fp = _SysOpen(tmpPath, 0); if(fp == -1) { printf("Directory does not exist\n"); return; } - finfo(fp, &stats, 0); - close(fp); + _SysFInfo(fp, &stats, 0); + _SysClose(fp); if( !(stats.flags & FILEFLAG_DIRECTORY) ) { printf("Not a Directory\n"); @@ -297,7 +291,7 @@ void Command_Cd(int argc, char **argv) strcpy(gsCurrentDirectory, tmpPath); // Register change with kernel - chdir( gsCurrentDirectory ); + _SysChdir( gsCurrentDirectory ); } /** @@ -323,7 +317,7 @@ void Command_Dir(int argc, char **argv) dirLen = strlen(tmpPath); // Open Directory - dp = open(tmpPath, OPENFLAG_READ); + dp = _SysOpen(tmpPath, OPENFLAG_READ); // Check if file opened if(dp == -1) { @@ -331,16 +325,16 @@ void Command_Dir(int argc, char **argv) return; } // Get File Stats - if( finfo(dp, &info, 0) == -1 ) + if( _SysFInfo(dp, &info, 0) == -1 ) { - close(dp); + _SysClose(dp); printf("stat Failed, Bad File Descriptor\n"); return; } // Check if it's a directory if(!(info.flags & FILEFLAG_DIRECTORY)) { - close(dp); + _SysClose(dp); printf("Unable to open directory `%s', Not a directory\n", tmpPath); return; } @@ -354,7 +348,7 @@ void Command_Dir(int argc, char **argv) fileName = (char*)(tmpPath+dirLen); // Read Directory Content - while( (fp = readdir(dp, fileName)) ) + while( (fp = _SysReadDir(dp, fileName)) ) { if(fp < 0) { @@ -363,10 +357,10 @@ void Command_Dir(int argc, char **argv) break; } // Open File - fp = open(tmpPath, 0); + fp = _SysOpen(tmpPath, 0); if(fp == -1) continue; // Get File Stats - finfo(fp, &info, 0); + _SysFInfo(fp, &info, 0); if(info.flags & FILEFLAG_DIRECTORY) printf("d"); @@ -393,7 +387,7 @@ void Command_Dir(int argc, char **argv) if(acl.perms & 2) modeStr[7] = 'w'; else modeStr[7] = '-'; if(acl.perms & 8) modeStr[8] = 'x'; else modeStr[8] = '-'; printf(modeStr); - close(fp); + _SysClose(fp); // Colour Code if(info.flags & FILEFLAG_DIRECTORY) // Directory: Green @@ -414,5 +408,5 @@ void Command_Dir(int argc, char **argv) printf("\n"); } // Close Directory - close(dp); + _SysClose(dp); }