void Parse_Args(char *str, char **dest);\r
void Command_Colour(int argc, char **argv);\r
void Command_Clear(int argc, char **argv);\r
-//void Command_Ls(int argc, char **argv);\r
void Command_Cd(int argc, char **argv);\r
-//void Command_Cat(int argc, char **argv);\r
+void Command_Dir(int argc, char **argv);\r
\r
// ==== CONSTANT GLOBALS ====\r
char *cCOLOUR_NAMES[8] = {"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"};\r
char *name;\r
void (*fcn)(int argc, char **argv);\r
} cBUILTINS[] = {\r
- {"colour", Command_Colour}, {"clear", Command_Clear}, {"cd", Command_Cd}\r
+ {"colour", Command_Colour}, {"clear", Command_Clear},\r
+ {"cd", Command_Cd}, {"dir", Command_Dir}\r
};\r
#define BUILTIN_COUNT (sizeof(cBUILTINS)/sizeof(cBUILTINS[0]))\r
\r
continue;\r
}\r
// Check if the file is a directory\r
- finfo( length, &info );
+ finfo( length, &info, 0 );
close( length );\r
if(info.flags & FILEFLAG_DIRECTORY) {\r
Print("`");Print(saArgs[1]); // Error Message\r
Print("' is a directory.\n");\r
continue;\r
}\r
+ // Load new executable\r
pid = clone(CLONE_VM, 0);\r
- if(pid == 0) execve(gsTmpBuffer, &saArgs[1], NULL);\r
+ if(pid == 0) execve(gsTmpBuffer, &saArgs[1], envp);\r
if(pid <= 0) {\r
Print("Unablt to create process: `");Print(gsTmpBuffer);Print("'\n"); // Error Message
//SysDebug("pid = %i\n", pid);\r
}\r
else {\r
- int status\r
- waitpid(pid, &status);\r
+ int status;\r
+ waittid(pid, &status);\r
}\r
}\r
}\r
write(_stdout, 26, "Directory does not exist\n");\r
return;\r
}\r
- finfo(fp, &stats);\r
+ finfo(fp, &stats, 0);\r
close(fp);\r
\r
if( !(stats.flags & FILEFLAG_DIRECTORY) ) {\r
strcpy(gsCurrentDirectory, tmpPath);\r
}\r
\r
+/**\r
+ */\r
+void Command_Dir(int argc, char **argv)\r
+{\r
+ int dp, fp, dirLen;\r
+ //char modeStr[11] = "RWXrwxRWX ";\r
+ char tmpPath[1024];\r
+ char fileName[256];\r
+ t_sysFInfo info;\r
+ \r
+ // Generate Directory Path\r
+ if(argc > 1)\r
+ dirLen = GeneratePath(argv[1], gsCurrentDirectory, tmpPath);\r
+ else\r
+ {\r
+ strcpy(tmpPath, gsCurrentDirectory);\r
+ }\r
+ dirLen = strlen(tmpPath);\r
+ \r
+ // Open Directory\r
+ dp = open(tmpPath, OPENFLAG_READ);\r
+ // Check if file opened\r
+ if(dp == -1)\r
+ {\r
+ //printf("Unable to open directory `%s', File cannot be found\n", tmpPath);\r
+ //write(_stdout, 27, "Unable to open directory `");\r
+ //write(_stdout, strlen(tmpPath)+1, tmpPath);\r
+ //write(_stdout, 25, "', File cannot be found\n");\r
+ return;\r
+ }\r
+ // Get File Stats\r
+ if( finfo(dp, &info, 0) == -1 )\r
+ {\r
+ close(dp);\r
+ write(_stdout, 34, "stat Failed, Bad File Descriptor\n");\r
+ return;\r
+ }\r
+ // Check if it's a directory\r
+ if(!(info.flags & FILEFLAG_DIRECTORY))\r
+ {\r
+ close(dp);\r
+ write(_stdout, 27, "Unable to open directory `");\r
+ write(_stdout, strlen(tmpPath)+1, tmpPath);\r
+ write(_stdout, 20, "', Not a directory\n");\r
+ return;\r
+ }\r
+ \r
+ // Append Shash for file paths\r
+ if(tmpPath[dirLen-1] != '/')\r
+ {\r
+ tmpPath[dirLen++] = '/';\r
+ tmpPath[dirLen] = '\0';\r
+ }\r
+ // Read Directory Content\r
+ while( (fp = readdir(dp, fileName)) )\r
+ {\r
+ if(fp < 0)\r
+ {\r
+ if(fp == -3)\r
+ write(_stdout, 42, "Invalid Permissions to traverse directory\n");\r
+ break;\r
+ }\r
+ // Create File Path\r
+ strcpy((char*)(tmpPath+dirLen), fileName);\r
+ // Open File\r
+ fp = open(tmpPath, 0);\r
+ if(fp == -1) continue;\r
+ // Get File Stats\r
+ finfo(fp, &info, 0);\r
+ close(fp);\r
+ \r
+ // Colour Code\r
+ write(_stdout, 6, "\x1B[37m"); //White\r
+ if(info.flags & FILEFLAG_DIRECTORY) //Directory Green\r
+ write(_stdout, 6, "\x1B[32m");\r
+ \r
+ //Print Mode\r
+ #if 0\r
+ if(stats.st_mode & 0400) modeStr[0] = 'R'; else modeStr[0] = '-';\r
+ if(stats.st_mode & 0200) modeStr[1] = 'W'; else modeStr[1] = '-';\r
+ if(stats.st_mode & 0100) modeStr[2] = 'X'; else modeStr[2] = '-';\r
+ if(stats.st_mode & 0040) modeStr[3] = 'R'; else modeStr[3] = '-';\r
+ if(stats.st_mode & 0020) modeStr[4] = 'W'; else modeStr[4] = '-';\r
+ if(stats.st_mode & 0010) modeStr[5] = 'X'; else modeStr[5] = '-';\r
+ if(stats.st_mode & 0004) modeStr[6] = 'R'; else modeStr[6] = '-';\r
+ if(stats.st_mode & 0002) modeStr[7] = 'W'; else modeStr[7] = '-';\r
+ if(stats.st_mode & 0001) modeStr[8] = 'X'; else modeStr[8] = '-';\r
+ write(_stdout, 10, modeStr);\r
+ #endif\r
+ \r
+ //Print Name\r
+ write(_stdout, strlen(fileName), fileName);\r
+ //Print slash if applicable\r
+ if(info.flags & FILEFLAG_DIRECTORY)\r
+ write(_stdout, 1, "/");\r
+ \r
+ // Revert Colout and end line\r
+ write(_stdout, 6, "\x1B[37m");\r
+ write(_stdout, 2, "\n");\r
+ }\r
+ // Close Directory\r
+ close(dp);\r
+}\r