/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet cmds; while (current != NULL) { content = current->content; if (content->own_cmd == 0 && content->pid != -1) { waitpid(content->pid, &data->exit_code, 0); data->exit_code = data->exit_code / 256; } else data->exit_code = 0; current = current->next; } ft_lstclear(data->cmds, ft_cmddel); return (0); } void ft_ctrlc(int num) { (void) num; if (*ft_get_heredoc() != -1) { close(*ft_get_heredoc()); *ft_get_heredoc() = -1; } else { rl_replace_line("", 0); rl_on_new_line(); ft_putchar_fd('\n', 1); rl_redisplay(); } } void ft_quit(int num) { (void) num; rl_replace_line("", 0); rl_redisplay(); ft_printf("%c%c %c%c", 0, 0, 0, 0); } int main(int ac, char **av, char **env) { t_data data; char *line; (void) ac; (void) av; signal(SIGINT, ft_ctrlc); signal(SIGQUIT, ft_quit); data.exit_code = 0; data.exit_code_str = NULL; data.cmds = malloc(sizeof(t_cmd *)); if (data.cmds == NULL) return (1); *data.cmds = NULL; data.env = init_env(env); if (data.env == NULL) return (1); line = ft_get_user_input(); while (line != NULL) { if (ft_minishell(&data, line) == 1) break ; free(line); line = ft_get_user_input(); if (line == NULL) break ; } free(data.exit_code_str); ft_lstclear(data.cmds, ft_cmddel); free(data.cmds); ft_lstclear(data.env, env_del); free(data.env); return (data.exit_code); }