From dc0fc094f4760255310599c63e31ca39d48943b8 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Wed, 22 Mar 2017 18:22:17 +0100 Subject: [PATCH 1/3] brackets resolution --- 42sh/includes/types.h | 4 +--- 42sh/src/parser/aggregate_sym.c | 7 +++---- 42sh/src/parser/eval_sym.c | 5 ++--- 42sh/src/parser/produce_sym.c | 10 +++++----- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 4ee154f1..bb9e85b5 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:30:06 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:15:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -196,8 +196,6 @@ enum e_sym OPEN_FUNC, CLOSE_FUNC, CLOSE_LIST, - SEMI_SUBSHELL, - SEMI_BRACE, REDIR, CMD, HEREDOCDATA, diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 5e8450bc..fbc02382 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/22 16:54:58 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:13:04 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,7 +38,8 @@ t_aggrematch g_aggrematch[] = {TK_DONE, COMPOUND_LIST, DO_GROUP, TK_DO}, {TK_ESAC, TK_IN, CASE_CLAUSE, TK_CASE}, {TK_ESAC, CASE_LIST_NS, CASE_CLAUSE, TK_CASE}, - {TK_PAREN_CLOSE, SEMI_SUBSHELL, SUBSHELL, TK_PAREN_OPEN}, + {TK_PAREN_CLOSE, SUBSHELL, SUBSHELL, TK_PAREN_OPEN}, +// {TK_PAREN_CLOSE, SEMI_SUBSHELL, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, COMPOUND_LIST, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, CMD_SUPERIOR, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, PIPE_SEMI_SEQUENCE, SUBSHELL, TK_PAREN_OPEN}, @@ -221,9 +222,7 @@ t_aggrematch g_aggrematch[] = {COMPOUND_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {CLOSE_LIST, PATTERN, CASE_LIST_NS, PATTERN_CASE}, {CLOSE_LIST, FUNC_NAME, FUNCTION_DEFINITION, FUNC_NAME}, - {SUBSHELL, TK_PAREN_OPEN, SEMI_SUBSHELL, 0}, {SUBSHELL, ALL, COMPOUND_COMMAND, 0}, - {BRACE_CLAUSE, TK_LBRACE, SEMI_BRACE, 0}, {BRACE_CLAUSE, ALL, COMPOUND_COMMAND, 0}, {COMPOUND_COMMAND, FUNC_NAME, COMMAND, FUNC_NAME}, {AND_OR_MINOR, PIPE_SEMI_SEQUENCE, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE}, diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 82db6598..1ebd22ee 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/22 16:56:05 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:14:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -578,7 +578,7 @@ t_stackmatch g_stackmatch[] = {TK_PAREN_CLOSE, COMPOUND_LIST}, {TK_PAREN_CLOSE, FUNC_NAME}, {TK_PAREN_CLOSE, OPEN_FUNC}, - {TK_PAREN_CLOSE, SEMI_SUBSHELL}, + {TK_PAREN_CLOSE, SUBSHELL}, {TK_RBRACE, TK_SEMI}, {TK_RBRACE, END_COMMAND}, {TK_RBRACE, SEPARATOR_OP}, @@ -1048,7 +1048,6 @@ t_stackmatch g_stackmatch[] = {SUBSHELL, COMPLETE_CONDITION}, {SUBSHELL, CONDITION}, {SUBSHELL, AND_OR_MAJOR}, - {SEMI_SUBSHELL, TK_PAREN_OPEN}, {COMPOUND_COMMAND, LINEBREAK}, {COMPOUND_COMMAND, TK_PAREN_OPEN}, {COMPOUND_COMMAND, TK_LBRACE}, diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 090b39cd..a7aceda1 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/22 16:34:24 by ariard ### ########.fr */ +/* Updated: 2017/03/22 18:15:08 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,14 +68,14 @@ t_prodmatch g_prodmatch[] = {TK_ASSIGNMENT_WORD, TK_ELIF, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, TK_ELSE, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, NEWLINE_LIST, CMD_PREFIX}, - {TK_ASSIGNMENT_WORD, CMD_NAME, CMD_PREFIX}, - {TK_ASSIGNMENT_WORD, CMD_SUPERIOR, CMD_PREFIX}, - {TK_ASSIGNMENT_WORD, COMPOUND_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, COMPLETE_CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, AND_OR, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, AND_OR_MAJOR, CMD_PREFIX}, - {TK_ASSIGNMENT_WORD, PIPE_SEMI_SEQUENCE, CMD_PREFIX}, + {TK_ASSIGNMENT_WORD, PIPE_SEMI_SEQUENCE, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, SEQUENCE, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, COMPLETE_COMMANDS, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, CMD_WORD, CMD_SUFFIX}, From 2d42874c482ae05363fbfbb365c48eb288b8902d Mon Sep 17 00:00:00 2001 From: M600 Date: Wed, 22 Mar 2017 18:24:21 +0100 Subject: [PATCH 2/3] Completion: Output spaced name with escape char --- 42sh/includes/completion.h | 3 +- 42sh/src/completion/c_misc.c | 51 +++++++++++++++++++++++++++++++++- 42sh/src/completion/c_output.c | 7 +++-- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index b2b62c12..7ce7db9e 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/17 17:23:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 18:19:43 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -185,5 +185,6 @@ char *path_solver(t_comp *c, char *cmd, char *cwd); int c_exclusion_folder(t_comp *c); int ft_sstrlen(char **s); char *ft_sstrtostr(char **s, char *sep); +char *ft_add_escape(char *str, char to_escape); #endif diff --git a/42sh/src/completion/c_misc.c b/42sh/src/completion/c_misc.c index 92dd2101..1a979b1d 100644 --- a/42sh/src/completion/c_misc.c +++ b/42sh/src/completion/c_misc.c @@ -6,12 +6,61 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/16 22:17:10 by alao #+# #+# */ -/* Updated: 2017/03/17 16:51:53 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 18:23:04 by alao ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +/* +** Count the number of time char c is in str. +*/ + +static size_t ft_strxchr(char *str, char c) +{ + size_t rt; + + rt = 0; + while(*str) + { + if (*str == c) + rt++; + str++; + } + return (rt); +} + +/* +** Add escape char \ for char to_escape. +*/ + +char *ft_add_escape(char *str, char to_escape) +{ + char *rt; + int i; + int j; + + if (!str) + return (NULL); + if (!ft_strxchr(str, ' ')) + return (ft_strdup(str)); + rt = ft_strnew(ft_strlen(str) + ft_strxchr(str, to_escape)); + i = 0; + j = 0; + while (str[i]) + { + if (str[i] == to_escape) + { + i++; + rt[j++] = '\\'; + rt[j++] = ' '; + } + else + rt[j++] = str[i++]; + } + return (rt); +} + /* ** Support: Return the size of a char**. */ diff --git a/42sh/src/completion/c_output.c b/42sh/src/completion/c_output.c index c4aead28..ed2a512d 100644 --- a/42sh/src/completion/c_output.c +++ b/42sh/src/completion/c_output.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 13:10:38 by alao #+# #+# */ -/* Updated: 2017/03/21 14:37:14 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 18:20:29 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,19 +53,22 @@ int c_updater(t_comp *c, char *select) { char *tmp; char *rt; + char *alter; tmp = NULL; rt = NULL; + alter = ft_add_escape(select, ' '); if (c->match) tmp = ft_strsub(c->rcmd, 0, ft_strlen(c->rcmd) - ft_strlen(c->match)); else tmp = ft_strdup(c->rcmd); - rt = ft_strjoin(tmp, select); + rt = ft_strjoin(tmp, alter); tmp ? ft_memdel((void *)&tmp) : (0); c->rcmd ? ft_memdel((void *)&c->rcmd) : (0); c->rcmd = ft_strdup(rt); c_updater_rcmd(c); rt ? ft_memdel((void *)&rt) : (0); + alter ? ft_memdel((void *)&alter) : (0); c_clear(data_singleton()); return (1); } From 16e23e8a632f8e588549391ad27306ec63c7fe3e Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Wed, 22 Mar 2017 19:35:02 +0100 Subject: [PATCH 3/3] close #150 --- 42sh/src/exec/pfree_func.c | 3 +-- 42sh/src/exec/plaunch_function.c | 6 +++--- 42sh/src/main/main.c | 3 +-- 42sh/src/parser/add_func.c | 6 ++++-- 42sh/src/parser/aggregate_sym.c | 7 +------ 42sh/src/parser/eval_sym.c | 3 +-- 42sh/src/parser/produce_sym.c | 2 +- 7 files changed, 12 insertions(+), 18 deletions(-) diff --git a/42sh/src/exec/pfree_func.c b/42sh/src/exec/pfree_func.c index 98e5fe2f..b8a467b7 100644 --- a/42sh/src/exec/pfree_func.c +++ b/42sh/src/exec/pfree_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/21 20:18:34 by ariard #+# #+# */ -/* Updated: 2017/03/21 20:53:45 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:25:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int pfree_func(t_process *p) { - ft_putstr("hello"); btree_del(&p->data.function.content, &ast_free); return (0); } diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index 6a41a54a..0d5364de 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,13 +6,13 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/22 16:22:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 19:30:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached\n" +#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached" int plaunch_function(t_process *p) { @@ -36,6 +36,6 @@ int plaunch_function(t_process *p) builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", ft_itoa(value), 0}, NULL); ft_exec(&p->data.function.content); - DG(); + builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", "0", 0}, NULL); return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 23405356..60194ede 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/22 17:44:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:00:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,6 @@ static int handle_instruction(t_list **token, t_btree **ast) return (ret); if (do_lexer_routine(token, stream) > 0) continue ; - token_print(*token); if ((ret = do_parser_routine(token, ast)) == 1 && SH_NO_INTERACTIVE(data->opts)) return (ret); diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index f6b1c456..3e4988f4 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/03/22 16:52:57 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 19:21:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -100,7 +100,7 @@ t_list *is_already_func(t_btree **new) ret = (new_name && new_name[0] && old_name && old_name[0] && !ft_strcmp(new_name[0], old_name[0])) ? 0 : 1; ft_tabdel(&old_name); - tmp = tmp->next; + tmp = (ret) ? tmp->next : tmp; } ft_tabdel(&new_name); if (!ret) @@ -116,8 +116,10 @@ int add_one_func(t_btree **ast, t_list **lst) (void)lst; func_ast = btree_map(*ast, &node_copy); if ((old_func = is_already_func(&func_ast))) + { ft_lst_delif(&data_singleton()->lst_func, old_func->content, &ft_addrcmp, &tree_func_free); + } ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); return (0); } diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index fbc02382..21b6a56f 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/22 18:13:04 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:00:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -381,20 +381,15 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) return (1); i = -1; head = (*stack)->content; - DG("aggregate head %s && sym %s", - read_state(*head), read_state(*new_sym)); while (g_aggrematch[++i].top) if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) { - - DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); head = (*stack)->content; - DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym) && !(*state = ERROR)) return (1); diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 1ebd22ee..40ff2389 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/22 18:14:39 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:00:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -1272,7 +1272,6 @@ int eval_sym(t_list **stack, t_sym new_sym) return (1); head = (*stack)->content; i = 0; - DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); while (g_stackmatch[i].top) { if (new_sym == g_stackmatch[i].top && *head == g_stackmatch[i].under) diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index a7aceda1..b2e3f4c8 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/22 18:15:08 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:26:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */