Final cleanup before submitting
This commit is contained in:
parent
8e61e04e05
commit
01625790bd
@ -60,15 +60,12 @@ void ParseInput(char *inputString, CommandStruct *command, char *symbol)
|
||||
// Splits a string separated by spaces into an array of strings
|
||||
void SplitInput(char *inputString, CommandStruct *command)
|
||||
{
|
||||
// Parse command
|
||||
int *argc = &(command->argc);
|
||||
char *token = strtok(inputString, " ");
|
||||
command->argv[*argc] = token;
|
||||
(*argc)++;
|
||||
while (token != NULL)
|
||||
{
|
||||
// This only holds 1 command at a time then it overrides
|
||||
// Will need modified
|
||||
token = strtok(NULL, " ");
|
||||
command->argv[*argc] = token;
|
||||
(*argc)++;
|
||||
@ -88,17 +85,14 @@ int CheckSymbol(CommandStruct* command, char symbol, int start)
|
||||
}
|
||||
|
||||
// Checking redirection
|
||||
// TODO: Work on one symbol at a time
|
||||
// inputString may not be useful here, only *command
|
||||
// Try to add a layer of abstraction where possible
|
||||
// I.E. think about using function instead for checking
|
||||
void CheckRedirection(CommandStruct* command)
|
||||
{
|
||||
// check command standard output
|
||||
// TODO: Check command->argv[] for symbol instead
|
||||
for (int i = 0; i < command->argc; i++)
|
||||
{
|
||||
if ((command->argv[i][0] == '>') && (command->argv[i][1] == '>')) printf(">> was found.\n");
|
||||
if ((command->argv[i][0] == '>') && (command->argv[i][1] == '>'))
|
||||
printf(">> was found.\n");
|
||||
// ParseInput(inputString, command, ">>");
|
||||
if (command->argv[i][0] == '<')
|
||||
printf("< was found.\n");
|
||||
@ -115,6 +109,7 @@ void CheckRedirection(CommandStruct* command)
|
||||
return;
|
||||
}
|
||||
|
||||
// Count number of appearances of a symbol in a CommandStruct
|
||||
int CountSymbol(CommandStruct* command, char symbol)
|
||||
{
|
||||
int count = 0;
|
||||
@ -182,19 +177,12 @@ int ExecPipe(CommandStruct* commandParent, CommandStruct* commandChild, int* pip
|
||||
pipe(pipefd);
|
||||
for (int i = 0; i < pipeAmount; i++)
|
||||
{
|
||||
|
||||
// if (pipeLocation > 0)
|
||||
// startArgc = pipeLocation + 1;
|
||||
pipeLocation = CheckSymbol(commandParent, '|', startArgc);
|
||||
// if (pipeLocation >= 0)
|
||||
endArgc = pipeLocation;
|
||||
// if (pipeLocation < 0)
|
||||
// endArgc = commandParent->argc;
|
||||
CopyCommandStruct(commandParent, commandChild, startArgc, endArgc);
|
||||
forkPID = fork();
|
||||
if (forkPID == 0)
|
||||
return forkPID;
|
||||
// if (forkPID != 0)
|
||||
close(pipefd[0]);
|
||||
close(pipefd[1]);
|
||||
wait(&forkPID);
|
||||
|
11
src/Pish.c
11
src/Pish.c
@ -10,15 +10,6 @@
|
||||
#include "Integrated.h"
|
||||
#include "Pish.h"
|
||||
|
||||
// Example command: ps aux | grep 'Z'
|
||||
// Pipe left: [ps aux]
|
||||
// argv: [ps, aux]
|
||||
// Pipe right: [grep 'Z']
|
||||
// argv: [grep, 'Z']
|
||||
|
||||
// check for first pipe, split into before and after pipe,
|
||||
// connect left and right execs
|
||||
|
||||
// Main function for Pish program
|
||||
void Pish(void)
|
||||
{
|
||||
@ -93,7 +84,7 @@ void RunChild(CommandStruct* commandChild, int* pipefd)
|
||||
close(pipefd[1]);
|
||||
// execve() is recommended, execvpe() may be better
|
||||
CheckRedirection(commandChild);
|
||||
ioRedirection(commandChild);
|
||||
// ioRedirection(commandChild);
|
||||
execvp(commandChild->argv[0], commandChild->argv);
|
||||
// exec does not return if it succeeds
|
||||
printf("ERROR: Could not execute %s\n", commandChild->argv[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user