From 2d631469e6bd15794dcc09b11ee852acc4e6ab22 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 1 Dec 2016 17:47:41 +0100 Subject: [PATCH] execution of &&/|| done, added aol_status and aol_search to data (aol=and_or_list) --- 42sh/includes/exec.h | 4 +-- 42sh/includes/lexer.h | 49 ++++++++++++-------------- 42sh/includes/line_editing.h | 37 +++++++++---------- 42sh/includes/minishell.h | 16 ++++----- 42sh/includes/parser.h | 37 ++++++++++--------- 42sh/src/exec/exec_and_if.c | 17 +++++++-- 42sh/src/exec/exec_command.c | 12 +++---- 42sh/src/exec/exec_dgreat.c | 4 +-- 42sh/src/exec/exec_great.c | 4 +-- 42sh/src/exec/exec_less.c | 4 +-- 42sh/src/exec/exec_or_if.c | 17 +++++++-- 42sh/src/exec/fd_reset.c | 21 ----------- 42sh/src/exec/ft_cmd.c | 3 +- 42sh/src/exec/ft_exec.c | 2 +- 42sh/src/lexer/ft_tokenize.c | 4 +-- 42sh/src/line-editing/ft_set_termios.c | 3 +- 42sh/src/main/data_init.c | 4 ++- 42sh/src/main/ft_putast.c | 2 +- 42sh/src/main/ft_putast2.c | 12 +++---- 42sh/src/main/main.c | 2 +- 42sh/src/parser/ft_parse.c | 4 +-- 42sh/src/parser/parse_dgreat.c | 6 ++-- 42sh/src/parser/parse_dless.c | 4 +-- 42sh/src/parser/parse_great.c | 6 ++-- 42sh/src/parser/parse_greatand.c | 6 ++-- 42sh/src/parser/parse_less.c | 6 ++-- 42sh/src/parser/parse_lessand.c | 6 ++-- 42sh/src/parser/parse_word.c | 4 +-- 28 files changed, 150 insertions(+), 146 deletions(-) delete mode 100644 42sh/src/exec/fd_reset.c diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 37d20604..107973b8 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: 2016/11/30 22:47:18 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:47:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ typedef struct s_exec t_exec; -struct s_exec +struct s_exec { t_type type; int (*f)(t_btree *ast, t_data *data); diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index e4f40bae..4233e196 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: 2016/12/01 12:15:50 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:21:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,13 +31,6 @@ # define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20) -typedef long long t_type; -typedef enum e_lexstate t_lexstate; -typedef struct s_token t_token; -typedef struct s_data t_data; -typedef int t_lexer(t_list **alst, - char *str); - enum e_lexstate { DEFAULT, @@ -54,16 +47,19 @@ enum e_lexstate BACKSLASH, }; -struct s_token +struct s_token { - t_type type; - char *data; - int size; + t_type type; + char *data; + int size; }; -extern t_lexer *g_lexer[]; +typedef struct s_data t_data; +typedef struct s_token t_token; +typedef enum e_lexstate t_lexstate; + +extern int (*g_lexer[])(t_list **alst, char *str); -/* t_token *token_getnext(int *pos,char *line); */ t_token *token_init(); int ft_tokenize(t_list **alst, char *str, t_lexstate state); int token_append(t_token *token, char c); @@ -74,18 +70,17 @@ void token_print(t_list *lst); int ft_is_delim(char c); void qstate_update(t_data *data, char c); -t_lexer lexer_default; -t_lexer lexer_delim; -t_lexer lexer_sep; -t_lexer lexer_word; -t_lexer lexer_number; -t_lexer lexer_greatand; -t_lexer lexer_lessand; -t_lexer lexer_quote; -t_lexer lexer_dquote; -t_lexer lexer_backslash; - -t_lexer lexer_less; -t_lexer lexer_great; +int lexer_default(t_list **alst, char *str); +int lexer_delim(t_list **alst, char *str); +int lexer_sep(t_list **alst, char *str); +int lexer_word(t_list **alst, char *str); +int lexer_number(t_list **alst, char *str); +int lexer_less(t_list **alst, char *str); +int lexer_great(t_list **alst, char *str); +int lexer_lessand(t_list **alst, char *str); +int lexer_greatand(t_list **alst, char *str); +int lexer_quote(t_list **alst, char *str); +int lexer_dquote(t_list **alst, char *str); +int lexer_backslash(t_list **alst, char *str); #endif diff --git a/42sh/includes/line_editing.h b/42sh/includes/line_editing.h index 2cad4345..3ba924a5 100644 --- a/42sh/includes/line_editing.h +++ b/42sh/includes/line_editing.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:38:21 by jhalford #+# #+# */ -/* Updated: 2016/12/01 12:13:57 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 15:59:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,22 +52,23 @@ int ft_interactive_sh(t_data *data); int ft_prompt(void); int ft_history_add(t_data *data); -typedef int key_press(t_data *data, char *buf); -key_press ft_clear_line; -key_press ft_line_up; -key_press ft_line_down; -key_press ft_line_start; -key_press ft_line_end; -key_press ft_history_up; -key_press ft_history_down; -key_press ft_cursor_left; -key_press ft_cursor_right; -key_press ft_word_left; -key_press ft_word_right; -key_press ft_key_del; -key_press ft_key_enter; -key_press ft_key_ctrl_d; -key_press ft_key_ctrl_c; -key_press ft_key_default; +int ft_clear_line(t_data *data, char *buf); +int ft_line_up(t_data *data, char *buf); +int ft_line_down(t_data *data, char *buf); +int ft_line_start(t_data *data, char *buf); +int ft_line_end(t_data *data, char *buf); + +int ft_key_del(t_data *data, char *buf); +int ft_key_enter(t_data *data, char *buf); +int ft_key_ctrl_d(t_data *data, char *buf); +int ft_key_ctrl_c(t_data *data, char *buf); +int ft_key_default(t_data *data, char *buf); + +int ft_history_up(t_data *data, char *buf); +int ft_history_down(t_data *data, char *buf); +int ft_cursor_left(t_data *data, char *buf); +int ft_cursor_right(t_data *data, char *buf); +int ft_word_left(t_data *data, char *buf); +int ft_word_right(t_data *data, char *buf); #endif diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 31f3a836..79f26788 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: 2016/12/01 14:46:21 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 17:31:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,19 +27,17 @@ # include # include +typedef long long t_type; -typedef enum e_qstate t_qstate; -typedef struct s_data t_data; - -enum e_qstate +typedef enum e_qstate { Q_NONE, Q_QUOTE, Q_DQUOTE, Q_BACKSLASH, -}; +} t_qstate; -struct s_data +typedef struct s_data { char **env; t_dlist *history; @@ -48,7 +46,9 @@ struct s_data t_list *qstack; int fdin; int fdout; -}; + char *aol_status; + int aol_search; +} t_data; extern t_stof g_builtins[]; extern pid_t g_pid; diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 09eb75fc..a398d0f8 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: 2016/12/01 12:15:54 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:35:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,36 +15,41 @@ # include "minishell.h" -typedef long long t_type; typedef struct s_parser t_parser; typedef struct s_astnode t_astnode; typedef struct s_redir t_redir; +typedef union u_astdata t_astdata; +typedef union u_word t_word; -struct s_parser +struct s_parser { t_type type; int (*f)(t_btree **ast, t_list **start, t_list **token); }; -struct s_redir +union u_word +{ + char *word; + int fd; +}; + +struct s_redir { int n; int close; - union u_word - { - char *word; - int fd; - } u_word; + t_word word; }; -struct s_astnode +union u_astdata { - t_type type; - union u_astdata - { - t_redir redir; - char **sstr; - } u_data; + t_redir redir; + char **sstr; +}; + +struct s_astnode +{ + t_type type; + t_astdata data; }; extern t_parser g_parser[]; diff --git a/42sh/src/exec/exec_and_if.c b/42sh/src/exec/exec_and_if.c index 34bb5ebb..9e0f13ce 100644 --- a/42sh/src/exec/exec_and_if.c +++ b/42sh/src/exec/exec_and_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */ -/* Updated: 2016/11/30 21:06:05 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 17:46:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,18 @@ int exec_and_if(t_btree *ast, t_data *data) { - ft_exec(ast->left, data); - ft_exec(ast->right, data); + if (data->aol_status == NULL + || (data->aol_search == TK_AND_IF && *data->aol_status == '0') + || (data->aol_search == TK_OR_IF && *data->aol_status != '0')) + { + ft_exec(ast->left, data); + data->aol_status = ft_getenv(data->env, "?"); + } + data->aol_search = TK_AND_IF; + if (*data->aol_status == '0' + || ((t_astnode*)ast->right->item)->type != TK_COMMAND) + ft_exec(ast->right, data); + data->aol_status = NULL; + data->aol_search = 0; return (0); } diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 3194c99e..ee4c1077 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2016/11/29 20:30:49 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:48:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,10 @@ int exec_command(t_btree *ast, t_data *data) t_astnode *node; node = ast->item; - ft_putstr_fd("befor exec: ", 2); - ft_sstrprint_fd(2, ((t_astnode*)ast->item)->u_data.sstr, ','); - ft_putchar_fd('\n', 2); - ft_cmd_process(node->u_data.sstr, data); - ft_putstr_fd("after exec\n", 2); + /* ft_putstr_fd("befor exec: ", 2); */ + /* ft_sstrprint_fd(2, ((t_astnode*)ast->item)->u_data.sstr, ','); */ + /* ft_putchar_fd('\n', 2); */ + ft_cmd_process(node->data.sstr, data); + /* ft_putstr_fd("after exec\n", 2); */ return (0); } diff --git a/42sh/src/exec/exec_dgreat.c b/42sh/src/exec/exec_dgreat.c index cfb62633..91ba3b47 100644 --- a/42sh/src/exec/exec_dgreat.c +++ b/42sh/src/exec/exec_dgreat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:15:13 by jhalford #+# #+# */ -/* Updated: 2016/11/29 20:29:10 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:48:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int exec_dgreat(t_btree *ast, t_data *data) int fd; node = ast->item; - fd = open(node->u_data.redir.u_word.word, O_WRONLY | O_APPEND | O_CREAT, 0644); + fd = open(node->data.redir.word.word, O_WRONLY | O_APPEND | O_CREAT, 0644); data->fdout = fd; ft_exec(ast->left, data); diff --git a/42sh/src/exec/exec_great.c b/42sh/src/exec/exec_great.c index d9b193de..e909d382 100644 --- a/42sh/src/exec/exec_great.c +++ b/42sh/src/exec/exec_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */ -/* Updated: 2016/11/29 20:26:40 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:49:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int exec_great(t_btree *ast, t_data *data) int fd; node = ast->item; - fd = open(node->u_data.redir.u_word.word, O_WRONLY | O_TRUNC | O_CREAT, 0644); + fd = open(node->data.redir.word.word, O_WRONLY | O_TRUNC | O_CREAT, 0644); data->fdout = fd; ft_exec(ast->left, data); diff --git a/42sh/src/exec/exec_less.c b/42sh/src/exec/exec_less.c index 9e2250ef..5af0a695 100644 --- a/42sh/src/exec/exec_less.c +++ b/42sh/src/exec/exec_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:27:08 by jhalford #+# #+# */ -/* Updated: 2016/11/29 20:29:01 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:52:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int exec_less(t_btree *ast, t_data *data) int fd; node = ast->item; - fd = open(node->u_data.redir.u_word.word, O_RDONLY); + fd = open(node->data.redir.word.word, O_RDONLY); data->fdin = fd; ft_exec(ast->left, data); diff --git a/42sh/src/exec/exec_or_if.c b/42sh/src/exec/exec_or_if.c index d28a347b..4c436116 100644 --- a/42sh/src/exec/exec_or_if.c +++ b/42sh/src/exec/exec_or_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */ -/* Updated: 2016/11/30 21:45:53 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 17:46:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,18 @@ int exec_or_if(t_btree *ast, t_data *data) { - ft_exec(ast->left, data); - ft_exec(ast->right, data); + if (data->aol_status == NULL + || (data->aol_search == TK_AND_IF && *data->aol_status == '0') + || (data->aol_search == TK_OR_IF && *data->aol_status != '0')) + { + ft_exec(ast->left, data); + data->aol_status = ft_getenv(data->env, "?"); + } + data->aol_search = TK_OR_IF; + if (*data->aol_status != '0' + || ((t_astnode*)ast->right->item)->type != TK_COMMAND) + ft_exec(ast->right, data); + data->aol_status = NULL; + data->aol_search = 0; return (0); } diff --git a/42sh/src/exec/fd_reset.c b/42sh/src/exec/fd_reset.c deleted file mode 100644 index 60d195df..00000000 --- a/42sh/src/exec/fd_reset.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* fd_reset.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/29 19:20:05 by jhalford #+# #+# */ -/* Updated: 2016/11/29 19:47:01 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void fd_reset(t_data *data) -{ - dup2(data->save_in, STDIN); - dup2(data->save_out, STDOUT); - data->fdin = STDIN; - data->fdout = STDOUT; -} diff --git a/42sh/src/exec/ft_cmd.c b/42sh/src/exec/ft_cmd.c index aae7b1e9..7e0d0517 100644 --- a/42sh/src/exec/ft_cmd.c +++ b/42sh/src/exec/ft_cmd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 21:13:18 by jhalford #+# #+# */ -/* Updated: 2016/12/01 14:46:48 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 17:22:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,7 @@ int ft_cmd_process(char **argv, t_data *data) else if (!(execpath = ft_findexec(path, argv[0]))) { ft_dprintf(2, "%s: command not found: %s\n", SHELL_NAME, argv[0]); + builtin_setenv((char*[3]){"?", "127"}, data); return (-1); } return (ft_cmd_exec(execpath, argv, data)); diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index ec42031d..bcd77c7f 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: 2016/11/30 20:52:07 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 17:18:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/ft_tokenize.c index 0079ad13..f2613209 100644 --- a/42sh/src/lexer/ft_tokenize.c +++ b/42sh/src/lexer/ft_tokenize.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */ -/* Updated: 2016/11/30 16:57:55 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:21:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -t_lexer *g_lexer[] = +int (*g_lexer[])(t_list **alst, char *str) = { &lexer_default, &lexer_delim, diff --git a/42sh/src/line-editing/ft_set_termios.c b/42sh/src/line-editing/ft_set_termios.c index 3037e940..24343268 100644 --- a/42sh/src/line-editing/ft_set_termios.c +++ b/42sh/src/line-editing/ft_set_termios.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:14:09 by jhalford #+# #+# */ -/* Updated: 2016/12/01 14:46:08 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:48:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,6 @@ int ft_set_termios(t_data *data, int input_mode) if ((term_name = ft_getenv(data->env, "TERM")) == NULL) return (-1); - ft_debug(); if (tgetent(NULL, term_name) != 1) return (-1); if (tcgetattr(0, &term) == -1) diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 41f32763..b6bbe8f6 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: 2016/12/01 14:46:13 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 17:31:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,8 @@ int data_init(t_data *data) data->history = NULL; data->fdin = STDIN; data->fdout = STDOUT; + data->aol_status = NULL; + data->aol_search = 0; if (!(data->history = ft_dlstnew(NULL, 0))) return (-1); return (0); diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 431c651c..9aca552d 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: 2016/11/30 21:48:51 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:54:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_putast2.c b/42sh/src/main/ft_putast2.c index df1e45f6..4d23eb88 100644 --- a/42sh/src/main/ft_putast2.c +++ b/42sh/src/main/ft_putast2.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2016/11/28 18:35:12 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:44:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,20 +24,20 @@ void ft_putast2(void *nodein) else if (node->type == TK_COMMAND) { ft_putstr_fd("COMMAND: ", 2); - ft_sstrprint_fd(2, node->u_data.sstr, ','); + ft_sstrprint_fd(2, node->data.sstr, ','); ft_putchar_fd('\n', 2); } else if (node->type & TK_REDIR) { - ft_putnbr_fd(node->u_data.redir.n, 2); + ft_putnbr_fd(node->data.redir.n, 2); if (node->type == TK_GREATAND || node->type == TK_LESSAND) { if (node->type == TK_GREATAND) ft_putstr_fd(">&:", 2); else ft_putstr_fd("<&:", 2); - ft_putnbr_fd(node->u_data.redir.u_word.fd, 2); - if (node->u_data.redir.close) + ft_putnbr_fd(node->data.redir.word.fd, 2); + if (node->data.redir.close) ft_putstr_fd(" (closed)", 2); } else @@ -50,7 +50,7 @@ void ft_putast2(void *nodein) ft_putstr_fd(">>:", 2); else if (node->type == TK_DLESS) ft_putstr_fd("<<:", 2); - ft_putstr_fd(node->u_data.redir.u_word.word, 2); + ft_putstr_fd(node->data.redir.word.word, 2); } ft_putchar_fd('\n', 2); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 89f460d4..72c3bf80 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 21:13:34 by jhalford #+# #+# */ -/* Updated: 2016/12/01 13:47:36 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 14:48:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 71f0e9c8..a614ed43 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */ -/* Updated: 2016/11/30 21:05:53 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:53:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,7 @@ int ft_parse(t_btree **ast, t_list **start) if (!*ast) { *ast = btree_create_node(&item, sizeof(item)); - ((t_astnode *)(*ast)->item)->u_data.sstr = NULL; + ((t_astnode *)(*ast)->item)->data.sstr = NULL; } while (g_parser[i].type) { diff --git a/42sh/src/parser/parse_dgreat.c b/42sh/src/parser/parse_dgreat.c index 1ad24b00..a27b7602 100644 --- a/42sh/src/parser/parse_dgreat.c +++ b/42sh/src/parser/parse_dgreat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2016/11/14 16:23:48 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:36:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,8 @@ int parse_dgreat(t_btree **ast, t_list **start, t_list **lst) next_tok = (*lst)->next->content; if (next_tok->type != TK_WORD) return (1); - node->u_data.redir.n = ft_atoi(tok->data); - node->u_data.redir.u_word.word = ft_strdup(next_tok->data); + node->data.redir.n = ft_atoi(tok->data); + node->data.redir.word.word = ft_strdup(next_tok->data); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free); ft_parse(&(*ast)->left, start); diff --git a/42sh/src/parser/parse_dless.c b/42sh/src/parser/parse_dless.c index 512772fc..e16e3a9c 100644 --- a/42sh/src/parser/parse_dless.c +++ b/42sh/src/parser/parse_dless.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2016/11/14 16:28:31 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:37:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ int parse_dless(t_btree **ast, t_list **start, t_list **lst) next_tok = (*lst)->next->content; if (next_tok->type != TK_WORD) return (1); - node->u_data.redir.u_word.word = ft_strdup(next_tok->data); + node->data.redir.word.word = ft_strdup(next_tok->data); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free); ft_parse(&(*ast)->left, start); diff --git a/42sh/src/parser/parse_great.c b/42sh/src/parser/parse_great.c index af9bb33c..b1dcd7e3 100644 --- a/42sh/src/parser/parse_great.c +++ b/42sh/src/parser/parse_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2016/11/30 21:45:46 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:37:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,8 @@ int parse_great(t_btree **ast, t_list **start, t_list **lst) next_tok = (*lst)->next->content; if (next_tok->type != TK_WORD) return (1); - node->u_data.redir.n = ft_atoi(tok->data); - node->u_data.redir.u_word.word = ft_strdup(next_tok->data); + node->data.redir.n = ft_atoi(tok->data); + node->data.redir.word.word = ft_strdup(next_tok->data); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free); diff --git a/42sh/src/parser/parse_greatand.c b/42sh/src/parser/parse_greatand.c index 35d3a4e8..b4d6f657 100644 --- a/42sh/src/parser/parse_greatand.c +++ b/42sh/src/parser/parse_greatand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2016/11/14 16:24:04 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:37:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,8 +22,8 @@ int parse_greatand(t_btree **ast, t_list **start, t_list **lst) node->type = TK_GREATAND; tok = (*lst)->content; and = ft_strchr(tok->data, '&'); - node->u_data.redir.u_word.fd = ft_atoi(and + 1); - node->u_data.redir.close = + node->data.redir.word.fd = ft_atoi(and + 1); + node->data.redir.close = tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0; ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_parse(&(*ast)->left, start); diff --git a/42sh/src/parser/parse_less.c b/42sh/src/parser/parse_less.c index b94b9129..5efd74b8 100644 --- a/42sh/src/parser/parse_less.c +++ b/42sh/src/parser/parse_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2016/11/30 18:03:37 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:36:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,8 @@ int parse_less(t_btree **ast, t_list **start, t_list **lst) next_tok = (*lst)->next->content; if (next_tok->type != TK_WORD) return (1); - node->u_data.redir.n = ft_atoi(tok->data); - node->u_data.redir.u_word.word = ft_strdup(next_tok->data); + node->data.redir.n = ft_atoi(tok->data); + node->data.redir.word.word = ft_strdup(next_tok->data); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free); ft_parse(&(*ast)->left, start); diff --git a/42sh/src/parser/parse_lessand.c b/42sh/src/parser/parse_lessand.c index 86a16413..8f5b0b9b 100644 --- a/42sh/src/parser/parse_lessand.c +++ b/42sh/src/parser/parse_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2016/11/14 16:14:17 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:37:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,8 +22,8 @@ int parse_lessand(t_btree **ast, t_list **start, t_list **lst) node->type = TK_LESSAND; tok = (*lst)->content; and = ft_strchr(tok->data, '&'); - node->u_data.redir.u_word.fd = ft_atoi(and + 1); - node->u_data.redir.close = + node->data.redir.word.fd = ft_atoi(and + 1); + node->data.redir.close = tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0; ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_parse(&(*ast)->left, start); diff --git a/42sh/src/parser/parse_word.c b/42sh/src/parser/parse_word.c index 87d48e48..979a4667 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: 2016/11/30 21:19:16 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 16:39:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ int parse_word(t_btree **ast, t_list **start, t_list **lst) token = (*lst)->content; node = (*ast)->item; node->type = TK_COMMAND; - node->u_data.sstr = ft_sstradd(node->u_data.sstr, token->data); + node->data.sstr = ft_sstradd(node->data.sstr, token->data); ft_parse(ast, &(*lst)->next); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);