ft_lstdup

This commit is contained in:
Antoine Riard 2017-03-08 01:47:40 +01:00
parent bac6e9d6d8
commit 37970c7274
24 changed files with 89 additions and 44 deletions

View file

@ -58,7 +58,6 @@ completion/c_rematch.c\
completion/c_sizing.c\ completion/c_sizing.c\
completion/c_terminal.c\ completion/c_terminal.c\
completion/completion.c\ completion/completion.c\
exec/ast_copy.c\
exec/ast_free.c\ exec/ast_free.c\
exec/bad_fd.c\ exec/bad_fd.c\
exec/error_badidentifier.c\ exec/error_badidentifier.c\
@ -94,6 +93,8 @@ exec/process_setexec.c\
exec/process_setgroup.c\ exec/process_setgroup.c\
exec/process_setsig.c\ exec/process_setsig.c\
exec/redir_free.c\ exec/redir_free.c\
exec/redir_copy.c\
exec/node_copy.c\
exec/redirect_dgreat.c\ exec/redirect_dgreat.c\
exec/redirect_dless.c\ exec/redirect_dless.c\
exec/redirect_great.c\ exec/redirect_great.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 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 set_exitstatus(int status, int override);
void ast_free(void *data, size_t content_size); 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); void redir_free(void *data, size_t content_size);
char **token_to_argv(t_ld *ld, int do_match); char **token_to_argv(t_ld *ld, int do_match);

6
42sh/laurier.sh Normal file
View file

@ -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

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:50:51 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

36
42sh/src/exec/node_copy.c Normal file
View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ast_copy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -1,25 +1,28 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* ast_copy.c :+: :+: :+: */ /* redir_copy.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 20:44:42 by wescande #+# #+# */ /* Created: 2017/03/08 00:02:58 by ariard #+# #+# */
/* Updated: 2017/03/07 21:25:15 by wescande ### ########.fr */ /* Updated: 2017/03/08 00:41:57 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #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); return (NULL);
node = btree_create_node(tree->item, tree->content_size); old = data;
node->left = ast_copy(tree->left); ft_bzero((void *)&new, sizeof(t_astdata));
node->right = ast_copy(tree->right); new->type = old->type;
return (node); new->n = old->n;
} new->word = ft_strdup(old->word);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 20:36:04 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; (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.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); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:05 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; (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.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); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:19:50 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) int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd)
{ {
(void)cmd; (void)cmd;
p->data.d_if.condition = ast_copy(ast->left); p->data.d_if.condition = btree_map(ast->left, &node_copy);
p->data.d_if.content = ast_copy(ast->right); p->data.d_if.content = btree_map(ast->right, &node_copy);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:10 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) int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd)
{ {
(void)cmd; (void)cmd;
p->data.d_while.condition = ast_copy(ast->left); p->data.d_while.condition = btree_map(ast->left, &node_copy);
p->data.d_while.content = ast_copy(ast->right); p->data.d_while.content = btree_map(ast->right, &node_copy);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:42:23 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,11 +6,11 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 16:29:57 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) 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; token->type = cn == '&' ? TK_AND_IF : TK_AMP;
else if (c == '|') else if (c == '|')
token->type = cn == '|' ? TK_OR_IF : TK_PIPE; 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 == ';') ? TK_SEMI : token->type;
token->type = (c == ';') && (cn == ';') ? TK_DSEMI : 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); lexer->pos += 1 + (token->type & (TK_AND_IF | TK_OR_IF | TK_DSEMI) ? 1 : 0);
return (lexer_lex(&(*alst)->next, lexer)); return (lexer_lex(&(*alst)->next, lexer));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:18:04 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -7,4 +7,4 @@ int instruction_free(t_list **token, t_parser *parser, t_btree **ast)
ft_lstdel(&parser->stack, NULL); ft_lstdel(&parser->stack, NULL);
btree_del(ast, &ast_free); btree_del(ast, &ast_free);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/04 20:42:13 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/19 18:12:52 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 22:17:14 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 19:12:07 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 18:41:50 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 15:08:16 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:57:44 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */