|
|
@ -23,43 +23,6 @@ void print_history(char *argv) |
|
|
|
puts(storage[i]); |
|
|
|
} |
|
|
|
|
|
|
|
int Is_pipe(char **argv) |
|
|
|
{ |
|
|
|
int i = 0; |
|
|
|
int Ispipe = 0; |
|
|
|
char *cmd_0[MAXLINE]; |
|
|
|
char *cmd_1[MAXLINE]; |
|
|
|
while (argv[i]!=NULL) |
|
|
|
{ |
|
|
|
if (argv[i][0] == '|') |
|
|
|
{ |
|
|
|
Ispipe = 1; |
|
|
|
} |
|
|
|
i++; |
|
|
|
} |
|
|
|
if(Ispipe == 0) |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
i = 0; |
|
|
|
while (argv[i][0] != '|') |
|
|
|
{ |
|
|
|
cmd_0[i] = argv[i]; |
|
|
|
i++; |
|
|
|
} |
|
|
|
cmd_0[i] = NULL; |
|
|
|
i++; |
|
|
|
int j = 0; |
|
|
|
while (argv[i]!=NULL) |
|
|
|
{ |
|
|
|
cmd_1[j] = argv[i]; |
|
|
|
i++; |
|
|
|
j++; |
|
|
|
} |
|
|
|
cmd_1[j] = NULL; |
|
|
|
shell_pip(cmd_0, cmd_1); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
void shell_pip(char **prog1, char **prog2) |
|
|
|
{ |
|
|
@ -93,29 +56,28 @@ void shell_pip(char **prog1, char **prog2) |
|
|
|
close(des_p[1]); |
|
|
|
wait(0); |
|
|
|
wait(0); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int Is_redirect(char **argv) |
|
|
|
int Is_pipe(char **argv) |
|
|
|
{ |
|
|
|
int i = 0; |
|
|
|
int Isopen = 0; |
|
|
|
int Ispipe = 0; |
|
|
|
char *cmd_0[MAXLINE]; |
|
|
|
char *cmd_1[MAXLINE]; |
|
|
|
while (argv[i]!=NULL) |
|
|
|
{ |
|
|
|
if (argv[i][0] == '>') |
|
|
|
if (argv[i][0] == '|') |
|
|
|
{ |
|
|
|
Isopen = 1; |
|
|
|
Ispipe = 1; |
|
|
|
} |
|
|
|
i++; |
|
|
|
} |
|
|
|
if(Isopen == 0) |
|
|
|
if(Ispipe == 0) |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
i = 0; |
|
|
|
while (argv[i][0] != '>') |
|
|
|
while (argv[i][0] != '|') |
|
|
|
{ |
|
|
|
cmd_0[i] = argv[i]; |
|
|
|
i++; |
|
|
@ -129,12 +91,12 @@ int Is_redirect(char **argv) |
|
|
|
i++; |
|
|
|
j++; |
|
|
|
} |
|
|
|
cmd_1[j] = NULL; |
|
|
|
|
|
|
|
shell_direct(cmd_0, cmd_1); |
|
|
|
cmd_1[j] = NULL; |
|
|
|
shell_pip(cmd_0, cmd_1); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void shell_direct(char **prog1, char **prog2) |
|
|
|
{ |
|
|
|
int fd; |
|
|
@ -169,6 +131,45 @@ void shell_direct(char **prog1, char **prog2) |
|
|
|
wait(0); |
|
|
|
} |
|
|
|
|
|
|
|
int Is_redirect(char **argv) |
|
|
|
{ |
|
|
|
int i = 0; |
|
|
|
int Isopen = 0; |
|
|
|
char *cmd_0[MAXLINE]; |
|
|
|
char *cmd_1[MAXLINE]; |
|
|
|
while (argv[i]!=NULL) |
|
|
|
{ |
|
|
|
if (argv[i][0] == '>') |
|
|
|
{ |
|
|
|
Isopen = 1; |
|
|
|
} |
|
|
|
i++; |
|
|
|
} |
|
|
|
if(Isopen == 0) |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
i = 0; |
|
|
|
while (argv[i][0] != '>') |
|
|
|
{ |
|
|
|
cmd_0[i] = argv[i]; |
|
|
|
i++; |
|
|
|
} |
|
|
|
cmd_0[i] = NULL; |
|
|
|
i++; |
|
|
|
int j = 0; |
|
|
|
while (argv[i]!=NULL) |
|
|
|
{ |
|
|
|
cmd_1[j] = argv[i]; |
|
|
|
i++; |
|
|
|
j++; |
|
|
|
} |
|
|
|
cmd_1[j] = NULL; |
|
|
|
|
|
|
|
shell_direct(cmd_0, cmd_1); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
void mytop() |
|
|
|
{ |
|
|
|