more parsing and some exec
This commit is contained in:
parent
92f2557e7e
commit
5f329666d3
22 changed files with 401 additions and 123 deletions
|
|
@ -3,8 +3,6 @@ CC = gcc
|
|||
TAGFILE = .tags
|
||||
|
||||
D_SRC = src
|
||||
# F_SRC := $(shell ls -1 $(D_SRC) | grep "\.c$$")
|
||||
# F_SRC := $(addprefix $(D_SRC)/, $(F_SRC))
|
||||
F_SRC := $(shell find $(D_SRC) -type f -regex ".*\.c$$")
|
||||
|
||||
D_OBJ = obj
|
||||
|
|
@ -61,10 +59,10 @@ $(D_OBJ)/%.o: $(D_SRC)/exec/%.c includes/exec.h
|
|||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
|
||||
libft/libft.a:
|
||||
libft:
|
||||
@$(MAKE) -C libft/ 2>/dev/null
|
||||
|
||||
$(NAME): $(DF_OBJ) libft/libft.a
|
||||
$(NAME): $(DF_OBJ) libft
|
||||
$(CC) $(O_INC) $(O_SER) $(O_LIB) $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS)
|
||||
|
||||
clean:
|
||||
|
|
|
|||
100
42sh/Session.vim
100
42sh/Session.vim
|
|
@ -1,100 +0,0 @@
|
|||
let SessionLoad = 1
|
||||
if &cp | set nocp | endif
|
||||
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
|
||||
let v:this_session=expand("<sfile>:p")
|
||||
silent only
|
||||
cd ~/42/minishell
|
||||
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
||||
let s:wipebuf = bufnr('%')
|
||||
endif
|
||||
set shortmess=aoO
|
||||
badd +23 includes/minishell.h
|
||||
badd +1 src/user-interaction/ft_word_left.c
|
||||
badd +11 src/user-interaction/ft_cursor_left.c
|
||||
badd +8 src/user-interaction/ft_interactive_sh.c
|
||||
badd +5 src/user-interaction/ft_word_right.c
|
||||
badd +18 src/user-interaction/ft_cursor_right.c
|
||||
badd +7 src/user-interaction/ft_clear_line.c
|
||||
badd +1 src/user-interaction/ft_line_start.c
|
||||
badd +5 src/user-interaction/ft_line_end.c
|
||||
badd +40 src/main/main.c
|
||||
badd +12 src/builtin/builtin_exit.c
|
||||
badd +1 src/user-interaction/ft_cmd.c
|
||||
badd +8 src/line-editing/ft_cmd.c
|
||||
badd +2 src/main/ft_cmd.c
|
||||
badd +13 src/main/sig_handler.c
|
||||
badd +1 src/main/prompt.c
|
||||
badd +3 src/main/ft_prompt.c
|
||||
badd +15 src/line-editing/ft_interactive_sh.c
|
||||
badd +7 src/line-editing/ft_key_ctrl_d.c
|
||||
badd +32 src/builtin/builtin_cd.c
|
||||
badd +4 src/main/lib_expansion.c
|
||||
badd +19 libft/src/str/ft_strjoin.c
|
||||
badd +19 libft/src/str/ft_strlen.c
|
||||
badd +22 libft/src/str/ft_strcat.c
|
||||
badd +20 src/minishell-exec/ft_cmd.c
|
||||
badd +10 src/line-editing/ft_key_enter.c
|
||||
badd +16 src/line-editing/ft_history_add.c
|
||||
badd +9 src/line-editing/ft_history_up.c
|
||||
badd +18 src/line-editing/ft_history_down.c
|
||||
badd +62 src/token/ft_tokenize.c
|
||||
badd +30 src/line-editing/line-editing.h
|
||||
badd +1 libft/Makefile
|
||||
badd +14 Makefile
|
||||
badd +18 line-editing/Makefile
|
||||
badd +14 line-editing/includes/line_editing.h
|
||||
badd +25 src/line-editing/includes/line_editing.h
|
||||
badd +47 src/line-editing/src/ft_interactive_sh.c
|
||||
badd +20 src/line-editing/src/ft_key_enter.c
|
||||
badd +14 src/line-editing/ft_prompt.c
|
||||
badd +22 src/line-editing/ft_tc_init.c
|
||||
badd +1 libft/includes/libft.h
|
||||
badd +5 libft/includes/get_next_line.h
|
||||
badd +15 src/token/token_init.c
|
||||
badd +69 src/token/includes/token.h
|
||||
badd +15 src/token/token_recognition.c
|
||||
badd +27 src/token/token_delimit.c
|
||||
badd +11 src/token/token_operator_match.c
|
||||
badd +7 src/token/token_next.c
|
||||
badd +23 src/token/token_append.c
|
||||
argglobal
|
||||
silent! argdel *
|
||||
edit src/token/token_next.c
|
||||
set splitbelow splitright
|
||||
set nosplitbelow
|
||||
set nosplitright
|
||||
wincmd t
|
||||
set winheight=1 winwidth=1
|
||||
argglobal
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
setlocal fmr={{{,}}}
|
||||
setlocal fdi=#
|
||||
setlocal fdl=0
|
||||
setlocal fml=1
|
||||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 13 - ((6 * winheight(0) + 20) / 41)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
13
|
||||
normal! 0
|
||||
tabnext 1
|
||||
if exists('s:wipebuf')
|
||||
silent exe 'bwipe ' . s:wipebuf
|
||||
endif
|
||||
unlet! s:wipebuf
|
||||
set winheight=1 winwidth=20 shortmess=filnxtToO
|
||||
let s:sx = expand("<sfile>:p:r")."x.vim"
|
||||
if file_readable(s:sx)
|
||||
exe "source " . fnameescape(s:sx)
|
||||
endif
|
||||
let &so = s:so_save | let &siso = s:siso_save
|
||||
let g:this_session = v:this_session
|
||||
let g:this_obsession = v:this_session
|
||||
let g:this_obsession_status = 2
|
||||
doautoall SessionLoadPost
|
||||
unlet SessionLoad
|
||||
" vim: set ft=vim :
|
||||
|
|
@ -17,5 +17,8 @@ int ft_exec(t_btree *ast);
|
|||
int ft_exec(t_btree *ast);
|
||||
int exec_semi(t_btree *ast);
|
||||
int exec_pipe(t_btree *ast);
|
||||
int exec_less(t_btree *ast);
|
||||
int exec_great(t_btree *ast);
|
||||
int exec_command(t_btree *ast);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 15:31:42 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/11 20:44:28 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/14 18:22:04 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -24,19 +24,24 @@
|
|||
# define TK_SEMI 0x0040
|
||||
# define TK_PIPE 0x0080
|
||||
# define TK_WORD 0x0100
|
||||
# define TK_COMMAND 0x0200
|
||||
|
||||
# define TK_REDIR 0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20
|
||||
|
||||
typedef long long t_type;
|
||||
typedef struct s_astnode t_astnode;
|
||||
typedef struct s_token t_token;
|
||||
typedef struct s_parser t_parser;
|
||||
typedef struct s_astnode t_astnode;
|
||||
typedef struct s_redir t_redir;
|
||||
|
||||
struct s_astnode
|
||||
struct s_redir
|
||||
{
|
||||
t_type type;
|
||||
union u_astdata
|
||||
int n;
|
||||
union u_word
|
||||
{
|
||||
int a;
|
||||
} data;
|
||||
char *word;
|
||||
int fd;
|
||||
} u_word;
|
||||
};
|
||||
|
||||
struct s_token
|
||||
|
|
@ -52,6 +57,16 @@ struct s_parser
|
|||
int (*f)(t_btree **ast, t_list *start, t_list *token);
|
||||
};
|
||||
|
||||
struct s_astnode
|
||||
{
|
||||
t_type type;
|
||||
union u_astdata
|
||||
{
|
||||
t_redir redir;
|
||||
char **sstr;
|
||||
} u_data;
|
||||
};
|
||||
|
||||
extern t_parser g_parser[];
|
||||
|
||||
t_token *token_init();
|
||||
|
|
@ -64,4 +79,13 @@ void token_print(t_list *lst);
|
|||
|
||||
int ft_parse(t_btree **ast, t_list *token);
|
||||
int parse_separator(t_btree **ast, t_list *start, t_list *lst);
|
||||
int parse_less(t_btree **ast, t_list *start, t_list *lst);
|
||||
int parse_great(t_btree **ast, t_list *start, t_list *lst);
|
||||
int parse_dless(t_btree **ast, t_list *start, t_list *lst);
|
||||
int parse_dgreat(t_btree **ast, t_list *start, t_list *lst);
|
||||
int parse_lessand(t_btree **ast, t_list *start, t_list *lst);
|
||||
int parse_greatand(t_btree **ast, t_list *start, t_list *lst);
|
||||
int parse_word(t_btree **ast, t_list *start, t_list *lst);
|
||||
|
||||
void tree_type(t_btree *tree);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/11 17:04:25 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/14 11:26:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
20
42sh/src/exec/exec_command.c
Normal file
20
42sh/src/exec/exec_command.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_command.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 17:44:35 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
int exec_command(t_btree *ast)
|
||||
{
|
||||
(void)ast;
|
||||
ft_putendl("exec_commands");
|
||||
return (0);
|
||||
}
|
||||
20
42sh/src/exec/exec_great.c
Normal file
20
42sh/src/exec/exec_great.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_great.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 17:44:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
int exec_great(t_btree *ast)
|
||||
{
|
||||
(void)ast;
|
||||
ft_putendl("exec_great");
|
||||
return (0);
|
||||
}
|
||||
20
42sh/src/exec/exec_less.c
Normal file
20
42sh/src/exec/exec_less.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:27:08 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 17:45:04 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
int exec_less(t_btree *ast)
|
||||
{
|
||||
(void)ast;
|
||||
ft_putendl("exec_less");
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -4,6 +4,9 @@ t_exec g_exec[] =
|
|||
{
|
||||
{TK_SEMI, &exec_semi},
|
||||
{TK_PIPE, &exec_pipe},
|
||||
{TK_LESS, &exec_less},
|
||||
{TK_GREAT, &exec_great},
|
||||
{TK_COMMAND, &exec_command},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_parse.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 11:30:08 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 18:28:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer_parser.h"
|
||||
|
||||
t_parser g_parser[] =
|
||||
{
|
||||
{TK_SEMI, &parse_separator},
|
||||
{TK_PIPE, &parse_separator},
|
||||
{TK_LESS, &parse_less},
|
||||
{TK_GREAT, &parse_great},
|
||||
{TK_DLESS, &parse_dless},
|
||||
{TK_DGREAT, &parse_dgreat},
|
||||
{TK_LESSAND, &parse_lessand},
|
||||
{TK_GREATAND, &parse_greatand},
|
||||
{TK_WORD, &parse_word},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
int ft_parse(t_btree **ast, t_list *token)
|
||||
int ft_parse(t_btree **ast, t_list *start)
|
||||
{
|
||||
t_list *lst;
|
||||
t_astnode item;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if(!token)
|
||||
if(!start)
|
||||
return (0);
|
||||
if (!*ast)
|
||||
*ast = btree_create_node(&item, sizeof(item));
|
||||
while (g_parser[i].type)
|
||||
{
|
||||
if ((lst = ft_lst_find(token,
|
||||
(int [1]){g_parser[i].type}, &token_cmp_type)))
|
||||
if ((lst = ft_lst_find(start, &g_parser[i].type, &token_cmp_type)))
|
||||
{
|
||||
item.type = g_parser[i].type;
|
||||
*ast = btree_create_node(&item, sizeof(item));
|
||||
if (g_parser[i].f)
|
||||
(*g_parser[i].f)(ast, token, lst);
|
||||
(*g_parser[i].f)(ast, start, lst);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
36
42sh/src/lexer-parser/parse_dgreat.c
Normal file
36
42sh/src/lexer-parser/parse_dgreat.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:23:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer_parser.h"
|
||||
|
||||
int parse_dgreat(t_btree **ast, t_list *start, t_list *lst)
|
||||
{
|
||||
t_astnode *item;
|
||||
t_token *tok;
|
||||
t_token *next_tok;
|
||||
|
||||
item = (*ast)->item;
|
||||
item->type = TK_LESS;
|
||||
if (!lst->next)
|
||||
return (1);
|
||||
tok = lst->content;
|
||||
next_tok = lst->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
item->u_data.redir.u_word.word = ft_strdup(next_tok->data);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
ft_lst_delif(&start, lst->content, &ft_addrcmp, &token_free);
|
||||
ft_lst_delif(&start, lst->next->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->right, lst->next);
|
||||
return (0);
|
||||
}
|
||||
|
||||
35
42sh/src/lexer-parser/parse_dless.c
Normal file
35
42sh/src/lexer-parser/parse_dless.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:28:31 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer_parser.h"
|
||||
|
||||
int parse_dless(t_btree **ast, t_list *start, t_list *lst)
|
||||
{
|
||||
t_astnode *item;
|
||||
t_token *tok;
|
||||
t_token *next_tok;
|
||||
|
||||
item = (*ast)->item;
|
||||
item->type = TK_LESS;
|
||||
if (!lst->next)
|
||||
return (1);
|
||||
tok = lst->content;
|
||||
next_tok = lst->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
item->u_data.redir.u_word.word = ft_strdup(next_tok->data);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
ft_lst_delif(&start, lst->content, &ft_addrcmp, &token_free);
|
||||
ft_lst_delif(&start, lst->next->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->right, lst->next);
|
||||
return (0);
|
||||
}
|
||||
38
42sh/src/lexer-parser/parse_great.c
Normal file
38
42sh/src/lexer-parser/parse_great.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 17:47:35 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer_parser.h"
|
||||
|
||||
int parse_great(t_btree **ast, t_list *start, t_list *lst)
|
||||
{
|
||||
t_astnode *item;
|
||||
t_token *tok;
|
||||
t_token *next_tok;
|
||||
char *end;
|
||||
|
||||
item = (*ast)->item;
|
||||
item->type = TK_LESS;
|
||||
if (!lst->next)
|
||||
return (1);
|
||||
tok = lst->content;
|
||||
next_tok = lst->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
end = ft_strchr(tok->data, '>');
|
||||
*end = '\0';
|
||||
item->u_data.redir.n = ft_atoi(tok->data);
|
||||
item->u_data.redir.u_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);
|
||||
return (0);
|
||||
}
|
||||
35
42sh/src/lexer-parser/parse_greatand.c
Normal file
35
42sh/src/lexer-parser/parse_greatand.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:24:04 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer_parser.h"
|
||||
|
||||
int parse_greatand(t_btree **ast, t_list *start, t_list *lst)
|
||||
{
|
||||
t_astnode *item;
|
||||
t_token *tok;
|
||||
t_token *next_tok;
|
||||
|
||||
item = (*ast)->item;
|
||||
item->type = TK_LESS;
|
||||
if (!lst->next)
|
||||
return (1);
|
||||
tok = lst->content;
|
||||
next_tok = lst->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
item->u_data.redir.u_word.word = ft_strdup(next_tok->data);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
ft_lst_delif(&start, lst->content, &ft_addrcmp, &token_free);
|
||||
ft_lst_delif(&start, lst->next->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->right, lst->next);
|
||||
return (0);
|
||||
}
|
||||
38
42sh/src/lexer-parser/parse_less.c
Normal file
38
42sh/src/lexer-parser/parse_less.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 17:47:33 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer_parser.h"
|
||||
|
||||
int parse_less(t_btree **ast, t_list *start, t_list *lst)
|
||||
{
|
||||
t_astnode *item;
|
||||
t_token *tok;
|
||||
t_token *next_tok;
|
||||
char *end;
|
||||
|
||||
item = (*ast)->item;
|
||||
item->type = TK_LESS;
|
||||
if (!lst->next)
|
||||
return (1);
|
||||
tok = lst->content;
|
||||
next_tok = lst->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
end = ft_strchr(tok->data, '<');
|
||||
*end = '\0';
|
||||
item->u_data.redir.n = ft_atoi(tok->data);
|
||||
item->u_data.redir.u_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);
|
||||
return (0);
|
||||
}
|
||||
36
42sh/src/lexer-parser/parse_lessand.c
Normal file
36
42sh/src/lexer-parser/parse_lessand.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 16:14:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer_parser.h"
|
||||
|
||||
int parse_lessand(t_btree **ast, t_list *start, t_list *lst)
|
||||
{
|
||||
t_astnode *item;
|
||||
t_token *tok;
|
||||
t_token *next_tok;
|
||||
|
||||
item = (*ast)->item;
|
||||
item->type = TK_LESS;
|
||||
if (!lst->next)
|
||||
return (1);
|
||||
tok = lst->content;
|
||||
next_tok = lst->next->content;
|
||||
if (next_tok->type != TK_WORD)
|
||||
return (1);
|
||||
item->u_data.redir.u_word.word = ft_strdup(next_tok->data);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
ft_lst_delif(&start, lst->content, &ft_addrcmp, &token_free);
|
||||
ft_lst_delif(&start, lst->next->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->right, lst->next);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
int parse_separator(t_btree **ast, t_list *start, t_list *lst)
|
||||
{
|
||||
ft_parse(&(*ast)->right, lst->next);
|
||||
ft_lstdelone(&lst, &token_free);
|
||||
ft_lst_delif(&start, lst->content, &ft_addrcmp, &token_free);
|
||||
ft_parse(&(*ast)->left, start);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
28
42sh/src/lexer-parser/parse_word.c
Normal file
28
42sh/src/lexer-parser/parse_word.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 17:48:50 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer_parser.h"
|
||||
|
||||
int parse_word(t_btree **ast, t_list *start, t_list *lst)
|
||||
{
|
||||
t_astnode *item;
|
||||
t_token *tok;
|
||||
|
||||
(void)start;
|
||||
item = (*ast)->item;
|
||||
tok = lst->content;
|
||||
item->type = TK_COMMAND;
|
||||
item->u_data.sstr = ft_sstradd(item->u_data.sstr, tok->data);
|
||||
ft_parse(ast, lst->next);
|
||||
ft_lstdelone(&lst, &token_free);
|
||||
return (0);
|
||||
}
|
||||
0
42sh/src/lexer-parser/token_next.c
Normal file
0
42sh/src/lexer-parser/token_next.c
Normal file
21
42sh/src/lexer-parser/tree_type.c
Normal file
21
42sh/src/lexer-parser/tree_type.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tree_type.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/14 18:21:50 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lexer_parser.h"
|
||||
|
||||
void tree_type(t_btree *tree)
|
||||
{
|
||||
t_astnode *item;
|
||||
|
||||
item = tree->item;
|
||||
ft_printf("%i", item->type);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:44:30 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/10 14:21:42 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/14 17:58:14 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:35:14 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/11 17:10:01 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/14 18:28:40 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ int main(void)
|
|||
t_list *token;
|
||||
t_btree *ast;
|
||||
|
||||
ast = NULL;
|
||||
data.env = ft_sstrdup(environ);
|
||||
if (signal(SIGINT, sig_handler) == SIG_ERR)
|
||||
ft_printf("\ncan't catch SIGINT\n");
|
||||
|
|
@ -31,11 +32,14 @@ int main(void)
|
|||
if (ft_tokenize(&token, data.history->prev->content))
|
||||
return (1);
|
||||
token_print(token);
|
||||
/* (void)ast; */
|
||||
if (ft_parse(&ast, token))
|
||||
return (1);
|
||||
btree_print(ast, &tree_type);
|
||||
ft_printf("root: %i\n", ((t_astnode*)ast->item)->type);
|
||||
ft_lstdel(&token, &token_free);
|
||||
if (ft_exec(ast))
|
||||
return (1);
|
||||
/* if (ft_exec(ast)) */
|
||||
/* return (1); */
|
||||
|
||||
/* char **av = ft_cmd_getav(data.history->prev->content); */
|
||||
/* if (av && av[0]) */
|
||||
|
|
|
|||
Loading…
Reference in a new issue