pad mal de norme, aussi on enleve le backslash si necessaire au lexing

This commit is contained in:
Jack Halford 2016-12-03 13:15:58 +01:00
parent 2d631469e6
commit 972e3e6cbc
35 changed files with 221 additions and 193 deletions

View file

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

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:38:21 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_BSLASH "\x5c"
# define FT_KEY_DEL "\x7f" # define FT_KEY_DEL "\x7f"
enum e_qstate
{
Q_NONE,
Q_QUOTE,
Q_DQUOTE,
Q_BACKSLASH,
};
typedef struct s_data t_data; typedef struct s_data t_data;
typedef enum e_qstate t_qstate;
extern t_stof g_keys[]; 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_left(t_data *data, char *buf);
int ft_word_right(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 #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 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 long long t_type;
typedef enum e_qstate struct s_data
{
Q_NONE,
Q_QUOTE,
Q_DQUOTE,
Q_BACKSLASH,
} t_qstate;
typedef struct s_data
{ {
char **env; char **env;
t_dlist *history; t_dlist *history;
@ -48,7 +40,10 @@ typedef struct s_data
int fdout; int fdout;
char *aol_status; char *aol_status;
int aol_search; int aol_search;
} t_data; };
typedef struct s_data t_data;
typedef enum e_qstate t_qstate;
extern t_stof g_builtins[]; extern t_stof g_builtins[];
extern pid_t g_pid; extern pid_t g_pid;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:54 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:21:34 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,9 +27,8 @@ int ft_builtin(char **av, t_data *data)
int i; int i;
int ret; int ret;
i = 0; i = -1;
while (g_builtin[i].name) while (g_builtin[++i].name)
{
if (ft_strcmp(g_builtin[i].name, *av) == 0) if (ft_strcmp(g_builtin[i].name, *av) == 0)
{ {
if (data->fdout != STDOUT) if (data->fdout != STDOUT)
@ -48,7 +47,5 @@ int ft_builtin(char **av, t_data *data)
} }
return (1); return (1);
} }
i++;
}
return (0); return (0);
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin_cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
/* Updated: 2016/12/03 11:58:14 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
#define CDOPT_L 0x001 #define CDOPT_L 0x001
#define CDOPT_P 0x002 #define CDOPT_P 0x002

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:29:17 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; int j;
env = data->env; env = data->env;
/* ft_printf("builtin: %s\n", av[0]); */
i = 1; i = 1;
while (av[i]) while (av[i])
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 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; t_astnode *node;
node = ast->item; 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_cmd_process(node->data.sstr, data);
/* ft_putstr_fd("after exec\n", 2); */
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:15:13 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; node = ast->item;
fd = open(node->data.redir.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; data->fdout = fd;
ft_exec(ast->left, data); ft_exec(ast->left, data);
data->fdout = STDOUT; data->fdout = STDOUT;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:27:51 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; node = ast->item;
fd = open(node->data.redir.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; data->fdout = fd;
ft_exec(ast->left, data); ft_exec(ast->left, data);
data->fdout = STDOUT; data->fdout = STDOUT;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:27:08 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; node = ast->item;
fd = open(node->data.redir.word.word, O_RDONLY); fd = open(node->data.redir.word.word, O_RDONLY);
data->fdin = fd; data->fdin = fd;
ft_exec(ast->left, data); ft_exec(ast->left, data);
data->fdin = STDIN; data->fdin = STDIN;
return (0); return (0);
} }

View file

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

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 21:13:23 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); pipe(fds);
ft_dprintf(2, "pipe %i->%i\n", fds[PIPE_WRITE], fds[PIPE_READ]); ft_dprintf(2, "pipe %i->%i\n", fds[PIPE_WRITE], fds[PIPE_READ]);
data->fdout = fds[PIPE_WRITE]; data->fdout = fds[PIPE_WRITE];
ft_exec(ast->left, data); ft_exec(ast->left, data);
if (data->fdout != STDOUT) if (data->fdout != STDOUT)
close(data->fdout); close(data->fdout);
data->fdout = STDOUT; data->fdout = STDOUT;
data->fdin = fds[PIPE_READ]; data->fdin = fds[PIPE_READ];
ft_exec(ast->right, data); ft_exec(ast->right, data);
close(fds[PIPE_WRITE]); close(fds[PIPE_WRITE]);
close(fds[PIPE_READ]); close(fds[PIPE_READ]);
data->fdin = STDIN; data->fdin = STDIN;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 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) if (data->fdin != STDIN)
{ {
/* ft_dprintf(2, "redirecting input: %i->STDIN\n", data->fdin); */
dup2(data->fdin, STDIN); dup2(data->fdin, STDIN);
close(data->fdin); close(data->fdin);
} }
if (data->fdout != STDOUT) if (data->fdout != STDOUT)
{ {
/* ft_dprintf(2, "redirecting output: %i->STDOUT\n", data->fdout); */
dup2(data->fdout, STDOUT); dup2(data->fdout, STDOUT);
close(data->fdout); close(data->fdout);
} }

View file

@ -6,11 +6,12 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 21:13:18 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" #include "minishell.h"
extern pid_t g_pid; extern pid_t g_pid;
int ft_cmd_process(char **argv, t_data *data) 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]); ft_dprintf(2, "%s: permission denied: %s\n", SHELL_NAME, argv[0]);
return (-1); return (-1);
} }
/* ft_dprintf(2, "gonna fork, in=%i, out=%i\n", data->fdin, data->fdout); */
if ((pid = fork()) == -1) if ((pid = fork()) == -1)
return (-1); return (-1);
else if (pid == 0) else if (pid == 0)
@ -53,12 +53,10 @@ int ft_cmd_exec(char *execpath, char **argv, t_data *data)
environ = ft_sstrdup(data->env); environ = ft_sstrdup(data->env);
execve(execpath, argv, environ); execve(execpath, argv, environ);
} }
else else if ((g_pid = pid))
{ {
g_pid = pid;
if (data->fdout == STDOUT) if (data->fdout == STDOUT)
{ {
ft_dprintf(2, "[waiting for PID = %i]\n", pid);
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
builtin_setenv((char*[3]){"?", ft_itoa(status)}, data); builtin_setenv((char*[3]){"?", ft_itoa(status)}, data);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
/* Updated: 2016/12/01 17:18:03 by jhalford ### ########.fr */ /* Updated: 2016/12/03 11:58:36 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:37:11 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)); *alst = ft_lstnew(token, sizeof(*token));
if (ft_is_delim(*str)) if (ft_is_delim(*str))
state = DELIM; state = DELIM;
if (*str == '&' || *str == ';' || *str == '|') else if (*str == '&' || *str == ';' || *str == '|')
state = SEP; state = SEP;
else if (*str == '\'')
{
state = QUOTE;
str++;
}
else if (*str == '\"')
{
state = DQUOTE;
str++;
}
else if (*str == '\\') else if (*str == '\\')
state = BACKSLASH; 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)); return ((*g_lexer[state])(alst, str));
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_backslash.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:35:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_backslash(t_list **alst, char *str) int lexer_backslash(t_list **alst, char *str)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_delim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */
/* Updated: 2016/12/03 11:58:45 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_delim(t_list **alst, char *str) int lexer_delim(t_list **alst, char *str)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:58 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)); return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT));
if (*str == '\\') if (*str == '\\')
{ {
token_append(token, *str);
token_append(token, *(str + 1)); token_append(token, *(str + 1));
return (lexer_dquote(alst, str + 2)); return (lexer_dquote(alst, str + 2));
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_great.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:51:11 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_great(t_list **alst, char *str) int lexer_great(t_list **alst, char *str)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_greatand.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */
/* Updated: 2016/12/03 11:57:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_greatand(t_list **alst, char *str) int lexer_greatand(t_list **alst, char *str)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_less.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:06:53 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_less(t_list **alst, char *str) int lexer_less(t_list **alst, char *str)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_lessand.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */
/* Updated: 2016/12/03 11:58:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_lessand(t_list **alst, char *str) int lexer_lessand(t_list **alst, char *str)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_number.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:06:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_number(t_list **alst, char *str) int lexer_number(t_list **alst, char *str)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:08 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:07:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_quote(t_list **alst, char *str) int lexer_quote(t_list **alst, char *str)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_word.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:07:12 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
int lexer_word(t_list **alst, char *str) int lexer_word(t_list **alst, char *str)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 15:56:40 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; list = &data->qstack;
state = (*list)->content; state = (*list)->content;
/* ft_printf("befor state: %i\n", *state); */
if (c == -1) if (c == -1)
{ {
tmp = ft_lstpop(list); tmp = ft_lstpop(list);
@ -32,27 +31,11 @@ void qstate_update(t_data *data, char c)
new = (*list)->content; new = (*list)->content;
*new = *state; *new = *state;
if (*state == Q_NONE) if (*state == Q_NONE)
{ qstate_none(new, c);
if (c == '\\')
*new = Q_BACKSLASH;
else if (c == '\"')
*new = Q_DQUOTE;
else if (c == '\'')
*new = Q_QUOTE;
}
else if (*state == Q_QUOTE) else if (*state == Q_QUOTE)
{ qstate_quote(new, c);
if (c == '\'')
*new = Q_NONE;
}
else if (*state == Q_DQUOTE) else if (*state == Q_DQUOTE)
{ qstate_dquote(new, c);
if (c == '\\')
*new = Q_BACKSLASH;
else if (c == '\"')
*new = Q_NONE;
}
else if (*state == Q_BACKSLASH) else if (*state == Q_BACKSLASH)
*new = *(t_qstate*)(*list)->next->next->content; *new = *(t_qstate*)(*list)->next->next->content;
/* ft_printf("new state: %i\n", *new); */
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* token_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:07:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h" #include "lexer.h"
void token_free(void *data, size_t size) void token_free(void *data, size_t size)

View file

@ -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);
}

View file

@ -6,13 +6,13 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 15:30:25 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" #include "lexer.h"
t_token *token_init() t_token *token_init(void)
{ {
t_token *token; t_token *token;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:39:01 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) while (lst)
{ {
token = lst->content; 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; lst = lst->next;
} }
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:43:40 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) if (data->history)
while (data->history->next) while (data->history->next)
data->history = 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)); new = ft_dlstnew(str, sizeof(char) * (ft_strlen(str) + 1));
ft_dlstadd_before(&data->history, new); ft_dlstadd_before(&data->history, new);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:14:12 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,6 @@ t_stof g_keys[] = {
{FT_KEY_C_L, &ft_line_end}, {FT_KEY_C_L, &ft_line_end},
{FT_KEY_C_U, &ft_clear_line}, {FT_KEY_C_U, &ft_clear_line},
{FT_KEY_ESC, NULL}, {FT_KEY_ESC, NULL},
/* {FT_KEY_UP, &ft_history_up}, */ /* {FT_KEY_UP, &ft_history_up}, */
/* {FT_KEY_DOWN, &ft_history_down}, */ /* {FT_KEY_DOWN, &ft_history_down}, */
{FT_KEY_UP, NULL}, {FT_KEY_UP, NULL},
@ -28,12 +27,10 @@ t_stof g_keys[] = {
/* {FT_KEY_C_DOWN, &ft_line_down}, */ /* {FT_KEY_C_DOWN, &ft_line_down}, */
{FT_KEY_C_UP, NULL}, {FT_KEY_C_UP, NULL},
{FT_KEY_C_DOWN, NULL}, {FT_KEY_C_DOWN, NULL},
{FT_KEY_RIGHT, &ft_cursor_right}, {FT_KEY_RIGHT, &ft_cursor_right},
{FT_KEY_LEFT, &ft_cursor_left}, {FT_KEY_LEFT, &ft_cursor_left},
{FT_KEY_C_RIGHT, &ft_word_right}, {FT_KEY_C_RIGHT, &ft_word_right},
{FT_KEY_C_LEFT, &ft_word_left}, {FT_KEY_C_LEFT, &ft_word_left},
{FT_KEY_ENTER, &ft_key_enter}, {FT_KEY_ENTER, &ft_key_enter},
{FT_KEY_DEL, &ft_key_del}, {FT_KEY_DEL, &ft_key_del},
{FT_KEY_C_D, &ft_key_ctrl_d}, {FT_KEY_C_D, &ft_key_ctrl_d},
@ -63,8 +60,6 @@ int ft_interactive_sh(t_data *data)
{ {
ft_bzero(buf, 4); ft_bzero(buf, 4);
ret = read(0, 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; i = 0;
while (g_keys[i].name && ft_strcmp(buf, g_keys[i].name)) while (g_keys[i].name && ft_strcmp(buf, g_keys[i].name))
i++; i++;

View file

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