ast_comparator/test/student_data/handout/shlab-handout/cases/reference_24_tsh.c
/* 
 * builtin_cmd - If the user has typed a built-in command then execute
 *    it immediately.  
 */
If the user has typed a built-in command then execute
it immediately.
If the user has typed a built - in command then execute it immediately .
int builtin_cmd(char **argv) 
{
    char * cmd_str = argv[0];
    char * quit_str = "quit";
    char * fg_str = "fg";
    char * bg_str = "bg";
    char * jobs_str = "jobs";
    if(strncmp(cmd_str,quit_str,MAXLINE)==0)
    {
      int i;
      for (i = 0; i < MAXJOBS; i++) {
	  if (jobs[i].pid != 0) 
	  {
	    kill(jobs[i].pid,SIGTERM);
	  }
      }
      exit(0);
    }
    else if( (strncmp(cmd_str,fg_str,MAXLINE)==0) || (strncmp(cmd_str,bg_str,MAXLINE)==0)) 
    {
      do_bgfg(argv);
      return 1;
    }
    else if(strncmp(cmd_str,jobs_str,MAXLINE)==0)
    {
      listjobs(jobs);
      return 1;
    }
    else
    {
      return 0; 
    }
}
int builtin_cmd ( char * * argv ) { char * cmd_str = argv [ 0 ] ; char * quit_str = " " ; char * fg_str = " " ; char * bg_str = " " ; char * jobs_str = " " ; if ( strncmp ( cmd_str , quit_str , MAXLINE ) == 0 ) { int i ; for ( i = 0 ; i < MAXJOBS ; i ++ ) { if ( jobs [ i ] . pid != 0 ) { kill ( jobs [ i ] . pid , SIGTERM ) ; } } exit ( 0 ) ; } else if ( ( strncmp ( cmd_str , fg_str , MAXLINE ) == 0 ) || ( strncmp ( cmd_str , bg_str , MAXLINE ) == 0 ) ) { do_bgfg ( argv ) ; return 1 ; } else if ( strncmp ( cmd_str , jobs_str , MAXLINE ) == 0 ) { listjobs ( jobs ) ; return 1 ; } else { return 0 ; } }
builtin_cmd - If the user has typed a built-in command then execute
    it immediately.
builtin_cmd - If the user has typed a built - in command then execute it immediately .
//Recognizes and interprets the built-in commands: quit, fg, bg, and jobs. //printf("cmd str = %s\n",cmd_str); //Compare the cmd with built in ones //Compare maximum number of chars as maxline //Is quit command //Loop through and kill all child jobs //Is a valid job //Kill this job by sending sig term //Then kill self (quit) //Return not needed //fg or bg //Is fg or bg command //Run the do fg bg function //Is jobs command //Run the lsit jobs command /* not a builtin command */