diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 24b36150..d27214cd 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/01/31 18:35:34 by wescande ### ########.fr */ +/* Updated: 2017/02/02 14:55:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,7 +75,7 @@ extern int (*g_lexer[])(t_list **alst, char *str); t_token *token_init(); int ft_tokenize(t_list **alst, char *str, t_lexstate state); -int ft_post_tokenize(t_list **alst, char *str); +int ft_post_tokenize(t_list **alst, char **str); int token_append(t_token *token, char c, short int esc); void token_free(void *data, size_t size); int token_cmp_type(t_token *token, t_type *ref); diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 775ced98..a2b32c83 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/01/30 13:07:38 by wescande ### ########.fr */ +/* Updated: 2017/02/02 14:46:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index cdb28caa..3a6f5392 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ -/* Updated: 2017/01/31 19:17:25 by wescande ### ########.fr */ +/* Updated: 2017/02/02 14:03:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index dac7a201..035558a5 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,31 +6,39 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2017/02/01 19:29:27 by wescande ### ########.fr */ +/* Updated: 2017/02/02 14:49:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "exec.h" -static char **return_array_expand(t_ld *ld) +static char **token_to_argv(t_astnode *node) { - char **my_tab; - int index; - char **expand; - char **content; + char **my_tab; + int index; + char **expand; + char **content; + t_ld *ld; - my_tab = NULL; - while (ld) + if (node->type == TK_COMMAND) { - content = ld->content; - expand = glob(content[0], (unsigned char *)content[1]); - index = -1; - while (expand[++index]) - my_tab = ft_sstradd(my_tab, expand[index]); - ft_tabdel(&expand); - ld = ld->next; + ld = node->data.token; + my_tab = NULL; + while (ld) + { + content = ld->content; + expand = glob(content[0], (unsigned char *)content[1]); + index = -1; + while (expand[++index]) + my_tab = ft_sstradd(my_tab, expand[index]); + ft_tabdel(&expand); + ld = ld->next; + } + return (my_tab); } - return (my_tab); + else if (node->type == TK_SUBSHELL) + return (ft_sstrdup(node->data.sstr)); + return (NULL); } int exec_command(t_btree **ast) @@ -42,7 +50,7 @@ int exec_command(t_btree **ast) node = (*ast)->item; p = &data_singleton()->exec.process; job = &data_singleton()->exec.job; - p->av = return_array_expand(node->data.token); + p->av = token_to_argv(node); process_setexec(node->type, p); if (!(launch_process(p))) { diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 2f18bdc8..193eddcb 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/01/11 18:01:05 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 14:49:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,7 +38,6 @@ int ft_exec(t_btree **ast) while (g_execmap[i].type) { if (item->type & g_execmap[i].type) - /* return ((*g_execmap[i].f)(ast)); */ (*g_execmap[i].f)(ast); i++; } diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index db991821..38ff2aaf 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/01/31 13:47:57 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 14:28:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/glob/lib_perso/ft_tabdel.c b/42sh/src/glob/lib_perso/ft_tabdel.c index ac72a1a1..d4f9cff0 100644 --- a/42sh/src/glob/lib_perso/ft_tabdel.c +++ b/42sh/src/glob/lib_perso/ft_tabdel.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:29:54 by wescande #+# #+# */ -/* Updated: 2017/01/24 16:52:50 by wescande ### ########.fr */ +/* Updated: 2017/02/02 14:22:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index ee4824e4..6910a7c2 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/01/02 19:11:34 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 14:34:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,12 @@ void process_free(void *content, size_t content_size) t_process *p; (void)content_size; + DG("check 0"); p = content; + DG("check 1"); ft_strdel(&p->path); + DG("check 2"); ft_sstrfree(p->av); + DG("check 3"); free(p); } diff --git a/42sh/src/lexer/command_getoutput.c b/42sh/src/lexer/command_getoutput.c index 7e4b80f5..2684662a 100644 --- a/42sh/src/lexer/command_getoutput.c +++ b/42sh/src/lexer/command_getoutput.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */ -/* Updated: 2017/01/31 16:07:17 by wescande ### ########.fr */ +/* Updated: 2017/02/02 14:52:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/ft_post_tokenize.c b/42sh/src/lexer/ft_post_tokenize.c index a3de30d2..7545b99a 100644 --- a/42sh/src/lexer/ft_post_tokenize.c +++ b/42sh/src/lexer/ft_post_tokenize.c @@ -6,22 +6,22 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */ -/* Updated: 2017/01/12 13:58:20 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 14:54:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -int ft_post_tokenize(t_list **alst, char *str) +int ft_post_tokenize(t_list **alst, char **str) { int ret; - while ((ret = reduce_parens(alst, str))) + while ((ret = reduce_parens(alst, *str))) if (ret == -1) return (-1); - while ((ret = reduce_bquotes(alst, &str))) + while ((ret = reduce_bquotes(alst, str))) if (ret == -1) return (-1); - DG("new command from bquotes: '%s'", str); + DG("new command from bquotes: '%s'", *str); return (0); } diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/ft_tokenize.c index b94670d7..8abae3d3 100644 --- a/42sh/src/lexer/ft_tokenize.c +++ b/42sh/src/lexer/ft_tokenize.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */ -/* Updated: 2017/01/31 13:42:01 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 14:55:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/reduce_bquotes.c b/42sh/src/lexer/reduce_bquotes.c index 5198a2f2..1fe3cf4a 100644 --- a/42sh/src/lexer/reduce_bquotes.c +++ b/42sh/src/lexer/reduce_bquotes.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:46:27 by jhalford #+# #+# */ -/* Updated: 2017/01/12 15:10:16 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 14:52:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index c0aec11e..79e7f552 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/02/02 13:34:47 by gwojda ### ########.fr */ +/* Updated: 2017/02/02 14:38:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 6731ea08..5a28ed2d 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/01/31 19:41:25 by wescande ### ########.fr */ +/* Updated: 2017/02/02 14:55:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,16 +24,18 @@ int shell_single_command(char *command) DG("{inv}{mag}got command '%s'", command); if (ft_tokenize(&token, command, DEFAULT)) return (1); + if (ft_post_tokenize(&token, &command)) + return (1); if (!token) return (0); - if (ft_post_tokenize(&token, command)) - return (1); + ft_strdel(&command); token_print(token); if (ft_parse(&ast, &token)) return (1); btree_print(STDBUG, ast, &ft_putast); if (ft_exec(&ast)) return (1); + DG("after exec!"); return (0); } @@ -44,14 +46,14 @@ int main(int ac, char **av) shell_init(ac, av); if (data_singleton()->opts & SHELL_OPTS_LC) { - shell_single_command(shell_get_avdata()); + shell_single_command(ft_strdup(shell_get_avdata())); return (0); } while (1) { if (ft_readline()) return (1); - if (shell_single_command(data_singleton()->line.input)) + if (shell_single_command(ft_strdup(data_singleton()->line.input))) return (1); } return (0); diff --git a/42sh/src/parser/parse_subshell.c b/42sh/src/parser/parse_subshell.c index bcb38158..213fec47 100644 --- a/42sh/src/parser/parse_subshell.c +++ b/42sh/src/parser/parse_subshell.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:52:44 by jhalford #+# #+# */ -/* Updated: 2017/01/12 15:10:24 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 14:11:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_word.c b/42sh/src/parser/parse_word.c index b7b1743f..60535449 100644 --- a/42sh/src/parser/parse_word.c +++ b/42sh/src/parser/parse_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2017/01/31 19:17:58 by wescande ### ########.fr */ +/* Updated: 2017/02/02 14:24:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */