diff --git a/fun.h b/fun.h index 0f4f5ee..967fdf1 100644 --- a/fun.h +++ b/fun.h @@ -1,8 +1,11 @@ #ifndef FUN_H_INCLUDED #define FUN_H_INCLUDED - #define MAXLINE (80) +#include "fun_1.c" +#include "fun_2.c" + + void history(char *cmdline); void print_his(char *argv); diff --git a/fun_1.c b/fun_1.c index 9640173..1570845 100644 --- a/fun_1.c +++ b/fun_1.c @@ -1,7 +1,8 @@ #include #include #include -#include "fun.h" +#include +//#include "fun.h" void eval(char *cmdline) @@ -10,10 +11,8 @@ void eval(char *cmdline) char buf[MAXLINE]; int isBg; int pid; - strcpy(buf,cmdline); isBg = parseline(cmdline,argv); - if(argv[0] == NULL) { return; @@ -21,28 +20,23 @@ void eval(char *cmdline) if(!builtin_cmd(argv)) { -/* if((pid=fork())==0) { - setpgid(0,0); if(execvp(argv[0],argv)<0) { printf("%s:Command not found.\n",argv[0]); exit(0); } } - if(!isBg) { - waitfg(pid); + wait(NULL); } else { - printf("[%d] (%d) %s",pid2jid(pid),pid,cmdline); + return; } -*/ } - return; } int parseline(const char *cmdline, char **argv) @@ -103,6 +97,10 @@ int parseline(const char *cmdline, char **argv) int builtin_cmd(char **argv) { + if(Is_pipe(argv)==1) + { + return 1; + } if(!strcmp(argv[0],"quit")||!strcmp(argv[0],"exit")) { exit(0); @@ -112,7 +110,23 @@ int builtin_cmd(char **argv) print_his(argv[1]); return 1; } - if(!strcmp(argv[0],"jobs")) + if(!strcmp(argv[0],"cd")) + { + if (argv[1] == NULL) + { + return 1; + } + else + { + if (chdir(argv[1]) != 0) + { + perror("Error: "); + } + return 1; + } + } + + if(!strcmp(argv[0],"mytop")) { return 1; } diff --git a/fun_2.c b/fun_2.c index b7d0d71..7892d3c 100644 --- a/fun_2.c +++ b/fun_2.c @@ -1,5 +1,5 @@ #include -#include "fun.h" +//#include "fun.h" static int num = 0; static char storage[MAXLINE][MAXLINE]; @@ -20,4 +20,55 @@ void print_his(char *argv) } for(; i #include "fun.h" + int main() { char cmdline[MAXLINE]; while(1) { + int bufsize = MAXLINE; printf("COMMAND->"); - fgets(cmdline, MAXLINE, stdin); + fgets(cmdline, MAXLINE, stdin); eval(cmdline); history(cmdline); } + return 0; }