ast_comparator/test/student_data/anonymized/reference_37_tsh.c
/*
 * do_bgfg - Execute the builtin bg and fg commands
 */
Execute the builtin bg and fg commands
Execute the builtin bg and fg commands
void do_bgfg(char **argv)
{
    struct job_t *jb = NULL;
    if( argv[1] != NULL && argv[1][0] == '%' ) 
	{
        int jid = atoi( &argv[1][1] );
        if( !( jb = getjobjid( jobs, jid ) ) ){
            printf( "%s no such job found\n", argv[1] );
            return;
        }
    }
	else {
			if(argv[1] != NULL && isdigit(argv[1][0])) 
			{	pid_t pid = atoi( argv[1] );
				if( !( jb = getjobpid( jobs, pid ) ) )
				{
					printf( "%s no such process found\n", argv[1]);
					return;
				}
			}
		else if(argv[1]==NULL)
		{
			printf("%s command requires PID or %%jobid argument\n",argv[0]);
			return;
		}
		else
		{
			printf("%s argument must be a PID or %%jobid\n",argv[0]);
			return;
		}
			}
    if( kill( -jb->pid , SIGCONT ) < 0 ){
        unix_error("kill error");
    } else {
        if( !strcmp( argv[0],"bg" ) ){
            jb->state = BG;
            printf("[%d] (%d) %s",jb->jid,jb->pid,jb->cmdline);
        } else {
            jb->state = FG;
            waitfg( jb->pid );
        }
    }
    return;
}
void do_bgfg ( char * * argv ) { struct job_t * jb = NULL ; if ( argv [ 1 ] != NULL && argv [ 1 ] [ 0 ] == ' ' ) { int jid = atoi ( & argv [ 1 ] [ 1 ] ) ; if ( ! ( jb = getjobjid ( jobs , jid ) ) ) { printf ( " \n " , argv [ 1 ] ) ; return ; } } else { if ( argv [ 1 ] != NULL && isdigit ( argv [ 1 ] [ 0 ] ) ) { pid_t pid = atoi ( argv [ 1 ] ) ; if ( ! ( jb = getjobpid ( jobs , pid ) ) ) { printf ( " \n " , argv [ 1 ] ) ; return ; } } else if ( argv [ 1 ] == NULL ) { printf ( " \n " , argv [ 0 ] ) ; return ; } else { printf ( " \n " , argv [ 0 ] ) ; return ; } } if ( kill ( - jb -> pid , SIGCONT ) < 0 ) { unix_error ( " " ) ; } else { if ( ! strcmp ( argv [ 0 ] , " " ) ) { jb -> state = BG ; printf ( " " , jb -> jid , jb -> pid , jb -> cmdline ) ; } else { jb -> state = FG ; waitfg ( jb -> pid ) ; } } return ; }
do_bgfg - Execute the builtin bg and fg commands
do_bgfg - Execute the builtin bg and fg commands
// if job id or PID is given as argument //if % sign not given,than we have to check if a process id is given OR check for error //if a process id is given //if no arguments given //if argument given is not a number // send SIGCONT signal