pish/src/Integrated.c

45 lines
1.1 KiB
C
Raw Normal View History

#include <assert.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#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;
}
// 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);
}