From 8b5c742002ee48002334303ed03bd2440845c9d6 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 23 Mar 2017 15:19:41 +0100 Subject: [PATCH 1/6] bquotes inside dquotes lexing --- 42sh/Makefile | 1 + 42sh/includes/lexer.h | 3 ++- 42sh/src/lexer/get_lexer_stack2.c | 21 +++++++++++++++++++++ 42sh/src/lexer/lexer_bquote.c | 5 +++-- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 42sh/src/lexer/get_lexer_stack2.c diff --git a/42sh/Makefile b/42sh/Makefile index 10862470..715952e6 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -214,6 +214,7 @@ job_control/sigttin_handler.c\ job_control/sigttou_handler.c\ lexer/do_lexer_routine.c\ lexer/get_lexer_stack.c\ +lexer/get_lexer_stack2.c\ lexer/get_reserved_words.c\ lexer/get_state_global.c\ lexer/get_state_redir.c\ diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 91ec40ae..93fa6b49 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/22 22:07:49 by wescande ### ########.fr */ +/* Updated: 2017/03/23 15:18:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,6 +85,7 @@ char *stack_to_prompt(t_list *stack); t_lexstate get_state_global(t_lexer *lexer); t_lexstate get_state_redir(t_lexer *lexer); int get_lexer_stack(t_lexer lexer); +int get_lexer_stack2(t_lexer lexer); int get_reserved_words(t_list *temp); int isrw_delim(t_type type); int keep_last_type(t_type *type, t_list *token); diff --git a/42sh/src/lexer/get_lexer_stack2.c b/42sh/src/lexer/get_lexer_stack2.c new file mode 100644 index 00000000..015ae3a4 --- /dev/null +++ b/42sh/src/lexer/get_lexer_stack2.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_lexer_stack2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/23 15:15:46 by jhalford #+# #+# */ +/* Updated: 2017/03/23 15:19:00 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int get_lexer_stack2(t_lexer lexer) +{ + if (!(lexer.stack && lexer.stack->next)) + return (0); + return (*(int*)lexer.stack->next->content); +} + diff --git a/42sh/src/lexer/lexer_bquote.c b/42sh/src/lexer/lexer_bquote.c index 88f5af97..c2749334 100644 --- a/42sh/src/lexer/lexer_bquote.c +++ b/42sh/src/lexer/lexer_bquote.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */ -/* Updated: 2017/03/23 03:41:34 by wescande ### ########.fr */ +/* Updated: 2017/03/23 15:17:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,8 @@ int lexer_bquote(t_list **alst, t_lexer *lexer) if (lexer->str[lexer->pos] == 0) return (push(&lexer->stack, BACKSLASH) ? 0 : 0); } - token_append(token, lexer, back || token->type == TK_ASSIGNMENT_WORD, back); + token_append(token, lexer, back || token->type == TK_ASSIGNMENT_WORD + || get_lexer_stack2(*lexer) == DQUOTE, back); lexer->pos++; return (lexer_lex(alst, lexer)); } From 6935bc80dbb751c584d4408c2fd3260584184ed1 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 23 Mar 2017 15:36:59 +0100 Subject: [PATCH 2/6] =?UTF-8?q?completion=20tri=C3=A9e=20#168?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 42sh/libft/src/sstr/ft_sstrsort.c | 4 +-- 42sh/src/completion/c_find_env.c | 4 ++- 42sh/src/completion/c_parser.c | 46 +++++++++++++++++++++++++------ 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/42sh/libft/src/sstr/ft_sstrsort.c b/42sh/libft/src/sstr/ft_sstrsort.c index 180d4ea0..25cf4134 100644 --- a/42sh/libft/src/sstr/ft_sstrsort.c +++ b/42sh/libft/src/sstr/ft_sstrsort.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_sstrsort.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:37 by jhalford #+# #+# */ -/* Updated: 2016/11/23 14:46:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 14:40:25 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_find_env.c b/42sh/src/completion/c_find_env.c index f93297ff..07be72e8 100644 --- a/42sh/src/completion/c_find_env.c +++ b/42sh/src/completion/c_find_env.c @@ -6,12 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ -/* Updated: 2017/03/22 12:29:40 by alao ### ########.fr */ +/* Updated: 2017/03/23 15:35:59 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +void c_lst_id(t_comp *c); /* ** Create a new list node and add it by calling c_add_to_lst. */ @@ -50,5 +51,6 @@ int c_seek_env(t_comp *c, char *current_word) c_addnode(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i])); ++i; } + c_lst_id(c); return (0); } diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index 49721404..dc8d8ce7 100644 --- a/42sh/src/completion/c_parser.c +++ b/42sh/src/completion/c_parser.c @@ -6,33 +6,62 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:52:07 by alao #+# #+# */ -/* Updated: 2017/03/21 14:46:39 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 15:34:53 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +void c_lst_id(t_comp *c) +{ + t_clst *lst; + int i; + + i = 1; + lst = c->lst; + if (!lst) + return ; + lst->cursor = 1; + if (!lst) + return ; + while (1) + { + lst->id = i; + lst = lst->next; + ++i; + if (lst == c->lst) + break ; + } +} /* ** Add the matching element to the list */ void c_add_to_lst(t_comp *c, t_clst *node) { + t_clst *lst; + + lst = c->lst; if (c->lst == NULL) { c->lst = node; node->next = node; node->prev = node; - node->cursor = 1; - node->id = 1; } else { - node->id = c->lst->prev->id + 1; - c->lst->prev->next = node; - node->prev = c->lst->prev; - node->next = c->lst; - c->lst->prev = node; + while (ft_strcmp(lst->name, node->name) < 0) + { + lst = lst->next; + if (lst == c->lst) + break ; + } + lst->prev->next = node; + node->prev = lst->prev; + node->next = lst; + lst->prev = node; + if (lst == c->lst && ft_strcmp(lst->name, node->name) > 0) + c->lst = node; } } @@ -77,5 +106,6 @@ int c_parser(t_comp *c, char *path, char *name) while ((dirc = readdir(rep))) c_storing(c, dirc->d_name, dirc->d_type); closedir(rep); + c_lst_id(c); return (0); } From 809791f46e029a35f877b5e1278fb8c876aa689d Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 23 Mar 2017 15:43:54 +0100 Subject: [PATCH 3/6] fix pb sur le tri completion --- 42sh/includes/completion.h | 3 ++- 42sh/src/completion/c_find_abspath.c | 3 ++- 42sh/src/completion/c_find_binary.c | 3 ++- 42sh/src/completion/c_find_env.c | 3 +-- 42sh/src/completion/c_find_files.c | 3 ++- 42sh/src/completion/c_parser.c | 3 +-- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 7ce7db9e..935a279a 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/22 18:19:43 by alao ### ########.fr */ +/* Updated: 2017/03/23 15:41:32 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -186,5 +186,6 @@ 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); +void c_lst_id(t_comp *c); #endif diff --git a/42sh/src/completion/c_find_abspath.c b/42sh/src/completion/c_find_abspath.c index 9d2da32d..de4d0a44 100644 --- a/42sh/src/completion/c_find_abspath.c +++ b/42sh/src/completion/c_find_abspath.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */ -/* Updated: 2017/03/22 20:25:19 by alao ### ########.fr */ +/* Updated: 2017/03/23 15:42:37 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,4 +37,5 @@ void c_seek_abs_path(t_comp *c, char *current_word) c_parser(c, c->cpath, c->match); if (c->lst == NULL || c->lst == c->lst->prev) c_exclusion_folder(c); + c_lst_id(c); } diff --git a/42sh/src/completion/c_find_binary.c b/42sh/src/completion/c_find_binary.c index 61c6efd5..88ad164e 100644 --- a/42sh/src/completion/c_find_binary.c +++ b/42sh/src/completion/c_find_binary.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:30:57 by alao #+# #+# */ -/* Updated: 2017/03/16 08:28:03 by alao ### ########.fr */ +/* Updated: 2017/03/23 15:41:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,5 +35,6 @@ int c_seek_binary(t_data *s, t_comp *c) c_parser(c, paths[i++], c->rcmd); tmp ? ft_memdel((void *)&tmp) : (0); paths ? ft_sstrfree(paths) : (0); + c_lst_id(c); return (0); } diff --git a/42sh/src/completion/c_find_env.c b/42sh/src/completion/c_find_env.c index 07be72e8..a80c60db 100644 --- a/42sh/src/completion/c_find_env.c +++ b/42sh/src/completion/c_find_env.c @@ -6,13 +6,12 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ -/* Updated: 2017/03/23 15:35:59 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 15:41:19 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" -void c_lst_id(t_comp *c); /* ** Create a new list node and add it by calling c_add_to_lst. */ diff --git a/42sh/src/completion/c_find_files.c b/42sh/src/completion/c_find_files.c index 6052b698..854d3b49 100644 --- a/42sh/src/completion/c_find_files.c +++ b/42sh/src/completion/c_find_files.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:31:21 by alao #+# #+# */ -/* Updated: 2017/03/22 16:02:18 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 15:42:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -105,5 +105,6 @@ int c_seek_files(t_data *s, t_comp *c, char *current_word) if (c->match && ft_strequ(c->match, c->lst->name)) c_exclusion_folder(c); } + c_lst_id(c); return (0); } diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index dc8d8ce7..94b2ad1e 100644 --- a/42sh/src/completion/c_parser.c +++ b/42sh/src/completion/c_parser.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:52:07 by alao #+# #+# */ -/* Updated: 2017/03/23 15:34:53 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 15:42:30 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -106,6 +106,5 @@ int c_parser(t_comp *c, char *path, char *name) while ((dirc = readdir(rep))) c_storing(c, dirc->d_name, dirc->d_type); closedir(rep); - c_lst_id(c); return (0); } From 061daad09c5f55e3e151e9291274ed2e4d42d039 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 23 Mar 2017 16:29:48 +0100 Subject: [PATCH 4/6] norme --- 42sh/includes/ft_readline.h | 17 ++++-- 42sh/includes/job_control.h | 4 +- 42sh/src/completion/c_misc.c | 10 ++-- 42sh/src/completion/c_parser.c | 3 +- 42sh/src/lexer/get_lexer_stack2.c | 5 +- .../copy_cut_paste/copy_cut_paste.c | 57 +++++++++---------- .../copy_cut_paste/underline_down.c | 5 +- .../copy_cut_paste/underline_end.c | 5 +- .../copy_cut_paste/underline_home.c | 5 +- .../copy_cut_paste/underline_left.c | 10 ++-- .../copy_cut_paste/underline_right.c | 10 ++-- .../copy_cut_paste/underline_up.c | 5 +- 12 files changed, 75 insertions(+), 61 deletions(-) diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 41bb2d9c..e4412ffc 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 11:45:05 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:16:57 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -88,7 +88,14 @@ typedef struct s_key int (*f)(char **str, size_t *pos); } t_key; +typedef struct s_cpy +{ + int value; + int (*f)(char **str, size_t *pos, size_t pos_ref); +} t_cpy; + extern t_key g_keys[]; +extern t_cpy g_cpy[]; void ft_reset_tab(char *tabl); void ft_putnc(char c, int n); @@ -130,13 +137,13 @@ size_t ft_hist_len(void); int underline_right(char **str, size_t *pos, size_t pos_ref); int underline_left(char **str, size_t *pos, size_t pos_ref); -void underline_home(char **str, size_t *pos, size_t pos_ref); -void underline_end(char **str, size_t *pos, size_t pos_ref); +int underline_home(char **str, size_t *pos, size_t pos_ref); +int underline_end(char **str, size_t *pos, size_t pos_ref); +int underline_down(char **str, size_t *pos, size_t pos_ref); +int underline_up(char **str, size_t *pos, size_t pos_ref); void underline_check_end_of_line(char *str, size_t pos); void reset_term(char **str, size_t *pos); void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp); -void underline_down(char **str, size_t *pos, size_t pos_ref); -void underline_up(char **str, size_t *pos, size_t pos_ref); int ft_read_stdin(char **input); diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 8840d4b0..8396bca3 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* job_control.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:24:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 16:13:56 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_misc.c b/42sh/src/completion/c_misc.c index 1a979b1d..0535d8f3 100644 --- a/42sh/src/completion/c_misc.c +++ b/42sh/src/completion/c_misc.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/16 22:17:10 by alao #+# #+# */ -/* Updated: 2017/03/22 18:23:04 by alao ### ########.fr */ +/* Updated: 2017/03/23 16:11:29 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ static size_t ft_strxchr(char *str, char c) size_t rt; rt = 0; - while(*str) + while (*str) { if (*str == c) rt++; @@ -34,7 +34,7 @@ static size_t ft_strxchr(char *str, char c) ** Add escape char \ for char to_escape. */ -char *ft_add_escape(char *str, char to_escape) +char *ft_add_escape(char *str, char to_escape) { char *rt; int i; @@ -65,7 +65,7 @@ char *ft_add_escape(char *str, char to_escape) ** Support: Return the size of a char**. */ -int ft_sstrlen(char **s) +int ft_sstrlen(char **s) { int i; @@ -79,7 +79,7 @@ int ft_sstrlen(char **s) ** Support: Tranform a char** as char* with char*sep in between. */ -char *ft_sstrtostr(char **s, char *sep) +char *ft_sstrtostr(char **s, char *sep) { char *tmp; char *tmp2; diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index 94b2ad1e..0625ad20 100644 --- a/42sh/src/completion/c_parser.c +++ b/42sh/src/completion/c_parser.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:52:07 by alao #+# #+# */ -/* Updated: 2017/03/23 15:42:30 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:12:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,6 +33,7 @@ void c_lst_id(t_comp *c) break ; } } + /* ** Add the matching element to the list */ diff --git a/42sh/src/lexer/get_lexer_stack2.c b/42sh/src/lexer/get_lexer_stack2.c index 015ae3a4..ff1c56d6 100644 --- a/42sh/src/lexer/get_lexer_stack2.c +++ b/42sh/src/lexer/get_lexer_stack2.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* get_lexer_stack2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/23 15:15:46 by jhalford #+# #+# */ -/* Updated: 2017/03/23 15:19:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 16:12:26 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,4 +18,3 @@ int get_lexer_stack2(t_lexer lexer) return (0); return (*(int*)lexer.stack->next->content); } - 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 f76a8635..508d73f5 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,16 +6,28 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ -/* Updated: 2017/03/23 11:44:51 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:28:01 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +t_cpy g_cpy[] = +{ + {FLECHE_GAUCHE , &underline_left }, + {FLECHE_DROITE , &underline_right }, + {FLECHE_HAUT , &underline_up }, + {FLECHE_BAS , &underline_down }, + {TOUCHE_HOME , &underline_home }, + {TOUCHE_END , &underline_end }, + {0 , 0 }, +}; + int ft_x(char **str, size_t *pos) { - int ret; size_t pos_ref; + int ret; + int i; pos_ref = *pos; ft_strdel(&data_singleton()->line.copy_tmp); @@ -25,21 +37,14 @@ int ft_x(char **str, size_t *pos) while (42) { ret = 0; + i = 0; if (read(STDIN, &ret, sizeof(int)) < 0) return (-1); - if (ret == FLECHE_GAUCHE && !underline_left(str, pos, pos_ref)) - return (0); - else if (ret == FLECHE_DROITE && !underline_right(str, pos, pos_ref)) - return (0); - else if (ret == TOUCHE_HOME) - underline_home(str, pos, pos_ref); - else if (ret == TOUCHE_END) - underline_end(str, pos, pos_ref); - else if (ret == FLECHE_HAUT) - underline_up(str, pos, pos_ref); - else if (ret == FLECHE_BAS) - underline_down(str, pos, pos_ref); - else if (ret != FLECHE_DROITE && ret != FLECHE_GAUCHE) + while (g_cpy[i].value && g_cpy[i].value != ret) + ++i; + if (g_cpy[i].value && (ret = g_cpy[i].f(str, pos, pos_ref))) + return (ret); + else break ; } if (data_singleton()->line.copy_tmp && *data_singleton()->line.copy_tmp) @@ -49,8 +54,9 @@ int ft_x(char **str, size_t *pos) int ft_c(char **str, size_t *pos) { - int ret; size_t pos_ref; + int ret; + int i; pos_ref = *pos; ft_strdel(&data_singleton()->line.copy_tmp); @@ -60,21 +66,14 @@ int ft_c(char **str, size_t *pos) while (42) { ret = 0; + i = 0; if (read(STDIN, &ret, sizeof(int)) < 0) return (-1); - if (ret == FLECHE_GAUCHE && !underline_left(str, pos, pos_ref)) - return (0); - else if (ret == FLECHE_DROITE && !underline_right(str, pos, pos_ref)) - return (0); - else if (ret == TOUCHE_HOME) - underline_home(str, pos, pos_ref); - else if (ret == TOUCHE_END) - underline_end(str, pos, pos_ref); - else if (ret == FLECHE_HAUT) - underline_up(str, pos, pos_ref); - else if (ret == FLECHE_BAS) - underline_down(str, pos, pos_ref); - else if (ret != FLECHE_DROITE && ret != FLECHE_GAUCHE) + while (g_cpy[i].value && g_cpy[i].value != ret) + ++i; + if (g_cpy[i].value && (ret = g_cpy[i].f(str, pos, pos_ref))) + return (ret); + else if (!g_cpy[i].value) break ; } reset_term(str, pos); diff --git a/42sh/src/line_editing/copy_cut_paste/underline_down.c b/42sh/src/line_editing/copy_cut_paste/underline_down.c index 5d6a1c85..68011b25 100644 --- a/42sh/src/line_editing/copy_cut_paste/underline_down.c +++ b/42sh/src/line_editing/copy_cut_paste/underline_down.c @@ -6,13 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/23 11:43:40 by gwojda #+# #+# */ -/* Updated: 2017/03/23 11:45:20 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:21:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void underline_down(char **str, size_t *pos, size_t pos_ref) +int underline_down(char **str, size_t *pos, size_t pos_ref) { size_t pos_tmp; int i; @@ -36,4 +36,5 @@ void underline_down(char **str, size_t *pos, size_t pos_ref) underline_left(str, pos, pos_ref); --pos_tmp; } + return (0); } diff --git a/42sh/src/line_editing/copy_cut_paste/underline_end.c b/42sh/src/line_editing/copy_cut_paste/underline_end.c index c43e9ce5..6c08cd23 100644 --- a/42sh/src/line_editing/copy_cut_paste/underline_end.c +++ b/42sh/src/line_editing/copy_cut_paste/underline_end.c @@ -6,13 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 23:18:15 by gwojda #+# #+# */ -/* Updated: 2017/03/22 23:42:27 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:21:53 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void underline_end(char **str, size_t *pos, size_t pos_ref) +int underline_end(char **str, size_t *pos, size_t pos_ref) { size_t pos_tmp; @@ -32,4 +32,5 @@ void underline_end(char **str, size_t *pos, size_t pos_ref) underline_left(str, pos, pos_ref); --pos_tmp; } + return (0); } diff --git a/42sh/src/line_editing/copy_cut_paste/underline_home.c b/42sh/src/line_editing/copy_cut_paste/underline_home.c index 0c6fe355..e1153a65 100644 --- a/42sh/src/line_editing/copy_cut_paste/underline_home.c +++ b/42sh/src/line_editing/copy_cut_paste/underline_home.c @@ -6,13 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 23:11:05 by gwojda #+# #+# */ -/* Updated: 2017/03/22 23:44:44 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:22:01 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void underline_home(char **str, size_t *pos, size_t pos_ref) +int underline_home(char **str, size_t *pos, size_t pos_ref) { size_t pos_tmp; @@ -29,4 +29,5 @@ void underline_home(char **str, size_t *pos, size_t pos_ref) --pos_tmp; } *pos = pos_tmp; + return (0); } diff --git a/42sh/src/line_editing/copy_cut_paste/underline_left.c b/42sh/src/line_editing/copy_cut_paste/underline_left.c index 0d3cd41a..7bd01924 100644 --- a/42sh/src/line_editing/copy_cut_paste/underline_left.c +++ b/42sh/src/line_editing/copy_cut_paste/underline_left.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 22:54:28 by gwojda #+# #+# */ -/* Updated: 2017/03/22 23:08:58 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:25:19 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ static int reset_term_hard(void) ft_putnc('\b', ft_strlen(data_singleton()->line.copy_tmp)); ft_strdel(&data_singleton()->line.copy_tmp); data_singleton()->line.pos_tmp = 0; - return (0); + return (1); } static void left_abs(char **str, size_t *pos) @@ -27,10 +27,12 @@ static void left_abs(char **str, size_t *pos) ft_putchar('\b'); data_singleton()->line.pos_tmp = 0; ft_puttermcaps("mr"); + ft_putstr("\x1b[38;5;196m"); data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()-> line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); ft_putchar((*str)[*pos]); underline_check_end_of_line(*str, *pos + 1); + ft_putstr("\033[22;37m"); ft_puttermcaps("me"); ft_putchar('\b'); } @@ -51,12 +53,12 @@ static void left_mv_back(char **str, size_t *pos) int underline_left(char **str, size_t *pos, size_t pos_ref) { if (!*pos) - return (1); + return (0); if ((*str)[*pos - 1] == '\n') return (reset_term_hard()); if (*pos > pos_ref) left_mv_back(str, pos); else left_abs(str, pos); - return (1); + return (0); } diff --git a/42sh/src/line_editing/copy_cut_paste/underline_right.c b/42sh/src/line_editing/copy_cut_paste/underline_right.c index 6a7f8f32..ebb42684 100644 --- a/42sh/src/line_editing/copy_cut_paste/underline_right.c +++ b/42sh/src/line_editing/copy_cut_paste/underline_right.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 22:50:52 by gwojda #+# #+# */ -/* Updated: 2017/03/23 10:59:04 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:25:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,15 +18,17 @@ static int reset_term_hard(void) ft_putstr(data_singleton()->line.copy_tmp); ft_strdel(&data_singleton()->line.copy_tmp); data_singleton()->line.pos_tmp = 0; - return (0); + return (1); } static void right_abs(char **str, size_t *pos) { ft_puttermcaps("mr"); + ft_putstr("\x1b[38;5;196m"); data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()-> line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); ft_putchar((*str)[*pos]); + ft_putstr("\033[22;37m"); ft_puttermcaps("me"); ++(data_singleton()->line.pos_tmp); ++(*pos); @@ -47,12 +49,12 @@ static void right_mv_back(char **str, size_t *pos) int underline_right(char **str, size_t *pos, size_t pos_ref) { if (!(*pos < ft_strlen(*str))) - return (1); + return (0); if ((*str)[*pos] == '\n') return (reset_term_hard()); if (*pos >= pos_ref) right_abs(str, pos); else right_mv_back(str, pos); - return (1); + return (0); } diff --git a/42sh/src/line_editing/copy_cut_paste/underline_up.c b/42sh/src/line_editing/copy_cut_paste/underline_up.c index b9e017bb..52dc394b 100644 --- a/42sh/src/line_editing/copy_cut_paste/underline_up.c +++ b/42sh/src/line_editing/copy_cut_paste/underline_up.c @@ -6,13 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/23 11:35:48 by gwojda #+# #+# */ -/* Updated: 2017/03/23 11:39:49 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:22:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void underline_up(char **str, size_t *pos, size_t pos_ref) +int underline_up(char **str, size_t *pos, size_t pos_ref) { size_t pos_tmp; int i; @@ -33,4 +33,5 @@ void underline_up(char **str, size_t *pos, size_t pos_ref) --i; } *pos = pos_tmp; + return (0); } From e8b9befea2fff460945a9be224a2319a7c0b15e9 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Thu, 23 Mar 2017 16:30:37 +0100 Subject: [PATCH 5/6] exec func + correction syntax if --- 42sh/Makefile | 1 + 42sh/file | 1 + 42sh/file1 | 1 + 42sh/includes/exec.h | 3 +- 42sh/src/builtin/builtin_math.c | 9 +++-- 42sh/src/exec/exec_func.c | 56 ++++++++++++++++++++++++++++++++ 42sh/src/exec/ft_exec.c | 3 +- 42sh/src/exec/node_copy.c | 12 ++----- 42sh/src/exec/plaunch_function.c | 18 +++------- 42sh/src/exec/process_redirect.c | 3 +- 42sh/src/exec/pset_cmd.c | 2 +- 42sh/src/main/data_init.c | 5 +-- 42sh/src/main/main.c | 3 +- 42sh/src/parser/add_cmd.c | 2 +- 42sh/src/parser/add_func.c | 49 +--------------------------- 42sh/src/parser/add_redir.c | 2 +- 42sh/src/parser/aggregate_sym.c | 2 +- 42sh/src/parser/build_tree.c | 3 +- 42sh/src/parser/eval_sym.c | 17 +++++++++- 19 files changed, 102 insertions(+), 90 deletions(-) create mode 100644 42sh/file create mode 100644 42sh/file1 create mode 100644 42sh/src/exec/exec_func.c diff --git a/42sh/Makefile b/42sh/Makefile index 10862470..9ae84f28 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -72,6 +72,7 @@ exec/exec_bang.c\ exec/exec_case_branch.c\ exec/exec_elif.c\ exec/exec_else.c\ +exec/exec_func.c\ exec/exec_leaf.c\ exec/exec_or_if.c\ exec/exec_pipe.c\ diff --git a/42sh/file b/42sh/file new file mode 100644 index 00000000..6e4754fa --- /dev/null +++ b/42sh/file @@ -0,0 +1 @@ +YOLO diff --git a/42sh/file1 b/42sh/file1 new file mode 100644 index 00000000..aedbfa69 --- /dev/null +++ b/42sh/file1 @@ -0,0 +1 @@ +nous diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 7313f13b..92a89a05 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/22 16:35:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 16:27:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -227,5 +227,6 @@ int exec_var(t_btree **ast); int exec_case_branch(t_btree **ast); int exec_math(t_btree **ast); int exec_bang(t_btree **ast); +int exec_func(t_btree **ast); #endif diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index d2916c52..21492d7f 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/17 18:54:00 by ariard #+# #+# */ -/* Updated: 2017/03/23 01:08:14 by ariard ### ########.fr */ +/* Updated: 2017/03/23 15:06:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,8 +25,6 @@ static char *do_math(char *value, char operator, char *operand) ope1 = ft_atoi(value); ope2 = ft_atoi(operand); - DG("value %s -> %i", value, ope1); - DG("operand %s -> %i", operand, ope2); if ((operator == '/') && ope2 == 0) return (SH_ERR(MATHERR_4) ? NULL : NULL); if ((operator == '%') && ope2 == 0) @@ -36,7 +34,6 @@ static char *do_math(char *value, char operator, char *operand) ope1 = (operator == '/') ? ope1 / ope2 : ope1; ope1 = (operator == '*') ? ope1 * ope2 : ope1; ope1 = (operator == '%') ? ope1 % ope2 : ope1; - DG("output=%s (%i)", ft_itoa(ope1), ope1); return (ft_itoa(ope1)); } @@ -48,8 +45,10 @@ int builtin_math(const char *path, char *const av[], char *const envp[]) (void)path; (void)envp; - if (!av || !av[1] || !av[2] || !av[3] || av[4]) + DG(); + if (!av || !av[0] || !av[1] || !av[2] || !av[3] || av[4]) return (SH_ERR(MATHERR_0)); + DG(); value = ft_getenv(data_singleton()->local_var, av[1]); operator = av[2][0]; if (!(ft_strchr("+-/*%", operator))) diff --git a/42sh/src/exec/exec_func.c b/42sh/src/exec/exec_func.c new file mode 100644 index 00000000..7ddb750d --- /dev/null +++ b/42sh/src/exec/exec_func.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exec_func.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/23 16:25:23 by ariard #+# #+# */ +/* Updated: 2017/03/23 16:27:57 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +t_list *is_already_func(t_btree **new) +{ + t_list *tmp; + t_btree **ast; + char **new_name; + char **old_name; + int ret; + + tmp = data_singleton()->lst_func; + new_name = token_to_argv(((t_astnode *)(*new)->item)->data.cmd.token, 1); + ret = 1; + while (tmp && ret) + { + if ((ast = tmp->content) && !*ast) + break ; + old_name = token_to_argv(((t_astnode *) + (*ast)->item)->data.cmd.token, 1); + 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 = (ret) ? tmp->next : tmp; + } + ft_tabdel(&new_name); + if (!ret) + return (tmp); + return (NULL); +} + +int exec_func(t_btree **ast) +{ + t_btree *func_ast; + t_list *old_func; + + 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/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 5cf734ba..b88b6acc 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/03/22 19:52:58 by ariard ### ########.fr */ +/* Updated: 2017/03/23 16:25:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,7 @@ t_itof g_execmap[] = {SUBSHELL, &exec_leaf}, {TK_LBRACE, &exec_leaf}, {TK_BANG, &exec_bang}, + {FNAME, &exec_func}, {CMD, &exec_leaf}, {0, 0}, }; diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index e5e662ec..78cffe56 100644 --- a/42sh/src/exec/node_copy.c +++ b/42sh/src/exec/node_copy.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ -/* Updated: 2017/03/22 21:50:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 16:28:41 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,13 +25,7 @@ void *node_copy(void *data) new->full = old->full; new->type = old->type; new->pattern = old->pattern; - if (old->type == CMD || old->type == TK_ASSIGNMENT_WORD) - { - new->data.cmd.redir = ft_lstmap(old->data.cmd.redir, &redir_copy); - new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); - } - if (old->type == TK_FOR || old->type == TK_PAREN_OPEN - || old->type == TK_CASE || old->type == FNAME) - new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); + new->data.cmd.redir = ft_lstmap(old->data.cmd.redir, &redir_copy); + new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); return (new); } diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index b3530d32..d7759396 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/23 06:19:00 by wescande ### ########.fr */ +/* Updated: 2017/03/23 15:06:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,24 +17,14 @@ int plaunch_function(t_process *p) { - static int protection= 0; - /* char *val; */ - - /* if (ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) > FUNC_LVL) */ - /* return(SH_ERR(FUNCERR_0)); */ + static int protection; + if (!protection) + protection = 0; if (protection >= FUNC_LVL) return(SH_ERR(FUNCERR_0)); protection++; - -// jack faut qu on parle - /* val = ft_itoa(ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) + 1); */ - /* builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", val, NULL}, NULL); */ - /* ft_strdel(&val); */ ft_exec(&p->data.function.content); - /* val = ft_itoa(ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) - 1); */ - /* builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", val, NULL}, NULL); */ - /* ft_strdel(&val); */ protection--; return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index 5b1d0c8d..743382d2 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/21 17:40:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 16:06:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,6 +37,7 @@ int process_redirect(t_process *p) while (redirs) { redir = redirs->content; + DG("redir type is %s", read_state(redir->type)); if (redir->n > 9) return (bad_fd(redir->n)); i = -1; diff --git a/42sh/src/exec/pset_cmd.c b/42sh/src/exec/pset_cmd.c index 2dc99f87..fc1515f5 100644 --- a/42sh/src/exec/pset_cmd.c +++ b/42sh/src/exec/pset_cmd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 12:41:54 by jhalford #+# #+# */ -/* Updated: 2017/03/23 06:29:11 by wescande ### ########.fr */ +/* Updated: 2017/03/23 14:48:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 97ff9b29..cf83e669 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/23 06:19:27 by wescande ### ########.fr */ +/* Updated: 2017/03/23 14:57:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,9 +66,6 @@ int data_init(int ac, char **av) data->lst_func = NULL; lexer_init(&data->lexer); parser_init(&data->parser); - /* if (!ft_getenv(data_singleton()->env, "FUNC_LVL")) */ - /* builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", "-1", */ - /* NULL}, NULL); */ if ((term_name = ft_getenv(data->env, "TERM")) == NULL) { term_name = "dumb"; diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 69fedd03..4ae34096 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/23 00:28:58 by ariard ### ########.fr */ +/* Updated: 2017/03/23 15:16:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,6 +49,7 @@ static int handle_instruction(t_list **token, t_btree **ast) else if (ret > 0) break ; } + btree_print(STDBUG, *ast, &ft_putast); if (data->parser.state == SUCCESS && ft_exec(ast) < 0) exit(1); else if (data->parser.state != SUCCESS) diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 95a4690e..8a6b896b 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/03/17 19:31:52 by ariard ### ########.fr */ +/* Updated: 2017/03/23 16:29:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index 3e4988f4..27a87b4c 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 19:21:58 by ariard ### ########.fr */ +/* Updated: 2017/03/23 16:26:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,53 +73,6 @@ int add_func_cmd(t_btree **ast, t_list **lst) || token->type == TK_FI || token->type == TK_RBRACE || token->type == TK_PAREN_CLOSE) && node->type == FNAME && node->nest == 0) - { node->full = 1; - add_one_func(ast, lst); - } return (add_cmd(&(*ast)->right, lst)); } - -t_list *is_already_func(t_btree **new) -{ - t_list *tmp; - t_btree **ast; - char **new_name; - char **old_name; - int ret; - - tmp = data_singleton()->lst_func; - new_name = token_to_argv(((t_astnode *)(*new)->item)->data.cmd.token, 1); - ret = 1; - while (tmp && ret) - { - if ((ast = tmp->content) && !*ast) - break ; - old_name = token_to_argv(((t_astnode *) - (*ast)->item)->data.cmd.token, 1); - 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 = (ret) ? tmp->next : tmp; - } - ft_tabdel(&new_name); - if (!ret) - return (tmp); - return (NULL); -} - -int add_one_func(t_btree **ast, t_list **lst) -{ - t_btree *func_ast; - t_list *old_func; - - (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/add_redir.c b/42sh/src/parser/add_redir.c index a9f828e0..725f5b15 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/17 17:54:49 by ariard ### ########.fr */ +/* Updated: 2017/03/23 16:29:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 21b6a56f..69796880 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 19:00:06 by ariard ### ########.fr */ +/* Updated: 2017/03/23 16:03:22 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 37a2c560..dd3c3883 100644 --- a/42sh/src/parser/build_tree.c +++ b/42sh/src/parser/build_tree.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ -/* Updated: 2017/03/17 19:50:08 by ariard ### ########.fr */ +/* Updated: 2017/03/23 15:26:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,6 +84,7 @@ int build_tree(t_btree **ast, t_list **lst) i = 0; token = (*lst)->content; check_cache(token, cache); + DG("new"); while (g_treematch[i].type) { if ((isseparator(token, cache) && g_treematch[i].type == token->type)) diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 40ff2389..aea47306 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 19:00:15 by ariard ### ########.fr */ +/* Updated: 2017/03/23 16:04:51 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -842,6 +842,21 @@ t_stackmatch g_stackmatch[] = {COMPLETE_CONDITION, COMPLETE_COMMANDS}, {COMPLETE_CONDITION, COMPLETE_CONDITION}, {COMPLETE_CONDITION, SEQUENCE}, + {COMPLETE_CONDITION, TK_WHILE}, + {COMPLETE_CONDITION, TK_UNTIL}, + {COMPLETE_CONDITION, TK_DO}, + {COMPLETE_CONDITION, TK_IF}, + {COMPLETE_CONDITION, TK_ELIF}, + {COMPLETE_CONDITION, TK_THEN}, + {COMPLETE_CONDITION, TK_ELSE}, + {COMPLETE_CONDITION, COMPOUND_LIST}, + {COMPLETE_CONDITION, CASE_LIST_NS}, + {COMPLETE_CONDITION, TK_BANG}, + {COMPLETE_CONDITION, SEPARATOR_OP}, + {COMPLETE_CONDITION, NEWLINE_LIST}, + {COMPLETE_CONDITION, AND_OR_MAJOR}, + {COMPLETE_CONDITION, CASE_LIST_NS}, + {COMPLETE_CONDITION, FUNC_NAME}, {FNAME, LINEBREAK}, {FNAME, TK_PAREN_OPEN}, {FNAME, TK_LBRACE}, From 6b6376fe70e0a9c5b520260de8e750f3743134c7 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 23 Mar 2017 16:39:51 +0100 Subject: [PATCH 6/6] setlocal not allowed --- 42sh/Makefile | 4 ++-- 42sh/libft/Makefile | 4 ++-- 42sh/src/main/main.c | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 715952e6..bb747d52 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/23 03:25:35 by wescande ### ########.fr # +# Updated: 2017/03/23 16:37:26 by gwojda ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror #-fvisibility=hidden #-fsanitize=address +FLAGS = -Wall -Wextra -Werror -fvisibility=hidden -fsanitize=address D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index 4ce95f9b..a7370723 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -6,7 +6,7 @@ # By: jhalford +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2017/02/07 16:09:36 by jhalford #+# #+# # -# Updated: 2017/03/21 12:25:27 by gwojda ### ########.fr # +# Updated: 2017/03/23 16:38:05 by gwojda ### ########.fr # # # # **************************************************************************** # @@ -19,7 +19,7 @@ RM = /bin/rm -rf W_FLAGS = -Wall -Wextra -Werror -g D_FLAGS = -g -V_FLAGS = #-fvisibility=hidden +V_FLAGS = -fvisibility=hidden FLAGS = $(W_FLAGS) $(D_FLAGS) $(V_FLAGS) DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 69fedd03..d6e7106a 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/23 00:28:58 by ariard ### ########.fr */ +/* Updated: 2017/03/23 16:39:07 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,6 @@ int main(int ac, char **av) g_argv = av; DG("----------------"); - setlocale(LC_ALL, ""); if (shell_init(ac, av) != 0) return (1); token = NULL;