From 37970c7274897be1ebd6054bf3748500aeb97618 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Wed, 8 Mar 2017 01:47:40 +0100 Subject: [PATCH] ft_lstdup --- 42sh/Makefile | 3 +- 42sh/includes/exec.h | 6 ++-- 42sh/laurier.sh | 6 ++++ 42sh/src/exec/ast_free.c | 2 +- 42sh/src/exec/ft_exec.c | 2 +- 42sh/src/exec/node_copy.c | 36 ++++++++++++++++++++++ 42sh/src/exec/{ast_copy.c => redir_copy.c} | 27 ++++++++-------- 42sh/src/exec/set_process_case.c | 4 +-- 42sh/src/exec/set_process_for.c | 4 +-- 42sh/src/exec/set_process_if.c | 6 ++-- 42sh/src/exec/set_process_while.c | 6 ++-- 42sh/src/glob/lib_perso/ft_ld_copy.c | 2 +- 42sh/src/lexer/lexer_sep.c | 7 ++--- 42sh/src/main/ft_putast.c | 2 +- 42sh/src/main/instruction_free.c | 2 +- 42sh/src/main/main.c | 2 +- 42sh/src/parser/add_case.c | 2 +- 42sh/src/parser/add_condition.c | 2 +- 42sh/src/parser/add_loop.c | 2 +- 42sh/src/parser/add_redir.c | 2 +- 42sh/src/parser/add_sep.c | 2 +- 42sh/src/parser/add_subshell.c | 2 +- 42sh/src/parser/add_var.c | 2 +- 42sh/src/parser/tree_wrapper.c | 2 +- 24 files changed, 89 insertions(+), 44 deletions(-) create mode 100644 42sh/laurier.sh create mode 100644 42sh/src/exec/node_copy.c rename 42sh/src/exec/{ast_copy.c => redir_copy.c} (58%) diff --git a/42sh/Makefile b/42sh/Makefile index c7bc80e0..58949194 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -58,7 +58,6 @@ completion/c_rematch.c\ completion/c_sizing.c\ completion/c_terminal.c\ completion/completion.c\ -exec/ast_copy.c\ exec/ast_free.c\ exec/bad_fd.c\ exec/error_badidentifier.c\ @@ -94,6 +93,8 @@ exec/process_setexec.c\ exec/process_setgroup.c\ exec/process_setsig.c\ exec/redir_free.c\ +exec/redir_copy.c\ +exec/node_copy.c\ exec/redirect_dgreat.c\ exec/redirect_dless.c\ exec/redirect_great.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 9d3936ea..fc0a5419 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/07 21:08:54 by wescande ### ########.fr */ +/* Updated: 2017/03/08 01:00:34 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -169,7 +169,9 @@ char *ft_findexec(char *path, char *file); void set_exitstatus(int status, int override); void ast_free(void *data, size_t content_size); -t_btree *ast_copy(t_btree *tree); +void *node_copy(void *data); +void *redir_copy(void *data); + void redir_free(void *data, size_t content_size); char **token_to_argv(t_ld *ld, int do_match); diff --git a/42sh/laurier.sh b/42sh/laurier.sh new file mode 100644 index 00000000..9e88cdd1 --- /dev/null +++ b/42sh/laurier.sh @@ -0,0 +1,6 @@ +read -p "Quel est ton login ?" login +while [ 1 ] +do + echo "Tu es le meilleur codeur de l'ecole $login" + sleep 1 +done diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index e9577366..4d7d2c93 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ -/* Updated: 2017/03/07 18:34:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 00:59:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 072ac974..127b8cd5 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/07 20:54:28 by wescande ### ########.fr */ +/* Updated: 2017/03/07 22:49:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c new file mode 100644 index 00000000..23c4fd13 --- /dev/null +++ b/42sh/src/exec/node_copy.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ast_copy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/07 20:44:42 by wescande #+# #+# */ +/* Updated: 2017/03/08 01:00:05 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void *node_copy(void *data) +{ + t_astnode *new; + t_astnode *old; + + if (!data) + return (NULL); + old = data; + ft_bzero((void *)&new, sizeof(t_astdata)); + new->nest = old->nest; + new->full = old->full; + new->type = old->type; + new->pattern = old->pattern; + if (old->type == CMD || old->type == TK_ASSIGNEMENT_WORD) + { + new->data.cmd.redir = ft_lstdup(&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) + new->data.cmd.wordlist = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); + return (new); +} diff --git a/42sh/src/exec/ast_copy.c b/42sh/src/exec/redir_copy.c similarity index 58% rename from 42sh/src/exec/ast_copy.c rename to 42sh/src/exec/redir_copy.c index 76fa0417..65e843e2 100644 --- a/42sh/src/exec/ast_copy.c +++ b/42sh/src/exec/redir_copy.c @@ -1,25 +1,28 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ast_copy.c :+: :+: :+: */ +/* redir_copy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/07 20:44:42 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:25:15 by wescande ### ########.fr */ +/* Created: 2017/03/08 00:02:58 by ariard #+# #+# */ +/* Updated: 2017/03/08 00:41:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_btree *ast_copy(t_btree *tree) +void *redir_copy(void *data) { - t_btree *node; + t_redir *old; + t_redir *new; - if (!tree) + if (!data) return (NULL); - node = btree_create_node(tree->item, tree->content_size); - node->left = ast_copy(tree->left); - node->right = ast_copy(tree->right); - return (node); -} + old = data; + ft_bzero((void *)&new, sizeof(t_astdata)); + new->type = old->type; + new->n = old->n; + new->word = ft_strdup(old->word); + return (0); +} diff --git a/42sh/src/exec/set_process_case.c b/42sh/src/exec/set_process_case.c index d8dcaba8..8e5b4e42 100644 --- a/42sh/src/exec/set_process_case.c +++ b/42sh/src/exec/set_process_case.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:14:19 by wescande ### ########.fr */ +/* Updated: 2017/03/08 01:01:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,6 @@ int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd) { (void)cmd; p->data.d_case.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy); - p->data.d_case.content = ast_copy(ast->right); + p->data.d_case.content = btree_map(ast->right, &node_copy); return (0); } diff --git a/42sh/src/exec/set_process_for.c b/42sh/src/exec/set_process_for.c index 34134a33..cc8767a7 100644 --- a/42sh/src/exec/set_process_for.c +++ b/42sh/src/exec/set_process_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:05 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:14:33 by wescande ### ########.fr */ +/* Updated: 2017/03/08 01:02:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,6 @@ int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd) { (void)cmd; p->data.d_for.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy); - p->data.d_for.content = ast_copy(ast->right); + p->data.d_for.content = btree_map(ast->right, &node_copy); return (0); } diff --git a/42sh/src/exec/set_process_if.c b/42sh/src/exec/set_process_if.c index 3f8d721a..792611b5 100644 --- a/42sh/src/exec/set_process_if.c +++ b/42sh/src/exec/set_process_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:19:50 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:10:47 by wescande ### ########.fr */ +/* Updated: 2017/03/08 00:59:08 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd) { (void)cmd; - p->data.d_if.condition = ast_copy(ast->left); - p->data.d_if.content = ast_copy(ast->right); + p->data.d_if.condition = btree_map(ast->left, &node_copy); + p->data.d_if.content = btree_map(ast->right, &node_copy); return (0); } diff --git a/42sh/src/exec/set_process_while.c b/42sh/src/exec/set_process_while.c index f0908887..6854d85d 100644 --- a/42sh/src/exec/set_process_while.c +++ b/42sh/src/exec/set_process_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:10 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:11:38 by wescande ### ########.fr */ +/* Updated: 2017/03/08 01:03:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd) { (void)cmd; - p->data.d_while.condition = ast_copy(ast->left); - p->data.d_while.content = ast_copy(ast->right); + p->data.d_while.condition = btree_map(ast->left, &node_copy); + p->data.d_while.content = btree_map(ast->right, &node_copy); return (0); } diff --git a/42sh/src/glob/lib_perso/ft_ld_copy.c b/42sh/src/glob/lib_perso/ft_ld_copy.c index 941e4c5f..86d43dcc 100644 --- a/42sh/src/glob/lib_perso/ft_ld_copy.c +++ b/42sh/src/glob/lib_perso/ft_ld_copy.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:42:23 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:21:30 by wescande ### ########.fr */ +/* Updated: 2017/03/08 00:58:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index c159a930..6420498f 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,11 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ -/* Updated: 2017/03/07 19:40:52 by ariard ### ########.fr */ +/* Updated: 2017/03/07 20:26:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ -#include "minishell.h" +#include "lexer.h" int lexer_sep(t_list **alst, t_lexer *lexer) { @@ -37,11 +37,8 @@ int lexer_sep(t_list **alst, t_lexer *lexer) token->type = cn == '&' ? TK_AND_IF : TK_AMP; else if (c == '|') token->type = cn == '|' ? TK_OR_IF : TK_PIPE; - else if (c == '!') - token->type = TK_BANG; token->type = (c == ';') ? TK_SEMI : token->type; token->type = (c == ';') && (cn == ';') ? TK_DSEMI : token->type; -// c est ici que ca bug, ca marche plus les bitwise sur des enums lexer->pos += 1 + (token->type & (TK_AND_IF | TK_OR_IF | TK_DSEMI) ? 1 : 0); return (lexer_lex(&(*alst)->next, lexer)); } diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 405104b6..b223e7e3 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2017/03/05 14:57:19 by ariard ### ########.fr */ +/* Updated: 2017/03/07 23:35:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/instruction_free.c b/42sh/src/main/instruction_free.c index 69a80006..a1b27fa2 100644 --- a/42sh/src/main/instruction_free.c +++ b/42sh/src/main/instruction_free.c @@ -7,4 +7,4 @@ int instruction_free(t_list **token, t_parser *parser, t_btree **ast) ft_lstdel(&parser->stack, NULL); btree_del(ast, &ast_free); return (0); -} +} diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index ad862a61..0527cf28 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/07 16:41:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/07 21:53:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index 04a3cdea..bd228540 100644 --- a/42sh/src/parser/add_case.c +++ b/42sh/src/parser/add_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 20:42:13 by ariard #+# #+# */ -/* Updated: 2017/03/07 19:32:45 by ariard ### ########.fr */ +/* Updated: 2017/03/07 22:46:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index 902606c5..c563cbb1 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 18:12:52 by ariard #+# #+# */ -/* Updated: 2017/03/05 15:32:49 by wescande ### ########.fr */ +/* Updated: 2017/03/07 22:46:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index b393ebef..f7a6999e 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ -/* Updated: 2017/03/06 19:06:03 by ariard ### ########.fr */ +/* Updated: 2017/03/07 22:46:20 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 41df28a0..3040c067 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/06 15:54:24 by ariard ### ########.fr */ +/* Updated: 2017/03/07 22:46:46 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index 2985134c..0a3a2a22 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/04 21:43:00 by ariard ### ########.fr */ +/* Updated: 2017/03/07 22:46:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_subshell.c b/42sh/src/parser/add_subshell.c index 9b5f6c58..88f25c43 100644 --- a/42sh/src/parser/add_subshell.c +++ b/42sh/src/parser/add_subshell.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ -/* Updated: 2017/03/05 15:34:12 by wescande ### ########.fr */ +/* Updated: 2017/03/07 22:46:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_var.c b/42sh/src/parser/add_var.c index e191490f..fe17bb85 100644 --- a/42sh/src/parser/add_var.c +++ b/42sh/src/parser/add_var.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 15:08:16 by ariard #+# #+# */ -/* Updated: 2017/03/07 14:40:21 by ariard ### ########.fr */ +/* Updated: 2017/03/07 22:47:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index 1a11caaf..c57cc34a 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ -/* Updated: 2017/03/06 19:01:18 by ariard ### ########.fr */ +/* Updated: 2017/03/08 00:02:46 by ariard ### ########.fr */ /* */ /* ************************************************************************** */