2022-10-27 00:25:40 -05:00
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <pwd.h>
|
2022-10-19 21:44:28 -05:00
|
|
|
#include <stdlib.h>
|
2022-10-27 00:25:40 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2022-10-19 21:44:28 -05:00
|
|
|
#include "Integrated.h"
|
|
|
|
|
|
|
|
// 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;
|
2022-10-27 00:25:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reads ~/.pishrc and runs each command in the file
|
|
|
|
void ReadPishrc(void)
|
|
|
|
{
|
|
|
|
char* homeDir = (getpwuid(getuid()))->pw_dir;
|
|
|
|
strcat(homeDir, "/.pishrc");
|
|
|
|
int fd = open(homeDir, O_RDONLY | O_CREAT);
|
|
|
|
char commandString[1000] = "";
|
|
|
|
char buffer;
|
|
|
|
assert(fd > -1);
|
|
|
|
while (read(fd, &buffer, 1) > 0)
|
|
|
|
{
|
|
|
|
strcat(commandString, &buffer);
|
|
|
|
if (buffer == '\n')
|
|
|
|
{
|
|
|
|
// TODO: Make each command run
|
|
|
|
printf("%s\n", commandString);
|
|
|
|
memset(commandString, 0, sizeof(commandString));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(close(fd) >= 0);
|
2022-10-19 21:44:28 -05:00
|
|
|
}
|