Adjusted GetHomeDir() and fixed cd command
This commit is contained in:
parent
94f2c4fcb8
commit
e0905dbaf2
@ -5,7 +5,7 @@
|
||||
|
||||
const char* GetHomeDir(void);
|
||||
void ioRedirection(CommandStruct *command);
|
||||
void IntegratedCheck(CommandStruct* command);
|
||||
int IntegratedCheck(CommandStruct* command);
|
||||
void GetInput(char* inputString);
|
||||
void append(char *input, char *file);
|
||||
void input(char *command);
|
||||
|
@ -5,7 +5,7 @@
|
||||
void ResetCommandStruct(CommandStruct* command)
|
||||
{
|
||||
for (int i = 0; i < command->argc; i++)
|
||||
command->argv[i] = "";
|
||||
command->argv[i] = NULL;
|
||||
command->argc = 0;
|
||||
return;
|
||||
}
|
||||
|
@ -14,20 +14,25 @@
|
||||
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(CommandStruct *command)
|
||||
int IntegratedCheck(CommandStruct *command)
|
||||
{
|
||||
if (strcmp(command->argv[0], "exit") == 0)
|
||||
exit(0);
|
||||
// If there is an argument, change to argument location
|
||||
// Else, change to home directory
|
||||
if (command->argv[0][0] == 'c' && command->argv[0][1] == 'd')
|
||||
;
|
||||
return;
|
||||
{
|
||||
if (command->argv[1] != NULL)
|
||||
chdir(command->argv[1]);
|
||||
if (command->argv[1] == NULL)
|
||||
chdir(GetHomeDir());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Prints a prompt and then reads a command from the terminal
|
||||
@ -67,7 +72,9 @@ void ReadPishrc(CommandStruct *command, char *inputString)
|
||||
char buffer[1];
|
||||
int forkID;
|
||||
int *argc = &(command->argc);
|
||||
int fd = open(GetHomeDir(), O_RDONLY | O_CREAT);
|
||||
char* pishLocation = GetHomeDir();
|
||||
strcat(pishLocation, "/.pishrc");
|
||||
int fd = open(pishLocation, O_RDONLY | O_CREAT);
|
||||
assert(fd > -1);
|
||||
while (read(fd, buffer, 1) > 0)
|
||||
{
|
||||
|
@ -21,7 +21,8 @@ void Pish(void)
|
||||
strcpy(inputString, ""); // Clean inputString
|
||||
GetInput(inputString);
|
||||
ParseInput(inputString, command);
|
||||
IntegratedCheck(command);
|
||||
if (IntegratedCheck(command))
|
||||
continue;
|
||||
forkPID = fork();
|
||||
// Child
|
||||
if (forkPID == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user