static int my_print_error_fg(char *str, char *name, t_process *proc) { proc->status = 1; if ((my_print_error(str, name)) == -1) return (FAILURE); return (SUCCESS); }
int my_fg(t_mini *shell, t_process *proc) { if (isatty(0) && isatty(1)) return (my_baby_fg(shell, proc)); else my_print_error("fg: no job control in this shell\n"); proc->status = 1; return (SUCCESS); }
static int fg_solo() { if (g_background.active_jobs_count > 0 && g_background.active_jobs[g_background.active_jobs_count - 1]) return (g_background.max_job_count - 1); else my_print_error("fg: please specify a job_id\n"); return (-1); }
int main(int argc, char **argv) { t_vm *vm; int i; if ((vm = malloc(sizeof(t_vm))) == NULL) my_print_error("Error with a memory allocation\n"); if ((vm->arena = malloc(sizeof(t_vm))) == NULL) my_print_error("Error with a memory allocation\n"); init_arena(vm->arena->arena, MEM_SIZE); check_arg(argc); i = check_dump(vm, argv); check_champ(vm, argc, argv, i); init_champs(vm); my_parsing(vm, argc, argv, i); init_mlx(vm); aff_grid(vm); my_hook(vm); corewar(vm); return (0); }
int my_bg(t_mini *shell, t_process *proc) { int job_id; (void)shell; job_id = -1; proc->status = 0; if (g_background.active_jobs_count == 0) return (no_jobs(proc)); if (!(proc->cmd_argv[1]) && g_background.active_jobs_count > 0 && g_background.active_jobs[g_background.active_jobs_count - 1]) job_id = g_background.active_jobs_count - 1; else if (proc->cmd_argv[1] && ((job_id = my_getnbr(proc->cmd_argv[1])) < 0 || job_id >= g_background.active_jobs_count)) my_print_error("42sh: no such job [%s]\n", proc->cmd_argv[1]); if (job_id > -1 && job_id < g_background.active_jobs_count) { g_background.active_jobs[job_id]->mode = BACKGROUND; if (put_to_background(g_background.active_jobs[job_id], 0) == FAILURE) my_print_error("bg: putting to background failed\n"); } return (SUCCESS); }
static int no_jobs(t_process *proc) { my_print_error("bg: no jobs to resume\n"); proc->status = 1; return (SUCCESS); }