diff --git a/42sh/42ShellTester/file b/42sh/42ShellTester/file new file mode 100644 index 00000000..13370648 --- /dev/null +++ b/42sh/42ShellTester/file @@ -0,0 +1,10 @@ +42ShellTester.sh +README.md +file +lib +log +minishell_error +spec +support +tasks +tmp diff --git a/42sh/42ShellTester/log b/42sh/42ShellTester/log new file mode 100644 index 00000000..975234a4 --- /dev/null +++ b/42sh/42ShellTester/log @@ -0,0 +1,164 @@ +.x........................xxxx....x. + +---------------------------------------------------------------- + +21sh/misc/002-simple-command-line (FAILED) + + Description: + The purpose of this test is to check that the Shell is able to execute a simple command line that contains separators `;`, pipes `|`, and a right redirection `>`. + + Before test: + 01: rm -rf "./size" + 02: rm -rf "TOKEN201703270303" + 03: echo '^'$(echo TOKEN201703270303_FILE_TOKEN201703270303_STDOUT | wc -c)'$' > "./size" + + STDIN: + 01: mkdir TOKEN201703270303 ; cd TOKEN201703270303 ; touch TOKEN201703270303_FILE ; ls -1 ; ls | cat | wc -c > TOKEN201703270303_STDOUT ; cat TOKEN201703270303_STDOUT + + STDOUT: + SUCCESS expected_to match_regex `TOKEN201703270303_FILE$` + FAILURE expected_to match_each_regex_of_file `./size` + 01: TOKEN201703270303_FILE + 02: 23 + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +21sh/redirections/outputs/truncating/multiple/002-together-stdout-first (FAILED) + + Description: + A right redirection can be associated to the twice outputs by using `M>&N`, that means `redirect M to where N is redirected`. + In this test the standard output is specified first. + + Before test: + 01: rm -f new_file_stderr_and_stdout + + STDIN: + 01: ./write_on_stdout_and_stderr TOKEN201703270303_1 TOKEN201703270303_2 1>new_file_stderr_and_stdout 2>&1 + + STDOUT: + SUCCESS expected_to_not match_regex `TOKEN201703270303_1` + SUCCESS expected_to_not match_regex `TOKEN201703270303_2` + (no output) + + STDERR: + SUCCESS expected_to_not match_regex `TOKEN201703270303_1` + SUCCESS expected_to_not match_regex `TOKEN201703270303_2` + (no output) + + MISC: + FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_1$` + SUCCESS expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_2$` + +---------------------------------------------------------------- + +21sh/redirections/outputs/truncating/multiple/003-together-stderr-first (FAILED) + + Description: + A right redirection can be associated to the twice outputs by using `M>&N`, that means `redirect M to where N is redirected`. + In this test the standard error is specified first. + + Before test: + 01: rm -f new_file_stderr_and_stdout + + STDIN: + 01: ./write_on_stdout_and_stderr TOKEN201703270303_1 TOKEN201703270303_2 2>new_file_stderr_and_stdout 1>&2 + + STDOUT: + SUCCESS expected_to_not match_regex `TOKEN201703270303_1` + SUCCESS expected_to_not match_regex `TOKEN201703270303_2` + (no output) + + STDERR: + SUCCESS expected_to_not match_regex `TOKEN201703270303_1` + SUCCESS expected_to_not match_regex `TOKEN201703270303_2` + (no output) + + MISC: + SUCCESS expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_1$` + FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_2$` + +---------------------------------------------------------------- + +21sh/redirections/outputs/truncating/multiple/004-together (FAILED) + + Description: + A right redirection can be associated to the twice outputs by using `&>...`, that means `redirect stdout and stderr to ...`. + + Before test: + 01: rm -f "new_file_stderr_and_stdout" + + STDIN: + 01: ./write_on_stdout_and_stderr TOKEN201703270303_1 TOKEN201703270303_2 &>new_file_stderr_and_stdout + + STDOUT: + FAILURE expected_to_not match_regex `TOKEN201703270303_1` + SUCCESS expected_to_not match_regex `TOKEN201703270303_2` + 01: TOKEN201703270303_1 + + STDERR: + SUCCESS expected_to_not match_regex `TOKEN201703270303_1` + FAILURE expected_to_not match_regex `TOKEN201703270303_2` + 01: TOKEN201703270303_2 + + MISC: + FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_1$` + FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_2$` + +---------------------------------------------------------------- + +21sh/redirections/outputs/truncating/multiple/005-together-with-whitespaces (FAILED) + + Description: + A right redirection can be associated to the twice outputs by using `&>...`, that means `redirect stdout and stderr to ...`. + In this test, we specify the file name in a separate field. + + Before test: + 01: rm -f new_file_stderr_and_stdout + + STDIN: + 01: ./write_on_stdout_and_stderr TOKEN201703270303_1 TOKEN201703270303_2 &> new_file_stderr_and_stdout + + STDOUT: + FAILURE expected_to_not match_regex `TOKEN201703270303_1` + SUCCESS expected_to_not match_regex `TOKEN201703270303_2` + 01: TOKEN201703270303_1 + + STDERR: + SUCCESS expected_to_not match_regex `TOKEN201703270303_1` + FAILURE expected_to_not match_regex `TOKEN201703270303_2` + 01: TOKEN201703270303_2 + + MISC: + FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_1$` + FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703270303_2$` + +---------------------------------------------------------------- + +21sh/separators/semicolon/003-parse-error-empty-inline-command (FAILED) + + Description: + The purpose of this test is to check that using the simicolon separator `;` with empty commands results in error. + + STDIN: + 01: ./write_on_stdout TOKEN201703270303 ; ; ./exit_with_status 42 + + STDOUT: + SUCCESS expected_to be_empty + (no output) + + STDERR: + SUCCESS expected_to_not be_empty + SUCCESS might match_regex `([Ss]yntax|[Pp]arse) error` + 01: syntax error near unexpected token `;' + + MISC: + SUCCESS expected_to_not exit_with_status `42` + FAILURE expected_to_not exit_with_status `0` + +Total tests: 36 +Total failed tests: 6 +Total pending tests: 0 diff --git a/42sh/Makefile b/42sh/Makefile index 7da7e17a..3841e2ea 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/27 02:54:02 by jhalford ### ########.fr # +# Updated: 2017/03/27 19:45:47 by jhalford ### ########.fr # # # # **************************************************************************** # @@ -78,8 +78,6 @@ 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\ @@ -197,6 +195,7 @@ job_control/job_update_id.c\ job_control/job_update_status.c\ job_control/job_wait.c\ job_control/jobc_destroy.c\ +job_control/jobc_init.c\ job_control/mark_job_as_running.c\ job_control/pprint_brace.c\ job_control/pprint_case.c\ @@ -227,6 +226,7 @@ lexer/insert_newline.c\ lexer/isrw_delim.c\ lexer/keep_last_type.c\ lexer/lexer_backslash.c\ +lexer/lexer_bang.c\ lexer/lexer_bquote.c\ lexer/lexer_curly_braces.c\ lexer/lexer_default.c\ @@ -284,8 +284,9 @@ main/data_exit.c\ main/data_init.c\ main/data_singleton.c\ main/main.c\ +main/shell_fds.c\ main/shell_init.c\ -main/shell_reset.c\ +main/shell_sig.c\ parser/add_bang.c\ parser/add_case.c\ parser/add_cmd.c\ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 935a279a..c2ac1d27 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/23 15:41:32 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 17:42:17 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,8 @@ # define KP_D 4348699 # define KP_L 4479771 # define KP_R 4414235 +# define KP_T 9 +# define KP_TS 5921563 /* ** Autocompletion list for the valid candidates from the parser. @@ -187,5 +189,6 @@ int ft_sstrlen(char **s); char *ft_sstrtostr(char **s, char *sep); char *ft_add_escape(char *str, char to_escape); void c_lst_id(t_comp *c); +char *c_strdupi(char *s, int (*f)(char)); #endif diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 3f0cdd7c..6a07c386 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/27 02:54:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:46:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -131,7 +131,6 @@ struct s_job struct s_exec { t_job job; - t_list *fd_save[10]; t_flag attrs; int fdin; t_list *op_stack; @@ -141,8 +140,6 @@ struct s_exec int exec_init(t_exec *exec); int exec_destroy(t_exec *exec); -int exec_pushfds(); -int exec_popfds(); int process_fork(t_process *p); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index e4412ffc..f08d88b2 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/23 16:16:57 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 18:00:07 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -134,6 +134,7 @@ int ft_nb_of_line(char *str, size_t pos); int ft_get_size_prev(char *str, size_t pos); void sigwinch_resize(int sig); size_t ft_hist_len(void); +int hist_is_delim(char c); int underline_right(char **str, size_t *pos, size_t pos_ref); int underline_left(char **str, size_t *pos, size_t pos_ref); diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 6d9a8b19..26262861 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/27 03:11:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 16:01:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,6 +35,7 @@ struct s_jobc struct termios shell_tmodes; }; +int jobc_init(t_jobc *jobc); int jobc_destroy(t_jobc *jobc); t_list *job_getprocess(pid_t pid); diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 93fa6b49..f52902bb 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/23 15:18:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:17:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,7 @@ enum e_lexstate HEREDOC, NEWLINE, DELIM, + BANG, SEP, WORD, NUMBER, @@ -99,6 +100,7 @@ int lexer_default(t_list **alst, t_lexer *lexer); int lexer_newline(t_list **alst, t_lexer *lexer); int lexer_heredoc(t_list **alst, t_lexer *lexer); int lexer_delim(t_list **alst, t_lexer *lexer); +int lexer_bang(t_list **alst, t_lexer *lexer); int lexer_sep(t_list **alst, t_lexer *lexer); int lexer_word(t_list **alst, t_lexer *lexer); int lexer_number(t_list **alst, t_lexer *lexer); diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 2488f600..0b755490 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/25 15:44:08 by ariard ### ########.fr */ +/* Updated: 2017/03/27 15:55:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,6 +48,7 @@ struct s_data char **argv; t_line line; t_lexer lexer; + t_list *fd_save[10]; t_parser parser; t_comp *comp; t_exec exec; @@ -64,8 +65,14 @@ int data_init(int ac, char **av, char **env); void data_exit(void); int get_c_arg(char *opt_arg, t_data *data); -void shell_resetfds(void); -void shell_resetsig(void); +void shell_sig_reset(void); + +void shell_fds_init(void); +void shell_fds_destroy(void); +int shell_fds_pop(void); +int shell_fds_push(void); +void shell_fds_reset(void); +void shell_fds_destroy(void); char *ft_putast(void *node); void ft_putast2(void *node); diff --git a/42sh/libft/includes/cliopts.h b/42sh/libft/includes/cliopts.h index cb8acc5d..b39d445b 100644 --- a/42sh/libft/includes/cliopts.h +++ b/42sh/libft/includes/cliopts.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* cliopts.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */ -/* Updated: 2017/03/25 21:31:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:46:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/lst/ft_lst_delif.c b/42sh/libft/src/lst/ft_lst_delif.c index 7580ea7d..768272b5 100644 --- a/42sh/libft/src/lst/ft_lst_delif.c +++ b/42sh/libft/src/lst/ft_lst_delif.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_lst_delif.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */ -/* Updated: 2017/03/13 15:36:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 17:45:01 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/sys/is_directory.c b/42sh/libft/src/sys/is_directory.c index accd92a4..98ca4bad 100644 --- a/42sh/libft/src/sys/is_directory.c +++ b/42sh/libft/src/sys/is_directory.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 01:40:31 by jhalford #+# #+# */ -/* Updated: 2017/03/25 01:42:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 16:58:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ int is_directory(const char *path) { struct stat path_stat; - stat(path, &path_stat); + if (stat(path, &path_stat) != 0) + return (0); return (S_ISDIR(path_stat.st_mode)); } diff --git a/42sh/libft/src/sys/try_access.c b/42sh/libft/src/sys/try_access.c index 729eed6d..7567c337 100644 --- a/42sh/libft/src/sys/try_access.c +++ b/42sh/libft/src/sys/try_access.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */ -/* Updated: 2017/03/27 02:54:39 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:46:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,10 +15,10 @@ int try_access(char *file, int exists, t_flag a_flag) { if (exists && access(file, F_OK) != 0) - return (ERR_SET(E_SYS_NOFILE, file) * 0 - 1); + return (ERR_SET(E_SYS_NOFILE, file)); else if (is_directory(file)) - return (ERR_SET(E_SYS_ISDIR, file) * 0 - 1); + return (ERR_SET(E_SYS_ISDIR, file)); else if (access(file, F_OK) == 0 && access(file, a_flag) != 0) - return (ERR_SET(E_SYS_NOPERM, file) * 0 - 1); + return (ERR_SET(E_SYS_NOPERM, file)); return (0); } diff --git a/42sh/sample/again.sh b/42sh/sample/again.sh new file mode 100644 index 00000000..1a85b88c --- /dev/null +++ b/42sh/sample/again.sh @@ -0,0 +1,2 @@ +echo "echo hello" >> sample/again.sh +echo hello diff --git a/42sh/sample/andor.sh b/42sh/sample/andor.sh new file mode 100644 index 00000000..76759a12 --- /dev/null +++ b/42sh/sample/andor.sh @@ -0,0 +1,8 @@ +pwd > file && pwd >> file || ls | cat && ls | cat >> file || ls +cat -e file + +sleep 2 +echo "My sample :" +echo +cat sample/andor.sh + diff --git a/42sh/sample/brace.sh b/42sh/sample/brace.sh new file mode 100644 index 00000000..6f0a47f3 --- /dev/null +++ b/42sh/sample/brace.sh @@ -0,0 +1,9 @@ +{ ls ; pwd } > file +cat -e file + +sleep 2 +echo +echo "My sample :" +sleep 2 +echo +cat sample/brace.sh diff --git a/42sh/sample/case.sh b/42sh/sample/case.sh new file mode 100644 index 00000000..420f2235 --- /dev/null +++ b/42sh/sample/case.sh @@ -0,0 +1,16 @@ +case toto in + ( tutu ) echo PERDU ;; + ( titi ) echo PERDU ;; + ( toto ) case lala in + ( lolo ) echo PERDU ;; + ( lala ) echo GAGNE ;; + esac ;; +esac > file +cat -e file + +sleep 2 +echo +echo "My sample :" +sleep 2 +echo +cat sample/case.sh diff --git a/42sh/sample/comment.sh b/42sh/sample/comment.sh new file mode 100644 index 00000000..e4d6764f --- /dev/null +++ b/42sh/sample/comment.sh @@ -0,0 +1,9 @@ +ls # Da comment +pwd + +sleep 2 +echo +echo "My sample :" +sleep 2 +echo +cat sample/comment.sh diff --git a/42sh/sample/eof.sh b/42sh/sample/eof.sh new file mode 100644 index 00000000..e7c86456 --- /dev/null +++ b/42sh/sample/eof.sh @@ -0,0 +1,3 @@ +while [ 1 ] +do + ls diff --git a/42sh/sample/for.sh b/42sh/sample/for.sh new file mode 100644 index 00000000..2d6dbe87 --- /dev/null +++ b/42sh/sample/for.sh @@ -0,0 +1,13 @@ +for i in src/*/*.c +do + echo $i | cat -e > file + cat -e file >> another_file + cat -e another_file +done + +sleep 2 +echo +echo "My sample :" +sleep 2 +echo +cat sample/for.sh diff --git a/42sh/sample/func.sh b/42sh/sample/func.sh new file mode 100644 index 00000000..585f90a0 --- /dev/null +++ b/42sh/sample/func.sh @@ -0,0 +1,14 @@ +hello() ( + hello() ( + echo hello ; hello ) + hello +) + +hello + +sleep 2 +echo +echo "My sample :" +sleep 2 +echo +cat sample/func.sh diff --git a/42sh/sample/if.sh b/42sh/sample/if.sh new file mode 100644 index 00000000..6364a745 --- /dev/null +++ b/42sh/sample/if.sh @@ -0,0 +1,25 @@ +if false +then + echo PERDU +elif false +then + echo PERDU +elif true +then + if false + then + echo PERDU + elif + echo GAGNE + fi > file +else + echo PERDU +fi +cat -e file + +sleep 2 +echo +echo "My sample :" +sleep 2 +echo +cat sample/if.sh diff --git a/42sh/sample/mix.sh b/42sh/sample/mix.sh new file mode 100644 index 00000000..9cfd3fc2 --- /dev/null +++ b/42sh/sample/mix.sh @@ -0,0 +1,30 @@ +VAR=10 +if true +then + echo "Salut" ; echo "Correcteur" + while [ $VAR -gt 0 ] + do + until true + do + echo KO SI JE M AFFICHE + done + if true + then + echo OK SI JE M AFFICHE + elif [ -f Makefile ] + then + echo KO SI JE M AFFICHE + else + echo KO SI JE M AFFICHE + fi + echo "Encore un tour" + math VAR - 1 + done +fi + +sleep 2 +echo +echo "My sample :" +sleep 3 +echo +cat sample/mix/mix.sh diff --git a/42sh/sample/muchloop.sh b/42sh/sample/muchloop.sh new file mode 100644 index 00000000..a4bd4192 --- /dev/null +++ b/42sh/sample/muchloop.sh @@ -0,0 +1,31 @@ +while [ 1 ] +do + while [ 1 ] + do + while [ 1 ] + do + while [ 1 ] + do + while [ 1 ] + do + while [ 1 ] + do + while [ 1 ] + do + while [ 1 ] + do + while [ 1 ] + do + while [ 1 ] + do + echo "SO MUCH LOOOOP" + done + done + done + done + done + done + done + done + done +done diff --git a/42sh/sample/script.sh b/42sh/sample/script.sh new file mode 100644 index 00000000..d45d0907 --- /dev/null +++ b/42sh/sample/script.sh @@ -0,0 +1,16 @@ +clear +YES=y +NO=n +echo "Welcome in 42Zash, new corrector, what is your login ?" + +until [ $REP == $YES ] +do + read -p "> " LOGIN + echo + read -p "Ok, fine, your login is $LOGIN, right ?(y/n) " REP + if [ $REP = $NO ] + then + echo + echo "Don't worry let's do it again" + fi +done diff --git a/42sh/sample/subshell.sh b/42sh/sample/subshell.sh new file mode 100644 index 00000000..8c386eed --- /dev/null +++ b/42sh/sample/subshell.sh @@ -0,0 +1,17 @@ +echo aaa \ + | (echo bbb 1; cat -e ;echo ccc 1) \ + | (echo bbb 2; cat -e ;echo ccc 2) \ + | (echo bbb 3; cat -e ;echo ccc 3) \ + | (echo bbb 4; cat -e ;echo ccc 4) \ + | (echo bbb 5; cat -e ;echo ccc 5) \ + | (echo bbb 6; cat -e ;echo ccc 6) \ + | (echo bbb 7; cat -e ;echo ccc 7) \ + | (echo bbb 8; cat -e ;echo ccc 8) \ + | (echo bbb 9; cat -e ;echo ccc 9) + + +sleep 2 +echo "My sample :" +echo +sleep 2 +cat sample/subshell.sh diff --git a/42sh/sample/toomuchdone.sh b/42sh/sample/toomuchdone.sh new file mode 100644 index 00000000..069b98ff --- /dev/null +++ b/42sh/sample/toomuchdone.sh @@ -0,0 +1,4 @@ +while [ 1 ] +do + ls +done done diff --git a/42sh/sample/until.sh b/42sh/sample/until.sh new file mode 100644 index 00000000..845b901e --- /dev/null +++ b/42sh/sample/until.sh @@ -0,0 +1,30 @@ +VAR1=0 +until [ $VAR1 -gt 10 ] +do + VAR2=0 + until [ $VAR2 -gt 10 ] + do + VAR3=0 + until [ $VAR3 -gt 10 ] + do + math VAR3 + 1 + echo "3rd is $VAR3" + done + math VAR2 + 1 + echo "2nd is $VAR2" + done + math VAR1 + 1 + echo "1st is $VAR1" + sleep 1 +done +echo +echo "VAR1: $VAR1" +echo "VAR2: $VAR2" +echo "VAR3: $VAR3" + +sleep 2 +echo +echo "My sample :" +sleep 2 +echo +cat sample/until.sh diff --git a/42sh/sample/var.sh b/42sh/sample/var.sh new file mode 100644 index 00000000..e1dca148 --- /dev/null +++ b/42sh/sample/var.sh @@ -0,0 +1,11 @@ +HELLO=WORLD HELLO=SALUT HELLO="BUENOS DIAS" +echo $HELLO +SALUT=$HELLO +echo $SALUT + +sleep 2 +echo +echo "My sample :" +sleep 2 +echo +cat sample/var.sh diff --git a/42sh/sample/while.sh b/42sh/sample/while.sh new file mode 100644 index 00000000..2f1448c6 --- /dev/null +++ b/42sh/sample/while.sh @@ -0,0 +1,24 @@ +VAR=10 +while + while [ $VAR -gt 0 ] + do + echo "Inside inner loop" | cat -e + math VAR - 1 + done + if [ $VAR -eq -42 ] + then + false + else + true + fi +do + echo "I'm the execution block" + VAR=-42 +done + +sleep 2 +echo +echo "My sample :" +sleep 3 +echo +cat sample/while.sh diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/src/builtin/builtin_cd.c index 5c95e860..c9e2228f 100644 --- a/42sh/src/builtin/builtin_cd.c +++ b/42sh/src/builtin/builtin_cd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 18:20:42 by ariard #+# #+# */ -/* Updated: 2017/03/26 14:11:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:45:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_env.c b/42sh/src/builtin/builtin_env.c index 73c3f826..ad5da964 100644 --- a/42sh/src/builtin/builtin_env.c +++ b/42sh/src/builtin/builtin_env.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */ -/* Updated: 2017/03/25 20:40:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:52:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,10 @@ int builtin_env(const char *path, (void)envp; if (bt_env_parse(&dat, (char**)argv)) + { + ft_sstrfree(dat.custom_env); return (ft_perror("env") && SH_ERR("usage: %s", ENV_USAGE)); + } if (!*dat.av_data) return (display_env(dat.custom_env)); else if ((pid = fork()) == 0) diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 0798eb5a..65a87bcc 100644 --- a/42sh/src/builtin/is_builtin.c +++ b/42sh/src/builtin/is_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ -/* Updated: 2017/03/25 16:36:55 by ariard ### ########.fr */ +/* Updated: 2017/03/27 16:03:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_find_env.c b/42sh/src/completion/c_find_env.c index 18686006..0ad450d1 100644 --- a/42sh/src/completion/c_find_env.c +++ b/42sh/src/completion/c_find_env.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ -/* Updated: 2017/03/23 19:07:56 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 18:50:23 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_match.c b/42sh/src/completion/c_match.c index 77fe9600..e41437e1 100644 --- a/42sh/src/completion/c_match.c +++ b/42sh/src/completion/c_match.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/03/23 19:02:28 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 18:51:59 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ static int c_is_delim(char c) return (0); } -static char *c_strdupi(char *s, int (*f)(char)) +char *c_strdupi(char *s, int (*f)(char)) { int i; char *str; diff --git a/42sh/src/completion/c_match_update.c b/42sh/src/completion/c_match_update.c index e9195ea9..bda1b63b 100644 --- a/42sh/src/completion/c_match_update.c +++ b/42sh/src/completion/c_match_update.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 12:03:30 by alao #+# #+# */ -/* Updated: 2017/03/22 12:25:26 by alao ### ########.fr */ +/* Updated: 2017/03/27 18:50:28 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,6 @@ static int c_refresh_match(t_comp *c, long int keypress) kpconv[1] = '\0'; tmp = c->match ? ft_strjoin(c->match, kpconv) : ft_strdup(kpconv); c->match ? ft_memdel((void *)&c->match) : (0); - c->match = ft_strdup(tmp); tmp ? ft_memdel((void *)&tmp) : (0); tmp = ft_strjoin(c->rcmd, kpconv); c->rcmd ? ft_memdel((void *)&c->rcmd) : (0); @@ -57,12 +56,12 @@ int c_rematch(t_comp *c, long int keypress) c_term_clear(c); c_refresh_match(c, keypress); c_clear_lst(c); + ft_print(keypress, &s->line.input, &s->line.pos); c_matching(s, c); if (s->comp && c->lst == NULL) c_clear(s); else if (s->comp && c->lst == c->lst->next) - return (1); - ft_print(keypress, &s->line.input, &s->line.pos); + return (ft_putchar('\b') + 1); return (1); } else diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index 2a5f7afb..c3fbae3e 100644 --- a/42sh/src/completion/completion.c +++ b/42sh/src/completion/completion.c @@ -6,18 +6,18 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/09/20 14:50:33 by alao #+# #+# */ -/* Updated: 2017/03/23 18:58:47 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 18:08:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" /* -** Function to select the next item in the list if it has already been created -** and if the key pressed is tab. +** Function to select the next or previous item in the list if it has already +** been created and if the key pressed is tab. */ -static void c_next_item(t_comp *c) +static void c_mv_tab(t_comp *c, int next) { t_clst *ptr; @@ -25,7 +25,10 @@ static void c_next_item(t_comp *c) while (!ptr->cursor) ptr = ptr->next; ptr->cursor = 0; - ptr->next->cursor = 1; + if (next) + ptr->next->cursor = 1; + else + ptr->prev->cursor = 1; } /* @@ -117,8 +120,8 @@ int completion(long int keypress) else { c_term_resize(s->comp); - if (keypress == TOUCHE_TAB) - c_next_item(s->comp); + if (keypress == KP_T || keypress == KP_TS) + keypress == KP_T ? c_mv_tab(s->comp, 1) : c_mv_tab(s->comp, 0); else if (c_keypress(s->comp, keypress)) return (1); } diff --git a/42sh/src/exec/exec_case_branch.c b/42sh/src/exec/exec_case_branch.c index 91fa3e1e..84dc6208 100644 --- a/42sh/src/exec/exec_case_branch.c +++ b/42sh/src/exec/exec_case_branch.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:33:45 by wescande #+# #+# */ -/* Updated: 2017/03/22 22:10:26 by ariard ### ########.fr */ +/* Updated: 2017/03/27 15:05:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,7 @@ int exec_case_branch(t_btree **ast) if (av && (ft_strcmp(av[0], ((char **)exec->case_pattern)[0]) == 0)) { exec->attrs |= EXEC_CASE_BRANCH; + ft_tabdel(&exec->case_pattern); ft_exec(&(*ast)->right); } ft_tabdel(&av); diff --git a/42sh/src/exec/exec_destroy.c b/42sh/src/exec/exec_destroy.c index f1d7c764..c01bae48 100644 --- a/42sh/src/exec/exec_destroy.c +++ b/42sh/src/exec/exec_destroy.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/27 03:09:58 by jhalford #+# #+# */ -/* Updated: 2017/03/27 03:10:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 15:56:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,9 @@ int exec_destroy(t_exec *exec) { if (!exec) - return (0); + return (1); ft_lstdel(&exec->op_stack, ft_lst_cfree); + exec->attrs = 0; + exec->fdin = STDIN; return (0); } diff --git a/42sh/src/exec/exec_init.c b/42sh/src/exec/exec_init.c index fc66168d..4491a770 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/27 02:55:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:46:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,19 +24,9 @@ int job_init(t_job *job) int exec_init(t_exec *exec) { - t_jobc *jobc; - int i; - - jobc = &data_singleton()->jobc; job_init(&exec->job); - i = -1; - while (++i < 10) - exec->fd_save[i] = NULL; - exec_pushfds(); exec->attrs = 0; exec->fdin = STDIN; exec->op_stack = NULL; - jobc->first_job = NULL; - jobc->current_id = 1; return (0); } diff --git a/42sh/src/exec/plaunch_builtin.c b/42sh/src/exec/plaunch_builtin.c index 93960d1a..1efa4ae8 100644 --- a/42sh/src/exec/plaunch_builtin.c +++ b/42sh/src/exec/plaunch_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/24 14:56:11 by wescande ### ########.fr */ +/* Updated: 2017/03/27 16:03:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_case.c b/42sh/src/exec/plaunch_case.c index 7c23b356..6c96e76e 100644 --- a/42sh/src/exec/plaunch_case.c +++ b/42sh/src/exec/plaunch_case.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ -/* Updated: 2017/03/22 22:00:16 by ariard ### ########.fr */ +/* Updated: 2017/03/27 15:06:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_file.c b/42sh/src/exec/plaunch_file.c index a9e66228..474bb30d 100644 --- a/42sh/src/exec/plaunch_file.c +++ b/42sh/src/exec/plaunch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/22 21:32:36 by wescande ### ########.fr */ +/* Updated: 2017/03/27 16:46:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,8 +28,8 @@ int plaunch_file(t_process *p) error_launch(p->data.cmd.av[0], ": is a directory", 126); else if (access(p->data.cmd.path, X_OK) == -1) error_launch("permission denied: ", p->data.cmd.av[0], 126); - (*p->data.cmd.execf)( - p->data.cmd.path, + shell_fds_destroy(); + execve(p->data.cmd.path, p->data.cmd.av, data_singleton()->env); error_launch("internal execve error on ", p->data.cmd.av[0], 42); diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 81ba525e..21c8bffe 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/27 02:54:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:45:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,21 +16,24 @@ int process_fork(t_process *p) { pid_t pid; + if (!p) + return (0); if ((pid = fork()) == -1) exit(SH_ERR("fork(): %s", strerror(errno))); - else if (pid) + else if (pid != 0) return (pid); - if (!p) - return (pid); - if (process_redirect(p)) - exit(1); - 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)); + jobc_destroy(&data_singleton()->jobc); + if ((pid = 1) && process_redirect(p) == 0) + { + shell_fds_push(); + process_setgroup(p, 0); + process_setsig(); + data_singleton()->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); + pid = p->map.launch(p); + } + shell_fds_destroy(); + exit(pid); } int process_launch(t_process *p) @@ -52,12 +55,12 @@ int process_launch(t_process *p) set_exitstatus(1, 1); else { - exec_pushfds(); + shell_fds_push(); p->map.launch(p); - exec_popfds(); - shell_resetfds(); - shell_resetsig(); + shell_fds_pop(); } + shell_fds_reset(); + shell_sig_reset(); process_free(p, 0); return (0); } diff --git a/42sh/src/exec/pset_case.c b/42sh/src/exec/pset_case.c index c439fb2e..20602607 100644 --- a/42sh/src/exec/pset_case.c +++ b/42sh/src/exec/pset_case.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/23 00:31:39 by ariard ### ########.fr */ +/* Updated: 2017/03/27 03:42:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_dgreat.c b/42sh/src/exec/redirect_dgreat.c index 323122a2..80a23adc 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/27 02:56:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:45:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_dless.c b/42sh/src/exec/redirect_dless.c index d8063a57..e204d3c3 100644 --- a/42sh/src/exec/redirect_dless.c +++ b/42sh/src/exec/redirect_dless.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 12:36:10 by jhalford #+# #+# */ -/* Updated: 2017/03/25 01:45:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:41:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,6 @@ int redirect_dless(t_redir *redir) str = redir->heredoc_data; write(fds[PIPE_WRITE], str, ft_strlen(str)); close(fds[PIPE_WRITE]); - dup2(fds[PIPE_READ], redir->n); - close(fds[PIPE_READ]); + fd_replace(fds[PIPE_READ], redir->n); return (0); } diff --git a/42sh/src/exec/redirect_great.c b/42sh/src/exec/redirect_great.c index 1eb17b37..c75cd2a0 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/27 02:56:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:45:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index 10c979ac..e241ba40 100644 --- a/42sh/src/exec/redirect_greatand.c +++ b/42sh/src/exec/redirect_greatand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */ -/* Updated: 2017/03/25 00:58:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 03:18:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ int redirect_greatand(t_redir *redir) if (fdold > 9) return (bad_fd(fdold)); if (fd_is_valid(fdold, O_WRONLY | O_RDWR)) - fd_replace(fdold, fdnew); + dup2(fdold, fdnew); else return (bad_fd(fdold)); return (0); diff --git a/42sh/src/exec/redirect_less.c b/42sh/src/exec/redirect_less.c index 92fa3ed5..3c2d72de 100644 --- a/42sh/src/exec/redirect_less.c +++ b/42sh/src/exec/redirect_less.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* redirect_less.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */ -/* Updated: 2017/03/27 02:56:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:44:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_lessand.c b/42sh/src/exec/redirect_lessand.c index 0f4f5928..1be9e62c 100644 --- a/42sh/src/exec/redirect_lessand.c +++ b/42sh/src/exec/redirect_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */ -/* Updated: 2017/03/21 16:33:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 03:18:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ int redirect_lessand(t_redir *redir) if (fdold > 9) return (bad_fd(fdold)); if (fd_is_valid(fdold, O_RDONLY | O_RDWR)) - fd_replace(fdold, fdnew); + dup2(fdold, fdnew); else return (bad_fd(fdold)); return (0); diff --git a/42sh/src/history/history_parsing.c b/42sh/src/history/history_parsing.c index b664743c..a459e0f9 100644 --- a/42sh/src/history/history_parsing.c +++ b/42sh/src/history/history_parsing.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */ -/* Updated: 2017/03/27 02:56:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:44:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -65,7 +65,7 @@ static int history_parsing_nb_and_name(char *str, int *i) ft_strdupi_w(str + *i + 2)); else if (str[*i + 1] && str[*i + 1] != ' ') ft_realloc_str_history_2(&(data_singleton()->line.input), *i, - ft_strdupi_w(str + *i + 1)); + c_strdupi(str + *i + 1, hist_is_delim)); else return (0); return (1); diff --git a/42sh/src/history/history_parsing_toolz.c b/42sh/src/history/history_parsing_toolz.c index 4c2f00b7..c6d0272f 100644 --- a/42sh/src/history/history_parsing_toolz.c +++ b/42sh/src/history/history_parsing_toolz.c @@ -6,12 +6,19 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 14:09:39 by gwojda #+# #+# */ -/* Updated: 2017/03/16 11:58:10 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 18:07:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +int hist_is_delim(char c) +{ + if (c == ' ' || c == '"') + return (1); + return (0); +} + static char *ft_nget_histo(size_t nb_his) { t_list_history *list; diff --git a/42sh/src/job_control/do_job_notification.c b/42sh/src/job_control/do_job_notification.c index b9536e8a..4fa661df 100644 --- a/42sh/src/job_control/do_job_notification.c +++ b/42sh/src/job_control/do_job_notification.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ -/* Updated: 2017/03/21 14:14:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 15:58:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_update_status.c b/42sh/src/job_control/job_update_status.c index 4467696e..8b00a02b 100644 --- a/42sh/src/job_control/job_update_status.c +++ b/42sh/src/job_control/job_update_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ -/* Updated: 2017/03/27 03:07:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 03:17:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,6 @@ void job_update_status(void) if ((pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG)) == -1 && errno != ECHILD) SH_ERR("waitpid(): %s", strerror(errno)); - DG("wait trigger pid=%i", pid); if (pid <= 1 || mark_process_status(pid, status)) break ; } diff --git a/42sh/src/job_control/jobc_destroy.c b/42sh/src/job_control/jobc_destroy.c index 2f86df98..068d1238 100644 --- a/42sh/src/job_control/jobc_destroy.c +++ b/42sh/src/job_control/jobc_destroy.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/27 03:09:41 by jhalford #+# #+# */ -/* Updated: 2017/03/27 03:10:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 15:59:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_popfds.c b/42sh/src/job_control/jobc_init.c similarity index 66% rename from 42sh/src/exec/exec_popfds.c rename to 42sh/src/job_control/jobc_init.c index d4fc942e..fd8fc134 100644 --- a/42sh/src/exec/exec_popfds.c +++ b/42sh/src/job_control/jobc_init.c @@ -1,30 +1,20 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* exec_popfds.c :+: :+: :+: */ +/* jobc_init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/26 21:31:05 by jhalford #+# #+# */ -/* Updated: 2017/03/27 00:58:34 by jhalford ### ########.fr */ +/* Created: 2017/03/27 15:59:03 by jhalford #+# #+# */ +/* Updated: 2017/03/27 16:01:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int exec_popfds(void) +int jobc_init(t_jobc *jobc) { - int i; - int fd; - t_exec *exec; - - exec = &data_singleton()->exec; - i = -1; - while (++i < 10) - { - fd = pop(&exec->fd_save[i]); - if (fd != -1) - close(fd); - } + jobc->first_job = NULL; + jobc->current_id = 1; return (0); } diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index aa08fe4e..b741215b 100644 --- a/42sh/src/lexer/get_state_global.c +++ b/42sh/src/lexer/get_state_global.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ -/* Updated: 2017/03/24 14:51:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:39:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,8 @@ t_lexstate get_state_global(t_lexer *lexer) cl = lexer->pos ? lexer->str[lexer->pos - 1] : 0; ret = 0; if ((ft_is_delim(c) && (ret = DELIM)) - || ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP)) + || ((c == '&' || c == ';' || c == '|') && (ret = SEP)) + || ((c == '!') && (ret = BANG)) || ((c == '\\') && (ret = BACKSLASH)) || ((c == '\n') && (ret = NEWLINE)) || ((c == '\'') && (ret = QUOTE)) diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index 2a0a62c0..bfcf5f5a 100644 --- a/42sh/src/lexer/lexer_backslash.c +++ b/42sh/src/lexer/lexer_backslash.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* lexer_backslash.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ -/* Updated: 2017/03/27 02:16:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:14:22 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_pushfds.c b/42sh/src/lexer/lexer_bang.c similarity index 55% rename from 42sh/src/exec/exec_pushfds.c rename to 42sh/src/lexer/lexer_bang.c index 31c16cde..9fc18aab 100644 --- a/42sh/src/exec/exec_pushfds.c +++ b/42sh/src/lexer/lexer_bang.c @@ -1,29 +1,32 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* exec_pushfds.c :+: :+: :+: */ +/* lexer_bang.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/26 21:31:46 by jhalford #+# #+# */ -/* Updated: 2017/03/27 00:58:25 by jhalford ### ########.fr */ +/* Created: 2017/03/27 18:12:03 by jhalford #+# #+# */ +/* Updated: 2017/03/27 18:53:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int exec_pushfds(void) +int lexer_bang(t_list **alst, t_lexer *lexer) { - int i; - int fd; - t_exec *exec; + t_token *token; - exec = &data_singleton()->exec; - i = -1; - while (++i < 10) + token = (*alst)->content; + if (!token->type || token->type == TK_SEMI || token->type == TK_NEWLINE + || token->type == TK_AMP) { - fd = fcntl(i, F_DUPFD_CLOEXEC, 10); - push(&(exec->fd_save[i]), fd); + token->type = TK_BANG; + lexer->state = DEFAULT; + lexer->pos++; + return (lexer_lex(&(*alst)->next, lexer)); } - return (0); + token->type = TK_WORD; + lexer->state = WORD; + lexer->pos++; + return (lexer_lex(alst, lexer)); } diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index 51e50643..7a8ce91b 100644 --- a/42sh/src/lexer/lexer_dquote.c +++ b/42sh/src/lexer/lexer_dquote.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ -/* Updated: 2017/03/24 16:08:35 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 18:52:15 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,11 +25,12 @@ int lexer_dquote(t_list **alst, t_lexer *lexer) else push(&lexer->stack, DQUOTE); } - else if (lexer->str[lexer->pos] == '\\') + else if (lexer->str[lexer->pos] == '\\' && lexer->str[lexer->pos + 1] == 0) { lexer->pos++; if (lexer->str[lexer->pos] == 0) return (push(&lexer->stack, BACKSLASH) ? 0 : 0); + token_append(token, lexer, 1, 0); } else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE)) return (lexer_lex(alst, lexer)); diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index 53cec923..180a01c9 100644 --- a/42sh/src/lexer/lexer_lex.c +++ b/42sh/src/lexer/lexer_lex.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ -/* Updated: 2017/03/22 18:13:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:13:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) = &lexer_heredoc, &lexer_newline, &lexer_delim, + &lexer_bang, &lexer_sep, &lexer_word, &lexer_number, diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index b7a5c67f..c0e1745f 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:23:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:11:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line_editing/copy_cut_paste/copy_cut_paste.c b/42sh/src/line_editing/copy_cut_paste/copy_cut_paste.c index cec171fb..6fb8f6c2 100644 --- a/42sh/src/line_editing/copy_cut_paste/copy_cut_paste.c +++ b/42sh/src/line_editing/copy_cut_paste/copy_cut_paste.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ -/* Updated: 2017/03/24 11:57:45 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 16:59:59 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -104,7 +104,7 @@ int ft_v(char **str, size_t *pos) } ft_current_str(*str, *pos); ft_get_next_str(*str, pos); - ft_putnc('\b', *pos - tmp_pos); + ft_putnc('\b', *pos - tmp_pos + (((*str)[*pos]) ? 1 : 0)); *pos = tmp_pos; return (0); } diff --git a/42sh/src/line_editing/ft_prompt.c b/42sh/src/line_editing/ft_prompt.c index 3f12ed95..61a355a9 100644 --- a/42sh/src/line_editing/ft_prompt.c +++ b/42sh/src/line_editing/ft_prompt.c @@ -19,7 +19,6 @@ 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); @@ -36,6 +35,7 @@ static int promt_git_status(int fd) ft_strdel(&tmp); while (get_next_line(fd, &tmp) > 0) ft_strdel(&tmp); + close(fd); ft_strdel(&tmp); return (len + 8); } diff --git a/42sh/src/line_editing/init_line/init_termcaps.c b/42sh/src/line_editing/init_line/init_termcaps.c index b8b2dbdb..475bf580 100644 --- a/42sh/src/line_editing/init_line/init_termcaps.c +++ b/42sh/src/line_editing/init_line/init_termcaps.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:33:41 by gwojda #+# #+# */ -/* Updated: 2017/03/21 18:11:13 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 17:37:40 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line_editing/readline.c b/42sh/src/line_editing/readline.c index 82856a6f..c88c7dfe 100644 --- a/42sh/src/line_editing/readline.c +++ b/42sh/src/line_editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/25 18:17:57 by ariard ### ########.fr */ +/* Updated: 2017/03/27 18:10:21 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index a012f2a7..781bffd1 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/27 03:12:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:44:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,6 @@ void data_exit(void) { t_data *data; - int i; data = data_singleton(); ft_strdel(&data->binary); @@ -26,9 +25,7 @@ void data_exit(void) parser_destroy(&data->parser); exec_destroy(&data->exec); jobc_destroy(&data->jobc); - i = -1; - while (++i < 10) - ft_lstdel(&data->exec.fd_save[i], ft_lst_cfree); + shell_fds_destroy(); 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 a554d48f..d8f7c41d 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:54:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:04:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,6 +66,15 @@ static int shlvl_inc(void) return (0); } +int modules_init(t_data *data) +{ + lexer_init(&data->lexer); + parser_init(&data->parser); + exec_init(&data->exec); + jobc_init(&data->jobc); + return (0); +} + int data_init(int ac, char **av, char **env) { t_data *data; @@ -80,12 +89,10 @@ int data_init(int ac, char **av, char **env) localenv_init(); if (shlvl_inc()) return (-1); + modules_init(data); data->comp = NULL; data->opts = SH_INTERACTIVE | SH_OPTS_JOBC; data->lst_func = NULL; - 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 73156a39..af0b020e 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:57:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:47:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_fds.c b/42sh/src/main/shell_fds.c new file mode 100644 index 00000000..97487b80 --- /dev/null +++ b/42sh/src/main/shell_fds.c @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* shell_fds.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/27 15:32:13 by jhalford #+# #+# */ +/* Updated: 2017/03/27 18:02:46 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void shell_fds_init(void) +{ + t_data *data; + int i; + + data = data_singleton(); + i = -1; + while (++i < 10) + data->fd_save[i] = NULL; +} + +int shell_fds_push(void) +{ + t_data *data; + int i; + int fd; + + data = data_singleton(); + i = -1; + while (++i < 10) + { + fd = fcntl(i, F_DUPFD_CLOEXEC, 10); + push(&(data->fd_save[i]), fd); + } + return (0); +} + +int shell_fds_pop(void) +{ + t_data *data; + int i; + int fd; + + data = data_singleton(); + i = -1; + while (++i < 10) + { + fd = pop(&data->fd_save[i]); + if (fd != -1) + close(fd); + } + return (0); +} + +void shell_fds_reset(void) +{ + t_data *data; + int i; + int fd; + + data = data_singleton(); + i = -1; + while (++i < 10) + { + fd = top(data->fd_save[i]); + if (fd != -1) + dup2(fd, i); + } +} + +void shell_fds_destroy(void) +{ + t_data *data; + int i; + + data = data_singleton(); + i = -1; + while (++i < 10) + ft_lstdel(&data->fd_save[i], ft_lst_cfree); +} diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 3da5594a..7cc06210 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/27 02:55:15 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 19:44:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ static int interactive_settings(void) while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp())) kill(-*shell_pgid, SIGTTIN); *shell_pgid = getpid(); - shell_resetsig(); + shell_sig_reset(); if (setpgid(*shell_pgid, *shell_pgid)) { SH_ERR("setpgid(): %s", strerror(errno)); @@ -99,5 +99,7 @@ int shell_init(int ac, char **av, char **env) return (-1); if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0) return (-1); + shell_fds_init(); + shell_fds_push(); return (0); } diff --git a/42sh/src/main/shell_reset.c b/42sh/src/main/shell_sig.c similarity index 68% rename from 42sh/src/main/shell_reset.c rename to 42sh/src/main/shell_sig.c index dca33bfd..01ced561 100644 --- a/42sh/src/main/shell_reset.c +++ b/42sh/src/main/shell_sig.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* shell_reset.c :+: :+: :+: */ +/* shell_sig_reset.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/22 16:07:14 by jhalford #+# #+# */ -/* Updated: 2017/03/24 20:09:29 by jhalford ### ########.fr */ +/* Created: 2017/03/27 15:35:01 by jhalford #+# #+# */ +/* Updated: 2017/03/27 15:35:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void shell_resetsig(void) +void shell_sig_reset(void) { signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); @@ -21,19 +21,3 @@ void shell_resetsig(void) signal(SIGTTOU, SIG_IGN); signal(SIGCHLD, SIG_DFL); } - -void shell_resetfds(void) -{ - t_exec *exec; - int i; - int fd; - - exec = &data_singleton()->exec; - i = -1; - while (++i < 10) - { - fd = top(exec->fd_save[i]); - if (fd != -1) - dup2(fd, i); - } -} diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index d589639d..7fc190fd 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ -/* Updated: 2017/03/24 23:26:22 by ariard ### ########.fr */ +/* Updated: 2017/03/27 17:23:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,6 +89,7 @@ static t_aggrematch g_aggrematch[] = {NEWLINE_LIST, TK_ELIF, TK_ELIF, TK_ELIF}, {NEWLINE_LIST, TK_ELSE, TK_ELSE, TK_ELSE}, {NEWLINE_LIST, TK_WHILE, TK_WHILE, TK_WHILE}, + {NEWLINE_LIST, LOOP, LOOP, LOOP}, {NEWLINE_LIST, TK_LBRACE, TK_LBRACE, TK_LBRACE}, {NEWLINE_LIST, TK_UNTIL, TK_UNTIL, TK_UNTIL}, {NEWLINE_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, @@ -148,6 +149,7 @@ static t_aggrematch g_aggrematch[] = {CMD_SUFFIX, CMD_WORD, SIMPLE_COMMAND, CMD_PREFIX}, {CMD_SUFFIX, CMD_NAME, SIMPLE_COMMAND, CMD_NAME}, {CMD_SUFFIX, CMD_SUPERIOR, CMD_SUPERIOR, CMD_SUPERIOR}, + {CMD_SUFFIX, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST}, {CMD_SUFFIX, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE}, {CMD_SUFFIX, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, {CMD_PREFIX, LINEBREAK, SIMPLE_COMMAND, 0}, diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index a8582698..94747a30 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:11:21 by ariard #+# #+# */ -/* Updated: 2017/03/24 23:26:06 by ariard ### ########.fr */ +/* Updated: 2017/03/27 17:29:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -605,6 +605,7 @@ static t_stackmatch g_stackmatch[] = {NEWLINE_LIST, FOR_WORDLIST}, {NEWLINE_LIST, TK_IN}, {NEWLINE_LIST, TK_WHILE}, + {NEWLINE_LIST, LOOP}, {NEWLINE_LIST, FUNC_NAME}, {NEWLINE_LIST, TK_UNTIL}, {NEWLINE_LIST, TK_IF}, diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index ab5feb97..3a989fb5 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/03/23 16:47:59 by ariard ### ########.fr */ +/* Updated: 2017/03/27 17:22:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,7 @@ static t_prodmatch g_prodmatch[] = {TK_ASSIGNMENT_WORD, NEWLINE_LIST, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, CMD_NAME, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, CMD_SUPERIOR, CMD_SUFFIX}, - {TK_ASSIGNMENT_WORD, COMPOUND_LIST, CMD_SUFFIX}, + {TK_ASSIGNMENT_WORD, COMPOUND_LIST, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, COMPLETE_CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, AND_OR, CMD_PREFIX}, @@ -94,6 +94,7 @@ static t_prodmatch g_prodmatch[] = {TK_NEWLINE, TK_RBRACE, CMD_NAME}, {TK_NEWLINE, TK_IN, NEWLINE_LIST}, {TK_NEWLINE, TK_WHILE, NEWLINE_LIST}, + {TK_NEWLINE, LOOP, NEWLINE_LIST}, {TK_NEWLINE, TK_UNTIL, NEWLINE_LIST}, {TK_NEWLINE, TK_FOR, NEWLINE_LIST}, {TK_NEWLINE, TK_IF, NEWLINE_LIST}, diff --git a/42sh/test/fifi b/42sh/test/fifi new file mode 100644 index 00000000..e69de29b