ast_comparator/test/student_data/handout/shlab-handout/cases/31_tsh.c
/*
 * eval - Evaluate the command line that the user has just typed in
 *
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately. Otherwise, fork a child process and
 * run the job in the context of the child. If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.
 */
Evaluate the command line that the user has just typed in

If the user has requested a built-in command (quit, jobs, bg or fg)
then execute it immediately. Otherwise, fork a child process and
run the job in the context of the child. If the job is running in
the foreground, wait for it to terminate and then return.  Note:
each child process must have a unique process group ID so that our
background children don't receive SIGINT (SIGTSTP) from the kernel
when we type ctrl-c (ctrl-z) at the keyboard.
Evaluate the command line that the user has just typed in If the user has requested a built - in command ( quit jobs bg or fg ) then execute it immediately . Otherwise fork a child process and run the job in the context of the child . If the job is running in the foreground wait for it to terminate and then return . Note : each child process must have a unique process group ID so that our background children don ' t receive SIGINT ( SIGTSTP ) from the kernel when we type ctrl - c ( ctrl - z ) at the keyboard .
void eval(char *cmdline)
{
  char *argv[MAXARGS];
  int d; 
  pid_t pid;
  sigset_t mask; 
  d = parseline(cmdline, argv);
  if(builtin_cmd(argv)==0){
	if(sigprocmask(SIG_BLOCK, &mask, NULL) != 0){
		unix_error("error");
	}
	if(sigaddset(&mask, SIGCHLD) != 0){
		unix_error("error");
	}
	if(sigemptyset(&mask) != 0){
		unix_error("error");
	}
	if((pid=fork())<0){
		unix_error("error");
	}else if(pid==0){
		if(sigprocmask(SIG_UNBLOCK, &mask, NULL)!=0){
			unix_error("error");
		}
		if(setpgid(0,0) < 0){
			unix_error("error");
		}
		if(execvp(argv[0], argv)<0){
			printf("error");
			exit(1);
		}
	}else{
		if(sigprocmask(SIG_UNBLOCK, &mask, NULL)!=0){
			unix_error("error");
		}	
		if(!d){
			addjob(jobs, pid, FG, cmdline);
		}else{
			addjob(jobs, pid, BG, cmdline);
		}
		if(!d){
			waitfg(pid);
		}else{
			printf("[%d] (%d) %s", pid2jid(pid), pid, cmdline);
		}
	}
}
  return;
}
void eval ( char * cmdline ) { char * argv [ MAXARGS ] ; int d ; pid_t pid ; sigset_t mask ; d = parseline ( cmdline , argv ) ; if ( builtin_cmd ( argv ) == 0 ) { if ( sigprocmask ( SIG_BLOCK , & mask , NULL ) != 0 ) { unix_error ( " " ) ; } if ( sigaddset ( & mask , SIGCHLD ) != 0 ) { unix_error ( " " ) ; } if ( sigemptyset ( & mask ) != 0 ) { unix_error ( " " ) ; } if ( ( pid = fork ( ) ) < 0 ) { unix_error ( " " ) ; } else if ( pid == 0 ) { if ( sigprocmask ( SIG_UNBLOCK , & mask , NULL ) != 0 ) { unix_error ( " " ) ; } if ( setpgid ( 0 , 0 ) < 0 ) { unix_error ( " " ) ; } if ( execvp ( argv [ 0 ] , argv ) < 0 ) { printf ( " " ) ; exit ( 1 ) ; } } else { if ( sigprocmask ( SIG_UNBLOCK , & mask , NULL ) != 0 ) { unix_error ( " " ) ; } if ( ! d ) { addjob ( jobs , pid , FG , cmdline ) ; } else { addjob ( jobs , pid , BG , cmdline ) ; } if ( ! d ) { waitfg ( pid ) ; } else { printf ( " " , pid2jid ( pid ) , pid , cmdline ) ; } } } return ; }
eval - Evaluate the command line that the user has just typed in
eval - Evaluate the command line that the user has just typed in
//decide the bg or fg
 //sig function means we will treat signal as a set. and the function emptyset, addset, procmask is a function of those sigset.
 //first check if it is builtin or not
 //if not, 
 // this is function that makes wait the unimportant signal. if it has wrong way to do it, we should report the error
 //we can add, if we fail we should report it is error
 //sigemptyset is the function to make set empty, if not it must be error
 //the pid can not be negative.
 //
 //if the wait has a problem
 //if it is builtin-command?
 //if it is FG,
 //if it is BG,
