diff --git a/42sh/42ShellTester/file b/42sh/42ShellTester/file deleted file mode 100644 index 13370648..00000000 --- a/42sh/42ShellTester/file +++ /dev/null @@ -1,10 +0,0 @@ -42ShellTester.sh -README.md -file -lib -log -minishell_error -spec -support -tasks -tmp diff --git a/42sh/42ShellTester/log b/42sh/42ShellTester/log deleted file mode 100644 index bd9f852b..00000000 --- a/42sh/42ShellTester/log +++ /dev/null @@ -1,159 +0,0 @@ -.x..........................xx....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 "TOKEN201703271859" - 03: echo '^'$(echo TOKEN201703271859_FILE_TOKEN201703271859_STDOUT | wc -c)'$' > "./size" - - STDIN: - 01: mkdir TOKEN201703271859 ; cd TOKEN201703271859 ; touch TOKEN201703271859_FILE ; ls -1 ; ls | cat | wc -c > TOKEN201703271859_STDOUT ; cat TOKEN201703271859_STDOUT - - STDOUT: - FAILURE expected_to match_regex `TOKEN201703271859_FILE$` - FAILURE expected_to match_each_regex_of_file `./size` - (no output) - - STDERR: - SUCCESS expected_to be_empty - (no output) - ----------------------------------------------------------------- - -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 TOKEN201703271859_1 TOKEN201703271859_2 &>new_file_stderr_and_stdout - - STDOUT: - FAILURE expected_to_not match_regex `TOKEN201703271859_1` - SUCCESS expected_to_not match_regex `TOKEN201703271859_2` - 01: TOKEN201703271859_1 - - STDERR: - SUCCESS expected_to_not match_regex `TOKEN201703271859_1` - FAILURE expected_to_not match_regex `TOKEN201703271859_2` - 01: TOKEN201703271859_2 - - MISC: - FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703271859_1$` - FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703271859_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 TOKEN201703271859_1 TOKEN201703271859_2 &> new_file_stderr_and_stdout - - STDOUT: - FAILURE expected_to_not match_regex `TOKEN201703271859_1` - SUCCESS expected_to_not match_regex `TOKEN201703271859_2` - 01: TOKEN201703271859_1 - - STDERR: - SUCCESS expected_to_not match_regex `TOKEN201703271859_1` - FAILURE expected_to_not match_regex `TOKEN201703271859_2` - 01: TOKEN201703271859_2 - - MISC: - FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703271859_1$` - FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703271859_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 TOKEN201703271859 ; ; ./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: 4 -Total pending tests: 0 -38;5;160m(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 TOKEN201703271859_1 TOKEN201703271859_2 &> new_file_stderr_and_stdout - - STDOUT: - FAILURE expected_to_not match_regex `TOKEN201703271859_1` - SUCCESS expected_to_not match_regex `TOKEN201703271859_2` - 01: TOKEN201703271859_1 - - STDERR: - SUCCESS expected_to_not match_regex `TOKEN201703271859_1` - FAILURE expected_to_not match_regex `TOKEN201703271859_2` - 01: TOKEN201703271859_2 - - MISC: - FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703271859_1$` - FAILURE expected_to create_file `new_file_stderr_and_stdout` matching_regex `TOKEN201703271859_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 TOKEN201703271859 ; ; ./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: 4 -Total pending tests: 0 diff --git a/42sh/auteur b/42sh/auteur index b0e9923f..a68bfe60 100644 --- a/42sh/auteur +++ b/42sh/auteur @@ -1 +1 @@ -jhalford +wescande diff --git a/42sh/src/completion/c_match_update.c b/42sh/src/completion/c_match_update.c index 11ef0788..1d09528d 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/28 09:10:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 16:13:46 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 21c8bffe..ca41fa95 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 19:45:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 16:13:56 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,12 @@ 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 != 0) return (pid); + if (!p) + return (0); exec_destroy(&data_singleton()->exec); jobc_destroy(&data_singleton()->jobc); if ((pid = 1) && process_redirect(p) == 0) diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index 6c16b270..bd943423 100644 --- a/42sh/src/history/surch_in_history.c +++ b/42sh/src/history/surch_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ -/* Updated: 2017/03/20 14:09:01 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 12:22:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,6 +61,8 @@ static int ft_modify_str(char *str_srch, size_t srch_pos, char **str, *str = ft_strdup(*str); ft_current_str(*str, *pos); ft_get_next_str(*str, pos); + if ((*str)[*pos]) + ++(*pos); } free(str_srch); return (0); diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index 5076679c..922f1966 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/27 21:27:35 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 15:46:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,17 +19,16 @@ int lexer_dquote(t_list **alst, t_lexer *lexer) token = (*alst)->content; token->type = token->type ? token->type : TK_WORD; if (lexer->str[lexer->pos] == '"') + get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD) ? + pop(&lexer->stack) : push(&lexer->stack, DQUOTE) && 0; + else if (lexer->str[lexer->pos] == '\\') { - if (get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD)) - pop(&lexer->stack); - else - push(&lexer->stack, DQUOTE); - } - else if (lexer->str[lexer->pos] == '\\' && lexer->str[lexer->pos + 1] == 0) - { - lexer->pos++; - if (lexer->str[lexer->pos] == 0) + if (lexer->str[++lexer->pos] == 0) return (push(&lexer->stack, BACKSLASH) ? 0 : 0); + else if (lexer->str[lexer->pos] == '"') + token_append(token, lexer, 1, 1); + else + --lexer->pos; } else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE)) return (lexer_lex(alst, lexer)); diff --git a/42sh/src/line_editing/readline.c b/42sh/src/line_editing/readline.c index c88c7dfe..4e3170a8 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/27 18:10:21 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 14:57:13 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ int readline(int has_prompt, char **input) data_singleton()->line.prompt_size = 1; if (!SH_IS_INTERACTIVE(data_singleton()->opts)) { + ft_strdel(input); if ((ret = get_next_line(data_singleton()->fd, input)) >= 0) return (!ret); return (ret); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index f1565132..30e1f656 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/28 07:46:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 16:14:10 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,22 @@ static int do_readline_routine(char **stream) return (ret); } +static int exec_instruction(t_btree **ast, char **stream) +{ + t_data *data; + + data = data_singleton(); + if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str) + ft_add_str_in_history(data->lexer.str); + else + ft_strdel(stream); + if (data->parser.state == SUCCESS && ft_exec(ast) < 0) + exit(1); + else if (data->parser.state != SUCCESS) + set_exitstatus(1, 1); + return (0); +} + static int handle_instruction(t_list **token, t_btree **ast) { int ret; @@ -52,13 +68,7 @@ static int handle_instruction(t_list **token, t_btree **ast) else if (ret > 0) break ; } - if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str) - ft_add_str_in_history(data->lexer.str); - if (data->parser.state == SUCCESS && ft_exec(ast) < 0) - exit(1); - else if (data->parser.state != SUCCESS) - set_exitstatus(1, 1); - return (0); + return (exec_instruction(ast, &stream)); } int main(int ac, char **av, char **env)