X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2FCLIShell_src%2Fmain.c;h=aa1d9abec48744cd0f5182998adb526848ee1439;hb=f6b468cee21ebf1c9b98efec5315950aa043ead5;hp=8786262252c902e16517f9035986c0dc6285b3bc;hpb=ac1f47d1946550a734222165148bebd1cb7ff205;p=tpg%2Facess2.git diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 87862622..aa1d9abe 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -31,7 +31,7 @@ struct { // ==== LOCAL VARIABLES ==== char gsCommandBuffer[1024]; -char *gsCurrentDirectory = "/"; +char *gsCurrentDirectory = NULL; char gsTmpBuffer[1024]; char **gasCommandHistory; int giLastCommand = 0; @@ -50,8 +50,19 @@ int main(int argc, char *argv[], char *envp[]) //Command_Clear(0, NULL); + { + char *tmp = getenv("CWD"); + if(tmp) { + gsCurrentDirectory = malloc(strlen(tmp)+1); + strcpy(gsCurrentDirectory, tmp); + } else { + gsCurrentDirectory = malloc(2); + strcpy(gsCurrentDirectory, "/"); + } + } + write(_stdout, 1, "\n"); - write(_stdout, 36, "Acess Shell Version 3\n"); + write(_stdout, 22, "Acess Shell Version 3\n"); write(_stdout, 2, "\n"); for(;;) { @@ -59,6 +70,7 @@ int main(int argc, char *argv[], char *envp[]) if(saArgs[0]) free(saArgs); if(!bCached) free(sCommandStr); bCached = 0; + write(_stdout, 1, "\n"); write(_stdout, strlen(gsCurrentDirectory), gsCurrentDirectory); write(_stdout, 3, "$ "); @@ -324,6 +336,8 @@ void Command_Cd(int argc, char **argv) return; } + free(gsCurrentDirectory); + gsCurrentDirectory = malloc(strlen(tmpPath)+1); strcpy(gsCurrentDirectory, tmpPath); } @@ -332,7 +346,7 @@ void Command_Cd(int argc, char **argv) void Command_Dir(int argc, char **argv) { int dp, fp, dirLen; - //char modeStr[11] = "RWXrwxRWX "; + char modeStr[11] = "RWXrwxRWX "; char tmpPath[1024]; char *fileName; t_sysFInfo info; @@ -397,10 +411,13 @@ void Command_Dir(int argc, char **argv) if(fp == -1) continue; // Get File Stats finfo(fp, &info, 0); - close(fp); - //Print Mode - //#if 0 + if(info.flags & FILEFLAG_DIRECTORY) + write(_stdout, 1, "d"); + else + write(_stdout, 1, "-"); + + // Print Mode acl.group = 0; acl.id = info.uid; _SysGetACL(fp, &acl); if(acl.perms & 1) modeStr[0] = 'r'; else modeStr[0] = '-'; @@ -417,15 +434,16 @@ void Command_Dir(int argc, char **argv) if(acl.perms & 1) modeStr[7] = 'w'; else modeStr[7] = '-'; if(acl.perms & 1) modeStr[8] = 'x'; else modeStr[8] = '-'; write(_stdout, 10, modeStr); - //#endif + close(fp); // Colour Code if(info.flags & FILEFLAG_DIRECTORY) // Directory: Green write(_stdout, 6, "\x1B[32m"); - else - write(_stdout, 6, "\x1B[37m"); // Default: White + // Default: White + // Print Name write(_stdout, strlen(fileName), fileName); + // Print slash if applicable if(info.flags & FILEFLAG_DIRECTORY) write(_stdout, 1, "/"); @@ -433,10 +451,8 @@ void Command_Dir(int argc, char **argv) // Revert Colour write(_stdout, 6, "\x1B[37m"); - // Put Size - printf("\n", info.size); - - //write(_stdout, 1, "\n"); + // Newline! + write(_stdout, 1, "\n"); } // Close Directory close(dp);