ast_comparator/test/student_data/handout/shlab-handout/cases/reference_26_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(struct cmdline_tokens cmd_tokens) {
    int i;
    char **argv;
    int fd; 
    switch (cmd_tokens.builtins) {
        case BUILTIN_QUIT:
            exit(0);
            return 1;
            break;
        case BUILTIN_BG: 
        case BUILTIN_FG: 
            argv = cmd_tokens.argv;     
            if (argv[1] == NULL) {
                printf("There are no arguments!");
            } else {
                i = 0;
                if (argv[1][0] == '%') {
                    i = 1;
                }
                while (argv[1][i] != '\0') {
                    if (!isdigit(argv[1][i])) {
                        break;
                    }
                    ++i;
                }
                if (argv[1][i] == '\0') {
                    do_bgfg(argv);
                } else {
                    printf("%s: argument must be a PID or %%jobid\n", argv[0]);
                }
            }
            return 1;
            break;
        case BUILTIN_JOBS:
            if (cmd_tokens.outfile) {
                fd = open(cmd_tokens.outfile, O_WRONLY, 0);
                listjobs(jobs, fd);
                close(fd);
            } else {
                listjobs(jobs, STDOUT_FILENO);
            }
            return 1; 
            break;
        default: return 0; 
    }
}
int builtin_cmd ( struct cmdline_tokens cmd_tokens ) { int i ; char * * argv ; int fd ; switch ( cmd_tokens . builtins ) { case BUILTIN_QUIT : exit ( 0 ) ; return 1 ; break ; case BUILTIN_BG : case BUILTIN_FG : argv = cmd_tokens . argv ; if ( argv [ 1 ] == NULL ) { printf ( " " ) ; } else { i = 0 ; if ( argv [ 1 ] [ 0 ] == ' ' ) { i = 1 ; } while ( argv [ 1 ] [ i ] != ' \0 ' ) { if ( ! isdigit ( argv [ 1 ] [ i ] ) ) { break ; } ++ i ; } if ( argv [ 1 ] [ i ] == ' \0 ' ) { do_bgfg ( argv ) ; } else { printf ( " \n " , argv [ 0 ] ) ; } } return 1 ; break ; case BUILTIN_JOBS : if ( cmd_tokens . outfile ) { fd = open ( cmd_tokens . outfile , O_WRONLY , 0 ) ; listjobs ( jobs , fd ) ; close ( fd ) ; } else { listjobs ( jobs , STDOUT_FILENO ) ; } return 1 ; break ; default : 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 .
/**
     * NOTE:
     * Based on tutorial the cmd_tokens were to be passed to builtin_cmd
     * But earlier argv was being passed.
     * Still using argv but getting that from cmd_tokens instead of passing to the function directly
     */ // File discriptor // Quit Command // Command background // Command foreground // Getting argv here /* Builtin command */ /* Not a builtin command */