execution of &&/|| done, added aol_status and aol_search to data (aol=and_or_list)
This commit is contained in:
parent
1f36fc1501
commit
2d631469e6
28 changed files with 150 additions and 146 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 22:47:18 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:47:40 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
typedef struct s_exec t_exec;
|
||||
|
||||
struct s_exec
|
||||
struct s_exec
|
||||
{
|
||||
t_type type;
|
||||
int (*f)(t_btree *ast, t_data *data);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 12:15:50 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:21:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -31,13 +31,6 @@
|
|||
|
||||
# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
|
||||
|
||||
typedef long long t_type;
|
||||
typedef enum e_lexstate t_lexstate;
|
||||
typedef struct s_token t_token;
|
||||
typedef struct s_data t_data;
|
||||
typedef int t_lexer(t_list **alst,
|
||||
char *str);
|
||||
|
||||
enum e_lexstate
|
||||
{
|
||||
DEFAULT,
|
||||
|
|
@ -54,16 +47,19 @@ enum e_lexstate
|
|||
BACKSLASH,
|
||||
};
|
||||
|
||||
struct s_token
|
||||
struct s_token
|
||||
{
|
||||
t_type type;
|
||||
char *data;
|
||||
int size;
|
||||
t_type type;
|
||||
char *data;
|
||||
int size;
|
||||
};
|
||||
|
||||
extern t_lexer *g_lexer[];
|
||||
typedef struct s_data t_data;
|
||||
typedef struct s_token t_token;
|
||||
typedef enum e_lexstate t_lexstate;
|
||||
|
||||
extern int (*g_lexer[])(t_list **alst, char *str);
|
||||
|
||||
/* t_token *token_getnext(int *pos,char *line); */
|
||||
t_token *token_init();
|
||||
int ft_tokenize(t_list **alst, char *str, t_lexstate state);
|
||||
int token_append(t_token *token, char c);
|
||||
|
|
@ -74,18 +70,17 @@ void token_print(t_list *lst);
|
|||
int ft_is_delim(char c);
|
||||
void qstate_update(t_data *data, char c);
|
||||
|
||||
t_lexer lexer_default;
|
||||
t_lexer lexer_delim;
|
||||
t_lexer lexer_sep;
|
||||
t_lexer lexer_word;
|
||||
t_lexer lexer_number;
|
||||
t_lexer lexer_greatand;
|
||||
t_lexer lexer_lessand;
|
||||
t_lexer lexer_quote;
|
||||
t_lexer lexer_dquote;
|
||||
t_lexer lexer_backslash;
|
||||
|
||||
t_lexer lexer_less;
|
||||
t_lexer lexer_great;
|
||||
int lexer_default(t_list **alst, char *str);
|
||||
int lexer_delim(t_list **alst, char *str);
|
||||
int lexer_sep(t_list **alst, char *str);
|
||||
int lexer_word(t_list **alst, char *str);
|
||||
int lexer_number(t_list **alst, char *str);
|
||||
int lexer_less(t_list **alst, char *str);
|
||||
int lexer_great(t_list **alst, char *str);
|
||||
int lexer_lessand(t_list **alst, char *str);
|
||||
int lexer_greatand(t_list **alst, char *str);
|
||||
int lexer_quote(t_list **alst, char *str);
|
||||
int lexer_dquote(t_list **alst, char *str);
|
||||
int lexer_backslash(t_list **alst, char *str);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:38:21 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 12:13:57 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 15:59:19 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -52,22 +52,23 @@ int ft_interactive_sh(t_data *data);
|
|||
int ft_prompt(void);
|
||||
int ft_history_add(t_data *data);
|
||||
|
||||
typedef int key_press(t_data *data, char *buf);
|
||||
key_press ft_clear_line;
|
||||
key_press ft_line_up;
|
||||
key_press ft_line_down;
|
||||
key_press ft_line_start;
|
||||
key_press ft_line_end;
|
||||
key_press ft_history_up;
|
||||
key_press ft_history_down;
|
||||
key_press ft_cursor_left;
|
||||
key_press ft_cursor_right;
|
||||
key_press ft_word_left;
|
||||
key_press ft_word_right;
|
||||
key_press ft_key_del;
|
||||
key_press ft_key_enter;
|
||||
key_press ft_key_ctrl_d;
|
||||
key_press ft_key_ctrl_c;
|
||||
key_press ft_key_default;
|
||||
int ft_clear_line(t_data *data, char *buf);
|
||||
int ft_line_up(t_data *data, char *buf);
|
||||
int ft_line_down(t_data *data, char *buf);
|
||||
int ft_line_start(t_data *data, char *buf);
|
||||
int ft_line_end(t_data *data, char *buf);
|
||||
|
||||
int ft_key_del(t_data *data, char *buf);
|
||||
int ft_key_enter(t_data *data, char *buf);
|
||||
int ft_key_ctrl_d(t_data *data, char *buf);
|
||||
int ft_key_ctrl_c(t_data *data, char *buf);
|
||||
int ft_key_default(t_data *data, char *buf);
|
||||
|
||||
int ft_history_up(t_data *data, char *buf);
|
||||
int ft_history_down(t_data *data, char *buf);
|
||||
int ft_cursor_left(t_data *data, char *buf);
|
||||
int ft_cursor_right(t_data *data, char *buf);
|
||||
int ft_word_left(t_data *data, char *buf);
|
||||
int ft_word_right(t_data *data, char *buf);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 14:46:21 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 17:31:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,19 +27,17 @@
|
|||
# include <signal.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
typedef long long t_type;
|
||||
|
||||
typedef enum e_qstate t_qstate;
|
||||
typedef struct s_data t_data;
|
||||
|
||||
enum e_qstate
|
||||
typedef enum e_qstate
|
||||
{
|
||||
Q_NONE,
|
||||
Q_QUOTE,
|
||||
Q_DQUOTE,
|
||||
Q_BACKSLASH,
|
||||
};
|
||||
} t_qstate;
|
||||
|
||||
struct s_data
|
||||
typedef struct s_data
|
||||
{
|
||||
char **env;
|
||||
t_dlist *history;
|
||||
|
|
@ -48,7 +46,9 @@ struct s_data
|
|||
t_list *qstack;
|
||||
int fdin;
|
||||
int fdout;
|
||||
};
|
||||
char *aol_status;
|
||||
int aol_search;
|
||||
} t_data;
|
||||
|
||||
extern t_stof g_builtins[];
|
||||
extern pid_t g_pid;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 12:15:54 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:35:54 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,36 +15,41 @@
|
|||
|
||||
# include "minishell.h"
|
||||
|
||||
typedef long long t_type;
|
||||
typedef struct s_parser t_parser;
|
||||
typedef struct s_astnode t_astnode;
|
||||
typedef struct s_redir t_redir;
|
||||
typedef union u_astdata t_astdata;
|
||||
typedef union u_word t_word;
|
||||
|
||||
struct s_parser
|
||||
struct s_parser
|
||||
{
|
||||
t_type type;
|
||||
int (*f)(t_btree **ast, t_list **start, t_list **token);
|
||||
};
|
||||
|
||||
struct s_redir
|
||||
union u_word
|
||||
{
|
||||
char *word;
|
||||
int fd;
|
||||
};
|
||||
|
||||
struct s_redir
|
||||
{
|
||||
int n;
|
||||
int close;
|
||||
union u_word
|
||||
{
|
||||
char *word;
|
||||
int fd;
|
||||
} u_word;
|
||||
t_word word;
|
||||
};
|
||||
|
||||
struct s_astnode
|
||||
union u_astdata
|
||||
{
|
||||
t_type type;
|
||||
union u_astdata
|
||||
{
|
||||
t_redir redir;
|
||||
char **sstr;
|
||||
} u_data;
|
||||
t_redir redir;
|
||||
char **sstr;
|
||||
};
|
||||
|
||||
struct s_astnode
|
||||
{
|
||||
t_type type;
|
||||
t_astdata data;
|
||||
};
|
||||
|
||||
extern t_parser g_parser[];
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 21:06:05 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 17:46:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,7 +14,18 @@
|
|||
|
||||
int exec_and_if(t_btree *ast, t_data *data)
|
||||
{
|
||||
ft_exec(ast->left, data);
|
||||
ft_exec(ast->right, data);
|
||||
if (data->aol_status == NULL
|
||||
|| (data->aol_search == TK_AND_IF && *data->aol_status == '0')
|
||||
|| (data->aol_search == TK_OR_IF && *data->aol_status != '0'))
|
||||
{
|
||||
ft_exec(ast->left, data);
|
||||
data->aol_status = ft_getenv(data->env, "?");
|
||||
}
|
||||
data->aol_search = TK_AND_IF;
|
||||
if (*data->aol_status == '0'
|
||||
|| ((t_astnode*)ast->right->item)->type != TK_COMMAND)
|
||||
ft_exec(ast->right, data);
|
||||
data->aol_status = NULL;
|
||||
data->aol_search = 0;
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/29 20:30:49 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:48:42 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,10 +17,10 @@ int exec_command(t_btree *ast, t_data *data)
|
|||
t_astnode *node;
|
||||
|
||||
node = ast->item;
|
||||
ft_putstr_fd("befor exec: ", 2);
|
||||
ft_sstrprint_fd(2, ((t_astnode*)ast->item)->u_data.sstr, ',');
|
||||
ft_putchar_fd('\n', 2);
|
||||
ft_cmd_process(node->u_data.sstr, data);
|
||||
ft_putstr_fd("after exec\n", 2);
|
||||
/* ft_putstr_fd("befor exec: ", 2); */
|
||||
/* ft_sstrprint_fd(2, ((t_astnode*)ast->item)->u_data.sstr, ','); */
|
||||
/* ft_putchar_fd('\n', 2); */
|
||||
ft_cmd_process(node->data.sstr, data);
|
||||
/* ft_putstr_fd("after exec\n", 2); */
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 18:15:13 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/29 20:29:10 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:48:54 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ int exec_dgreat(t_btree *ast, t_data *data)
|
|||
int fd;
|
||||
|
||||
node = ast->item;
|
||||
fd = open(node->u_data.redir.u_word.word, O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||
fd = open(node->data.redir.word.word, O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||
data->fdout = fd;
|
||||
|
||||
ft_exec(ast->left, data);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/29 20:26:40 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:49:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ int exec_great(t_btree *ast, t_data *data)
|
|||
int fd;
|
||||
|
||||
node = ast->item;
|
||||
fd = open(node->u_data.redir.u_word.word, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||
fd = open(node->data.redir.word.word, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||
data->fdout = fd;
|
||||
|
||||
ft_exec(ast->left, data);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:27:08 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/29 20:29:01 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:52:21 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ int exec_less(t_btree *ast, t_data *data)
|
|||
int fd;
|
||||
|
||||
node = ast->item;
|
||||
fd = open(node->u_data.redir.u_word.word, O_RDONLY);
|
||||
fd = open(node->data.redir.word.word, O_RDONLY);
|
||||
data->fdin = fd;
|
||||
|
||||
ft_exec(ast->left, data);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 21:45:53 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 17:46:53 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,7 +14,18 @@
|
|||
|
||||
int exec_or_if(t_btree *ast, t_data *data)
|
||||
{
|
||||
ft_exec(ast->left, data);
|
||||
ft_exec(ast->right, data);
|
||||
if (data->aol_status == NULL
|
||||
|| (data->aol_search == TK_AND_IF && *data->aol_status == '0')
|
||||
|| (data->aol_search == TK_OR_IF && *data->aol_status != '0'))
|
||||
{
|
||||
ft_exec(ast->left, data);
|
||||
data->aol_status = ft_getenv(data->env, "?");
|
||||
}
|
||||
data->aol_search = TK_OR_IF;
|
||||
if (*data->aol_status != '0'
|
||||
|| ((t_astnode*)ast->right->item)->type != TK_COMMAND)
|
||||
ft_exec(ast->right, data);
|
||||
data->aol_status = NULL;
|
||||
data->aol_search = 0;
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fd_reset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 19:20:05 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/29 19:47:01 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void fd_reset(t_data *data)
|
||||
{
|
||||
dup2(data->save_in, STDIN);
|
||||
dup2(data->save_out, STDOUT);
|
||||
data->fdin = STDIN;
|
||||
data->fdout = STDOUT;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 21:13:18 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 14:46:48 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 17:22:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,6 +27,7 @@ int ft_cmd_process(char **argv, t_data *data)
|
|||
else if (!(execpath = ft_findexec(path, argv[0])))
|
||||
{
|
||||
ft_dprintf(2, "%s: command not found: %s\n", SHELL_NAME, argv[0]);
|
||||
builtin_setenv((char*[3]){"?", "127"}, data);
|
||||
return (-1);
|
||||
}
|
||||
return (ft_cmd_exec(execpath, argv, data));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 20:52:07 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 17:18:03 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 16:57:55 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:21:26 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
t_lexer *g_lexer[] =
|
||||
int (*g_lexer[])(t_list **alst, char *str) =
|
||||
{
|
||||
&lexer_default,
|
||||
&lexer_delim,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:14:09 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 14:46:08 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:48:27 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,7 +19,6 @@ int ft_set_termios(t_data *data, int input_mode)
|
|||
|
||||
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
|
||||
return (-1);
|
||||
ft_debug();
|
||||
if (tgetent(NULL, term_name) != 1)
|
||||
return (-1);
|
||||
if (tcgetattr(0, &term) == -1)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 14:46:13 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 17:31:00 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,6 +21,8 @@ int data_init(t_data *data)
|
|||
data->history = NULL;
|
||||
data->fdin = STDIN;
|
||||
data->fdout = STDOUT;
|
||||
data->aol_status = NULL;
|
||||
data->aol_search = 0;
|
||||
if (!(data->history = ft_dlstnew(NULL, 0)))
|
||||
return (-1);
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 21:48:51 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:54:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/28 18:35:12 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:44:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -24,20 +24,20 @@ void ft_putast2(void *nodein)
|
|||
else if (node->type == TK_COMMAND)
|
||||
{
|
||||
ft_putstr_fd("COMMAND: ", 2);
|
||||
ft_sstrprint_fd(2, node->u_data.sstr, ',');
|
||||
ft_sstrprint_fd(2, node->data.sstr, ',');
|
||||
ft_putchar_fd('\n', 2);
|
||||
}
|
||||
else if (node->type & TK_REDIR)
|
||||
{
|
||||
ft_putnbr_fd(node->u_data.redir.n, 2);
|
||||
ft_putnbr_fd(node->data.redir.n, 2);
|
||||
if (node->type == TK_GREATAND || node->type == TK_LESSAND)
|
||||
{
|
||||
if (node->type == TK_GREATAND)
|
||||
ft_putstr_fd(">&:", 2);
|
||||
else
|
||||
ft_putstr_fd("<&:", 2);
|
||||
ft_putnbr_fd(node->u_data.redir.u_word.fd, 2);
|
||||
if (node->u_data.redir.close)
|
||||
ft_putnbr_fd(node->data.redir.word.fd, 2);
|
||||
if (node->data.redir.close)
|
||||
ft_putstr_fd(" (closed)", 2);
|
||||
}
|
||||
else
|
||||
|
|
@ -50,7 +50,7 @@ void ft_putast2(void *nodein)
|
|||
ft_putstr_fd(">>:", 2);
|
||||
else if (node->type == TK_DLESS)
|
||||
ft_putstr_fd("<<:", 2);
|
||||
ft_putstr_fd(node->u_data.redir.u_word.word, 2);
|
||||
ft_putstr_fd(node->data.redir.word.word, 2);
|
||||
}
|
||||
ft_putchar_fd('\n', 2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 21:13:34 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 13:47:36 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 14:48:04 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 21:05:53 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:53:41 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ int ft_parse(t_btree **ast, t_list **start)
|
|||
if (!*ast)
|
||||
{
|
||||
*ast = btree_create_node(&item, sizeof(item));
|
||||
((t_astnode *)(*ast)->item)->u_data.sstr = NULL;
|
||||
((t_astnode *)(*ast)->item)->data.sstr = NULL;
|
||||
}
|
||||
while (g_parser[i].type)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:23:48 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:36:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,8 +26,8 @@ int parse_dgreat(t_btree **ast, t_list **start, t_list **lst)
|
|||
next_tok = (*lst)->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
node->u_data.redir.n = ft_atoi(tok->data);
|
||||
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
|
||||
node->data.redir.n = ft_atoi(tok->data);
|
||||
node->data.redir.word.word = ft_strdup(next_tok->data);
|
||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:28:31 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:37:20 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ int parse_dless(t_btree **ast, t_list **start, t_list **lst)
|
|||
next_tok = (*lst)->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
|
||||
node->data.redir.word.word = ft_strdup(next_tok->data);
|
||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 21:45:46 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:37:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,8 +26,8 @@ int parse_great(t_btree **ast, t_list **start, t_list **lst)
|
|||
next_tok = (*lst)->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
node->u_data.redir.n = ft_atoi(tok->data);
|
||||
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
|
||||
node->data.redir.n = ft_atoi(tok->data);
|
||||
node->data.redir.word.word = ft_strdup(next_tok->data);
|
||||
|
||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:24:04 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:37:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,8 +22,8 @@ int parse_greatand(t_btree **ast, t_list **start, t_list **lst)
|
|||
node->type = TK_GREATAND;
|
||||
tok = (*lst)->content;
|
||||
and = ft_strchr(tok->data, '&');
|
||||
node->u_data.redir.u_word.fd = ft_atoi(and + 1);
|
||||
node->u_data.redir.close =
|
||||
node->data.redir.word.fd = ft_atoi(and + 1);
|
||||
node->data.redir.close =
|
||||
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
|
||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 18:03:37 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:36:44 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,8 +26,8 @@ int parse_less(t_btree **ast, t_list **start, t_list **lst)
|
|||
next_tok = (*lst)->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
node->u_data.redir.n = ft_atoi(tok->data);
|
||||
node->u_data.redir.u_word.word = ft_strdup(next_tok->data);
|
||||
node->data.redir.n = ft_atoi(tok->data);
|
||||
node->data.redir.word.word = ft_strdup(next_tok->data);
|
||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:14:17 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:37:54 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,8 +22,8 @@ int parse_lessand(t_btree **ast, t_list **start, t_list **lst)
|
|||
node->type = TK_LESSAND;
|
||||
tok = (*lst)->content;
|
||||
and = ft_strchr(tok->data, '&');
|
||||
node->u_data.redir.u_word.fd = ft_atoi(and + 1);
|
||||
node->u_data.redir.close =
|
||||
node->data.redir.word.fd = ft_atoi(and + 1);
|
||||
node->data.redir.close =
|
||||
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
|
||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/30 21:19:16 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/12/01 16:39:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ int parse_word(t_btree **ast, t_list **start, t_list **lst)
|
|||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
node->type = TK_COMMAND;
|
||||
node->u_data.sstr = ft_sstradd(node->u_data.sstr, token->data);
|
||||
node->data.sstr = ft_sstradd(node->data.sstr, token->data);
|
||||
ft_parse(ast, &(*lst)->next);
|
||||
|
||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||
|
|
|
|||
Loading…
Reference in a new issue