diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 4233e196..b52d4bd6 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 16:21:29 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 18:01:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/line_editing.h b/42sh/includes/line_editing.h index 3ba924a5..3d6aa007 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 15:59:19 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:51:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,16 @@ # define FT_KEY_BSLASH "\x5c" # define FT_KEY_DEL "\x7f" +enum e_qstate +{ + Q_NONE, + Q_QUOTE, + Q_DQUOTE, + Q_BACKSLASH, +}; + typedef struct s_data t_data; +typedef enum e_qstate t_qstate; extern t_stof g_keys[]; @@ -71,4 +80,8 @@ 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); +void qstate_none(t_qstate *new, char c); +void qstate_quote(t_qstate *new, char c); +void qstate_dquote(t_qstate *new, char c); + #endif diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 79f26788..eb9c955b 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 17:31:10 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:54:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,15 +29,7 @@ typedef long long t_type; -typedef enum e_qstate -{ - Q_NONE, - Q_QUOTE, - Q_DQUOTE, - Q_BACKSLASH, -} t_qstate; - -typedef struct s_data +struct s_data { char **env; t_dlist *history; @@ -48,7 +40,10 @@ typedef struct s_data int fdout; char *aol_status; int aol_search; -} t_data; +}; + +typedef struct s_data t_data; +typedef enum e_qstate t_qstate; extern t_stof g_builtins[]; extern pid_t g_pid; diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index a398d0f8..79b606dd 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 16:35:54 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:08:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin.c b/42sh/src/builtin/builtin.c index 65fabb68..884af0d7 100644 --- a/42sh/src/builtin/builtin.c +++ b/42sh/src/builtin/builtin.c @@ -6,20 +6,20 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:21:34 by jhalford #+# #+# */ -/* Updated: 2016/12/01 12:12:12 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:55:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" t_stof g_builtin[] = { - {"echo", &builtin_echo}, - {"cd", &builtin_cd}, - {"setenv", &builtin_setenv}, - {"unsetenv", &builtin_unsetenv}, - {"env", &builtin_env}, - {"exit", &builtin_exit}, - {NULL, NULL}, + {"echo", &builtin_echo}, + {"cd", &builtin_cd}, + {"setenv", &builtin_setenv}, + {"unsetenv", &builtin_unsetenv}, + {"env", &builtin_env}, + {"exit", &builtin_exit}, + {NULL, NULL}, }; int ft_builtin(char **av, t_data *data) @@ -27,9 +27,8 @@ int ft_builtin(char **av, t_data *data) int i; int ret; - i = 0; - while (g_builtin[i].name) - { + i = -1; + while (g_builtin[++i].name) if (ft_strcmp(g_builtin[i].name, *av) == 0) { if (data->fdout != STDOUT) @@ -48,7 +47,5 @@ int ft_builtin(char **av, t_data *data) } return (1); } - i++; - } return (0); } diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/src/builtin/builtin_cd.c index 236dfbd7..d42e6309 100644 --- a/42sh/src/builtin/builtin_cd.c +++ b/42sh/src/builtin/builtin_cd.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtin_cd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */ +/* Updated: 2016/12/03 11:58:14 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "minishell.h" #define CDOPT_L 0x001 #define CDOPT_P 0x002 diff --git a/42sh/src/builtin/builtin_unsetenv.c b/42sh/src/builtin/builtin_unsetenv.c index ead029cb..93104cda 100644 --- a/42sh/src/builtin/builtin_unsetenv.c +++ b/42sh/src/builtin/builtin_unsetenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */ -/* Updated: 2016/11/28 14:29:50 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:55:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,6 @@ int builtin_unsetenv(char **av, t_data *data) int j; env = data->env; - /* ft_printf("builtin: %s\n", av[0]); */ i = 1; while (av[i]) { diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index ee4c1077..0f055cdb 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/12/01 16:48:42 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:56:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,6 @@ 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->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 91ba3b47..7a3c2062 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/01 16:48:54 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:56:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,9 +20,7 @@ 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; - ft_exec(ast->left, data); - data->fdout = STDOUT; return (0); } diff --git a/42sh/src/exec/exec_great.c b/42sh/src/exec/exec_great.c index e909d382..1b7519bd 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/01 16:49:16 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:56:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,9 +20,7 @@ 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; - ft_exec(ast->left, data); - data->fdout = STDOUT; return (0); } diff --git a/42sh/src/exec/exec_less.c b/42sh/src/exec/exec_less.c index 5af0a695..0656073a 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/01 16:52:21 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:57:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,9 +20,7 @@ int exec_less(t_btree *ast, t_data *data) node = ast->item; fd = open(node->data.redir.word.word, O_RDONLY); data->fdin = fd; - ft_exec(ast->left, data); - data->fdin = STDIN; return (0); } diff --git a/42sh/src/exec/exec_or_if.c b/42sh/src/exec/exec_or_if.c index 4c436116..7376bdf0 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:46:53 by jhalford ### ########.fr */ +/* Updated: 2016/12/01 17:51:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_pipe.c b/42sh/src/exec/exec_pipe.c index fa194bc6..a0cec109 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/11/29 19:19:50 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:56:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,16 +19,12 @@ 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]; - ft_exec(ast->left, data); - if (data->fdout != STDOUT) close(data->fdout); data->fdout = STDOUT; data->fdin = fds[PIPE_READ]; - ft_exec(ast->right, data); - close(fds[PIPE_WRITE]); close(fds[PIPE_READ]); data->fdin = STDIN; diff --git a/42sh/src/exec/fd_redirect.c b/42sh/src/exec/fd_redirect.c index 95220ca2..4fd97271 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/11/29 20:21:17 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:58:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,13 +16,11 @@ void fd_redirect(t_data *data) { if (data->fdin != STDIN) { - /* ft_dprintf(2, "redirecting input: %i->STDIN\n", data->fdin); */ dup2(data->fdin, STDIN); close(data->fdin); } if (data->fdout != STDOUT) { - /* ft_dprintf(2, "redirecting output: %i->STDOUT\n", data->fdout); */ dup2(data->fdout, STDOUT); close(data->fdout); } diff --git a/42sh/src/exec/ft_cmd.c b/42sh/src/exec/ft_cmd.c index 7e0d0517..b95041b2 100644 --- a/42sh/src/exec/ft_cmd.c +++ b/42sh/src/exec/ft_cmd.c @@ -6,11 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 21:13:18 by jhalford #+# #+# */ -/* Updated: 2016/12/01 17:22:51 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:06:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" + extern pid_t g_pid; int ft_cmd_process(char **argv, t_data *data) @@ -44,7 +45,6 @@ int ft_cmd_exec(char *execpath, char **argv, t_data *data) ft_dprintf(2, "%s: permission denied: %s\n", SHELL_NAME, argv[0]); return (-1); } - /* ft_dprintf(2, "gonna fork, in=%i, out=%i\n", data->fdin, data->fdout); */ if ((pid = fork()) == -1) return (-1); else if (pid == 0) @@ -53,12 +53,10 @@ int ft_cmd_exec(char *execpath, char **argv, t_data *data) environ = ft_sstrdup(data->env); execve(execpath, argv, environ); } - else + else if ((g_pid = pid)) { - g_pid = pid; if (data->fdout == STDOUT) { - ft_dprintf(2, "[waiting for PID = %i]\n", pid); 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 bcd77c7f..d9857a83 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/12/01 17:18:03 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:58:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ int ft_exec(t_btree *ast, t_data *data) i = 0; item = ast->item; - if(!ast) + if (!ast) return (0); while (g_exec[i].type) { diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/ft_tokenize.c index f2613209..34c39844 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/01 16:21:26 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:50:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,19 +44,13 @@ int ft_tokenize(t_list **alst, char *str, t_lexstate state) *alst = ft_lstnew(token, sizeof(*token)); if (ft_is_delim(*str)) state = DELIM; - if (*str == '&' || *str == ';' || *str == '|') + else if (*str == '&' || *str == ';' || *str == '|') state = SEP; - else if (*str == '\'') - { - state = QUOTE; - str++; - } - else if (*str == '\"') - { - state = DQUOTE; - str++; - } else if (*str == '\\') state = BACKSLASH; + else if (*str == '\'') + return ((*g_lexer[QUOTE])(alst, str + 1)); + else if (*str == '\"') + return ((*g_lexer[DQUOTE])(alst, str + 1)); return ((*g_lexer[state])(alst, str)); } diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index 85b837c4..9a6f2438 100644 --- a/42sh/src/lexer/lexer_backslash.c +++ b/42sh/src/lexer/lexer_backslash.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_backslash.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:35:13 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" int lexer_backslash(t_list **alst, char *str) diff --git a/42sh/src/lexer/lexer_delim.c b/42sh/src/lexer/lexer_delim.c index ce046ef5..6c79b0a8 100644 --- a/42sh/src/lexer/lexer_delim.c +++ b/42sh/src/lexer/lexer_delim.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_delim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ +/* Updated: 2016/12/03 11:58:45 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" int lexer_delim(t_list **alst, char *str) diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index 0b9745ed..0bf59e62 100644 --- a/42sh/src/lexer/lexer_dquote.c +++ b/42sh/src/lexer/lexer_dquote.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ -/* Updated: 2016/11/28 18:43:39 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:43:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,6 @@ int lexer_dquote(t_list **alst, char *str) return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT)); if (*str == '\\') { - token_append(token, *str); token_append(token, *(str + 1)); return (lexer_dquote(alst, str + 2)); } diff --git a/42sh/src/lexer/lexer_great.c b/42sh/src/lexer/lexer_great.c index 16f7767e..910f48b2 100644 --- a/42sh/src/lexer/lexer_great.c +++ b/42sh/src/lexer/lexer_great.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_great.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:51:11 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" int lexer_great(t_list **alst, char *str) diff --git a/42sh/src/lexer/lexer_greatand.c b/42sh/src/lexer/lexer_greatand.c index c19ed388..7a32ef24 100644 --- a/42sh/src/lexer/lexer_greatand.c +++ b/42sh/src/lexer/lexer_greatand.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_greatand.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */ +/* Updated: 2016/12/03 11:57:09 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" int lexer_greatand(t_list **alst, char *str) diff --git a/42sh/src/lexer/lexer_less.c b/42sh/src/lexer/lexer_less.c index 9b7a38e8..45dd0613 100644 --- a/42sh/src/lexer/lexer_less.c +++ b/42sh/src/lexer/lexer_less.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_less.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:06:53 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" int lexer_less(t_list **alst, char *str) diff --git a/42sh/src/lexer/lexer_lessand.c b/42sh/src/lexer/lexer_lessand.c index 7a0ada9f..089c78bd 100644 --- a/42sh/src/lexer/lexer_lessand.c +++ b/42sh/src/lexer/lexer_lessand.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_lessand.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */ +/* Updated: 2016/12/03 11:58:52 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" int lexer_lessand(t_list **alst, char *str) diff --git a/42sh/src/lexer/lexer_number.c b/42sh/src/lexer/lexer_number.c index c28068b2..83816749 100644 --- a/42sh/src/lexer/lexer_number.c +++ b/42sh/src/lexer/lexer_number.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_number.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:06:46 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" int lexer_number(t_list **alst, char *str) diff --git a/42sh/src/lexer/lexer_quote.c b/42sh/src/lexer/lexer_quote.c index 8c9d1bc4..46344785 100644 --- a/42sh/src/lexer/lexer_quote.c +++ b/42sh/src/lexer/lexer_quote.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_quote.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 12:07:08 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:07:08 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" int lexer_quote(t_list **alst, char *str) diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index bbd35cc8..f6375e58 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_word.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:07:12 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" int lexer_word(t_list **alst, char *str) diff --git a/42sh/src/lexer/qstate_update.c b/42sh/src/lexer/qstate_update.c index 12c62b27..f45393f7 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/11/29 15:57:46 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:36:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,6 @@ void qstate_update(t_data *data, char c) list = &data->qstack; state = (*list)->content; - /* ft_printf("befor state: %i\n", *state); */ if (c == -1) { tmp = ft_lstpop(list); @@ -32,27 +31,11 @@ void qstate_update(t_data *data, char c) new = (*list)->content; *new = *state; if (*state == Q_NONE) - { - if (c == '\\') - *new = Q_BACKSLASH; - else if (c == '\"') - *new = Q_DQUOTE; - else if (c == '\'') - *new = Q_QUOTE; - } + qstate_none(new, c); else if (*state == Q_QUOTE) - { - if (c == '\'') - *new = Q_NONE; - } + qstate_quote(new, c); else if (*state == Q_DQUOTE) - { - if (c == '\\') - *new = Q_BACKSLASH; - else if (c == '\"') - *new = Q_NONE; - } + qstate_dquote(new, c); else if (*state == Q_BACKSLASH) *new = *(t_qstate*)(*list)->next->next->content; - /* ft_printf("new state: %i\n", *new); */ } diff --git a/42sh/src/lexer/token_free.c b/42sh/src/lexer/token_free.c index 58bb294c..d987dfd3 100644 --- a/42sh/src/lexer/token_free.c +++ b/42sh/src/lexer/token_free.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* token_free.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:07:30 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "lexer.h" void token_free(void *data, size_t size) diff --git a/42sh/src/lexer/token_getnext.c b/42sh/src/lexer/token_getnext.c deleted file mode 100644 index 8773a754..00000000 --- a/42sh/src/lexer/token_getnext.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "lexer.h" - -static int is_separator(char c) -{ - return (c==' ' || c=='\t' || c=='\n'); -} - - -static int is_stop_char(char c) -{ - return (c=='\0' || is_separator(c) || - c=='|' || c=='&' || c==';' || c=='<' || c=='>'); -} - -t_token *token_getnext(int *pos, char *line) -{ - int i; - t_token *token; - - i = 0; - if (!line[*pos]) - return (NULL); - token = token_init(); - while (is_separator(line[*pos])) - (*pos)++; - if (ft_strchr("|;", line[*pos])) - { - if (line[*pos] == ';') - token->type = TK_SEMI; - else if (line[*pos] == '|') - token->type = TK_PIPE; - token_append(token, line[(*pos)++]); - return (token); - } - while (ft_isdigit(line[*pos])) - token_append(token, line[(*pos)++]); - if (ft_strchr("<>", line[(*pos)])) - { - token->type = (*pos == '>' ? TK_GREAT : TK_LESS); - token_append(token, line[(*pos)++]); - if (line[(*pos)] == *pos - 1) - token->type = (token->type == TK_GREAT ? TK_DGREAT : TK_DLESS); - else if (line[(*pos)] == '&') - { - token->type = (token->type == TK_GREAT ? TK_GREATAND : TK_LESSAND); - token_append(token, line[(*pos)++]); - while (ft_isdigit(line[*pos])) - token_append(token, line[(*pos)++]); - if (line[*pos] == '-') - token_append(token, line[(*pos)++]); - } - return (token); - } - else - { - token->type = TK_WORD; - while (!is_stop_char(line[*pos])) - token_append(token, line[(*pos)++]); - return (token); - } - return (token); -} diff --git a/42sh/src/lexer/token_init.c b/42sh/src/lexer/token_init.c index a2a4795b..d9c474fd 100644 --- a/42sh/src/lexer/token_init.c +++ b/42sh/src/lexer/token_init.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */ -/* Updated: 2016/11/11 17:47:14 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:07:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" -t_token *token_init() +t_token *token_init(void) { t_token *token; diff --git a/42sh/src/lexer/token_print.c b/42sh/src/lexer/token_print.c index 6ab2b601..aa5e1108 100644 --- a/42sh/src/lexer/token_print.c +++ b/42sh/src/lexer/token_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ -/* Updated: 2016/11/30 20:50:19 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:08:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ void token_print(t_list *lst) while (lst) { token = lst->content; - ft_dprintf(2, "%#010llx: '%s' (at %p next at %p)\n", token->type, token->data, lst, lst->next); + ft_dprintf(2, "%#010llx: '%s'\n", token->type, token->data); lst = lst->next; } } diff --git a/42sh/src/line-editing/ft_history_add.c b/42sh/src/line-editing/ft_history_add.c index 15f83f09..903d8f7b 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/11/10 13:43:50 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:51:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,8 @@ int ft_history_add(t_data *data) if (data->history) while (data->history->next) data->history = data->history->next; - if (!data->history->prev || ft_strcmp(str, (char *)data->history->prev->content)) + if (!data->history->prev + || ft_strcmp(str, (char *)data->history->prev->content)) { new = ft_dlstnew(str, sizeof(char) * (ft_strlen(str) + 1)); ft_dlstadd_before(&data->history, new); diff --git a/42sh/src/line-editing/ft_interactive_sh.c b/42sh/src/line-editing/ft_interactive_sh.c index 5db1826c..0e25da09 100644 --- a/42sh/src/line-editing/ft_interactive_sh.c +++ b/42sh/src/line-editing/ft_interactive_sh.c @@ -6,40 +6,37 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:14:12 by jhalford #+# #+# */ -/* Updated: 2016/12/01 12:42:35 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:54:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "line_editing.h" t_stof g_keys[] = { - {FT_KEY_C_K, NULL}, - {FT_KEY_TAB, NULL}, - {FT_KEY_C_H, &ft_line_start}, - {FT_KEY_C_L, &ft_line_end}, - {FT_KEY_C_U, &ft_clear_line}, - {FT_KEY_ESC, NULL}, - - /* {FT_KEY_UP, &ft_history_up}, */ - /* {FT_KEY_DOWN, &ft_history_down}, */ - {FT_KEY_UP, NULL}, - {FT_KEY_DOWN, NULL}, - /* {FT_KEY_C_UP, &ft_line_up}, */ - /* {FT_KEY_C_DOWN, &ft_line_down}, */ - {FT_KEY_C_UP, NULL}, - {FT_KEY_C_DOWN, NULL}, - - {FT_KEY_RIGHT, &ft_cursor_right}, - {FT_KEY_LEFT, &ft_cursor_left}, - {FT_KEY_C_RIGHT, &ft_word_right}, - {FT_KEY_C_LEFT, &ft_word_left}, - - {FT_KEY_ENTER, &ft_key_enter}, - {FT_KEY_DEL, &ft_key_del}, - {FT_KEY_C_D, &ft_key_ctrl_d}, - {FT_KEY_C_C, &ft_key_ctrl_c}, - {FT_KEY_C_Z, NULL}, - {NULL, &ft_key_default}, + {FT_KEY_C_K, NULL}, + {FT_KEY_TAB, NULL}, + {FT_KEY_C_H, &ft_line_start}, + {FT_KEY_C_L, &ft_line_end}, + {FT_KEY_C_U, &ft_clear_line}, + {FT_KEY_ESC, NULL}, + /* {FT_KEY_UP, &ft_history_up}, */ + /* {FT_KEY_DOWN, &ft_history_down}, */ + {FT_KEY_UP, NULL}, + {FT_KEY_DOWN, NULL}, + /* {FT_KEY_C_UP, &ft_line_up}, */ + /* {FT_KEY_C_DOWN, &ft_line_down}, */ + {FT_KEY_C_UP, NULL}, + {FT_KEY_C_DOWN, NULL}, + {FT_KEY_RIGHT, &ft_cursor_right}, + {FT_KEY_LEFT, &ft_cursor_left}, + {FT_KEY_C_RIGHT, &ft_word_right}, + {FT_KEY_C_LEFT, &ft_word_left}, + {FT_KEY_ENTER, &ft_key_enter}, + {FT_KEY_DEL, &ft_key_del}, + {FT_KEY_C_D, &ft_key_ctrl_d}, + {FT_KEY_C_C, &ft_key_ctrl_c}, + {FT_KEY_C_Z, NULL}, + {NULL, &ft_key_default}, }; int ft_interactive_sh(t_data *data) @@ -63,8 +60,6 @@ int ft_interactive_sh(t_data *data) { ft_bzero(buf, 4); ret = read(0, buf, 4); - /* ft_printf("read=%i: %#x,%#x,%#x\n", ret, buf[0], buf[1], buf[2]); */ - /* continue ; */ i = 0; while (g_keys[i].name && ft_strcmp(buf, g_keys[i].name)) i++; diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 72c3bf80..baebd59e 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 14:48:04 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 13:15:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */