From 5bafc74afe4d911bc02d503c7f27bfb190af2f48 Mon Sep 17 00:00:00 2001 From: gwojda Date: Tue, 28 Mar 2017 12:23:03 +0200 Subject: [PATCH 1/4] fix decalage d'un char sur control R + ligne avec retour a la ligne --- 42sh/src/history/surch_in_history.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); From 6d786aed3344a846d9f4c8d0d26f0a165fd86ccc Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Tue, 28 Mar 2017 15:47:05 +0200 Subject: [PATCH 2/4] correctif escaped dquote inside dquote --- 42sh/src/lexer/lexer_dquote.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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)); From 0dbba0e11483fd77a454df5eabfa59638514a952 Mon Sep 17 00:00:00 2001 From: wescande Date: Tue, 28 Mar 2017 16:02:16 +0200 Subject: [PATCH 3/4] rectif leaks sample + rectif bquote --- 42sh/src/exec/process_launch.c | 6 +++--- 42sh/src/line_editing/readline.c | 3 ++- 42sh/src/main/main.c | 26 ++++++++++++++++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 9e82b20b..9ea29b09 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 16:46:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 15:36:13 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/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 aa624bd2..b4d0e4cd 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/27 20:57:57 by ariard ### ########.fr */ +/* Updated: 2017/03/28 16:00:36 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) From 8979cab11c7aa3c5d7d3c759385ceabf4747919a Mon Sep 17 00:00:00 2001 From: wescande Date: Tue, 28 Mar 2017 16:09:58 +0200 Subject: [PATCH 4/4] NORME --- 42sh/src/completion/c_match_update.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/42sh/src/completion/c_match_update.c b/42sh/src/completion/c_match_update.c index 9b5bbde5..e8f0ea68 100644 --- a/42sh/src/completion/c_match_update.c +++ b/42sh/src/completion/c_match_update.c @@ -6,13 +6,13 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 12:03:30 by alao #+# #+# */ -/* Updated: 2017/03/28 08:14:15 by alao ### ########.fr */ +/* Updated: 2017/03/28 16:09:08 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" -static char *c_current_words(void) +static char *c_current_words(void) { size_t pos; char *str;