From 0a6654f70770721a9029d04641f688e312624ad7 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sat, 25 Mar 2017 23:55:23 +0100 Subject: [PATCH 01/10] :fire: exec_destroy (#196 #198) --- 42sh/includes/exec.h | 1 + 42sh/libft/src/sys/open_access.c | 2 -- 42sh/src/exec/exec_reset.c | 16 ++++++++++++++++ 42sh/src/exec/process_launch.c | 1 + 42sh/src/main/data_exit.c | 4 ++-- 42sh/src/main/shell_init.c | 9 +++++++-- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 1bf1074b..b14e1d2d 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -140,6 +140,7 @@ struct s_exec }; int exec_reset(void); +int exec_destroy(void); int exec_pushfds(); int exec_popfds(); int process_fork(t_process *p); diff --git a/42sh/libft/src/sys/open_access.c b/42sh/libft/src/sys/open_access.c index 40811fe7..bc1ee88e 100644 --- a/42sh/libft/src/sys/open_access.c +++ b/42sh/libft/src/sys/open_access.c @@ -23,8 +23,6 @@ int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm) if (access(file, F_OK) == 0 && access(file, a_flag) != 0) return (-ERR_SET(E_SYS_NOPERM, file)); if ((fd = open(file, o_flag, o_perm)) < 0) - { exit(1); - } return (fd); } diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index b9330b38..0e55431e 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -62,3 +62,19 @@ int exec_reset(void) jobc->current_id = 1; return (0); } + +int exec_destroy(void) +{ + int i; + t_jobc *jobc; + t_exec *exec; + + exec = &data_singleton()->exec; + jobc = &data_singleton()->jobc; + ft_lstdel(&exec->op_stack, ft_lst_cfree); + ft_lstdel(&jobc->first_job, job_free); + i = -1; + while (++i < 10) + ft_lstdel(&exec->fd_save[i], ft_lst_cfree); + return (0); +} diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index ac107417..5a0b711b 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -26,6 +26,7 @@ int process_fork(t_process *p) exit(1); process_setgroup(p, 0); process_setsig(); + exec_destroy(); exec_reset(); data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index 753ea33f..d8911c0f 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -19,13 +19,13 @@ void data_exit(void) data = data_singleton(); ft_strdel(&data->line.input); ft_strdel(&data->binary); - exec_popfds(); + /* exec_popfds(); */ ft_sstrfree(data->env); ft_sstrfree(data->local_var); ft_sstrfree(data->argv); lexer_destroy(&data->lexer); parser_destroy(&data->parser); - ft_lstdel(&data->jobc.first_job, &job_free); + exec_destroy(); ft_lstdel(&data->lst_func, &tree_func_free); ft_save_termios(-1); ft_free_hash_table(); diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index dc2bd6b8..ec68356f 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -11,7 +11,9 @@ /* ************************************************************************** */ #include "minishell.h" -#define SHELL_USAGE "42sh [-c command | [<]script] [--no-jobcontrol]" +#define SHELL_USAGE1 "usage: 42sh [--no-jobcontrol]" +#define SHELL_USAGE2 " or 42sh -c command" +#define SHELL_USAGE3 " or 42sh script" static t_cliopts g_opts[] = { @@ -87,7 +89,10 @@ int shell_init(int ac, char **av, char **env) if (data_init(ac, av, env) < 0) return (-1); if (cliopts_get(av, g_opts, data)) - return (ft_perror(NULL) && SH_ERR("usage: %s", SHELL_USAGE)); + return (ft_perror(NULL) + && SH_ERR("%s", SHELL_USAGE1) + && SH_ERR("%s", SHELL_USAGE2) + && SH_ERR("%s", SHELL_USAGE3)); if (!isatty(STDIN) || *data->av_data) data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); if ((data->fd = get_input_fd(data, NULL)) < 0) From e4824905f2d9b771d695a05e80ae8d7557ab10a4 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 26 Mar 2017 21:41:06 +0200 Subject: [PATCH 02/10] new exec_init/destroy --- 42sh/Makefile | 539 +++++++++--------- 42sh/includes/exec.h | 6 +- 42sh/libft/includes/libft.h | 2 +- 42sh/libft/src/lst/ft_lst_print.c | 2 +- 42sh/libft/src/lst/ft_lstdel.c | 11 +- 42sh/libft/src/lst/ft_lstdelone.c | 2 +- 42sh/libft/src/lst/pop.c | 7 +- .../src/exec/{exec_reset.c => exec_destroy.c} | 58 +- 42sh/src/exec/exec_init.c | 42 ++ 42sh/src/exec/exec_popfds.c | 25 + 42sh/src/exec/exec_pushfds.c | 25 + 42sh/src/exec/process_launch.c | 5 +- 42sh/src/main/data_exit.c | 6 +- 42sh/src/main/data_init.c | 4 +- 42sh/src/main/main.c | 5 +- 42sh/src/parser/parser_init.c | 2 +- 42sh/src/parser/push_stack.c | 2 +- 42sh/src/parser/stack_init.c | 5 +- 18 files changed, 396 insertions(+), 352 deletions(-) rename 42sh/src/exec/{exec_reset.c => exec_destroy.c} (53%) create mode 100644 42sh/src/exec/exec_init.c create mode 100644 42sh/src/exec/exec_popfds.c create mode 100644 42sh/src/exec/exec_pushfds.c diff --git a/42sh/Makefile b/42sh/Makefile index 7f741ccd..1efb305d 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -29,289 +29,292 @@ INC_DIR = includes/ OBJ_DIR = objs/ SRC_BASE = \ -completion/c_pathsolver.c\ -completion/c_init.c\ -completion/c_printer.c\ -completion/c_find_binary.c\ -completion/c_find_env.c\ -completion/c_clear.c\ -completion/c_parser.c\ -completion/c_arrow.c\ -completion/c_sizing.c\ -completion/completion.c\ -completion/c_match_glob.c\ -completion/c_find_files.c\ -completion/c_terminal.c\ -completion/c_output.c\ -completion/c_misc.c\ -completion/c_match.c\ -completion/c_match_update.c\ -completion/c_find_abspath.c\ -history/surch_in_history.c\ -history/history_parsing_toolz_2.c\ -history/history_parsing_toolz.c\ -history/list_toolz.c\ -history/add_str_in_history.c\ -history/history_parsing.c\ -history/history.c\ -job_control/pprint_while.c\ -job_control/mark_job_as_running.c\ -job_control/pprint_case.c\ -job_control/job_notify_new.c\ -job_control/sigint_handler.c\ -job_control/job_update_status.c\ -job_control/job_format_head.c\ -job_control/job_is_completed.c\ -job_control/job_wait.c\ -job_control/sigtstp_handler.c\ -job_control/job_free.c\ -job_control/pprint_for.c\ -job_control/pprint_if.c\ -job_control/job_hup_all.c\ -job_control/put_job_in_foreground.c\ -job_control/job_is_stopped.c\ -job_control/process_free.c\ -job_control/sigttin_handler.c\ -job_control/sigttou_handler.c\ -job_control/builtin_jobs.c\ -job_control/process_cmp_pid.c\ -job_control/pprint_subshell.c\ -job_control/job_remove.c\ -job_control/builtin_bg.c\ -job_control/job_run.c\ -job_control/has_stopped_job.c\ -job_control/pprint_cmd.c\ -job_control/job_cmp_id.c\ -job_control/pprint_brace.c\ -job_control/job_addprocess.c\ -job_control/job_update_id.c\ -job_control/do_job_notification.c\ -job_control/job_getrank.c\ -job_control/has_running_job.c\ -job_control/process_format.c\ -job_control/job_getprocess.c\ -job_control/job_notify_change.c\ -job_control/job_format.c\ -job_control/put_job_in_background.c\ -job_control/pprint_until.c\ -job_control/pprint_function.c\ -job_control/builtin_fg.c\ -job_control/sigchld_handler.c\ -parser/tree_func_free.c\ -parser/parser_destroy.c\ -parser/tree_wrapper.c\ -parser/pop_stack.c\ -parser/add_cmd.c\ -parser/parser_init.c\ -parser/aggregate_sym.c\ -parser/redir_init.c\ -parser/do_parser_routine.c\ -parser/stack_init.c\ -parser/add_number.c\ -parser/add_func.c\ -parser/add_loop.c\ -parser/read_stack.c\ -parser/push_stack.c\ -parser/add_sep.c\ -parser/ft_parse.c\ -parser/add_condition.c\ -parser/produce_sym.c\ -parser/heredoc_parser.c\ -parser/add_case.c\ -parser/sym_free.c\ -parser/add_subshell.c\ -parser/build_tree.c\ -parser/eval_sym.c\ -parser/error_syntax.c\ -parser/add_bang.c\ -parser/add_redir.c\ -main/data_exit.c\ -main/ft_putast.c\ -main/main.c\ -main/shell_reset.c\ -main/data_singleton.c\ -main/data_init.c\ -main/shell_init.c\ -line_editing/lib_line_editing/toolz_termcaps.c\ -line_editing/lib_line_editing/tool_line_2.c\ -line_editing/lib_line_editing/tool_line.c\ -line_editing/lib_line_editing/toolz.c\ -line_editing/lib_line_editing/toolz_parseur.c\ -line_editing/lib_line_editing/ft_nb_line.c\ -line_editing/lib_line_editing/toolz2.c\ -line_editing/resize.c\ -line_editing/control_features.c\ -line_editing/print_del_completion/queue.c\ -line_editing/print_del_completion/completion.c\ -line_editing/print_del_completion/print_and_del.c\ -line_editing/get_key.c\ -line_editing/ft_prompt.c\ -line_editing/readline.c\ -line_editing/move_term/move_up_and_down.c\ -line_editing/move_term/home_end.c\ -line_editing/move_term/move_to_word.c\ -line_editing/move_term/move_left_and_right.c\ -line_editing/init_line/init_termcaps.c\ -line_editing/init_line/init_history.c\ -line_editing/init_line/init_line.c\ -line_editing/copy_cut_paste/underline_home.c\ -line_editing/copy_cut_paste/underline_down.c\ -line_editing/copy_cut_paste/underline_end.c\ -line_editing/copy_cut_paste/underline_reset.c\ -line_editing/copy_cut_paste/underline_function.c\ -line_editing/copy_cut_paste/copy_cut_paste.c\ -line_editing/copy_cut_paste/underline_right.c\ -line_editing/copy_cut_paste/underline_up.c\ -line_editing/copy_cut_paste/underline_left.c\ -glob/expand_home.c\ -glob/expand_bquote.c\ -glob/dir_glob.c\ -glob/ft_strsplit_esc.c\ -glob/expand_var.c\ -glob/glob.c\ -glob/word_is_assignment.c\ -glob/match_pattern.c\ -glob/lib_perso/ft_ld_front.c\ -glob/lib_perso/ft_ld_new.c\ -glob/lib_perso/ft_ld_size.c\ -glob/lib_perso/ft_tablen.c\ -glob/lib_perso/ft_ld_pushfront.c\ -glob/lib_perso/ft_ld_swap.c\ -glob/lib_perso/ft_ld_order.c\ -glob/lib_perso/ft_strsubf.c\ -glob/lib_perso/ft_ld_reverse.c\ -glob/lib_perso/ft_ld_to_tab.c\ -glob/lib_perso/ft_tabdel.c\ -glob/lib_perso/ft_strjoinf.c\ -glob/lib_perso/ft_ld_del.c\ -glob/lib_perso/ft_ld_back.c\ -glob/lib_perso/ft_memrealloc.c\ -glob/lib_perso/ft_ld_copy.c\ -glob/lib_perso/ft_ld_pushback.c\ -glob/lib_perso/ft_ld_clear.c\ -glob/expand_brace.c\ -glob/tab_esc_copy.c\ -glob/ft_strsplit_spe.c\ -glob/esc_print.c\ -glob/expand_esc.c\ -glob/is_char_esc.c\ -glob/command_getoutput.c\ -glob/gen_tab_esc.c\ -lexer/lexer_delim.c\ -lexer/lexer_paren.c\ -lexer/get_state_redir.c\ -lexer/lexer_quote.c\ -lexer/lexer_dquote.c\ -lexer/token_free.c\ -lexer/token_cmp_type.c\ -lexer/lexer_sep.c\ -lexer/lexer_heredoc.c\ -lexer/token_init.c\ -lexer/lexer_less.c\ -lexer/insert_newline.c\ -lexer/get_lexer_stack2.c\ -lexer/lexer_init.c\ -lexer/keep_last_type.c\ -lexer/isrw_delim.c\ -lexer/lexer_lex.c\ -lexer/lexer_destroy.c\ -lexer/lexer_word.c\ -lexer/lexer_newline.c\ -lexer/get_lexer_stack.c\ -lexer/lexer_great.c\ -lexer/lexer_curly_braces.c\ -lexer/lexer_end.c\ -lexer/get_reserved_words.c\ -lexer/do_lexer_routine.c\ -lexer/token_append.c\ -lexer/get_state_global.c\ -lexer/lexer_bquote.c\ -lexer/lexer_default.c\ -lexer/token_print.c\ -lexer/lexer_backslash.c\ -lexer/lexer_number.c\ -builtin/builtin_func.c\ +builtin/bt_env_opt.c\ +builtin/bt_read_get.c\ +builtin/bt_read_term.c\ +builtin/builtin_cd.c\ +builtin/builtin_echo.c\ +builtin/builtin_env.c\ +builtin/builtin_exit.c\ builtin/builtin_export.c\ -builtin/builtin_unsetenv.c\ +builtin/builtin_func.c\ +builtin/builtin_hash.c\ +builtin/builtin_history.c\ +builtin/builtin_math.c\ +builtin/builtin_read.c\ builtin/builtin_setenv.c\ builtin/builtin_unset.c\ -builtin/builtin_math.c\ -builtin/bt_read_term.c\ -builtin/builtin_echo.c\ -builtin/builtin_hash.c\ -builtin/bt_env_opt.c\ -builtin/builtin_exit.c\ -builtin/builtin_cd.c\ -builtin/builtin_read.c\ +builtin/builtin_unsetenv.c\ builtin/is_builtin.c\ -builtin/bt_read_get.c\ -builtin/builtin_history.c\ -builtin/builtin_env.c\ -exec/pset_brace.c\ -exec/pset_if.c\ -exec/pfree_func.c\ -exec/plaunch_subshell.c\ -exec/pset_case.c\ +completion/c_arrow.c\ +completion/c_clear.c\ +completion/c_find_abspath.c\ +completion/c_find_binary.c\ +completion/c_find_env.c\ +completion/c_find_files.c\ +completion/c_init.c\ +completion/c_match.c\ +completion/c_match_glob.c\ +completion/c_match_update.c\ +completion/c_misc.c\ +completion/c_output.c\ +completion/c_parser.c\ +completion/c_pathsolver.c\ +completion/c_printer.c\ +completion/c_sizing.c\ +completion/c_terminal.c\ +completion/completion.c\ +exec/ast_free.c\ +exec/bad_fd.c\ exec/exec_ampersand.c\ exec/exec_and_if.c\ -exec/exec_var.c\ +exec/exec_bang.c\ exec/exec_case_branch.c\ -exec/redirect_greatand.c\ +exec/exec_destroy.c\ +exec/exec_elif.c\ +exec/exec_else.c\ +exec/exec_func.c\ +exec/exec_init.c\ +exec/exec_leaf.c\ +exec/exec_or_if.c\ +exec/exec_pipe.c\ +exec/exec_popfds.c\ +exec/exec_pushfds.c\ +exec/exec_semi.c\ +exec/exec_var.c\ +exec/fd_is_valid.c\ +exec/ft_exec.c\ +exec/ft_findexec.c\ +exec/is_function.c\ +exec/mark_process_status.c\ +exec/node_copy.c\ +exec/pfree_cmd.c\ +exec/pfree_cond.c\ +exec/pfree_func.c\ +exec/pfree_list.c\ +exec/pfree_subshell.c\ +exec/plaunch_brace.c\ +exec/plaunch_builtin.c\ +exec/plaunch_case.c\ +exec/plaunch_empty.c\ +exec/plaunch_file.c\ +exec/plaunch_for.c\ +exec/plaunch_function.c\ +exec/plaunch_if.c\ +exec/plaunch_subshell.c\ +exec/plaunch_until.c\ +exec/plaunch_while.c\ +exec/process_launch.c\ +exec/process_redirect.c\ +exec/process_set.c\ +exec/process_setgroup.c\ +exec/process_setsig.c\ +exec/pset_brace.c\ +exec/pset_case.c\ +exec/pset_cmd.c\ +exec/pset_for.c\ +exec/pset_if.c\ +exec/pset_subshell.c\ +exec/pset_until.c\ +exec/pset_while.c\ exec/redir_copy.c\ exec/redir_free.c\ -exec/token_to_argv.c\ -exec/exec_pipe.c\ -exec/pfree_cond.c\ -exec/pset_for.c\ -exec/pset_until.c\ -exec/exec_func.c\ -exec/exec_or_if.c\ -exec/node_copy.c\ -exec/pfree_list.c\ -exec/redirect_dless.c\ -exec/exec_bang.c\ exec/redirect_dgreat.c\ -exec/mark_process_status.c\ -exec/plaunch_for.c\ -exec/is_function.c\ -exec/pset_while.c\ -exec/exec_else.c\ -exec/ast_free.c\ -exec/exec_semi.c\ -exec/plaunch_while.c\ -exec/bad_fd.c\ -exec/exec_leaf.c\ -exec/plaunch_if.c\ -exec/plaunch_case.c\ -exec/process_redirect.c\ -exec/process_setgroup.c\ -exec/ft_exec.c\ -exec/set_exitstatus.c\ -exec/plaunch_brace.c\ -exec/plaunch_empty.c\ +exec/redirect_dless.c\ exec/redirect_great.c\ -exec/process_set.c\ -exec/exec_reset.c\ -exec/plaunch_until.c\ -exec/pset_cmd.c\ -exec/redirect_lessand.c\ -exec/ft_findexec.c\ +exec/redirect_greatand.c\ exec/redirect_less.c\ -exec/pset_subshell.c\ -exec/fd_is_valid.c\ -exec/exec_elif.c\ -exec/plaunch_builtin.c\ -exec/pfree_subshell.c\ -exec/plaunch_file.c\ -exec/process_setsig.c\ -exec/plaunch_function.c\ -exec/process_launch.c\ -exec/pfree_cmd.c\ +exec/redirect_lessand.c\ +exec/set_exitstatus.c\ +exec/token_to_argv.c\ +glob/command_getoutput.c\ +glob/dir_glob.c\ +glob/esc_print.c\ +glob/expand_bquote.c\ +glob/expand_brace.c\ +glob/expand_esc.c\ +glob/expand_home.c\ +glob/expand_var.c\ +glob/ft_strsplit_esc.c\ +glob/ft_strsplit_spe.c\ +glob/gen_tab_esc.c\ +glob/glob.c\ +glob/is_char_esc.c\ +glob/lib_perso/ft_ld_back.c\ +glob/lib_perso/ft_ld_clear.c\ +glob/lib_perso/ft_ld_copy.c\ +glob/lib_perso/ft_ld_del.c\ +glob/lib_perso/ft_ld_front.c\ +glob/lib_perso/ft_ld_new.c\ +glob/lib_perso/ft_ld_order.c\ +glob/lib_perso/ft_ld_pushback.c\ +glob/lib_perso/ft_ld_pushfront.c\ +glob/lib_perso/ft_ld_reverse.c\ +glob/lib_perso/ft_ld_size.c\ +glob/lib_perso/ft_ld_swap.c\ +glob/lib_perso/ft_ld_to_tab.c\ +glob/lib_perso/ft_memrealloc.c\ +glob/lib_perso/ft_strjoinf.c\ +glob/lib_perso/ft_strsubf.c\ +glob/lib_perso/ft_tabdel.c\ +glob/lib_perso/ft_tablen.c\ +glob/match_pattern.c\ +glob/tab_esc_copy.c\ +glob/word_is_assignment.c\ hash_table/ft_add_hash.c\ -hash_table/is_hash.c\ hash_table/hash.c\ hash_table/hash_free.c\ -hash_table/hash_str.c +hash_table/hash_str.c\ +hash_table/is_hash.c\ +history/add_str_in_history.c\ +history/history.c\ +history/history_parsing.c\ +history/history_parsing_toolz.c\ +history/history_parsing_toolz_2.c\ +history/list_toolz.c\ +history/surch_in_history.c\ +job_control/builtin_bg.c\ +job_control/builtin_fg.c\ +job_control/builtin_jobs.c\ +job_control/do_job_notification.c\ +job_control/has_running_job.c\ +job_control/has_stopped_job.c\ +job_control/job_addprocess.c\ +job_control/job_cmp_id.c\ +job_control/job_format.c\ +job_control/job_format_head.c\ +job_control/job_free.c\ +job_control/job_getprocess.c\ +job_control/job_getrank.c\ +job_control/job_hup_all.c\ +job_control/job_is_completed.c\ +job_control/job_is_stopped.c\ +job_control/job_notify_change.c\ +job_control/job_notify_new.c\ +job_control/job_remove.c\ +job_control/job_run.c\ +job_control/job_update_id.c\ +job_control/job_update_status.c\ +job_control/job_wait.c\ +job_control/mark_job_as_running.c\ +job_control/pprint_brace.c\ +job_control/pprint_case.c\ +job_control/pprint_cmd.c\ +job_control/pprint_for.c\ +job_control/pprint_function.c\ +job_control/pprint_if.c\ +job_control/pprint_subshell.c\ +job_control/pprint_until.c\ +job_control/pprint_while.c\ +job_control/process_cmp_pid.c\ +job_control/process_format.c\ +job_control/process_free.c\ +job_control/put_job_in_background.c\ +job_control/put_job_in_foreground.c\ +job_control/sigchld_handler.c\ +job_control/sigint_handler.c\ +job_control/sigtstp_handler.c\ +job_control/sigttin_handler.c\ +job_control/sigttou_handler.c\ +lexer/do_lexer_routine.c\ +lexer/get_lexer_stack.c\ +lexer/get_lexer_stack2.c\ +lexer/get_reserved_words.c\ +lexer/get_state_global.c\ +lexer/get_state_redir.c\ +lexer/insert_newline.c\ +lexer/isrw_delim.c\ +lexer/keep_last_type.c\ +lexer/lexer_backslash.c\ +lexer/lexer_bquote.c\ +lexer/lexer_curly_braces.c\ +lexer/lexer_default.c\ +lexer/lexer_delim.c\ +lexer/lexer_destroy.c\ +lexer/lexer_dquote.c\ +lexer/lexer_end.c\ +lexer/lexer_great.c\ +lexer/lexer_heredoc.c\ +lexer/lexer_init.c\ +lexer/lexer_less.c\ +lexer/lexer_lex.c\ +lexer/lexer_newline.c\ +lexer/lexer_number.c\ +lexer/lexer_paren.c\ +lexer/lexer_quote.c\ +lexer/lexer_sep.c\ +lexer/lexer_word.c\ +lexer/token_append.c\ +lexer/token_cmp_type.c\ +lexer/token_free.c\ +lexer/token_init.c\ +lexer/token_print.c\ +line_editing/control_features.c\ +line_editing/copy_cut_paste/copy_cut_paste.c\ +line_editing/copy_cut_paste/underline_down.c\ +line_editing/copy_cut_paste/underline_end.c\ +line_editing/copy_cut_paste/underline_function.c\ +line_editing/copy_cut_paste/underline_home.c\ +line_editing/copy_cut_paste/underline_left.c\ +line_editing/copy_cut_paste/underline_reset.c\ +line_editing/copy_cut_paste/underline_right.c\ +line_editing/copy_cut_paste/underline_up.c\ +line_editing/ft_prompt.c\ +line_editing/get_key.c\ +line_editing/init_line/init_history.c\ +line_editing/init_line/init_line.c\ +line_editing/init_line/init_termcaps.c\ +line_editing/lib_line_editing/ft_nb_line.c\ +line_editing/lib_line_editing/tool_line.c\ +line_editing/lib_line_editing/tool_line_2.c\ +line_editing/lib_line_editing/toolz.c\ +line_editing/lib_line_editing/toolz2.c\ +line_editing/lib_line_editing/toolz_parseur.c\ +line_editing/lib_line_editing/toolz_termcaps.c\ +line_editing/move_term/home_end.c\ +line_editing/move_term/move_left_and_right.c\ +line_editing/move_term/move_to_word.c\ +line_editing/move_term/move_up_and_down.c\ +line_editing/print_del_completion/completion.c\ +line_editing/print_del_completion/print_and_del.c\ +line_editing/print_del_completion/queue.c\ +line_editing/readline.c\ +line_editing/resize.c\ +main/data_exit.c\ +main/data_init.c\ +main/data_singleton.c\ +main/ft_putast.c\ +main/main.c\ +main/shell_init.c\ +main/shell_reset.c\ +parser/add_bang.c\ +parser/add_case.c\ +parser/add_cmd.c\ +parser/add_condition.c\ +parser/add_func.c\ +parser/add_loop.c\ +parser/add_number.c\ +parser/add_redir.c\ +parser/add_sep.c\ +parser/add_subshell.c\ +parser/aggregate_sym.c\ +parser/build_tree.c\ +parser/do_parser_routine.c\ +parser/error_syntax.c\ +parser/eval_sym.c\ +parser/ft_parse.c\ +parser/heredoc_parser.c\ +parser/parser_destroy.c\ +parser/parser_init.c\ +parser/pop_stack.c\ +parser/produce_sym.c\ +parser/push_stack.c\ +parser/read_stack.c\ +parser/redir_init.c\ +parser/stack_init.c\ +parser/sym_free.c\ +parser/tree_func_free.c\ +parser/tree_wrapper.c SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index b14e1d2d..c2445149 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/24 20:07:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:39:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -139,8 +139,8 @@ struct s_exec int control_count; }; -int exec_reset(void); -int exec_destroy(void); +int exec_init(t_exec *exec); +int exec_destroy(t_exec *exec); int exec_pushfds(); int exec_popfds(); int process_fork(t_process *p); diff --git a/42sh/libft/includes/libft.h b/42sh/libft/includes/libft.h index dbecfc8c..96b3f0c3 100644 --- a/42sh/libft/includes/libft.h +++ b/42sh/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/03/25 01:56:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:12:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/lst/ft_lst_print.c b/42sh/libft/src/lst/ft_lst_print.c index 94e5f315..0ff1d1a6 100644 --- a/42sh/libft/src/lst/ft_lst_print.c +++ b/42sh/libft/src/lst/ft_lst_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:27 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:25:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/lst/ft_lstdel.c b/42sh/libft/src/lst/ft_lstdel.c index ecebf830..f60ae2d0 100644 --- a/42sh/libft/src/lst/ft_lstdel.c +++ b/42sh/libft/src/lst/ft_lstdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */ -/* Updated: 2016/12/05 13:39:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:33:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,8 @@ void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { - if (alst && *alst && del) - { - ft_lstdel(&(*alst)->next, del); - ft_lstdelone(alst, del); - } + if (!(alst || *alst || del)) + return ; + ft_lstdel(&(*alst)->next, del); + ft_lstdelone(alst, del); } diff --git a/42sh/libft/src/lst/ft_lstdelone.c b/42sh/libft/src/lst/ft_lstdelone.c index d9743a95..e550e0f3 100644 --- a/42sh/libft/src/lst/ft_lstdelone.c +++ b/42sh/libft/src/lst/ft_lstdelone.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 13:39:33 by jhalford #+# #+# */ -/* Updated: 2017/03/18 17:17:50 by ariard ### ########.fr */ +/* Updated: 2017/03/26 21:24:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/lst/pop.c b/42sh/libft/src/lst/pop.c index df3be22e..9e7d713d 100644 --- a/42sh/libft/src/lst/pop.c +++ b/42sh/libft/src/lst/pop.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:56 by jhalford #+# #+# */ -/* Updated: 2017/03/24 20:05:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:25:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,11 @@ int pop(t_list **lst) t_list *top; int item; + if (!(lst || *lst)) + return (0); top = *lst; item = top ? *(int*)top->content : 0; - if (lst && *lst) - *lst = (*lst)->next; + *lst = (*lst)->next; ft_lstdelone(&top, ft_lst_cfree); return (item); } diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_destroy.c similarity index 53% rename from 42sh/src/exec/exec_reset.c rename to 42sh/src/exec/exec_destroy.c index 0e55431e..bbbdace0 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_destroy.c @@ -6,75 +6,23 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/24 23:29:00 by ariard ### ########.fr */ +/* Updated: 2017/03/26 21:40:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int exec_reset_job(t_job *job) -{ - job->id = 0; - job->pgid = 0; - job->attrs = 0; - job->first_process = NULL; - tcgetattr(STDIN, &job->tmodes); - return (0); -} - -int exec_pushfds(void) -{ - int i; - t_exec *exec; - - exec = &data_singleton()->exec; - i = -1; - while (++i < 10) - push(&(exec->fd_save[i]), fcntl(i, F_DUPFD_CLOEXEC, 10)); - return (0); -} - -int exec_popfds(void) -{ - int i; - t_exec *exec; - - exec = &data_singleton()->exec; - i = -1; - while (++i < 10) - pop(&exec->fd_save[i]); - return (0); -} - -int exec_reset(void) +int exec_destroy(t_exec *exec) { t_jobc *jobc; - t_exec *exec; - - exec = &data_singleton()->exec; - jobc = &data_singleton()->jobc; - exec_pushfds(); - exec->op_stack = NULL; - exec->fdin = STDIN; - exec->attrs = 0; - exec_reset_job(&exec->job); - jobc->first_job = NULL; - jobc->current_id = 1; - return (0); -} - -int exec_destroy(void) -{ int i; - t_jobc *jobc; - t_exec *exec; - exec = &data_singleton()->exec; jobc = &data_singleton()->jobc; ft_lstdel(&exec->op_stack, ft_lst_cfree); ft_lstdel(&jobc->first_job, job_free); i = -1; while (++i < 10) ft_lstdel(&exec->fd_save[i], ft_lst_cfree); + exec_init(exec); return (0); } diff --git a/42sh/src/exec/exec_init.c b/42sh/src/exec/exec_init.c new file mode 100644 index 00000000..59c30110 --- /dev/null +++ b/42sh/src/exec/exec_init.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exec_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/26 21:28:09 by jhalford #+# #+# */ +/* Updated: 2017/03/26 21:40:15 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int job_init(t_job *job) +{ + job->id = 0; + job->pgid = 0; + job->attrs = 0; + job->first_process = NULL; + tcgetattr(STDIN, &job->tmodes); + return (0); +} + +int exec_init(t_exec *exec) +{ + t_jobc *jobc; + int i; + + jobc = &data_singleton()->jobc; + i = -1; + while (++i < 10) + exec->fd_save[i] = NULL; + exec_pushfds(); + exec->op_stack = NULL; + exec->fdin = STDIN; + exec->attrs = 0; + job_init(&exec->job); + jobc->first_job = NULL; + jobc->current_id = 1; + return (0); +} diff --git a/42sh/src/exec/exec_popfds.c b/42sh/src/exec/exec_popfds.c new file mode 100644 index 00000000..39d8c6a1 --- /dev/null +++ b/42sh/src/exec/exec_popfds.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exec_popfds.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/26 21:31:05 by jhalford #+# #+# */ +/* Updated: 2017/03/26 21:31:24 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int exec_popfds(void) +{ + int i; + t_exec *exec; + + exec = &data_singleton()->exec; + i = -1; + while (++i < 10) + pop(&exec->fd_save[i]); + return (0); +} diff --git a/42sh/src/exec/exec_pushfds.c b/42sh/src/exec/exec_pushfds.c new file mode 100644 index 00000000..7f156b1b --- /dev/null +++ b/42sh/src/exec/exec_pushfds.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exec_pushfds.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/26 21:31:46 by jhalford #+# #+# */ +/* Updated: 2017/03/26 21:34:27 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int exec_pushfds(void) +{ + int i; + t_exec *exec; + + exec = &data_singleton()->exec; + i = -1; + while (++i < 10) + push(&(exec->fd_save[i]), fcntl(i, F_DUPFD_CLOEXEC, 10)); + return (0); +} diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 5a0b711b..14d5c134 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/24 20:02:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:39:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,7 @@ int process_fork(t_process *p) exit(1); process_setgroup(p, 0); process_setsig(); - exec_destroy(); - exec_reset(); + exec_destroy(&data_singleton()->exec); data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; exit(p->map.launch(p)); diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index d8911c0f..d1bb2df3 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/03/25 20:27:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:40:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,13 +19,13 @@ void data_exit(void) data = data_singleton(); ft_strdel(&data->line.input); ft_strdel(&data->binary); - /* exec_popfds(); */ + exec_popfds(); ft_sstrfree(data->env); ft_sstrfree(data->local_var); ft_sstrfree(data->argv); lexer_destroy(&data->lexer); parser_destroy(&data->parser); - exec_destroy(); + exec_destroy(&data->exec); ft_lstdel(&data->lst_func, &tree_func_free); ft_save_termios(-1); ft_free_hash_table(); diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 4b0a771c..07e91e6a 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/24 17:12:51 by wescande ### ########.fr */ +/* Updated: 2017/03/26 21:40:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -82,8 +82,8 @@ int data_init(int ac, char **av, char **env) return (-1); data->comp = NULL; data->opts = SH_INTERACTIVE | SH_OPTS_JOBC; - exec_reset(); data->lst_func = NULL; + exec_init(&data->exec); lexer_init(&data->lexer); parser_init(&data->parser); if ((term_name = ft_getenv(data->env, "TERM")) == NULL) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index e7f55e88..a86c1fa2 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ -/* Updated: 2017/03/25 20:12:37 by ariard ### ########.fr */ +/* Updated: 2017/03/26 21:37:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,7 +79,8 @@ int main(int ac, char **av, char **env) ret = handle_instruction(&token, &ast); lexer_destroy(&data->lexer); parser_destroy(&data->parser); - ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree); + exec_destroy(&data->exec); + /* ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree); */ ft_lstdel(&token, &token_free); btree_del(&ast, &ast_free); if (ret == 1) diff --git a/42sh/src/parser/parser_init.c b/42sh/src/parser/parser_init.c index 8f86e68c..e31e0e19 100644 --- a/42sh/src/parser/parser_init.c +++ b/42sh/src/parser/parser_init.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/21 16:14:04 by ariard #+# #+# */ -/* Updated: 2017/03/16 22:13:39 by ariard ### ########.fr */ +/* Updated: 2017/03/26 21:36:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/push_stack.c b/42sh/src/parser/push_stack.c index 3ab774c2..7f74703e 100644 --- a/42sh/src/parser/push_stack.c +++ b/42sh/src/parser/push_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 16:48:30 by ariard #+# #+# */ -/* Updated: 2017/03/18 19:15:39 by ariard ### ########.fr */ +/* Updated: 2017/03/26 21:35:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/stack_init.c b/42sh/src/parser/stack_init.c index a9ae3199..391ffce8 100644 --- a/42sh/src/parser/stack_init.c +++ b/42sh/src/parser/stack_init.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/16 20:31:32 by ariard #+# #+# */ -/* Updated: 2017/03/17 18:24:46 by ariard ### ########.fr */ +/* Updated: 2017/03/26 21:37:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ int stack_init(t_parser *parser) { - ft_lstdel(&parser->stack, NULL); + ft_lstdel(&parser->stack, ft_lst_cfree); + /* parser->stack = NULL; */ push_stack(&parser->stack, TERMINUS); push_stack(&parser->stack, LINEBREAK); if (!parser->new_sym && !(parser->new_sym = ft_memalloc(sizeof(t_sym)))) From 2bb33fe50c0b3042ef58b6291bb05807522e2f8c Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 26 Mar 2017 21:59:36 +0200 Subject: [PATCH 03/10] lst OK --- 42sh/libft/src/lst/ft_lstdel.c | 4 ++-- 42sh/src/exec/exec_destroy.c | 4 +++- 42sh/src/exec/exec_init.c | 2 +- 42sh/src/exec/process_launch.c | 2 +- 42sh/src/history/add_str_in_history.c | 2 +- 42sh/src/main/data_exit.c | 5 ++--- 42sh/src/main/data_init.c | 4 ++-- 42sh/src/main/main.c | 3 +-- 42sh/src/parser/parser_destroy.c | 2 +- 42sh/src/parser/stack_init.c | 4 +--- 10 files changed, 15 insertions(+), 17 deletions(-) diff --git a/42sh/libft/src/lst/ft_lstdel.c b/42sh/libft/src/lst/ft_lstdel.c index f60ae2d0..720dd7e9 100644 --- a/42sh/libft/src/lst/ft_lstdel.c +++ b/42sh/libft/src/lst/ft_lstdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:33:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:56:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { - if (!(alst || *alst || del)) + if (!(alst && *alst && del)) return ; ft_lstdel(&(*alst)->next, del); ft_lstdelone(alst, del); diff --git a/42sh/src/exec/exec_destroy.c b/42sh/src/exec/exec_destroy.c index bbbdace0..1f9a068a 100644 --- a/42sh/src/exec/exec_destroy.c +++ b/42sh/src/exec/exec_destroy.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:40:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:56:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,8 @@ int exec_destroy(t_exec *exec) t_jobc *jobc; int i; + if (!exec) + return (0); jobc = &data_singleton()->jobc; ft_lstdel(&exec->op_stack, ft_lst_cfree); ft_lstdel(&jobc->first_job, job_free); diff --git a/42sh/src/exec/exec_init.c b/42sh/src/exec/exec_init.c index 59c30110..62aec97d 100644 --- a/42sh/src/exec/exec_init.c +++ b/42sh/src/exec/exec_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/26 21:28:09 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:40:15 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:59:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 14d5c134..6949e955 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:39:39 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:50:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/history/add_str_in_history.c b/42sh/src/history/add_str_in_history.c index 0ccfaff2..bfb83140 100644 --- a/42sh/src/history/add_str_in_history.c +++ b/42sh/src/history/add_str_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */ -/* Updated: 2017/03/25 20:26:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:59:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index d1bb2df3..42e361c3 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:40:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:59:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,8 @@ void data_exit(void) t_data *data; data = data_singleton(); - ft_strdel(&data->line.input); + /* ft_strdel(&data->line.input); */ ft_strdel(&data->binary); - exec_popfds(); ft_sstrfree(data->env); ft_sstrfree(data->local_var); ft_sstrfree(data->argv); diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 07e91e6a..a554d48f 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:40:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:54:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,9 +83,9 @@ int data_init(int ac, char **av, char **env) data->comp = NULL; data->opts = SH_INTERACTIVE | SH_OPTS_JOBC; data->lst_func = NULL; - exec_init(&data->exec); lexer_init(&data->lexer); parser_init(&data->parser); + exec_init(&data->exec); if ((term_name = ft_getenv(data->env, "TERM")) == NULL) term_name = "dumb"; if (tgetent(NULL, term_name) != 1) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index a86c1fa2..73156a39 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ -/* Updated: 2017/03/26 21:37:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:57:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -80,7 +80,6 @@ int main(int ac, char **av, char **env) lexer_destroy(&data->lexer); parser_destroy(&data->parser); exec_destroy(&data->exec); - /* ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree); */ ft_lstdel(&token, &token_free); btree_del(&ast, &ast_free); if (ret == 1) diff --git a/42sh/src/parser/parser_destroy.c b/42sh/src/parser/parser_destroy.c index 02b4bf6e..0ca8ffcd 100644 --- a/42sh/src/parser/parser_destroy.c +++ b/42sh/src/parser/parser_destroy.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/16 19:30:17 by ariard #+# #+# */ -/* Updated: 2017/03/18 18:45:22 by ariard ### ########.fr */ +/* Updated: 2017/03/26 21:46:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/stack_init.c b/42sh/src/parser/stack_init.c index 391ffce8..67270a1c 100644 --- a/42sh/src/parser/stack_init.c +++ b/42sh/src/parser/stack_init.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/16 20:31:32 by ariard #+# #+# */ -/* Updated: 2017/03/26 21:37:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 21:47:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,6 @@ int stack_init(t_parser *parser) { - ft_lstdel(&parser->stack, ft_lst_cfree); - /* parser->stack = NULL; */ push_stack(&parser->stack, TERMINUS); push_stack(&parser->stack, LINEBREAK); if (!parser->new_sym && !(parser->new_sym = ft_memalloc(sizeof(t_sym)))) From d7ad419073237eba2d835709f525aa7c344623ba Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 26 Mar 2017 22:14:55 +0200 Subject: [PATCH 04/10] (ls) OK --- 42sh/Makefile | 4 ++-- 42sh/libft/src/lst/pop.c | 4 ++-- 42sh/src/exec/exec_destroy.c | 3 +-- 42sh/src/exec/exec_init.c | 8 ++++---- 42sh/src/exec/process_launch.c | 3 ++- 42sh/src/exec/process_set.c | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 1efb305d..d75d9774 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/25 20:26:47 by jhalford ### ########.fr # +# Updated: 2017/03/26 22:13:53 by jhalford ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror -fsanitize=address#-fvisibility=hidden +FLAGS = -Wall -Wextra -Werror D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/libft/src/lst/pop.c b/42sh/libft/src/lst/pop.c index 9e7d713d..05beda83 100644 --- a/42sh/libft/src/lst/pop.c +++ b/42sh/libft/src/lst/pop.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:56 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:25:05 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 22:14:17 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ int pop(t_list **lst) t_list *top; int item; - if (!(lst || *lst)) + if (!(lst && *lst)) return (0); top = *lst; item = top ? *(int*)top->content : 0; diff --git a/42sh/src/exec/exec_destroy.c b/42sh/src/exec/exec_destroy.c index 1f9a068a..28f092f8 100644 --- a/42sh/src/exec/exec_destroy.c +++ b/42sh/src/exec/exec_destroy.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:56:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 22:10:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,5 @@ int exec_destroy(t_exec *exec) i = -1; while (++i < 10) ft_lstdel(&exec->fd_save[i], ft_lst_cfree); - exec_init(exec); return (0); } diff --git a/42sh/src/exec/exec_init.c b/42sh/src/exec/exec_init.c index 62aec97d..4bcae2d2 100644 --- a/42sh/src/exec/exec_init.c +++ b/42sh/src/exec/exec_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/26 21:28:09 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:59:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 22:13:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,14 +28,14 @@ int exec_init(t_exec *exec) int i; jobc = &data_singleton()->jobc; + job_init(&exec->job); i = -1; while (++i < 10) exec->fd_save[i] = NULL; exec_pushfds(); - exec->op_stack = NULL; - exec->fdin = STDIN; exec->attrs = 0; - job_init(&exec->job); + exec->fdin = STDIN; + exec->op_stack = NULL; jobc->first_job = NULL; jobc->current_id = 1; return (0); diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 6949e955..5dfe74fc 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:50:39 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 22:13:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,7 @@ int process_fork(t_process *p) process_setgroup(p, 0); process_setsig(); exec_destroy(&data_singleton()->exec); + exec_init(&data_singleton()->exec); data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; exit(p->map.launch(p)); diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index be240f3f..42f94d69 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/24 19:19:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 22:14:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,10 +30,10 @@ static int process_set_spec(t_process *p, t_btree *ast) int i; t_astnode *item; - i = -1; if (!ast) return (0); item = ast->item; + i = -1; while (g_setprocessmap[++i].id) if (item->type == g_setprocessmap[i].id) { @@ -70,5 +70,5 @@ int process_set(t_process *p, t_btree *ast) if (ast) p->redirs = ft_lstmap( ((t_astnode *)ast->item)->data.cmd.redir, &redir_copy); - return ((!ast) ? 0 : process_set_spec(p, ast)); + return (process_set_spec(p, ast)); } From 24404435882dddf605626b96025d164801e914ea Mon Sep 17 00:00:00 2001 From: Gautier Wojda Date: Sun, 26 Mar 2017 22:21:05 +0200 Subject: [PATCH 05/10] fix history bugs with quotes --- 42sh/src/history/history_parsing.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/42sh/src/history/history_parsing.c b/42sh/src/history/history_parsing.c index 70372393..802e92e1 100644 --- a/42sh/src/history/history_parsing.c +++ b/42sh/src/history/history_parsing.c @@ -34,10 +34,22 @@ static int history_parsing_nb_and_previous(char *str, int *i) return (0); } +static int check_validity(char *str, int i) +{ + if (i && str[i - 1] == '\\') + return (0); + else if (str[i + 1] == '"') + return (0); + return (1); + +} + static int history_parsing_nb_and_name(char *str, int *i) { int tmp; + if (!check_validity(str, *i)) + return (0); if (history_parsing_nb_and_previous(str, i)) return (1); else if (ft_isdigit(str[(*i) + 1]) && (size_t)ft_atoi(str + (*i) + 1) < @@ -80,14 +92,18 @@ int ft_history_parsing(int has_prompt, char **input) { int i; char boolean; + char quote; i = 0; + quote = 0; boolean = 0; if (!data_singleton()->line.input) return (0); while (data_singleton()->line.input && data_singleton()->line.input[i]) { - if (data_singleton()->line.input[i] == '!') + if (data_singleton()->line.input[i] == '\'') + quote = quote ? 0 : 1; + else if (!quote && data_singleton()->line.input[i] == '!') { boolean = 1; if (!history_parsing_nb_and_name(data_singleton()->line.input, &i)) From 57406817c7504e587e25e56da0a426c30fe8583e Mon Sep 17 00:00:00 2001 From: Gautier Wojda Date: Sun, 26 Mar 2017 23:30:54 +0200 Subject: [PATCH 06/10] fix bugs et invalid read hist --- 42sh/src/history/history_parsing.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/42sh/src/history/history_parsing.c b/42sh/src/history/history_parsing.c index 802e92e1..2c7040f3 100644 --- a/42sh/src/history/history_parsing.c +++ b/42sh/src/history/history_parsing.c @@ -19,7 +19,7 @@ static int history_parsing_nb_and_previous(char *str, int *i) if (!ft_strncmp("!!", str + *i, 2)) { ft_realloc_str_history(&(data_singleton()->line.input), *i, 0, 2); - ++(*i); + (*i) += 2; return (1); } else if (str[*i + 1] == '-' && ft_isdigit(str[*i + 2]) && @@ -38,7 +38,7 @@ static int check_validity(char *str, int i) { if (i && str[i - 1] == '\\') return (0); - else if (str[i + 1] == '"') + else if (!str[i + 1] || str[i + 1] == '"') return (0); return (1); @@ -97,22 +97,21 @@ int ft_history_parsing(int has_prompt, char **input) i = 0; quote = 0; boolean = 0; - if (!data_singleton()->line.input) - return (0); while (data_singleton()->line.input && data_singleton()->line.input[i]) { if (data_singleton()->line.input[i] == '\'') quote = quote ? 0 : 1; - else if (!quote && data_singleton()->line.input[i] == '!') + if (!quote && data_singleton()->line.input[i] == '!') { boolean = 1; if (!history_parsing_nb_and_name(data_singleton()->line.input, &i)) boolean = 0; else - break ; + i = -1; } ++i; } + *input = data_singleton()->line.input; if (boolean) return (rematch_history_parsing(has_prompt, input)); return (0); From 31d0a2e5ed52384b5f0ba37f596faf45ffecff96 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 27 Mar 2017 01:03:57 +0200 Subject: [PATCH 07/10] close #200 --- 42sh/Makefile | 4 ++-- 42sh/libft/Makefile | 3 ++- 42sh/libft/includes/sys.h | 5 +++-- 42sh/libft/src/sys/fd_replace.c | 4 ++-- .../src/sys/{open_access.c => try_access.c} | 22 ++++++++----------- 42sh/src/exec/exec_destroy.c | 4 +--- 42sh/src/exec/exec_popfds.c | 9 ++++++-- 42sh/src/exec/exec_pushfds.c | 8 +++++-- 42sh/src/exec/fd_is_valid.c | 5 +++-- 42sh/src/exec/process_launch.c | 8 +++---- 42sh/src/exec/process_set.c | 12 +++++----- 42sh/src/exec/redirect_dgreat.c | 11 ++++++---- 42sh/src/exec/redirect_great.c | 7 +++--- 42sh/src/exec/redirect_less.c | 9 ++++---- 42sh/src/line_editing/ft_prompt.c | 3 ++- 42sh/src/main/data_exit.c | 6 ++++- 16 files changed, 67 insertions(+), 53 deletions(-) rename 42sh/libft/src/sys/{open_access.c => try_access.c} (64%) diff --git a/42sh/Makefile b/42sh/Makefile index d75d9774..36d1d3b0 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/26 22:13:53 by jhalford ### ########.fr # +# Updated: 2017/03/26 22:15:25 by jhalford ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror +FLAGS = -Wall -Wextra -Werror -fsanitize=address D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index 7d483cd1..0c0530f9 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -194,12 +194,13 @@ str/ft_strtok.c\ str/ft_strtrim.c\ sys/create_directory.c\ sys/dup2_close.c\ +sys/fd_minor.c\ sys/fd_replace.c\ sys/ft_getenv.c\ sys/ft_xattr_count.c\ sys/ft_xattr_print.c\ sys/is_directory.c\ -sys/open_access.c\ +sys/try_access.c\ time/ft_mytime_free.c\ time/ft_mytime_get.c\ time/ft_time_isrecent.c diff --git a/42sh/libft/includes/sys.h b/42sh/libft/includes/sys.h index b3c42e22..25f77020 100644 --- a/42sh/libft/includes/sys.h +++ b/42sh/libft/includes/sys.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */ -/* Updated: 2017/03/25 15:12:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 00:05:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,11 +33,12 @@ int ft_xattr_count(char *path); char *ft_getenv(char **env, char *key); -int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm); +int try_access(char *file, int exists, t_flag a_flag); int is_directory(const char *path); char *create_directory(const char *path, const char *old_pathnames); int dup2_close(int fd1, int fd2); int fd_replace(int fd1, int fd2); +int fd_minor(int fd, int minor); #endif diff --git a/42sh/libft/src/sys/fd_replace.c b/42sh/libft/src/sys/fd_replace.c index 495ae484..a3502c52 100644 --- a/42sh/libft/src/sys/fd_replace.c +++ b/42sh/libft/src/sys/fd_replace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */ -/* Updated: 2017/03/24 22:59:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 00:18:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,5 +16,5 @@ int fd_replace(int fd1, int fd2) { if (fd1 != fd2) return (dup2_close(fd1, fd2)); - return (0); + return (-1); } diff --git a/42sh/libft/src/sys/open_access.c b/42sh/libft/src/sys/try_access.c similarity index 64% rename from 42sh/libft/src/sys/open_access.c rename to 42sh/libft/src/sys/try_access.c index bc1ee88e..79335cd4 100644 --- a/42sh/libft/src/sys/open_access.c +++ b/42sh/libft/src/sys/try_access.c @@ -6,23 +6,19 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */ -/* Updated: 2017/03/25 15:07:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 22:36:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm) +int try_access(char *file, int exists, t_flag a_flag) { - int fd; - - if (a_flag & F_OK && access(file, F_OK) != 0) - return (-ERR_SET(E_SYS_NOFILE, file)); - if (is_directory(file)) - return (-ERR_SET(E_SYS_ISDIR, file)); - if (access(file, F_OK) == 0 && access(file, a_flag) != 0) - return (-ERR_SET(E_SYS_NOPERM, file)); - if ((fd = open(file, o_flag, o_perm)) < 0) - exit(1); - return (fd); + if (exists && access(file, F_OK) != 0) + return (ERR_SET(E_SYS_NOFILE, file) * 0 - 1); + else if (is_directory(file)) + return (ERR_SET(E_SYS_ISDIR, file) * 0 - 1); + else if (access(file, F_OK) == 0 && access(file, a_flag) != 0) + return (ERR_SET(E_SYS_NOPERM, file) * 0 - 1); + return (0); } diff --git a/42sh/src/exec/exec_destroy.c b/42sh/src/exec/exec_destroy.c index 28f092f8..e6e2b525 100644 --- a/42sh/src/exec/exec_destroy.c +++ b/42sh/src/exec/exec_destroy.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/26 22:10:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 00:33:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,5 @@ int exec_destroy(t_exec *exec) ft_lstdel(&exec->op_stack, ft_lst_cfree); ft_lstdel(&jobc->first_job, job_free); i = -1; - while (++i < 10) - ft_lstdel(&exec->fd_save[i], ft_lst_cfree); return (0); } diff --git a/42sh/src/exec/exec_popfds.c b/42sh/src/exec/exec_popfds.c index 39d8c6a1..d4fc942e 100644 --- a/42sh/src/exec/exec_popfds.c +++ b/42sh/src/exec/exec_popfds.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/26 21:31:05 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:31:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 00:58:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,11 +15,16 @@ int exec_popfds(void) { int i; + int fd; t_exec *exec; exec = &data_singleton()->exec; i = -1; while (++i < 10) - pop(&exec->fd_save[i]); + { + fd = pop(&exec->fd_save[i]); + if (fd != -1) + close(fd); + } return (0); } diff --git a/42sh/src/exec/exec_pushfds.c b/42sh/src/exec/exec_pushfds.c index 7f156b1b..31c16cde 100644 --- a/42sh/src/exec/exec_pushfds.c +++ b/42sh/src/exec/exec_pushfds.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/26 21:31:46 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:34:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 00:58:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,11 +15,15 @@ int exec_pushfds(void) { int i; + int fd; t_exec *exec; exec = &data_singleton()->exec; i = -1; while (++i < 10) - push(&(exec->fd_save[i]), fcntl(i, F_DUPFD_CLOEXEC, 10)); + { + fd = fcntl(i, F_DUPFD_CLOEXEC, 10); + push(&(exec->fd_save[i]), fd); + } return (0); } diff --git a/42sh/src/exec/fd_is_valid.c b/42sh/src/exec/fd_is_valid.c index ebf60e6d..67a1c7f1 100644 --- a/42sh/src/exec/fd_is_valid.c +++ b/42sh/src/exec/fd_is_valid.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 13:46:40 by jhalford #+# #+# */ -/* Updated: 2017/03/20 21:13:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 00:51:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,5 +19,6 @@ int fd_is_valid(int fd, int has_mode) fd_modes = fcntl(fd, F_GETFL); fd_flags = fcntl(fd, F_GETFD); - return ((fd_flags != -1 || errno != EBADF) && fd_modes & has_mode); + return ((fd_flags != -1 || errno != EBADF) + && (has_mode == -1 || fd_modes & has_mode)); } diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 5dfe74fc..bde46f83 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/26 22:13:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 01:01:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,10 +54,10 @@ int process_launch(t_process *p) { exec_pushfds(); p->map.launch(p); + exec_popfds(); + shell_resetfds(); + shell_resetsig(); } - exec_popfds(); - shell_resetfds(); - shell_resetsig(); process_free(p, 0); return (0); } diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index 42f94d69..cbb3d11a 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/26 22:14:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 00:10:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,15 +58,13 @@ int process_set(t_process *p, t_btree *ast) || (EXEC_IS_OR_IF(exec->attrs) && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)) return (1); - fds[PIPE_WRITE] = STDOUT; - fds[PIPE_READ] = STDIN; - (op == TK_PIPE) ? pipe(fds) : (0); exec->job.attrs |= (op == TK_AMP ? JOB_BG : 0); p->fdin = exec->fdin; - p->to_close = fds[PIPE_READ]; - p->fdout = fds[PIPE_WRITE]; + (op == TK_PIPE) ? pipe(fds) : (0); + p->fdout = (op == TK_PIPE) ? fds[PIPE_WRITE] : STDOUT; + exec->fdin = (op == TK_PIPE) ? fds[PIPE_READ] : STDIN; + p->to_close = exec->fdin; p->pid = 0; - exec->fdin = fds[PIPE_READ]; if (ast) p->redirs = ft_lstmap( ((t_astnode *)ast->item)->data.cmd.redir, &redir_copy); diff --git a/42sh/src/exec/redirect_dgreat.c b/42sh/src/exec/redirect_dgreat.c index 3e448fd8..a2d57f1c 100644 --- a/42sh/src/exec/redirect_dgreat.c +++ b/42sh/src/exec/redirect_dgreat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:07:37 by jhalford #+# #+# */ -/* Updated: 2017/03/25 01:54:05 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 22:36:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,9 +18,12 @@ int redirect_dgreat(t_redir *redir) int fdnew; fdnew = redir->n; - if ((fdold = open_access(redir->word, R_OK, - O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0) + fdnew = redir->n; + if ((try_access(redir->word, 0, W_OK))) return (ft_perror(NULL)); - dup2(fdold, fdnew); + if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0) + exit (1); + + fd_replace(fdold, fdnew); return (0); } diff --git a/42sh/src/exec/redirect_great.c b/42sh/src/exec/redirect_great.c index d0cc00a9..bea4de8d 100644 --- a/42sh/src/exec/redirect_great.c +++ b/42sh/src/exec/redirect_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ -/* Updated: 2017/03/25 02:25:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/26 22:36:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,9 +18,10 @@ int redirect_great(t_redir *redir) int fdnew; fdnew = redir->n; - if ((fdold = open_access(redir->word, R_OK, - O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) + if ((try_access(redir->word, 0, W_OK))) return (ft_perror(NULL)); + if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) + exit (1); fd_replace(fdold, fdnew); return (0); } diff --git a/42sh/src/exec/redirect_less.c b/42sh/src/exec/redirect_less.c index 390c91e9..0e24b2c7 100644 --- a/42sh/src/exec/redirect_less.c +++ b/42sh/src/exec/redirect_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */ -/* Updated: 2017/03/26 18:25:38 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 01:02:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,9 +18,10 @@ int redirect_less(t_redir *redir) int fdnew; fdnew = redir->n; - if ((fdold = open_access(redir->word, F_OK | W_OK, - O_RDONLY, 0)) < 0) + if ((try_access(redir->word, 1, R_OK)) != 0) return (ft_perror(NULL)); - dup2(fdold, fdnew); + if ((fdold = open(redir->word, O_RDONLY, 0644)) < 0) + exit (1); + fd_replace(fdold, fdnew); return (0); } diff --git a/42sh/src/line_editing/ft_prompt.c b/42sh/src/line_editing/ft_prompt.c index c4d0201e..3f12ed95 100644 --- a/42sh/src/line_editing/ft_prompt.c +++ b/42sh/src/line_editing/ft_prompt.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ -/* Updated: 2017/03/23 10:52:08 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 01:00:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ static int promt_git_status(int fd) char *line; get_next_line(fd, &line); + close(fd); tmp = line; if (ft_strrchr(line, '/')) line = ft_strdup(ft_strrchr(line, '/') + 1); diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index 42e361c3..fcebafba 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/03/26 21:59:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 00:36:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ void data_exit(void) { t_data *data; + int i; data = data_singleton(); /* ft_strdel(&data->line.input); */ @@ -25,6 +26,9 @@ void data_exit(void) lexer_destroy(&data->lexer); parser_destroy(&data->parser); exec_destroy(&data->exec); + i = -1; + while (++i < 10) + ft_lstdel(&data->exec.fd_save[i], ft_lst_cfree); ft_lstdel(&data->lst_func, &tree_func_free); ft_save_termios(-1); ft_free_hash_table(); From 8f34c0f318bdff302adf96e6427aed09443119e1 Mon Sep 17 00:00:00 2001 From: william Date: Mon, 27 Mar 2017 01:07:32 +0200 Subject: [PATCH 08/10] rectif match with ? --- 42sh/src/glob/match_pattern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/42sh/src/glob/match_pattern.c b/42sh/src/glob/match_pattern.c index 94cbed7d..7ac647e6 100644 --- a/42sh/src/glob/match_pattern.c +++ b/42sh/src/glob/match_pattern.c @@ -113,7 +113,7 @@ int match_pattern(t_glob *gl, char *str, char *full_word) if (*str != *gl->pat) return (0); } - else if (*gl->pat == '?') + else if (*gl->pat == '?' && *str) ; else if (*gl->pat == '[') { From af7f1868b9629e27c1d5cb09afde63eaf54acb8c Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 27 Mar 2017 01:52:44 +0200 Subject: [PATCH 09/10] compile --- 42sh/libft/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index 0c0530f9..088122d9 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -194,7 +194,6 @@ str/ft_strtok.c\ str/ft_strtrim.c\ sys/create_directory.c\ sys/dup2_close.c\ -sys/fd_minor.c\ sys/fd_replace.c\ sys/ft_getenv.c\ sys/ft_xattr_count.c\ From 6569be04bbec52654bd294f629a902074eff6147 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 27 Mar 2017 02:19:01 +0200 Subject: [PATCH 10/10] [lexer] :frog: close #202 --- 42sh/src/lexer/lexer_backslash.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index e9970a94..2a0a62c0 100644 --- a/42sh/src/lexer/lexer_backslash.c +++ b/42sh/src/lexer/lexer_backslash.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ -/* Updated: 2017/03/21 13:42:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 02:16:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,16 +17,14 @@ int lexer_backslash(t_list **alst, t_lexer *lexer) t_token *token; token = (*alst)->content; - token->type = token->type ? token->type : TK_WORD; - lexer->pos++; - lexer->state = WORD; - if (lexer->str[lexer->pos] == 0) + lexer->state = DEFAULT; + if (lexer->str[lexer->pos + 1] == 0) { - if (!*token->data) - ft_lst_delif(alst, token, &ft_addrcmp, &token_free); + lexer->str[lexer->pos] = 0; push(&lexer->stack, BACKSLASH); return (0); } + lexer->pos++; token_append(token, lexer, 1, 1); lexer->pos++; return (lexer_lex(alst, lexer));