|
|
@ -1,7 +1,8 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <string.h> |
|
|
|
#include "fun.h" |
|
|
|
#include <wait.h> |
|
|
|
//#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; |
|
|
|
} |
|
|
|