diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 107973b8..3159300f 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/12/01 16:47:40 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:30:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,15 +17,15 @@ # define PIPE_READ 0 # define PIPE_WRITE 1 -typedef struct s_exec t_exec; +typedef struct s_execfunc t_execfunc; -struct s_exec +struct s_execfunc { t_type type; int (*f)(t_btree *ast, t_data *data); }; -extern t_exec g_exec[]; +extern t_execfunc g_execfunc[]; int ft_exec(t_btree *ast, t_data *data); diff --git a/42sh/includes/line_editing.h b/42sh/includes/line_editing.h index 3d6aa007..b81dfff8 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/03 12:51:30 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 13:44:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,9 +56,11 @@ typedef enum e_qstate t_qstate; extern t_stof g_keys[]; -int ft_set_termios(t_data *data, int input_mode); int ft_interactive_sh(t_data *data); +int input_init(t_data *data); +int ft_set_termios(t_data *data, int input_mode); int ft_prompt(void); + int ft_history_add(t_data *data); int ft_clear_line(t_data *data, char *buf); diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index eb9c955b..27a63214 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/03 12:54:06 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:27:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,20 +28,39 @@ # include typedef long long t_type; +typedef struct s_line t_line; +typedef struct s_comp t_comp; +typedef struct s_exec t_exec; -struct s_data +struct s_line { - char **env; t_dlist *history; - char *input; int input_pos; t_list *qstack; + char *input; +}; + +struct s_comp +{ + int a; +}; + +struct s_exec +{ int fdin; int fdout; char *aol_status; int aol_search; }; +struct s_data +{ + char **env; + t_exec exec; + t_line line; + t_comp comp; +}; + typedef struct s_data t_data; typedef enum e_qstate t_qstate; diff --git a/42sh/src/builtin/builtin.c b/42sh/src/builtin/builtin.c index 884af0d7..21efa5c3 100644 --- a/42sh/src/builtin/builtin.c +++ b/42sh/src/builtin/builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:21:34 by jhalford #+# #+# */ -/* Updated: 2016/12/03 11:55:49 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:17:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,7 @@ int ft_builtin(char **av, t_data *data) while (g_builtin[++i].name) if (ft_strcmp(g_builtin[i].name, *av) == 0) { - if (data->fdout != STDOUT) + if (data->exec.fdout != STDOUT) { if (fork() == 0) { diff --git a/42sh/src/exec/exec_and_if.c b/42sh/src/exec/exec_and_if.c index 9e0f13ce..c1e1f426 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/12/01 17:46:48 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:22:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,20 @@ int exec_and_if(t_btree *ast, t_data *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')) + if (data->exec.aol_status == NULL + || (data->exec.aol_search == TK_AND_IF + && *data->exec.aol_status == '0') + || (data->exec.aol_search == TK_OR_IF + && *data->exec.aol_status != '0')) { ft_exec(ast->left, data); - data->aol_status = ft_getenv(data->env, "?"); + data->exec.aol_status = ft_getenv(data->env, "?"); } - data->aol_search = TK_AND_IF; - if (*data->aol_status == '0' + data->exec.aol_search = TK_AND_IF; + if (*data->exec.aol_status == '0' || ((t_astnode*)ast->right->item)->type != TK_COMMAND) ft_exec(ast->right, data); - data->aol_status = NULL; - data->aol_search = 0; + data->exec.aol_status = NULL; + data->exec.aol_search = 0; return (0); } diff --git a/42sh/src/exec/exec_dgreat.c b/42sh/src/exec/exec_dgreat.c index 7a3c2062..0439372f 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/12/03 11:56:21 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:22:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,8 @@ int exec_dgreat(t_btree *ast, t_data *data) node = ast->item; fd = open(node->data.redir.word.word, O_WRONLY | O_APPEND | O_CREAT, 0644); - data->fdout = fd; + data->exec.fdout = fd; ft_exec(ast->left, data); - data->fdout = STDOUT; + data->exec.fdout = STDOUT; return (0); } diff --git a/42sh/src/exec/exec_great.c b/42sh/src/exec/exec_great.c index 1b7519bd..a971889a 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/12/03 11:56:28 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:22:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,8 @@ int exec_great(t_btree *ast, t_data *data) node = ast->item; fd = open(node->data.redir.word.word, O_WRONLY | O_TRUNC | O_CREAT, 0644); - data->fdout = fd; + data->exec.fdout = fd; ft_exec(ast->left, data); - data->fdout = STDOUT; + data->exec.fdout = STDOUT; return (0); } diff --git a/42sh/src/exec/exec_less.c b/42sh/src/exec/exec_less.c index 0656073a..7b3a8472 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/12/03 11:57:29 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:22:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,8 @@ int exec_less(t_btree *ast, t_data *data) node = ast->item; fd = open(node->data.redir.word.word, O_RDONLY); - data->fdin = fd; + data->exec.fdin = fd; ft_exec(ast->left, data); - data->fdin = STDIN; + data->exec.fdin = STDIN; return (0); } diff --git a/42sh/src/exec/exec_or_if.c b/42sh/src/exec/exec_or_if.c index 7376bdf0..511ad838 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/12/01 17:51:53 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:23:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,20 @@ int exec_or_if(t_btree *ast, t_data *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')) + if (data->exec.aol_status == NULL + || (data->exec.aol_search == TK_AND_IF + && *data->exec.aol_status == '0') + || (data->exec.aol_search == TK_OR_IF + && *data->exec.aol_status != '0')) { ft_exec(ast->left, data); - data->aol_status = ft_getenv(data->env, "?"); + data->exec.aol_status = ft_getenv(data->env, "?"); } - data->aol_search = TK_OR_IF; - if (*data->aol_status != '0' + data->exec.aol_search = TK_OR_IF; + if (*data->exec.aol_status != '0' || ((t_astnode*)ast->right->item)->type != TK_COMMAND) ft_exec(ast->right, data); - data->aol_status = NULL; - data->aol_search = 0; + data->exec.aol_status = NULL; + data->exec.aol_search = 0; return (0); } diff --git a/42sh/src/exec/exec_pipe.c b/42sh/src/exec/exec_pipe.c index a0cec109..9162a9e4 100644 --- a/42sh/src/exec/exec_pipe.c +++ b/42sh/src/exec/exec_pipe.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */ -/* Updated: 2016/12/03 11:56:38 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:23:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,16 +18,16 @@ int exec_pipe(t_btree *ast, t_data *data) pipe(fds); ft_dprintf(2, "pipe %i->%i\n", fds[PIPE_WRITE], fds[PIPE_READ]); - data->fdout = fds[PIPE_WRITE]; + data->exec.fdout = fds[PIPE_WRITE]; ft_exec(ast->left, data); - if (data->fdout != STDOUT) - close(data->fdout); - data->fdout = STDOUT; - data->fdin = fds[PIPE_READ]; + if (data->exec.fdout != STDOUT) + close(data->exec.fdout); + data->exec.fdout = STDOUT; + data->exec.fdin = fds[PIPE_READ]; ft_exec(ast->right, data); close(fds[PIPE_WRITE]); close(fds[PIPE_READ]); - data->fdin = STDIN; - data->fdout = STDOUT; + data->exec.fdin = STDIN; + data->exec.fdout = STDOUT; return (0); } diff --git a/42sh/src/exec/fd_redirect.c b/42sh/src/exec/fd_redirect.c index 4fd97271..6c1d8c47 100644 --- a/42sh/src/exec/fd_redirect.c +++ b/42sh/src/exec/fd_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2016/12/03 11:58:27 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:24:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,14 +14,14 @@ void fd_redirect(t_data *data) { - if (data->fdin != STDIN) + if (data->exec.fdin != STDIN) { - dup2(data->fdin, STDIN); - close(data->fdin); + dup2(data->exec.fdin, STDIN); + close(data->exec.fdin); } - if (data->fdout != STDOUT) + if (data->exec.fdout != STDOUT) { - dup2(data->fdout, STDOUT); - close(data->fdout); + dup2(data->exec.fdout, STDOUT); + close(data->exec.fdout); } } diff --git a/42sh/src/exec/ft_cmd.c b/42sh/src/exec/ft_cmd.c index b95041b2..a05d9e2b 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/03 12:06:32 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:24:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,7 +55,7 @@ int ft_cmd_exec(char *execpath, char **argv, t_data *data) } else if ((g_pid = pid)) { - if (data->fdout == STDOUT) + if (data->exec.fdout == STDOUT) { waitpid(pid, &status, 0); builtin_setenv((char*[3]){"?", ft_itoa(status)}, data); diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index d9857a83..e39d0da8 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2016/12/03 11:58:36 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:25:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "exec.h" -t_exec g_exec[] = +t_execfunc g_execfunc[] = { {TK_AND_IF, &exec_and_if}, {TK_OR_IF, &exec_or_if}, @@ -34,10 +34,10 @@ int ft_exec(t_btree *ast, t_data *data) item = ast->item; if (!ast) return (0); - while (g_exec[i].type) + while (g_execfunc[i].type) { - if (item->type == g_exec[i].type) - return ((*g_exec[i].f)(ast, data)); + if (item->type == g_execfunc[i].type) + return ((*g_execfunc[i].f)(ast, data)); i++; } return (0); diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/ft_tokenize.c index 34c39844..4353dff2 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: 2016/12/03 12:50:42 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 13:49:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/qstate_update.c b/42sh/src/lexer/qstate_update.c index f45393f7..351b552e 100644 --- a/42sh/src/lexer/qstate_update.c +++ b/42sh/src/lexer/qstate_update.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 15:56:40 by jhalford #+# #+# */ -/* Updated: 2016/12/03 12:36:20 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:36:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ void qstate_update(t_data *data, char c) t_list **list; t_list *tmp; - list = &data->qstack; + list = &data->line.qstack; state = (*list)->content; if (c == -1) { diff --git a/42sh/src/line-editing/ft_cursor_left.c b/42sh/src/line-editing/ft_cursor_left.c index a6d7b6b1..62ba6d74 100644 --- a/42sh/src/line-editing/ft_cursor_left.c +++ b/42sh/src/line-editing/ft_cursor_left.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:43:10 by jhalford #+# #+# */ -/* Updated: 2016/11/10 13:43:25 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:26:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,11 +18,11 @@ int ft_cursor_left(t_data *data, char *buf) res = NULL; (void)buf; - if (!data->input_pos) + if (!data->line.input_pos) return (0); - if (data->input[data->input_pos - 1] == '\n') + if (data->line.input[data->line.input_pos - 1] == '\n') return (0); - data->input_pos--; + data->line.input_pos--; if (!(res = tgetstr("le", NULL))) return (-1); tputs(tgoto(res, 0, 0), 0, &ft_putchar); diff --git a/42sh/src/line-editing/ft_cursor_right.c b/42sh/src/line-editing/ft_cursor_right.c index 71785cab..60ddedc4 100644 --- a/42sh/src/line-editing/ft_cursor_right.c +++ b/42sh/src/line-editing/ft_cursor_right.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:43:31 by jhalford #+# #+# */ -/* Updated: 2016/11/10 13:43:31 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:26:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,11 +18,11 @@ int ft_cursor_right(t_data *data, char *buf) res = NULL; (void)buf; - if (!data->input[data->input_pos]) + if (!data->line.input[data->line.input_pos]) return (0); - if (data->input[data->input_pos] == '\n') + if (data->line.input[data->line.input_pos] == '\n') return (0); - data->input_pos++; + data->line.input_pos++; if ((res = tgetstr("nd", NULL)) == NULL) return (-1); tputs(tgoto(res, 0, 0), 0, &ft_putchar); diff --git a/42sh/src/line-editing/ft_history_add.c b/42sh/src/line-editing/ft_history_add.c index 903d8f7b..aa796add 100644 --- a/42sh/src/line-editing/ft_history_add.c +++ b/42sh/src/line-editing/ft_history_add.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:43:40 by jhalford #+# #+# */ -/* Updated: 2016/12/03 12:51:27 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:27:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,17 +17,17 @@ int ft_history_add(t_data *data) t_dlist *new; char *str; - str = data->input; - if (data->history) - while (data->history->next) - data->history = data->history->next; - if (!data->history->prev - || ft_strcmp(str, (char *)data->history->prev->content)) + str = data->line.input; + if (data->line.history) + while (data->line.history->next) + data->line.history = data->line.history->next; + if (!data->line.history->prev + || ft_strcmp(str, (char *)data->line.history->prev->content)) { new = ft_dlstnew(str, sizeof(char) * (ft_strlen(str) + 1)); - ft_dlstadd_before(&data->history, new); - data->history = data->history->next; - ft_strdel((char **)&data->history->content); + ft_dlstadd_before(&data->line.history, new); + data->line.history = data->line.history->next; + ft_strdel((char **)&data->line.history->content); } return (0); } diff --git a/42sh/src/line-editing/ft_history_down.c b/42sh/src/line-editing/ft_history_down.c index 6f15dee6..989786a9 100644 --- a/42sh/src/line-editing/ft_history_down.c +++ b/42sh/src/line-editing/ft_history_down.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:44:06 by jhalford #+# #+# */ -/* Updated: 2016/11/10 13:44:06 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:27:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,18 +18,14 @@ int ft_history_down(t_data *data, char *buf) char *str; (void)buf; - if (!data->history) + if (!data->line.history) return (0); - if (!data->history->next) + if (!data->line.history->next) return (0); - data->history = data->history->next; - str = data->history->content; - /* *input_chain = ft_dlstlast(*input_chain); */ - /* ft_clear_input(input_chain); */ + data->line.history = data->line.history->next; + str = data->line.history->content; i = 0; - /* while (str[i]) */ - /* ft_key_basic(data, input_chain, str + i++); */ - if (!data->history->next) + if (!data->line.history->next) ft_strdel(&str); return (0); } diff --git a/42sh/src/line-editing/ft_history_up.c b/42sh/src/line-editing/ft_history_up.c index dccbfc93..04d4aa41 100644 --- a/42sh/src/line-editing/ft_history_up.c +++ b/42sh/src/line-editing/ft_history_up.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:44:15 by jhalford #+# #+# */ -/* Updated: 2016/11/10 13:44:15 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:28:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,20 +18,12 @@ int ft_history_up(t_data *data, char *buf) char *str; (void)buf; - if (!data->history) + if (!data->line.history) return (0); - if (!data->history->prev) + if (!data->line.history->prev) return (0); - /* if (!data->history->next) */ - /* data->history->content = ft_dlsttostr(*input_chain); */ - data->history = data->history->prev; - str = data->history->content; - /* *input_chain = ft_dlst_last(*input_chain); */ - /* ft_clear_line(data, input_chain, buf); */ + data->line.history = data->line.history->prev; + str = data->line.history->content; i = 0; - /* while (str[i]) */ - /* ft_key_basic(data, input_chain, str + i++); */ - /* if (!data->history->next) */ - /* ft_strdel(&str); */ return (0); } diff --git a/42sh/src/line-editing/ft_interactive_sh.c b/42sh/src/line-editing/ft_interactive_sh.c index 0e25da09..b82f4750 100644 --- a/42sh/src/line-editing/ft_interactive_sh.c +++ b/42sh/src/line-editing/ft_interactive_sh.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:14:12 by jhalford #+# #+# */ -/* Updated: 2016/12/03 12:54:48 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:37:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,20 +42,11 @@ t_stof g_keys[] = { int ft_interactive_sh(t_data *data) { char buf[4]; - char null; int ret; int i; - null = '\0'; - - ft_strdel(&data->input); - data->input = ft_memalloc(10); - data->input_pos = 0; - data->qstack = ft_lstnew(NULL, sizeof(t_qstate)); - *((t_qstate*)data->qstack->content) = Q_NONE; - if (ft_set_termios(data, 1)) + if ((input_init(data))) return (-1); - ft_prompt(); while (1) { ft_bzero(buf, 4); @@ -69,7 +60,7 @@ int ft_interactive_sh(t_data *data) return (-1); else if (ret == 2) { - ft_lstdel(&data->qstack, &ft_lst_cfree); + ft_lstdel(&data->line.qstack, &ft_lst_cfree); ft_set_termios(data, 0); return (0); } diff --git a/42sh/src/line-editing/ft_key_ctrl_c.c b/42sh/src/line-editing/ft_key_ctrl_c.c index bf34a8b8..eebb7d02 100644 --- a/42sh/src/line-editing/ft_key_ctrl_c.c +++ b/42sh/src/line-editing/ft_key_ctrl_c.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:44:24 by jhalford #+# #+# */ -/* Updated: 2016/11/10 13:44:24 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:29:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,9 +15,8 @@ int ft_key_ctrl_c(t_data *data, char *buf) { (void)buf; - - ft_strdel(&data->input); - data->input = ft_memalloc(10); + ft_strdel(&data->line.input); + data->line.input = ft_memalloc(10); ft_putendl(""); ft_prompt(); return (0); diff --git a/42sh/src/line-editing/ft_key_default.c b/42sh/src/line-editing/ft_key_default.c index 540be2c5..f440adbb 100644 --- a/42sh/src/line-editing/ft_key_default.c +++ b/42sh/src/line-editing/ft_key_default.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:45:23 by jhalford #+# #+# */ -/* Updated: 2016/11/29 13:49:51 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:37:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,9 @@ int ft_key_default(t_data *data, char *buf) char *res; char *tmp; - tmp = data->input; - data->input = ft_strinsert(data->input, *buf, data->input_pos); - data->input_pos++; + tmp = data->line.input; + data->line.input = ft_strinsert(data->line.input, *buf, data->line.input_pos); + data->line.input_pos++; ft_strdel(&tmp); qstate_update(data, *buf); if ((res = tgetstr("IC", NULL))) diff --git a/42sh/src/line-editing/ft_key_del.c b/42sh/src/line-editing/ft_key_del.c index f2c34cbc..4ce4e6fd 100644 --- a/42sh/src/line-editing/ft_key_del.c +++ b/42sh/src/line-editing/ft_key_del.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 15:57:43 by jhalford #+# #+# */ -/* Updated: 2016/11/29 15:57:44 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:30:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,14 +18,14 @@ int ft_key_del(t_data *data, char *buf) (void)data; (void)buf; - if (!data->input_pos) + if (!data->line.input_pos) return (0); - if (data->input[data->input_pos - 1] == '\n') + if (data->line.input[data->line.input_pos - 1] == '\n') return (0); qstate_update(data, -1); - ft_strcpy(data->input + data->input_pos - 1, - data->input + data->input_pos); - data->input_pos--; + ft_strcpy(data->line.input + data->line.input_pos - 1, + data->line.input + data->line.input_pos); + data->line.input_pos--; if ((res = tgetstr("le", NULL)) == NULL) { ft_printf("le error\n"); diff --git a/42sh/src/line-editing/ft_key_enter.c b/42sh/src/line-editing/ft_key_enter.c index 39531035..60acb82d 100644 --- a/42sh/src/line-editing/ft_key_enter.c +++ b/42sh/src/line-editing/ft_key_enter.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 15:56:36 by jhalford #+# #+# */ -/* Updated: 2016/11/29 15:56:36 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:30:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ int ft_key_enter(t_data *data, char *buf) { (void)buf; - if (*(t_qstate*)data->qstack->content == Q_NONE) + if (*(t_qstate*)data->line.qstack->content == Q_NONE) { ft_putchar('\n'); ft_history_add(data); diff --git a/42sh/src/line-editing/ft_word_left.c b/42sh/src/line-editing/ft_word_left.c index e5efc817..6689c508 100644 --- a/42sh/src/line-editing/ft_word_left.c +++ b/42sh/src/line-editing/ft_word_left.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:44:36 by jhalford #+# #+# */ -/* Updated: 2016/11/10 13:44:36 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:31:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,15 +15,11 @@ int ft_word_left(t_data *data, char *buf) { ft_cursor_left(data, buf); - while (FT_WS(data->input[data->input_pos - 1])) - { - if (!ft_cursor_left(data, buf)) - return (0) ; - } - while (!FT_WS(data->input[data->input_pos - 1])) - { + while (FT_WS(data->line.input[data->line.input_pos - 1])) + if (!ft_cursor_left(data, buf)) + return (0); + while (!FT_WS(data->line.input[data->line.input_pos - 1])) if (!ft_cursor_left(data, buf)) return (0); - } return (0); } diff --git a/42sh/src/line-editing/ft_word_right.c b/42sh/src/line-editing/ft_word_right.c index 6d1a6012..7999d2df 100644 --- a/42sh/src/line-editing/ft_word_right.c +++ b/42sh/src/line-editing/ft_word_right.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:44:37 by jhalford #+# #+# */ -/* Updated: 2016/11/10 13:44:37 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:31:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,15 +14,11 @@ int ft_word_right(t_data *data, char *buf) { - while (!FT_WS(data->input[data->input_pos])) - { + while (!FT_WS(data->line.input[data->line.input_pos])) if (!ft_cursor_right(data, buf)) return (0); - } - while (FT_WS(data->input[data->input_pos])) - { + while (FT_WS(data->line.input[data->line.input_pos])) if (!ft_cursor_right(data, buf)) - return (0) ; - } + return (0); return (0); } diff --git a/42sh/src/line-editing/input_init.c b/42sh/src/line-editing/input_init.c new file mode 100644 index 00000000..254c1133 --- /dev/null +++ b/42sh/src/line-editing/input_init.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* input_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 13:35:03 by jhalford #+# #+# */ +/* Updated: 2016/12/03 15:34:29 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int input_init(t_data *data) +{ + char null; + + null = '\0'; + ft_strdel(&data->line.input); + data->line.input = ft_memalloc(10); + data->line.input_pos = 0; + data->line.qstack = ft_lstnew(NULL, sizeof(t_qstate)); + *((t_qstate*)data->line.qstack->content) = Q_NONE; + if (ft_set_termios(data, 1)) + return (-1); + ft_prompt(); + return (0); +} diff --git a/42sh/src/line-editing/qstate_dquote.c b/42sh/src/line-editing/qstate_dquote.c new file mode 100644 index 00000000..15cd7f93 --- /dev/null +++ b/42sh/src/line-editing/qstate_dquote.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* qstate_dquote.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 12:10:09 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:26:09 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "line_editing.h" + +void qstate_dquote(t_qstate *new, char c) +{ + if (c == '\\') + *new = Q_BACKSLASH; + else if (c == '\"') + *new = Q_NONE; +} diff --git a/42sh/src/line-editing/qstate_none.c b/42sh/src/line-editing/qstate_none.c new file mode 100644 index 00000000..f1f2e8c4 --- /dev/null +++ b/42sh/src/line-editing/qstate_none.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* qstate_none.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 12:08:48 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:51:29 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "line_editing.h" + +void qstate_none(t_qstate *new, char c) +{ + if (c == '\\') + *new = Q_BACKSLASH; + else if (c == '\"') + *new = Q_DQUOTE; + else if (c == '\'') + *new = Q_QUOTE; +} diff --git a/42sh/src/line-editing/qstate_quote.c b/42sh/src/line-editing/qstate_quote.c new file mode 100644 index 00000000..3e76a128 --- /dev/null +++ b/42sh/src/line-editing/qstate_quote.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* qstate_quote.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 12:10:09 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:26:06 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "line_editing.h" + +void qstate_quote(t_qstate *new, char c) +{ + if (c == '\'') + *new = Q_NONE; +} diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index b6bbe8f6..ed6cd000 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 17:31:00 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:32:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,12 @@ int data_init(t_data *data) { atexit(&ft_cleanup); data->env = ft_sstrdup(environ); - data->history = NULL; - data->fdin = STDIN; - data->fdout = STDOUT; - data->aol_status = NULL; - data->aol_search = 0; - if (!(data->history = ft_dlstnew(NULL, 0))) + data->line.history = NULL; + data->exec.fdin = STDIN; + data->exec.fdout = STDOUT; + data->exec.aol_status = NULL; + data->exec.aol_search = 0; + if (!(data->line.history = ft_dlstnew(NULL, 0))) return (-1); return (0); } diff --git a/42sh/src/main/ft_cleanup.c b/42sh/src/main/ft_cleanup.c index c7c424c2..d06d7254 100644 --- a/42sh/src/main/ft_cleanup.c +++ b/42sh/src/main/ft_cleanup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 14:42:42 by jhalford #+# #+# */ -/* Updated: 2016/12/01 14:46:07 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:19:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 9aca552d..e1435c62 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/12/01 16:54:25 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 13:44:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,23 @@ char *ft_putast(void *nodein) { t_astnode *node; + struct s_tmp{ + char str[5]; + t_type type; + }; + +/* struct s_tmp[] = */ +/* { */ +/* {TK_AMP, " & "}, */ +/* {TK_SEMI, " & "}, */ +/* {TK_AND_IF, " & "}, */ +/* {TK_OR_IF, " & "}, */ +/* {TK_PIPE, " & "}, */ +/* {TK_COMMAND, " & "}, */ +/* {TK_GREAT, " & "}, */ +/* {TK_AMP, " & "}, */ +/* {TK_AMP, " & "}, */ +/* } */ node = nodein; if (node->type == TK_AMP) @@ -28,13 +45,7 @@ char *ft_putast(void *nodein) else if (node->type == TK_PIPE) return (" | "); else if (node->type == TK_COMMAND) - { - /*char **sstr = node->u_data.sstr; */ - /* while (*sstr) */ - /* ft_printf("%s,", *sstr++); */ - /* return (ft_itoa_base(node->type, "0123456789abcdef", "")); */ return (" COM "); - } else if (node->type == TK_GREAT) return (" > "); else if (node->type == TK_LESS) diff --git a/42sh/src/main/lib_expansion.c b/42sh/src/main/lib_expansion.c index 366bca87..8905c284 100644 --- a/42sh/src/main/lib_expansion.c +++ b/42sh/src/main/lib_expansion.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lib_expansion.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 13:37:41 by jhalford #+# #+# */ +/* Updated: 2016/12/03 13:37:41 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "minishell.h" void ft_expand_dollar(char **av, char **env) diff --git a/42sh/src/main/lib_path.c b/42sh/src/main/lib_path.c index ba899ea0..acd4c70d 100644 --- a/42sh/src/main/lib_path.c +++ b/42sh/src/main/lib_path.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lib_path.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 13:37:49 by jhalford #+# #+# */ +/* Updated: 2016/12/03 13:37:49 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "minishell.h" char *ft_findexec(char **path, char *file) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index baebd59e..a1ded8ed 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/03 13:15:35 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 15:33:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ int main(void) return (1); /* ft_dprintf(STDERR, "command='%s'\n", data.input); */ token = NULL; - if (ft_tokenize(&token, data.input, DEFAULT)) + if (ft_tokenize(&token, data.line.input, DEFAULT)) return (1); if (!token) continue ; diff --git a/42sh/src/main/sig_handler.c b/42sh/src/main/sig_handler.c index f9be53fb..d56b03ee 100644 --- a/42sh/src/main/sig_handler.c +++ b/42sh/src/main/sig_handler.c @@ -6,11 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:43:22 by jhalford #+# #+# */ -/* Updated: 2016/12/01 14:46:41 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 13:31:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" + pid_t g_pid; void sig_handler(int signo) diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index a614ed43..3793b5ea 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/12/01 16:53:41 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 13:50:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,7 +34,7 @@ int ft_parse(t_btree **ast, t_list **start) int i; i = 0; - if(!*start) + if (!*start) return (0); if (!*ast) { diff --git a/42sh/src/parser/parse_dless.c b/42sh/src/parser/parse_dless.c index e16e3a9c..a1970bbb 100644 --- a/42sh/src/parser/parse_dless.c +++ b/42sh/src/parser/parse_dless.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* parse_dless.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2016/12/01 16:37:20 by jhalford ### ########.fr */ +/* Created: 2016/12/03 13:31:40 by jhalford #+# #+# */ +/* Updated: 2016/12/03 13:31:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,4 +32,3 @@ int parse_dless(t_btree **ast, t_list **start, t_list **lst) ft_parse(&(*ast)->left, start); return (0); } - diff --git a/42sh/src/parser/parse_great.c b/42sh/src/parser/parse_great.c index b1dcd7e3..9081a02e 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/12/01 16:37:29 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 13:32:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_separator.c b/42sh/src/parser/parse_separator.c index fcea3ea7..dc35483e 100644 --- a/42sh/src/parser/parse_separator.c +++ b/42sh/src/parser/parse_separator.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */ -/* Updated: 2016/11/30 21:45:49 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 13:32:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,11 +20,8 @@ int parse_separator(t_btree **ast, t_list **start, t_list **lst) token = (*lst)->content; node = (*ast)->item; node->type = token->type; - ft_parse(&(*ast)->right, &(*lst)->next); - ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); - ft_parse(&(*ast)->left, start); return (0); }