#include #include #include #include #include #include #include #include #include #include #include "Integrated.h" // Gets home directory location of user const char* GetHomeDir(void) { char* homeDir = (getpwuid(getuid()))->pw_dir; strcat(homeDir, "/.pishrc"); return homeDir; } // Checks for commands that are built into Pish void IntegratedCheck(char* command) { if (command == "exit") exit(0); // If there is an argument, change to argument location // Else, change to home directory if (command[0] == 'c' && command[1] == 'd') ; return; } // Reads ~/.pishrc and runs each command in the file void ReadPishrc(CommandStruct* command, char* inputString) { char buffer; int forkID; int* argc = &(command->argc); int fd = open(GetHomeDir(), O_RDONLY | O_CREAT); assert(fd > -1); while (read(fd, &buffer, 1) > 0) { printf("%c", buffer); if (buffer == ' ') { command->argv[*argc] = inputString; strcpy(inputString, ""); *argc++; } if (buffer == '\n') { command->argv[*argc] = inputString; strcpy(inputString, ""); forkID = fork(); if (forkID == 0) execvp(command->argv[0], command->argv); wait(&forkID); ResetCommandStruct(command); } strcat(inputString, &buffer); } assert(close(fd) >= 0); }