tokenization finished. interactive shell improvements for signal handlind (ISIG option turned off). next step is parsing, thinking of AST structure
This commit is contained in:
parent
fff4912306
commit
43529fc845
31 changed files with 282 additions and 504 deletions
|
|
@ -35,7 +35,14 @@ ft_path_access src/main/lib_path.c /^int ft_path_access(char *execpath, char *e
|
||||||
ft_path_findexec src/main/lib_path.c /^char *ft_path_findexec(char **path, char *execname/
|
ft_path_findexec src/main/lib_path.c /^char *ft_path_findexec(char **path, char *execname/
|
||||||
ft_prompt src/line-editing/ft_prompt.c /^int ft_prompt(void)$/
|
ft_prompt src/line-editing/ft_prompt.c /^int ft_prompt(void)$/
|
||||||
ft_tc_init src/line-editing/ft_tc_init.c /^int ft_tc_init(t_data *data)$/
|
ft_tc_init src/line-editing/ft_tc_init.c /^int ft_tc_init(t_data *data)$/
|
||||||
ft_tokenize src/token/ft_tokenize.c /^t_list *ft_tokenize(char *str)$/
|
ft_tokenize src/token/ft_tokenize.c /^int ft_tokenize(t_list **alst, char *str)$/
|
||||||
ft_word_left src/line-editing/ft_word_left.c /^int ft_word_left(t_data *data, t_dlist **input_ch/
|
ft_word_left src/line-editing/ft_word_left.c /^int ft_word_left(t_data *data, t_dlist **input_ch/
|
||||||
ft_word_right src/line-editing/ft_word_right.c /^int ft_word_right(t_data *data, t_dlist **input_c/
|
ft_word_right src/line-editing/ft_word_right.c /^int ft_word_right(t_data *data, t_dlist **input_c/
|
||||||
|
is_separator src/token/token_getnext.c /^static int is_separator(char c)$/
|
||||||
|
is_stop_char src/token/token_getnext.c /^static int is_stop_char(char c)$/
|
||||||
sig_handler src/main/sig_handler.c /^void sig_handler(int signo)$/
|
sig_handler src/main/sig_handler.c /^void sig_handler(int signo)$/
|
||||||
|
token_append src/token/token_append.c /^int token_append(t_token *token, char c)$/
|
||||||
|
token_free src/token/token_free.c /^void token_free(void *data, size_t size)$/
|
||||||
|
token_getnext src/token/token_getnext.c /^t_token *token_getnext(int *pos, char *line)$/
|
||||||
|
token_init src/token/token_init.c /^t_token *token_init()$/
|
||||||
|
token_print src/token/token_print.c /^void token_print(t_list *lst)$/
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ D_OBJ = obj
|
||||||
F_OBJ = $(notdir $(F_SRC:.c=.o))
|
F_OBJ = $(notdir $(F_SRC:.c=.o))
|
||||||
DF_OBJ := $(addprefix $(D_OBJ)/, $(F_OBJ))
|
DF_OBJ := $(addprefix $(D_OBJ)/, $(F_OBJ))
|
||||||
|
|
||||||
D_INC = includes libft/includes src/line-editing/includes
|
D_INC = includes libft/includes src/line-editing/includes src/token/includes
|
||||||
O_INC = $(addprefix -I, $(D_INC))
|
O_INC = $(addprefix -I, $(D_INC))
|
||||||
|
|
||||||
D_SER = libft
|
D_SER = libft/
|
||||||
O_SER = $(addprefix -L, $(D_SER))
|
O_SER = $(addprefix -L, $(D_SER))
|
||||||
|
|
||||||
D_LIB = ft ncurses
|
D_LIB = ft ncurses
|
||||||
|
|
@ -28,22 +28,35 @@ RM = /bin/rm -rf
|
||||||
|
|
||||||
.PHONY: all clean fclean re tags test libft
|
.PHONY: all clean fclean re tags test libft
|
||||||
|
|
||||||
all: libft $(NAME) $(TAGFILE)
|
all: $(NAME)
|
||||||
|
|
||||||
$(TAGFILE): $(D_SRC)/*/*.c
|
$(D_OBJ)/%.o: $(D_SRC)/main/%.c includes/
|
||||||
@ctags -f $(TAGFILE) $(F_SRC)
|
|
||||||
@echo "Making tags..."
|
|
||||||
|
|
||||||
$(D_OBJ)/%.o: $(D_SRC)/*/%.c $(D_INC)
|
|
||||||
@$(MKDIR) $(D_OBJ)
|
@$(MKDIR) $(D_OBJ)
|
||||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||||
@echo "Compiling "$<"..."
|
@echo "Compiling "$<"..."
|
||||||
|
|
||||||
libft:
|
$(D_OBJ)/%.o: $(D_SRC)/line-editing/%.c src/line-editing/includes
|
||||||
@$(MAKE) -C libft/ 2>/dev/null
|
@$(MKDIR) $(D_OBJ)
|
||||||
|
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||||
|
@echo "Compiling "$<"..."
|
||||||
|
|
||||||
line-editing:
|
$(D_OBJ)/%.o: $(D_SRC)/builtin/%.c includes/
|
||||||
@$(MAKE) -C line-editing 2>/dev/null
|
@$(MKDIR) $(D_OBJ)
|
||||||
|
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||||
|
@echo "Compiling "$<"..."
|
||||||
|
|
||||||
|
$(D_OBJ)/%.o: $(D_SRC)/token/%.c src/token/includes
|
||||||
|
@$(MKDIR) $(D_OBJ)
|
||||||
|
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||||
|
@echo "Compiling "$<"..."
|
||||||
|
|
||||||
|
$(D_OBJ)/%.o: $(D_SRC)/minishell-exec/%.c includes/
|
||||||
|
@$(MKDIR) $(D_OBJ)
|
||||||
|
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||||
|
@echo "Compiling "$<"..."
|
||||||
|
|
||||||
|
libft/libft.a:
|
||||||
|
@$(MAKE) -C libft/ 2>/dev/null
|
||||||
|
|
||||||
$(NAME): $(DF_OBJ) libft/libft.a
|
$(NAME): $(DF_OBJ) libft/libft.a
|
||||||
$(CC) $(O_INC) $(O_SER) $(O_LIB) $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS)
|
$(CC) $(O_INC) $(O_SER) $(O_LIB) $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS)
|
||||||
|
|
|
||||||
223
42sh/Session.vim
223
42sh/Session.vim
|
|
@ -3,12 +3,12 @@ if &cp | set nocp | endif
|
||||||
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
|
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
|
||||||
let v:this_session=expand("<sfile>:p")
|
let v:this_session=expand("<sfile>:p")
|
||||||
silent only
|
silent only
|
||||||
cd ~/minishell
|
cd ~/42/minishell
|
||||||
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
||||||
let s:wipebuf = bufnr('%')
|
let s:wipebuf = bufnr('%')
|
||||||
endif
|
endif
|
||||||
set shortmess=aoO
|
set shortmess=aoO
|
||||||
badd +38 includes/minishell.h
|
badd +23 includes/minishell.h
|
||||||
badd +1 src/user-interaction/ft_word_left.c
|
badd +1 src/user-interaction/ft_word_left.c
|
||||||
badd +11 src/user-interaction/ft_cursor_left.c
|
badd +11 src/user-interaction/ft_cursor_left.c
|
||||||
badd +8 src/user-interaction/ft_interactive_sh.c
|
badd +8 src/user-interaction/ft_interactive_sh.c
|
||||||
|
|
@ -17,7 +17,7 @@ badd +18 src/user-interaction/ft_cursor_right.c
|
||||||
badd +7 src/user-interaction/ft_clear_line.c
|
badd +7 src/user-interaction/ft_clear_line.c
|
||||||
badd +1 src/user-interaction/ft_line_start.c
|
badd +1 src/user-interaction/ft_line_start.c
|
||||||
badd +5 src/user-interaction/ft_line_end.c
|
badd +5 src/user-interaction/ft_line_end.c
|
||||||
badd +2 src/main/main.c
|
badd +40 src/main/main.c
|
||||||
badd +12 src/builtin/builtin_exit.c
|
badd +12 src/builtin/builtin_exit.c
|
||||||
badd +1 src/user-interaction/ft_cmd.c
|
badd +1 src/user-interaction/ft_cmd.c
|
||||||
badd +8 src/line-editing/ft_cmd.c
|
badd +8 src/line-editing/ft_cmd.c
|
||||||
|
|
@ -25,7 +25,7 @@ badd +2 src/main/ft_cmd.c
|
||||||
badd +13 src/main/sig_handler.c
|
badd +13 src/main/sig_handler.c
|
||||||
badd +1 src/main/prompt.c
|
badd +1 src/main/prompt.c
|
||||||
badd +3 src/main/ft_prompt.c
|
badd +3 src/main/ft_prompt.c
|
||||||
badd +24 src/line-editing/ft_interactive_sh.c
|
badd +15 src/line-editing/ft_interactive_sh.c
|
||||||
badd +7 src/line-editing/ft_key_ctrl_d.c
|
badd +7 src/line-editing/ft_key_ctrl_d.c
|
||||||
badd +32 src/builtin/builtin_cd.c
|
badd +32 src/builtin/builtin_cd.c
|
||||||
badd +4 src/main/lib_expansion.c
|
badd +4 src/main/lib_expansion.c
|
||||||
|
|
@ -37,45 +37,34 @@ badd +10 src/line-editing/ft_key_enter.c
|
||||||
badd +16 src/line-editing/ft_history_add.c
|
badd +16 src/line-editing/ft_history_add.c
|
||||||
badd +9 src/line-editing/ft_history_up.c
|
badd +9 src/line-editing/ft_history_up.c
|
||||||
badd +18 src/line-editing/ft_history_down.c
|
badd +18 src/line-editing/ft_history_down.c
|
||||||
badd +26 src/token/ft_tokenize.c
|
badd +62 src/token/ft_tokenize.c
|
||||||
badd +30 src/line-editing/line-editing.h
|
badd +30 src/line-editing/line-editing.h
|
||||||
badd +1 libft/Makefile
|
badd +1 libft/Makefile
|
||||||
badd +36 Makefile
|
badd +14 Makefile
|
||||||
badd +18 line-editing/Makefile
|
badd +18 line-editing/Makefile
|
||||||
badd +14 line-editing/includes/line_editing.h
|
badd +14 line-editing/includes/line_editing.h
|
||||||
badd +15 src/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 +47 src/line-editing/src/ft_interactive_sh.c
|
||||||
badd +20 src/line-editing/src/ft_key_enter.c
|
badd +20 src/line-editing/src/ft_key_enter.c
|
||||||
badd +14 src/line-editing/ft_prompt.c
|
badd +14 src/line-editing/ft_prompt.c
|
||||||
badd +22 src/line-editing/ft_tc_init.c
|
badd +22 src/line-editing/ft_tc_init.c
|
||||||
badd +33 libft/includes/libft.h
|
badd +1 libft/includes/libft.h
|
||||||
badd +5 libft/includes/get_next_line.h
|
badd +5 libft/includes/get_next_line.h
|
||||||
badd +21 src/token/token_init.c
|
badd +15 src/token/token_init.c
|
||||||
badd +32 src/token/includes/token.h
|
badd +69 src/token/includes/token.h
|
||||||
badd +15 src/token/token_recognition.c
|
badd +15 src/token/token_recognition.c
|
||||||
badd +1 src
|
badd +27 src/token/token_delimit.c
|
||||||
badd +14 src/token/token_append.c
|
badd +11 src/token/token_operator_match.c
|
||||||
badd +20 libft/src/mem/ft_realloc.c
|
badd +7 src/token/token_next.c
|
||||||
badd +12 libft/src/mem/ft_memcpy.c
|
badd +23 src/token/token_append.c
|
||||||
badd +23 libft/src/mem/ft_memalloc.c
|
argglobal
|
||||||
badd +1 libft/src/mem/ft_memset.c
|
|
||||||
badd +23 libft/src/mem/ft_memmove.c
|
|
||||||
badd +14 libft/src/mem/ft_memchr.c
|
|
||||||
badd +13 src/token/token_delimit.c
|
|
||||||
badd +0 src/token/token_operator_match.c
|
|
||||||
silent! argdel *
|
silent! argdel *
|
||||||
edit src/main/main.c
|
edit src/token/token_next.c
|
||||||
set splitbelow splitright
|
set splitbelow splitright
|
||||||
wincmd _ | wincmd |
|
|
||||||
vsplit
|
|
||||||
1wincmd h
|
|
||||||
wincmd w
|
|
||||||
set nosplitbelow
|
set nosplitbelow
|
||||||
set nosplitright
|
set nosplitright
|
||||||
wincmd t
|
wincmd t
|
||||||
set winheight=1 winwidth=1
|
set winheight=1 winwidth=1
|
||||||
exe 'vert 1resize ' . ((&columns * 91 + 90) / 180)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 88 + 90) / 180)
|
|
||||||
argglobal
|
argglobal
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
|
|
@ -86,189 +75,13 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 35 - ((34 * winheight(0) + 37) / 75)
|
let s:l = 13 - ((6 * winheight(0) + 20) / 41)
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
|
||||||
exe s:l
|
|
||||||
normal! zt
|
|
||||||
35
|
|
||||||
normal! 020l
|
|
||||||
wincmd w
|
|
||||||
argglobal
|
|
||||||
edit src/line-editing/includes/line_editing.h
|
|
||||||
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 = 2 - ((1 * winheight(0) + 37) / 75)
|
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
|
||||||
exe s:l
|
|
||||||
normal! zt
|
|
||||||
2
|
|
||||||
normal! 0
|
|
||||||
wincmd w
|
|
||||||
exe 'vert 1resize ' . ((&columns * 91 + 90) / 180)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 88 + 90) / 180)
|
|
||||||
tabedit src/token/ft_tokenize.c
|
|
||||||
set splitbelow splitright
|
|
||||||
wincmd _ | wincmd |
|
|
||||||
vsplit
|
|
||||||
1wincmd h
|
|
||||||
wincmd w
|
|
||||||
set nosplitbelow
|
|
||||||
set nosplitright
|
|
||||||
wincmd t
|
|
||||||
set winheight=1 winwidth=1
|
|
||||||
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
|
||||||
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 = 28 - ((27 * winheight(0) + 37) / 75)
|
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
|
||||||
exe s:l
|
|
||||||
normal! zt
|
|
||||||
28
|
|
||||||
normal! 0
|
|
||||||
lcd ~/minishell
|
|
||||||
wincmd w
|
|
||||||
argglobal
|
|
||||||
edit ~/minishell/src/token/includes/token.h
|
|
||||||
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 = 48 - ((39 * winheight(0) + 37) / 75)
|
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
|
||||||
exe s:l
|
|
||||||
normal! zt
|
|
||||||
48
|
|
||||||
normal! 0
|
|
||||||
wincmd w
|
|
||||||
2wincmd w
|
|
||||||
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
|
||||||
tabedit ~/minishell/src/token/token_delimit.c
|
|
||||||
set splitbelow splitright
|
|
||||||
wincmd _ | wincmd |
|
|
||||||
vsplit
|
|
||||||
1wincmd h
|
|
||||||
wincmd w
|
|
||||||
set nosplitbelow
|
|
||||||
set nosplitright
|
|
||||||
wincmd t
|
|
||||||
set winheight=1 winwidth=1
|
|
||||||
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
|
||||||
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 - ((12 * winheight(0) + 37) / 75)
|
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
exe s:l
|
exe s:l
|
||||||
normal! zt
|
normal! zt
|
||||||
13
|
13
|
||||||
normal! 017l
|
|
||||||
lcd ~/minishell
|
|
||||||
wincmd w
|
|
||||||
argglobal
|
|
||||||
edit ~/minishell/src/token/token_operator_match.c
|
|
||||||
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 = 16 - ((15 * winheight(0) + 37) / 75)
|
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
|
||||||
exe s:l
|
|
||||||
normal! zt
|
|
||||||
16
|
|
||||||
normal! 0
|
normal! 0
|
||||||
lcd ~/minishell
|
tabnext 1
|
||||||
wincmd w
|
|
||||||
2wincmd w
|
|
||||||
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
|
||||||
tabedit ~/minishell/libft/src/mem/ft_realloc.c
|
|
||||||
set splitbelow splitright
|
|
||||||
wincmd _ | wincmd |
|
|
||||||
vsplit
|
|
||||||
1wincmd h
|
|
||||||
wincmd w
|
|
||||||
set nosplitbelow
|
|
||||||
set nosplitright
|
|
||||||
wincmd t
|
|
||||||
set winheight=1 winwidth=1
|
|
||||||
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
|
||||||
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 = 15 - ((14 * winheight(0) + 37) / 75)
|
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
|
||||||
exe s:l
|
|
||||||
normal! zt
|
|
||||||
15
|
|
||||||
normal! 014l
|
|
||||||
lcd ~/minishell
|
|
||||||
wincmd w
|
|
||||||
argglobal
|
|
||||||
edit ~/minishell/libft/includes/libft.h
|
|
||||||
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 = 131 - ((61 * winheight(0) + 37) / 75)
|
|
||||||
if s:l < 1 | let s:l = 1 | endif
|
|
||||||
exe s:l
|
|
||||||
normal! zt
|
|
||||||
131
|
|
||||||
normal! 0
|
|
||||||
lcd ~/minishell
|
|
||||||
wincmd w
|
|
||||||
2wincmd w
|
|
||||||
exe 'vert 1resize ' . ((&columns * 90 + 90) / 180)
|
|
||||||
exe 'vert 2resize ' . ((&columns * 89 + 90) / 180)
|
|
||||||
tabnext 2
|
|
||||||
if exists('s:wipebuf')
|
if exists('s:wipebuf')
|
||||||
silent exe 'bwipe ' . s:wipebuf
|
silent exe 'bwipe ' . s:wipebuf
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,14 @@
|
||||||
|
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include "line_editing.h"
|
# include "line_editing.h"
|
||||||
|
# include "token.h"
|
||||||
# include <dirent.h>
|
# include <dirent.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
|
|
||||||
# define MODE_INPUT 0b0001
|
|
||||||
# define MODE_EXEC 0b0010
|
|
||||||
|
|
||||||
extern t_stof g_builtins[];
|
extern t_stof g_builtins[];
|
||||||
extern pid_t g_pid;
|
extern pid_t g_pid;
|
||||||
extern int g_mode;
|
|
||||||
|
|
||||||
void sig_handler(int signo);
|
void sig_handler(int signo);
|
||||||
|
|
||||||
|
|
@ -36,18 +33,14 @@ char **ft_cmd_getav(char *cmd);
|
||||||
int ft_builtin(char **av, char ***env);
|
int ft_builtin(char **av, char ***env);
|
||||||
int builtin_echo(char **av, char ***env);
|
int builtin_echo(char **av, char ***env);
|
||||||
int builtin_cd(char **av, char ***env);
|
int builtin_cd(char **av, char ***env);
|
||||||
int builtin_cd_opts(char **av, int *opts);
|
|
||||||
char *builtin_cd_special(char **av, char **env);
|
|
||||||
int builtin_exit(char **av, char ***env);
|
int builtin_exit(char **av, char ***env);
|
||||||
int builtin_setenv(char **av, char ***env);
|
int builtin_setenv(char **av, char ***env);
|
||||||
int builtin_unsetenv(char **av, char ***env);
|
int builtin_unsetenv(char **av, char ***env);
|
||||||
int builtin_env(char **av, char ***env);
|
int builtin_env(char **av, char ***env);
|
||||||
|
|
||||||
void ft_expand_dollar(char **av, char **env);
|
void ft_expand_dollar(char **av, char **env);
|
||||||
char *ft_env_getval(char **env, char *key);
|
|
||||||
|
|
||||||
int ft_path_access(char *execpath, char *execname);
|
char *ft_findexec(char **path, char *file);
|
||||||
char *ft_path_findexec(char **path, char *execname);
|
|
||||||
|
|
||||||
int ft_tokenize(t_list **alst, char *str);
|
int ft_tokenize(t_list **alst, char *str);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
|
||||||
t_stof g_builtin[] = {
|
t_stof g_builtin[] = {
|
||||||
{"echo", &builtin_echo},
|
{"echo", &builtin_echo},
|
||||||
{"cd", &builtin_cd},
|
{"cd", &builtin_cd},
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,50 @@
|
||||||
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
||||||
#define CDERR_1 "cd: no such file or directory: %s\n"
|
#define CDERR_1 "cd: no such file or directory: %s\n"
|
||||||
|
|
||||||
int builtin_cd(char **av, char ***env_p)
|
static char *builtin_cd_special(char **av, char **env)
|
||||||
|
{
|
||||||
|
char *target;
|
||||||
|
|
||||||
|
if (!*av)
|
||||||
|
{
|
||||||
|
if (!(target = ft_getenv(env, "HOME")))
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
else if (ft_strcmp(*av, "-") == 0)
|
||||||
|
target = ft_getenv(env, "OLDPWD");
|
||||||
|
else
|
||||||
|
target = *av;
|
||||||
|
return (target);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int builtin_cd_opts(char **av, int *opts)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int tmp_opts;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
tmp_opts = 0;
|
||||||
|
if (av)
|
||||||
|
while (av[i] && av[i][0] == '-' && av[i][1])
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (av[i][++j])
|
||||||
|
{
|
||||||
|
if (av[i][j] == 'P')
|
||||||
|
tmp_opts |= CDOPT_P;
|
||||||
|
else if (av[i][j] == 'L')
|
||||||
|
tmp_opts |= CDOPT_L;
|
||||||
|
else
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
*opts |= tmp_opts;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int builtin_cd(char **av, char ***env_p)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int opts;
|
int opts;
|
||||||
|
|
@ -32,46 +75,3 @@ int builtin_cd(char **av, char ***env_p)
|
||||||
builtin_setenv(oldpwd, env_p);
|
builtin_setenv(oldpwd, env_p);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *builtin_cd_special(char **av, char **env)
|
|
||||||
{
|
|
||||||
char *target;
|
|
||||||
|
|
||||||
if (!*av)
|
|
||||||
{
|
|
||||||
if (!(target = ft_env_getval(env, "HOME")))
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
else if (ft_strcmp(*av, "-") == 0)
|
|
||||||
target = ft_env_getval(env, "OLDPWD");
|
|
||||||
else
|
|
||||||
target = *av;
|
|
||||||
return (target);
|
|
||||||
}
|
|
||||||
|
|
||||||
int builtin_cd_opts(char **av, int *opts)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int tmp_opts;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
tmp_opts = 0;
|
|
||||||
if (av)
|
|
||||||
while (av[i] && av[i][0] == '-' && av[i][1])
|
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
while (av[i][++j])
|
|
||||||
{
|
|
||||||
if (av[i][j] == 'P')
|
|
||||||
tmp_opts |= CDOPT_P;
|
|
||||||
else if (av[i][j] == 'L')
|
|
||||||
tmp_opts |= CDOPT_L;
|
|
||||||
else
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
*opts |= tmp_opts;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ int builtin_exit(char **av, char ***env_p)
|
||||||
if (av[1])
|
if (av[1])
|
||||||
status = ft_atoi(av[1]);
|
status = ft_atoi(av[1]);
|
||||||
else
|
else
|
||||||
status = ft_atoi(ft_env_getval(*env_p, "?"));
|
status = ft_atoi(ft_getenv(*env_p, "?"));
|
||||||
exit(status);
|
exit(status);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ int ft_history_add(t_data *data, t_dlist *input_chain)
|
||||||
str = ft_strcut(str, "\\\n");
|
str = ft_strcut(str, "\\\n");
|
||||||
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_dlst_new(str, sizeof(char) * (ft_strlen(str) + 1));
|
new = ft_dlstnew(str, sizeof(char) * (ft_strlen(str) + 1));
|
||||||
ft_dlst_add_before(&data->history, new);
|
ft_dlstadd_before(&data->history, new);
|
||||||
data->history = data->history->next;
|
data->history = data->history->next;
|
||||||
ft_strdel((char **)&data->history->content);
|
ft_strdel((char **)&data->history->content);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ int ft_history_down(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
return (0);
|
return (0);
|
||||||
data->history = data->history->next;
|
data->history = data->history->next;
|
||||||
str = data->history->content;
|
str = data->history->content;
|
||||||
*input_chain = ft_dlst_last(*input_chain);
|
*input_chain = ft_dlstlast(*input_chain);
|
||||||
/* ft_clear_input(input_chain); */
|
/* ft_clear_input(input_chain); */
|
||||||
i = 0;
|
i = 0;
|
||||||
while (str[i])
|
while (str[i])
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ t_stof g_keys[] = {
|
||||||
{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},
|
||||||
|
{FT_KEY_C_C, &ft_key_ctrl_c},
|
||||||
|
{FT_KEY_C_Z, NULL},
|
||||||
{NULL, &ft_key_basic},
|
{NULL, &ft_key_basic},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -48,21 +50,20 @@ int ft_interactive_sh(t_data *data)
|
||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
(void)data;
|
|
||||||
null = '\0';
|
null = '\0';
|
||||||
if (!data->history)
|
if (!data->history)
|
||||||
data->history = ft_dlst_new(NULL, 0);
|
data->history = ft_dlstnew(NULL, 0);
|
||||||
input_chain = ft_dlst_new(&null, sizeof(char));
|
input_chain = ft_dlstnew(&null, sizeof(char));
|
||||||
ft_tc_init(data);
|
ft_set_termios(data, 1);
|
||||||
ft_prompt();
|
ft_prompt();
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
ft_bzero(buf, 20);
|
ft_bzero(buf, 20);
|
||||||
/* ret = read(0, buf, 20); */
|
ret = read(0, buf, 20);
|
||||||
/* ft_printf("read=%i: %#x,%#x,%#x\n", ret, buf[0], buf[1], buf[2]); */
|
/* ft_printf("read=%i: %#x,%#x,%#x\n", ret, buf[0], buf[1], buf[2]); */
|
||||||
continue ;
|
/* continue ; */
|
||||||
i = 0;
|
i = 0;
|
||||||
while (g_keys[i].name && ft_strcmp(buf, g_keys[i].name) == 0)
|
while (g_keys[i].name && ft_strcmp(buf, g_keys[i].name))
|
||||||
i++;
|
i++;
|
||||||
if (!g_keys[i].f)
|
if (!g_keys[i].f)
|
||||||
continue ;
|
continue ;
|
||||||
|
|
@ -70,6 +71,9 @@ int ft_interactive_sh(t_data *data)
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
else if (ret == 2)
|
else if (ret == 2)
|
||||||
|
{
|
||||||
|
ft_set_termios(data, 0);
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ int ft_key_basic(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
char *res;
|
char *res;
|
||||||
|
|
||||||
(void)data;
|
(void)data;
|
||||||
new = ft_dlst_new(&buf[0], sizeof(char));
|
new = ft_dlstnew(&buf[0], sizeof(char));
|
||||||
ft_dlst_add_after(input_chain, new);
|
ft_dlstadd_after(input_chain, new);
|
||||||
if ((res = tgetstr("IC", NULL)) != NULL)
|
if ((res = tgetstr("IC", NULL)) != NULL)
|
||||||
{
|
{
|
||||||
tputs(tgoto(res, 0, 0), 1, &ft_putchar);
|
tputs(tgoto(res, 0, 0), 1, &ft_putchar);
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,27 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* token_recognition.c :+: :+: :+: */
|
/* ft_key_ctrl_c.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 15:37:22 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:44:24 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/10 15:48:45 by jhalford ### ########.fr */
|
/* Updated: 2016/11/10 13:44:24 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "token.h"
|
#include "line_editing.h"
|
||||||
|
|
||||||
int token_recognition(t_list *alst, char *str)
|
int ft_key_ctrl_c(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
(void)data;
|
||||||
|
(void)buf;
|
||||||
|
char null;
|
||||||
|
|
||||||
|
null = '\0';
|
||||||
|
ft_dlstdel(input_chain, ft_lst_cfree);
|
||||||
|
*input_chain = ft_dlstnew(&null, sizeof(char));
|
||||||
|
ft_putendl("");
|
||||||
|
ft_prompt();
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +22,7 @@ int ft_key_del(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
return (0);
|
return (0);
|
||||||
if (*(char*)(*input_chain)->content == '\n')
|
if (*(char*)(*input_chain)->content == '\n')
|
||||||
return (0);
|
return (0);
|
||||||
ft_dlst_delone(input_chain, &ft_lst_cfree);
|
ft_dlstdelone(input_chain, &ft_lst_cfree);
|
||||||
if ((res = tgetstr("le", NULL)) == NULL)
|
if ((res = tgetstr("le", NULL)) == NULL)
|
||||||
{
|
{
|
||||||
ft_printf("le error\n");
|
ft_printf("le error\n");
|
||||||
|
|
|
||||||
|
|
@ -22,5 +22,6 @@ int ft_key_enter(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
}
|
}
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
ft_history_add(data, *input_chain);
|
ft_history_add(data, *input_chain);
|
||||||
|
ft_dlstdel(input_chain, ft_lst_cfree);
|
||||||
return (2);
|
return (2);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@
|
||||||
|
|
||||||
#include "line_editing.h"
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_tc_init(t_data *data)
|
int ft_set_termios(t_data *data, int input_mode)
|
||||||
{
|
{
|
||||||
char *term_name;
|
|
||||||
struct termios term;
|
struct termios term;
|
||||||
|
char *term_name;
|
||||||
|
|
||||||
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
|
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
@ -24,7 +24,10 @@ int ft_tc_init(t_data *data)
|
||||||
if (tcgetattr(0, &term) == -1)
|
if (tcgetattr(0, &term) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
term.c_lflag &= ~(ICANON); // Met le terminal en mode canonique.
|
term.c_lflag &= ~(ICANON); // Met le terminal en mode canonique.
|
||||||
term.c_lflag &= ~(ECHO); // les touches tapées ne s'inscriront plus dans le terminal
|
if (input_mode == 1)
|
||||||
|
term.c_lflag &= ~(ISIG) & ~(ECHO);
|
||||||
|
else
|
||||||
|
term.c_lflag |= ISIG | ECHO;
|
||||||
term.c_cc[VMIN] = 1;
|
term.c_cc[VMIN] = 1;
|
||||||
term.c_cc[VTIME] = 0;
|
term.c_cc[VTIME] = 0;
|
||||||
if (tcsetattr(0, TCSADRAIN, &term) == -1)
|
if (tcsetattr(0, TCSADRAIN, &term) == -1)
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
# define SHELL_PROMPT "$> "
|
# define SHELL_PROMPT "$> "
|
||||||
# define BUFF_SIZE 32
|
# define BUFF_SIZE 32
|
||||||
# define READ_BUF 32
|
# define READ_BUF 32
|
||||||
|
# define FT_KEY_C_C "\x3"
|
||||||
# define FT_KEY_C_D "\x4"
|
# define FT_KEY_C_D "\x4"
|
||||||
# define FT_KEY_C_H "\x8"
|
# define FT_KEY_C_H "\x8"
|
||||||
# define FT_KEY_TAB "\x9"
|
# define FT_KEY_TAB "\x9"
|
||||||
|
|
@ -27,6 +28,7 @@
|
||||||
# define FT_KEY_C_K "\xb"
|
# define FT_KEY_C_K "\xb"
|
||||||
# define FT_KEY_C_L "\xc"
|
# define FT_KEY_C_L "\xc"
|
||||||
# define FT_KEY_C_U "\x15"
|
# define FT_KEY_C_U "\x15"
|
||||||
|
# define FT_KEY_C_Z "\x1a"
|
||||||
# define FT_KEY_ESC "\x1b"
|
# define FT_KEY_ESC "\x1b"
|
||||||
# define FT_KEY_UP "\x1b\x5b\x41"
|
# define FT_KEY_UP "\x1b\x5b\x41"
|
||||||
# define FT_KEY_DOWN "\x1b\x5b\x42"
|
# define FT_KEY_DOWN "\x1b\x5b\x42"
|
||||||
|
|
@ -52,7 +54,7 @@ struct s_data
|
||||||
|
|
||||||
extern t_stof g_keys[];
|
extern t_stof g_keys[];
|
||||||
|
|
||||||
int ft_tc_init(t_data *data);
|
int ft_set_termios(t_data *data, int input_mode);
|
||||||
int ft_interactive_sh(t_data *data);
|
int ft_interactive_sh(t_data *data);
|
||||||
int ft_prompt(void);
|
int ft_prompt(void);
|
||||||
int ft_input_is_escaped(t_dlist *input_chain);
|
int ft_input_is_escaped(t_dlist *input_chain);
|
||||||
|
|
@ -74,5 +76,6 @@ key_press ft_key_del;
|
||||||
key_press ft_key_enter;
|
key_press ft_key_enter;
|
||||||
key_press ft_key_basic;
|
key_press ft_key_basic;
|
||||||
key_press ft_key_ctrl_d;
|
key_press ft_key_ctrl_d;
|
||||||
|
key_press ft_key_ctrl_c;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
char *ft_env_getval(char **env, char *key)
|
|
||||||
{
|
|
||||||
if (!env)
|
|
||||||
return (NULL);
|
|
||||||
while (*env)
|
|
||||||
{
|
|
||||||
/* ft_printf("%s\n", env[i]); */
|
|
||||||
if (ft_strcmp(*env, key) == '=')
|
|
||||||
return (*env + ft_strlen(key) + 1);
|
|
||||||
env++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
@ -9,7 +9,7 @@ void ft_expand_dollar(char **av, char **env)
|
||||||
if ((dollar = ft_strchr(*av, '$')))
|
if ((dollar = ft_strchr(*av, '$')))
|
||||||
{
|
{
|
||||||
*dollar = '\0';
|
*dollar = '\0';
|
||||||
*av = ft_strjoin(*av, ft_env_getval(env, dollar + 1));
|
*av = ft_strjoin(*av, ft_getenv(env, dollar + 1));
|
||||||
}
|
}
|
||||||
av++;
|
av++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,6 @@
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int ft_path_access(char *execpath, char *execname)
|
char *ft_findexec(char **path, char *file)
|
||||||
{
|
|
||||||
if (access(execpath, X_OK) == -1)
|
|
||||||
{
|
|
||||||
ft_printf("minishell: permission denied: %s\n", execname);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_path_findexec(char **path, char *execname)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
@ -24,7 +14,7 @@ char *ft_path_findexec(char **path, char *execname)
|
||||||
continue ;
|
continue ;
|
||||||
while ((dirent = readdir(dir)))
|
while ((dirent = readdir(dir)))
|
||||||
{
|
{
|
||||||
if (ft_strcmp(dirent->d_name, execname))
|
if (ft_strcmp(dirent->d_name, file))
|
||||||
continue ;
|
continue ;
|
||||||
if (path[i][ft_strlen(path[i])] != '/')
|
if (path[i][ft_strlen(path[i])] != '/')
|
||||||
ft_strcat(path[i], "/");
|
ft_strcat(path[i], "/");
|
||||||
|
|
@ -32,6 +22,5 @@ char *ft_path_findexec(char **path, char *execname)
|
||||||
return (execpath);
|
return (execpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ft_printf("minishell: command not found: %s\n", execname);
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,39 +13,29 @@
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
int g_mode;
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
t_data data;
|
t_data data;
|
||||||
char *cmd;
|
|
||||||
char **av;
|
|
||||||
t_list *token;
|
t_list *token;
|
||||||
|
|
||||||
data.env = ft_sstrdup(environ);
|
data.env = ft_sstrdup(environ);
|
||||||
token = NULL;
|
|
||||||
if (signal(SIGINT, sig_handler) == SIG_ERR)
|
if (signal(SIGINT, sig_handler) == SIG_ERR)
|
||||||
ft_printf("\ncan't catch SIGINT\n");
|
ft_printf("\ncan't catch SIGINT\n");
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
g_mode = MODE_INPUT;
|
|
||||||
if (ft_interactive_sh(&data))
|
if (ft_interactive_sh(&data))
|
||||||
return (1);
|
return (1);
|
||||||
cmd = ft_strdup(data.history->prev->content);
|
/* ft_printf("got command:'%s'\n", data.history->prev->content); */
|
||||||
g_mode = MODE_EXEC;
|
if (ft_tokenize(&token, data.history->prev->content))
|
||||||
|
return (1);
|
||||||
|
/* token_print(token); */
|
||||||
|
/* t_btree *ast = ft_parse(&ast, token); */
|
||||||
|
ft_lstdel(&token, &token_free);
|
||||||
|
|
||||||
ft_printf("got command:'%s'\n", cmd);
|
/* char **av = ft_cmd_getav(data.history->prev->content); */
|
||||||
|
|
||||||
/* (void)av; */
|
|
||||||
/* ft_printf("got string:'%s'\n", cmd); */
|
|
||||||
|
|
||||||
/* av = ft_cmd_getav(cmd); */
|
|
||||||
/* if (av && av[0]) */
|
/* if (av && av[0]) */
|
||||||
/* ft_cmd_process(av, &data.env); */
|
/* ft_cmd_process(av, &data.env); */
|
||||||
|
|
||||||
(void)av;
|
|
||||||
if (ft_tokenize(&token, cmd))
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,10 @@
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
pid_t g_pid;
|
pid_t g_pid;
|
||||||
int g_mode;
|
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo != SIGINT)
|
if (signo == SIGINT)
|
||||||
return ;
|
|
||||||
if (g_mode == MODE_INPUT)
|
|
||||||
{
|
{
|
||||||
ft_printf("input mode SIGINT");
|
|
||||||
}
|
|
||||||
else if (g_mode == MODE_EXEC)
|
|
||||||
{
|
|
||||||
ft_putendl("^C");
|
|
||||||
if (g_pid)
|
if (g_pid)
|
||||||
kill(g_pid, SIGINT);
|
kill(g_pid, SIGINT);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,17 @@ int ft_cmd_process(char **argv, char ***env_p)
|
||||||
char **path;
|
char **path;
|
||||||
char *execpath;
|
char *execpath;
|
||||||
|
|
||||||
path = ft_strsplit(ft_env_getval(*env_p, "PATH"), ':');
|
path = ft_strsplit(ft_getenv(*env_p, "PATH"), ':');
|
||||||
ft_expand_dollar(argv, *env_p);
|
ft_expand_dollar(argv, *env_p);
|
||||||
if (ft_builtin(argv, env_p))
|
if (ft_builtin(argv, env_p))
|
||||||
return (0);
|
return (0);
|
||||||
else if (ft_strchr(argv[0], '/'))
|
else if (ft_strchr(argv[0], '/'))
|
||||||
execpath = argv[0];
|
execpath = argv[0];
|
||||||
else if (!(execpath = ft_path_findexec(path, argv[0])))
|
else if (!(execpath = ft_findexec(path, argv[0])))
|
||||||
|
{
|
||||||
|
ft_printf("minishell: command not found: %s\n", argv[0]);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
}
|
||||||
return (ft_cmd_exec(execpath, argv, env_p));
|
return (ft_cmd_exec(execpath, argv, env_p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,8 +28,11 @@ int ft_cmd_exec(char *execpath, char **argv, char ***env_p)
|
||||||
char **sstr;
|
char **sstr;
|
||||||
|
|
||||||
sstr = NULL;
|
sstr = NULL;
|
||||||
if (ft_path_access(execpath, argv[0]))
|
if (access(execpath, X_OK) == -1)
|
||||||
|
{
|
||||||
|
ft_printf("minishell: permission denied: %s\n", argv[0]);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
}
|
||||||
if ((pid = fork()) == -1)
|
if ((pid = fork()) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
else if (pid == 0)
|
else if (pid == 0)
|
||||||
|
|
|
||||||
|
|
@ -10,75 +10,20 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "token.h"
|
||||||
|
|
||||||
t_operator g_ops[] =
|
|
||||||
{
|
|
||||||
{TK_LESS, "<", NUM_BEFORE | WORD_AFTER},
|
|
||||||
{TK_GREAT, ">", NUM_BEFORE | WORD_AFTER},
|
|
||||||
{TK_DGREAT, ">>", NUM_BEFORE | WORD_AFTER},
|
|
||||||
|
|
||||||
{TK_LESSAND, "<&", NUM_BEFORE | WORD_AFTER | MIN_END},
|
|
||||||
{TK_GREATAND, ">&", NUM_BEFORE | WORD_AFTER | MIN_END},
|
|
||||||
|
|
||||||
{TK_DLESS, "<<", NUM_BEFORE | WORD_AFTER},
|
|
||||||
|
|
||||||
{TK_SCOLON, ";", 0},
|
|
||||||
{TK_PIPE, "|", 0},
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_tokenize(t_list **alst, char *str)
|
int ft_tokenize(t_list **alst, char *str)
|
||||||
{
|
{
|
||||||
static int quoted = 0;
|
t_token *token;
|
||||||
t_token *token;
|
char *cmd;
|
||||||
|
int pos;
|
||||||
|
|
||||||
if (!*alst)
|
cmd = ft_strdup(str);
|
||||||
alst = ft_lstnew(token_init(), sizeof(t_token));
|
while ((token = token_getnext(&pos, cmd)))
|
||||||
else
|
|
||||||
token = (*alst)->content;
|
|
||||||
if (!*str)
|
|
||||||
{
|
{
|
||||||
token_delimit(token);
|
*alst = ft_lstnew(token, sizeof(*token));
|
||||||
return (0);
|
alst = &(*alst)->next;
|
||||||
}
|
}
|
||||||
else if ((token->type | TK_OPERATOR) && !quoted)
|
ft_strdel(&cmd);
|
||||||
{
|
return (0);
|
||||||
if (token_operator_match(token, *str))
|
|
||||||
token_append(token, *str);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
token_delimit(token);
|
|
||||||
ft_tokenize(&(*alst)->next, str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ft_strchr(OPERATOR_START, *str) && !quoted)
|
|
||||||
{
|
|
||||||
token_delimit(token);
|
|
||||||
(*alst)->next = ft_lstnew(token_init(), sizeof(t_token));
|
|
||||||
(*alst) = (*alst)->next;
|
|
||||||
token = (*alst)->content;
|
|
||||||
token->type = TK_UNKNOWN;
|
|
||||||
token_append(token, *str);
|
|
||||||
ft_tokenize(alst, str + 1);
|
|
||||||
}
|
|
||||||
else if (*str == ' ' && !quoted)
|
|
||||||
{
|
|
||||||
token_delimit(token);
|
|
||||||
ft_tokenize(&(*alst)->next, str + 1);
|
|
||||||
}
|
|
||||||
else if (token->type == TOKEN_WORD)
|
|
||||||
token_append(token, *str);
|
|
||||||
else if (*str = '#')
|
|
||||||
{
|
|
||||||
while (*str && *str != '\n')
|
|
||||||
str++;
|
|
||||||
ft_tokenize(alst, str);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*alst)->next = ft_lstnew(token_init(), sizeof(t_token));
|
|
||||||
token->type = TK_WORD;
|
|
||||||
token_append(token, *str);
|
|
||||||
}
|
|
||||||
ft_tokenize(&(*alst)->next, str + 1);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,60 +13,33 @@
|
||||||
#ifndef TOKEN_H
|
#ifndef TOKEN_H
|
||||||
# define TOKEN_H
|
# define TOKEN_H
|
||||||
|
|
||||||
typedef long long t_type;
|
# include "libft.h"
|
||||||
|
|
||||||
# define TK_WORD 0x0001
|
# define TK_LESS 0x0001
|
||||||
# define TK_NEWLINE 0x0002
|
# define TK_GREAT 0x0002
|
||||||
# define TK_IOHERE 0x0004
|
# define TK_DLESS 0x0004
|
||||||
# define TK_LESS 0x0010
|
# define TK_DGREAT 0x0008
|
||||||
# define TK_GREAT 0x0020
|
# define TK_LESSAND 0x0010
|
||||||
# define TK_DLESS 0x0040
|
# define TK_GREATAND 0x0020
|
||||||
# define TK_DGREAT 0x0080
|
# define TK_SEMI 0x0040
|
||||||
# define TK_LESSAND 0x0100
|
# define TK_PIPE 0x0080
|
||||||
# define TK_GREATAND 0x0200
|
# define TK_WORD 0x0100
|
||||||
# define TK_SCOLON 0x0400
|
|
||||||
# define TK_PIPE 0x0800
|
|
||||||
# define TK_UNKNOWN 0x1000
|
|
||||||
|
|
||||||
# define TK_OPERATOR 1 & (~TK_WORD | ~TK_NEWLINE | ~TK_IOHERE)
|
typedef long long t_type;
|
||||||
# define OPERATOR_ST "<>;|0123456789"
|
|
||||||
|
|
||||||
# define NUM_BEFORE 0x0001
|
|
||||||
# define WORD_AFTER 0x0002
|
|
||||||
# define MIN_END 0x0004
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_operator t_operator;
|
|
||||||
typedef struct s_token t_token;
|
typedef struct s_token t_token;
|
||||||
typedef struct s_redir t_redir;
|
|
||||||
|
|
||||||
struct s_operator
|
|
||||||
{
|
|
||||||
t_type type;
|
|
||||||
char symbol[3];
|
|
||||||
t_type format;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct s_redir
|
|
||||||
{
|
|
||||||
t_type type;
|
|
||||||
int fd;
|
|
||||||
char *filename;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct s_token
|
struct s_token
|
||||||
{
|
{
|
||||||
t_type type;
|
t_type type;
|
||||||
char *content;
|
char *data;
|
||||||
char *size;
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern t_operator g_ops[];
|
|
||||||
|
|
||||||
t_token *token_init();
|
t_token *token_init();
|
||||||
|
t_token *token_getnext(int *pos,char *line);
|
||||||
int ft_tokenize(t_list **alst, char *str);
|
int ft_tokenize(t_list **alst, char *str);
|
||||||
int token_recognition(t_list *alst, char *str);
|
int token_append(t_token *token, char c);
|
||||||
int token_append(t_token *token, char str);
|
void token_free(void *data, size_t size);
|
||||||
int token_delimit(t_token *token);
|
void token_print(t_list *lst);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,13 @@
|
||||||
|
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
|
|
||||||
int token_append(t_token *token, char str)
|
int token_append(t_token *token, char c)
|
||||||
{
|
{
|
||||||
if (ft_strlen(token->data) <= token->size)
|
if ((int)ft_strlen(token->data) >= token->size)
|
||||||
{
|
{
|
||||||
token->data = (char *)ft_realloc(token->size + 10);
|
token->data = (char *)ft_realloc(token->data, token->size + 10);
|
||||||
token->size += 10;
|
token->size += 10;
|
||||||
}
|
}
|
||||||
ft_strcat(token->data, &str);
|
ft_strcat(token->data, (char[2]){c, '\0'});
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* token_delimit.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/11 17:47:31 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/11 20:25:08 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "token.h"
|
|
||||||
|
|
||||||
int token_delimit(t_token *token)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
11
42sh/src/token/token_free.c
Normal file
11
42sh/src/token/token_free.c
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
|
void token_free(void *data, size_t size)
|
||||||
|
{
|
||||||
|
t_token *token;
|
||||||
|
|
||||||
|
(void)size;
|
||||||
|
token = data;
|
||||||
|
ft_strdel(&token->data);
|
||||||
|
free(token);
|
||||||
|
}
|
||||||
62
42sh/src/token/token_getnext.c
Normal file
62
42sh/src/token/token_getnext.c
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
|
static int is_separator(char c)
|
||||||
|
{
|
||||||
|
return (c==' ' || c=='\t' || c=='\n' || c=='\r');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
@ -10,13 +10,13 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "token.h"
|
||||||
|
|
||||||
t_token *token_init(t_list **alst)
|
t_token *token_init()
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (t_token *)malloc(sizeof(t_token) + 1);
|
token = (t_token *)malloc(sizeof(t_token));
|
||||||
token->type = 0;
|
token->type = 0;
|
||||||
token->size = 10;
|
token->size = 10;
|
||||||
token->data = ft_strnew(token->size);
|
token->data = ft_strnew(token->size);
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* token_operator_match.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/11 20:12:52 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/11 20:13:36 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "token.h"
|
|
||||||
|
|
||||||
int token_operator_match(t_token *token)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
13
42sh/src/token/token_print.c
Normal file
13
42sh/src/token/token_print.c
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
|
void token_print(t_list *lst)
|
||||||
|
{
|
||||||
|
t_token *token;
|
||||||
|
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
token = lst->content;
|
||||||
|
ft_printf("%#06llx: '%s'\n", token->type, token->data);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue