X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2FCLIShell_src%2Fmain.c;h=6de92df42d99804328e83ec3cf86e74025ad2b8c;hb=13078002b01ee4f63eb2001d2ef479a2a006ea32;hp=ca06a0584deaab311dba073398690c34d689353c;hpb=001546477549f71fd1af08e13c60e0a39397532a;p=tpg%2Facess2.git diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index ca06a058..6de92df4 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -8,6 +8,8 @@ #include #include "header.h" #include +#include +#include #define _stdin 0 #define _stdout 1 @@ -31,11 +33,11 @@ struct { {"help", Command_Help}, {"clear", Command_Clear}, {"cd", Command_Cd}, {"dir", Command_Dir} }; -static char *cDEFAULT_PATH[] = {"/Acess/Bin"}; +static char *cDEFAULT_PATH[] = {"/Acess/Bin","/Acess/SBin"}; #define BUILTIN_COUNT (sizeof(cBUILTINS)/sizeof(cBUILTINS[0])) // ==== LOCAL VARIABLES ==== - int giNumPathDirs = 1; + int giNumPathDirs = 2; char **gasPathDirs = cDEFAULT_PATH; char **gasEnvironment; char gsCommandBuffer[1024]; @@ -55,7 +57,7 @@ int main(int argc, char *argv[], char **envp) gasEnvironment = envp; - Command_Clear(0, NULL); +// Command_Clear(0, NULL); { char *tmp = getenv("CWD"); @@ -80,6 +82,10 @@ int main(int argc, char *argv[], char **envp) // Read Command line sCommandStr = Readline( readline_state ); printf("\n"); + if( !sCommandStr ) { + perror("Readline"); + return 1; + } // Parse Command Line into arguments iArgCount = Parse_Args(sCommandStr, saArgs); @@ -208,14 +214,28 @@ void CallCommand(char **Args) // Create new process int fds[] = {0, 1, 2}; + int status; 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 + status = 0; } else { - int status; + _SysIOCtl(0, PTY_IOCTL_SETPGRP, &pid); _SysWaitTID(pid, &status); } + + // Return terminal to a sane state + { + int zero = 0; + _SysIOCtl(0, PTY_IOCTL_SETPGRP, &zero); + printf("\x1b[0m"); + } + // Print a status message if termination was non-clean + if( status ) + { + printf("[%i] exited %i\n", pid, status); + } } /** @@ -300,27 +320,23 @@ void Command_Cd(int argc, char **argv) */ void Command_Dir(int argc, char **argv) { - int dp, fp, dirLen; + int dp, fp; char modeStr[11] = "RWXrwxRWX "; - char tmpPath[1024]; - char *fileName; + char fileName[256]; t_sysFInfo info; t_sysACL acl; + + // -- Generate and open directory -- // Generate Directory Path + char tmpPath[1024]; if(argc > 1) - dirLen = GeneratePath(argv[1], gsCurrentDirectory, tmpPath); + GeneratePath(argv[1], gsCurrentDirectory, tmpPath); else - { strcpy(tmpPath, gsCurrentDirectory); - } - dirLen = strlen(tmpPath); - // Open Directory dp = _SysOpen(tmpPath, OPENFLAG_READ); - // Check if file opened - if(dp == -1) - { + if(dp == -1) { printf("Unable to open directory `%s', File cannot be found\n", tmpPath); return; } @@ -339,15 +355,7 @@ void Command_Dir(int argc, char **argv) return; } - // Append Shash for file paths - if(tmpPath[dirLen-1] != '/') - { - tmpPath[dirLen++] = '/'; - tmpPath[dirLen] = '\0'; - } - - fileName = (char*)(tmpPath+dirLen); - // Read Directory Content + // -- Read Directory Contents -- while( (fp = _SysReadDir(dp, fileName)) ) { if(fp < 0) @@ -357,7 +365,7 @@ void Command_Dir(int argc, char **argv) break; } // Open File - fp = _SysOpen(tmpPath, 0); + fp = _SysOpenChild(dp, fileName, 0); if(fp == -1) continue; // Get File Stats _SysFInfo(fp, &info, 0);