Skip to content
Snippets Groups Projects
Commit 88b5d051 authored by 9659tig's avatar 9659tig
Browse files

Final

parent cdd8c3a8
No related branches found
No related tags found
No related merge requests found
......@@ -46,24 +46,8 @@ typedef struct {
* Return 0 when user inputs "exit"
* Return <0 on error
*/
static int run_command(int nr_tokens, char *tokens[])
{
int status;
int flag =0, pipe_index;
pid_t child;
static void run_pipe(int pipe_index, char *tokens[]){
char *pipe1[TOKEN_LENGTH], *pipe2[TOKEN_LENGTH];
if (strcmp(tokens[0], "exit") == 0) return 0;
for (int i=0; tokens[i]!=NULL; i++)
{
if(!strcmp(tokens[i],"|")){
tokens[i] = NULL;
pipe_index = i;
flag = 1;
}
}
if (flag){
for (int i=0; i<=pipe_index; i++)
pipe1[i] = tokens[i];
......@@ -96,7 +80,7 @@ static int run_command(int nr_tokens, char *tokens[])
wait(0);
}
else if(!strcmp("cd",tokens[0]) || !strcmp("history",tokens[0]) || !strcmp("!",tokens[0])){
static void cd_history(int nr_tokens, char *tokens[]){
while(nr_tokens--){
if(!strcmp("cd",tokens[0])){
if (!tokens[1] || !strcmp("~",tokens[1])) {
......@@ -127,6 +111,29 @@ static int run_command(int nr_tokens, char *tokens[])
break;
}
}
static int run_command(int nr_tokens, char *tokens[])
{
int status;
int flag =0, pipe_index;
pid_t child;
if (strcmp(tokens[0], "exit") == 0) return 0;
for (int i=0; tokens[i]!=NULL; i++)
{
if(!strcmp(tokens[i],"|")){
tokens[i] = NULL;
pipe_index = i;
flag = 1;
}
}
if (flag)
run_pipe(pipe_index,tokens);
else if(!strcmp("cd",tokens[0]) || !strcmp("history",tokens[0]) || !strcmp("!",tokens[0]))
cd_history(nr_tokens,tokens);
else{
child = fork();
while (nr_tokens--)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment