ast_comparator/test/student_data/handout/shlab-handout/cases/reference_11_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) 
{
    int bg;              
    struct cmdline_tokens tok;
    bg = parseline(cmdline, &tok); 
    if (bg == -1) return;               
    if (tok.argv[0] == NULL)  return;   
    if(!builtin_cmd(&tok)){
        sigset_t newset,oldset;
        block_sigs(&newset, &oldset);
        pid_t pid = fork();
        if(pid < 0){
            unix_error("error in fork child process");
        }
        if(pid == 0){
            handle_child_process(&tok, bg, pid, &oldset);
        } else {
            handle_parent_process(&tok, bg, pid, &oldset, cmdline);
        }
    }
    return;
}
void eval ( char * cmdline ) { int bg ; struct cmdline_tokens tok ; bg = parseline ( cmdline , & tok ) ; if ( bg == -1 ) return ; if ( tok . argv [ 0 ] == NULL ) return ; if ( ! builtin_cmd ( & tok ) ) { sigset_t newset , oldset ; block_sigs ( & newset , & oldset ) ; pid_t pid = fork ( ) ; if ( pid < 0 ) { unix_error ( " " ) ; } if ( pid == 0 ) { handle_child_process ( & tok , bg , pid , & oldset ) ; } else { handle_parent_process ( & tok , bg , pid , & oldset , 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
/* should the job run in bg or fg? */ /* Parse command line */ /* parsing error */ /* ignore empty lines */