X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Usermode%2FApplications%2FCLIShell_src%2Fmain.c;h=1a501ad17c453dea52cba74bdaeaed8326d247d9;hb=733b37c90c20a76ec81c04431e8bc5224f053e28;hp=28007e12027ff90b9b9a5564a3d1c81c728188cb;hpb=04a050f42807686dc119838c82372409246d55bb;p=tpg%2Facess2.git diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 28007e12..1a501ad1 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -8,6 +8,7 @@ #include #include "header.h" #include +#include #define _stdin 0 #define _stdout 1 @@ -75,10 +76,15 @@ 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"); + if( !sCommandStr ) { + perror("Readline"); + return 1; + } // Parse Command Line into arguments iArgCount = Parse_Args(sCommandStr, saArgs); @@ -299,27 +305,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; } @@ -338,15 +340,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) @@ -356,7 +350,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);