work of 10/11/16, started tokenization
This commit is contained in:
parent
94cdecd642
commit
76535c73c1
35 changed files with 676 additions and 171 deletions
11
42sh/.tags
11
42sh/.tags
|
|
@ -11,9 +11,9 @@ builtin_setenv src/builtin/builtin_setenv.c /^int builtin_setenv(char **av, cha
|
||||||
builtin_unsetenv src/builtin/builtin_unsetenv.c /^int builtin_unsetenv(char **av, char ***env_p)$/
|
builtin_unsetenv src/builtin/builtin_unsetenv.c /^int builtin_unsetenv(char **av, char ***env_p)$/
|
||||||
ft_builtin src/builtin/builtin.c /^int ft_builtin(char **av, char ***env_p)$/
|
ft_builtin src/builtin/builtin.c /^int ft_builtin(char **av, char ***env_p)$/
|
||||||
ft_clear_line src/line-editing/ft_clear_line.c /^int ft_clear_line(t_data *data, t_dlist **input_c/
|
ft_clear_line src/line-editing/ft_clear_line.c /^int ft_clear_line(t_data *data, t_dlist **input_c/
|
||||||
ft_cmd_exec src/main/ft_cmd.c /^int ft_cmd_exec(char *execpath, char **argv, char/
|
ft_cmd_exec src/minishell-exec/ft_cmd.c /^int ft_cmd_exec(char *execpath, char **argv, char/
|
||||||
ft_cmd_getav src/main/ft_cmd.c /^char **ft_cmd_getav(char *cmd)$/
|
ft_cmd_getav src/minishell-exec/ft_cmd.c /^char **ft_cmd_getav(char *cmd)$/
|
||||||
ft_cmd_process src/main/ft_cmd.c /^int ft_cmd_process(char **argv, char ***env_p)$/
|
ft_cmd_process src/minishell-exec/ft_cmd.c /^int ft_cmd_process(char **argv, char ***env_p)$/
|
||||||
ft_cursor_left src/line-editing/ft_cursor_left.c /^int ft_cursor_left(t_data *data, t_dlist **input_/
|
ft_cursor_left src/line-editing/ft_cursor_left.c /^int ft_cursor_left(t_data *data, t_dlist **input_/
|
||||||
ft_cursor_right src/line-editing/ft_cursor_right.c /^int ft_cursor_right(t_data *data, t_dlist **input/
|
ft_cursor_right src/line-editing/ft_cursor_right.c /^int ft_cursor_right(t_data *data, t_dlist **input/
|
||||||
ft_env_getval src/main/lib_env.c /^char *ft_env_getval(char **env, char *key)$/
|
ft_env_getval src/main/lib_env.c /^char *ft_env_getval(char **env, char *key)$/
|
||||||
|
|
@ -33,8 +33,9 @@ ft_line_go_up src/line-editing/ft_line_up.c /^int ft_line_go_up(t_dlist **input
|
||||||
ft_line_start src/line-editing/ft_line_start.c /^int ft_line_start(t_data *data, t_dlist **input_c/
|
ft_line_start src/line-editing/ft_line_start.c /^int ft_line_start(t_data *data, t_dlist **input_c/
|
||||||
ft_path_access src/main/lib_path.c /^int ft_path_access(char *execpath, char *execname/
|
ft_path_access src/main/lib_path.c /^int ft_path_access(char *execpath, char *execname/
|
||||||
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/main/ft_prompt.c /^int ft_prompt(void)$/
|
ft_prompt src/line-editing/ft_prompt.c /^int ft_prompt(void)$/
|
||||||
ft_tc_init src/main/lib_tc.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_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/
|
||||||
sig_handler src/main/sig_handler.c /^void sig_handler(int signo)$/
|
sig_handler src/main/sig_handler.c /^void sig_handler(int signo)$/
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ 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
|
D_INC = includes libft/includes src/line-editing/includes
|
||||||
O_INC = $(addprefix -I, $(D_INC))
|
O_INC = $(addprefix -I, $(D_INC))
|
||||||
|
|
||||||
D_SER = libft
|
D_SER = libft
|
||||||
|
|
@ -42,6 +42,9 @@ $(D_OBJ)/%.o: $(D_SRC)/*/%.c $(D_INC)
|
||||||
libft:
|
libft:
|
||||||
@$(MAKE) -C libft/ 2>/dev/null
|
@$(MAKE) -C libft/ 2>/dev/null
|
||||||
|
|
||||||
|
line-editing:
|
||||||
|
@$(MAKE) -C line-editing 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)
|
||||||
|
|
||||||
|
|
|
||||||
157
42sh/Session.vim
157
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 ~/42/minishell
|
cd ~/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 +47 includes/minishell.h
|
badd +26 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,19 +17,43 @@ 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 +21 src/main/main.c
|
badd +24 src/main/main.c
|
||||||
badd +12 src/builtin/builtin_exit.c
|
badd +12 src/builtin/builtin_exit.c
|
||||||
badd +0 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
|
||||||
badd +2 src/main/ft_cmd.c
|
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 +1 src/line-editing/ft_interactive_sh.c
|
badd +45 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
|
||||||
argglobal
|
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 +19 src/token/ft_tokenize.c
|
||||||
|
badd +30 src/line-editing/line-editing.h
|
||||||
|
badd +1 libft/Makefile
|
||||||
|
badd +36 Makefile
|
||||||
|
badd +18 line-editing/Makefile
|
||||||
|
badd +14 line-editing/includes/line_editing.h
|
||||||
|
badd +15 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 +33 libft/includes/libft.h
|
||||||
|
badd +5 libft/includes/get_next_line.h
|
||||||
|
badd +22 src/token/token_init.c
|
||||||
|
badd +19 src/token/includes/token.h
|
||||||
|
badd +15 src/token/token_recognition.c
|
||||||
silent! argdel *
|
silent! argdel *
|
||||||
set stal=2
|
|
||||||
edit includes/minishell.h
|
edit includes/minishell.h
|
||||||
set splitbelow splitright
|
set splitbelow splitright
|
||||||
wincmd _ | wincmd |
|
wincmd _ | wincmd |
|
||||||
|
|
@ -40,8 +64,8 @@ set nosplitbelow
|
||||||
set nosplitright
|
set nosplitright
|
||||||
wincmd t
|
wincmd t
|
||||||
set winheight=1 winwidth=1
|
set winheight=1 winwidth=1
|
||||||
exe 'vert 1resize ' . ((&columns * 79 + 79) / 158)
|
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
|
||||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
|
||||||
argglobal
|
argglobal
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
|
|
@ -52,15 +76,15 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 68 - ((22 * winheight(0) + 19) / 38)
|
let s:l = 52 - ((51 * 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
|
||||||
68
|
52
|
||||||
normal! 025|
|
normal! 042l
|
||||||
wincmd w
|
wincmd w
|
||||||
argglobal
|
argglobal
|
||||||
edit src/main/main.c
|
edit src/line-editing/includes/line_editing.h
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
setlocal fmr={{{,}}}
|
setlocal fmr={{{,}}}
|
||||||
|
|
@ -70,16 +94,16 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 9 - ((8 * winheight(0) + 19) / 38)
|
let s:l = 46 - ((45 * 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
|
||||||
9
|
46
|
||||||
normal! 0
|
normal! 0
|
||||||
wincmd w
|
wincmd w
|
||||||
exe 'vert 1resize ' . ((&columns * 79 + 79) / 158)
|
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
|
||||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
|
||||||
tabedit src/line-editing/ft_interactive_sh.c
|
tabedit src/main/main.c
|
||||||
set splitbelow splitright
|
set splitbelow splitright
|
||||||
wincmd _ | wincmd |
|
wincmd _ | wincmd |
|
||||||
vsplit
|
vsplit
|
||||||
|
|
@ -89,8 +113,8 @@ set nosplitbelow
|
||||||
set nosplitright
|
set nosplitright
|
||||||
wincmd t
|
wincmd t
|
||||||
set winheight=1 winwidth=1
|
set winheight=1 winwidth=1
|
||||||
exe 'vert 1resize ' . ((&columns * 79 + 79) / 158)
|
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
|
||||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
|
||||||
argglobal
|
argglobal
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
|
|
@ -101,15 +125,15 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 36 - ((16 * winheight(0) + 19) / 38)
|
let s:l = 22 - ((19 * 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
|
||||||
36
|
22
|
||||||
normal! 05|
|
normal! 09l
|
||||||
wincmd w
|
wincmd w
|
||||||
argglobal
|
argglobal
|
||||||
edit src/main/sig_handler.c
|
edit src/line-editing/ft_interactive_sh.c
|
||||||
setlocal fdm=manual
|
setlocal fdm=manual
|
||||||
setlocal fde=0
|
setlocal fde=0
|
||||||
setlocal fmr={{{,}}}
|
setlocal fmr={{{,}}}
|
||||||
|
|
@ -119,18 +143,87 @@ setlocal fml=1
|
||||||
setlocal fdn=20
|
setlocal fdn=20
|
||||||
setlocal fen
|
setlocal fen
|
||||||
silent! normal! zE
|
silent! normal! zE
|
||||||
let s:l = 13 - ((12 * winheight(0) + 19) / 38)
|
let s:l = 56 - ((55 * 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
|
56
|
||||||
normal! 022|
|
normal! 012l
|
||||||
wincmd w
|
wincmd w
|
||||||
2wincmd w
|
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
|
||||||
exe 'vert 1resize ' . ((&columns * 79 + 79) / 158)
|
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
|
||||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
tabedit src/token/includes/token.h
|
||||||
tabnext 2
|
set splitbelow splitright
|
||||||
set stal=1
|
wincmd _ | wincmd |
|
||||||
|
vsplit
|
||||||
|
1wincmd h
|
||||||
|
wincmd w
|
||||||
|
set nosplitbelow
|
||||||
|
set nosplitright
|
||||||
|
wincmd t
|
||||||
|
set winheight=1 winwidth=1
|
||||||
|
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
|
||||||
|
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
|
||||||
|
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 = 18 - ((17 * winheight(0) + 37) / 75)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
18
|
||||||
|
normal! 0
|
||||||
|
wincmd w
|
||||||
|
argglobal
|
||||||
|
edit src/token/ft_tokenize.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 = 35 - ((34 * winheight(0) + 37) / 75)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
35
|
||||||
|
normal! 01l
|
||||||
|
wincmd w
|
||||||
|
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
|
||||||
|
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
|
||||||
|
tabedit src/token/token_init.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 = 19 - ((18 * winheight(0) + 37) / 75)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
19
|
||||||
|
normal! 031l
|
||||||
|
tabnext 3
|
||||||
if exists('s:wipebuf')
|
if exists('s:wipebuf')
|
||||||
silent exe 'bwipe ' . s:wipebuf
|
silent exe 'bwipe ' . s:wipebuf
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -1,80 +1,33 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* minishell.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 14:54:23 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef MINISHELL_H
|
#ifndef MINISHELL_H
|
||||||
# define MINISHELL_H
|
# define MINISHELL_H
|
||||||
|
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
|
# include "line_editing.h"
|
||||||
# include <dirent.h>
|
# include <dirent.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <curses.h>
|
|
||||||
# include <term.h>
|
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
|
|
||||||
# define SHELL_PROMPT "$> "
|
# define MODE_INPUT 0b0001
|
||||||
# define BUFF_SIZE 32
|
# define MODE_EXEC 0b0010
|
||||||
# define READ_BUF 32
|
|
||||||
# define FT_KEY_C_D "\x4"
|
|
||||||
# define FT_KEY_C_H "\x8"
|
|
||||||
# define FT_KEY_TAB "\x9"
|
|
||||||
# define FT_KEY_ENTER "\xa"
|
|
||||||
# define FT_KEY_C_K "\xb"
|
|
||||||
# define FT_KEY_C_L "\xc"
|
|
||||||
# define FT_KEY_C_U "\x15"
|
|
||||||
# define FT_KEY_ESC "\x1b"
|
|
||||||
# define FT_KEY_UP "\x1b\x5b\x41"
|
|
||||||
# define FT_KEY_DOWN "\x1b\x5b\x42"
|
|
||||||
# define FT_KEY_RIGHT "\x1b\x5b\x43"
|
|
||||||
# define FT_KEY_LEFT "\x1b\x5b\x44"
|
|
||||||
# define FT_KEY_C_UP "\x1b\x4f\x41"
|
|
||||||
# define FT_KEY_C_DOWN "\x1b\x4f\x42"
|
|
||||||
# define FT_KEY_C_RIGHT "\x1b\x4f\x43"
|
|
||||||
# define FT_KEY_C_LEFT "\x1b\x4f\x44"
|
|
||||||
# define FT_KEY_DEL "\x7f"
|
|
||||||
|
|
||||||
typedef struct s_stof
|
|
||||||
{
|
|
||||||
char *name;
|
|
||||||
int (*f)();
|
|
||||||
} t_stof;
|
|
||||||
|
|
||||||
typedef struct s_data
|
|
||||||
{
|
|
||||||
char **env;
|
|
||||||
t_dlist *history;
|
|
||||||
t_dlist *input_mem;
|
|
||||||
} t_data;
|
|
||||||
|
|
||||||
extern t_stof g_builtins[];
|
extern t_stof g_builtins[];
|
||||||
extern t_stof g_keys[];
|
|
||||||
extern pid_t g_pid;
|
extern pid_t g_pid;
|
||||||
extern int g_mode;
|
extern int g_mode;
|
||||||
|
|
||||||
void sig_handler(int signo);
|
void sig_handler(int signo);
|
||||||
#define MODE_INPUT 0b0001
|
|
||||||
#define MODE_EXEC 0b0010
|
|
||||||
|
|
||||||
|
|
||||||
int ft_tc_init(t_data *data);
|
|
||||||
int ft_interactive_sh(t_data *data);
|
|
||||||
int ft_prompt(void);
|
|
||||||
int ft_input_is_escaped(t_dlist *input_chain);
|
|
||||||
int ft_history_add(t_data *data, t_dlist *input_chain);
|
|
||||||
|
|
||||||
typedef int key_press(t_data *data, t_dlist **input_chain, 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_basic;
|
|
||||||
key_press ft_key_ctrl_d;
|
|
||||||
|
|
||||||
int ft_cmd_process(char **argv, char ***env_p);
|
int ft_cmd_process(char **argv, char ***env_p);
|
||||||
int ft_cmd_exec(char *execpath, char **argv, char ***env_p);
|
int ft_cmd_exec(char *execpath, char **argv, char ***env_p);
|
||||||
|
|
@ -96,4 +49,6 @@ char *ft_env_getval(char **env, char *key);
|
||||||
int ft_path_access(char *execpath, char *execname);
|
int ft_path_access(char *execpath, char *execname);
|
||||||
char *ft_path_findexec(char **path, char *execname);
|
char *ft_path_findexec(char **path, char *execname);
|
||||||
|
|
||||||
|
int ft_tokenize(t_list **alst, char *str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 87f043154c8e46ae7d0df30ec25ee420ce1b8099
|
Subproject commit b38fc62abb47b660dddc683266a7fc3aa805ab96
|
||||||
|
|
@ -3,8 +3,7 @@
|
||||||
#define CDOPT_P 0b010
|
#define CDOPT_P 0b010
|
||||||
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
||||||
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
||||||
#define CDERR_1 "cd: string not in pwd: %s\n"
|
#define CDERR_1 "cd: no such file or directory: %s\n"
|
||||||
#define CDERR_2 "cd: no such file or directory: %s\n"
|
|
||||||
|
|
||||||
int builtin_cd(char **av, char ***env_p)
|
int builtin_cd(char **av, char ***env_p)
|
||||||
{
|
{
|
||||||
|
|
@ -16,12 +15,13 @@ int builtin_cd(char **av, char ***env_p)
|
||||||
|
|
||||||
opts = 0;
|
opts = 0;
|
||||||
i = builtin_cd_opts(av, &opts);
|
i = builtin_cd_opts(av, &opts);
|
||||||
target = builtin_cd_special(av + i, *env_p);
|
if (!(target = builtin_cd_special(av + i, *env_p)))
|
||||||
|
return (0);
|
||||||
oldpwd[0] = ft_strdup("OLDPWD");
|
oldpwd[0] = ft_strdup("OLDPWD");
|
||||||
oldpwd[1] = getcwd(NULL, 0);
|
oldpwd[1] = getcwd(NULL, 0);
|
||||||
if (chdir(target))
|
if (chdir(target))
|
||||||
{
|
{
|
||||||
ft_printf(CDERR_2, target);
|
ft_printf(CDERR_1, target);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else if (target != av[i])
|
else if (target != av[i])
|
||||||
|
|
@ -30,10 +30,6 @@ int builtin_cd(char **av, char ***env_p)
|
||||||
pwd[1] = getcwd(NULL, 0);
|
pwd[1] = getcwd(NULL, 0);
|
||||||
builtin_setenv(pwd, env_p);
|
builtin_setenv(pwd, env_p);
|
||||||
builtin_setenv(oldpwd, env_p);
|
builtin_setenv(oldpwd, env_p);
|
||||||
/* { */
|
|
||||||
/* printf(CDERR_1, av[-i]); */
|
|
||||||
/* return (1) */
|
|
||||||
/* } */
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +38,10 @@ char *builtin_cd_special(char **av, char **env)
|
||||||
char *target;
|
char *target;
|
||||||
|
|
||||||
if (!*av)
|
if (!*av)
|
||||||
target = ft_env_getval(env, "HOME");
|
{
|
||||||
|
if (!(target = ft_env_getval(env, "HOME")))
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
else if (ft_strcmp(*av, "-") == 0)
|
else if (ft_strcmp(*av, "-") == 0)
|
||||||
target = ft_env_getval(env, "OLDPWD");
|
target = ft_env_getval(env, "OLDPWD");
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_clear_line.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:42:45 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:42:59 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_clear_line(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_clear_line(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_cursor_left.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:43:10 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:43:25 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_cursor_left(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_cursor_left(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_cursor_right.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:43:31 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:43:31 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_cursor_right(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_cursor_right(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_history_add.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:43:40 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:43:50 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_history_add(t_data *data, t_dlist *input_chain)
|
int ft_history_add(t_data *data, t_dlist *input_chain)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_history_down.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:06 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:06 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_history_down(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_history_down(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_history_up.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:15 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:15 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_history_up(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_history_up(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
@ -15,11 +27,11 @@ int ft_history_up(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
data->history = data->history->prev;
|
data->history = data->history->prev;
|
||||||
str = data->history->content;
|
str = data->history->content;
|
||||||
/* *input_chain = ft_dlst_last(*input_chain); */
|
/* *input_chain = ft_dlst_last(*input_chain); */
|
||||||
/* ft_clear_input(input_chain); */
|
ft_clear_line(data, input_chain, buf);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (str[i])
|
while (str[i])
|
||||||
ft_key_basic(data, input_chain, str + i++);
|
ft_key_basic(data, input_chain, str + i++);
|
||||||
if (!data->history->next)
|
/* if (!data->history->next) */
|
||||||
ft_strdel(&str);
|
/* ft_strdel(&str); */
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_input_is_escaped.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:17 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:17 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_input_is_escaped(t_dlist *input_chain)
|
int ft_input_is_escaped(t_dlist *input_chain)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_interactive_sh.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:21 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 14:59:44 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
t_stof g_keys[] = {
|
t_stof g_keys[] = {
|
||||||
{FT_KEY_C_K, NULL},
|
{FT_KEY_C_K, NULL},
|
||||||
|
|
@ -38,15 +50,19 @@ int ft_interactive_sh(t_data *data)
|
||||||
|
|
||||||
(void)data;
|
(void)data;
|
||||||
null = '\0';
|
null = '\0';
|
||||||
|
if (!data->history)
|
||||||
|
data->history = ft_dlst_new(NULL, 0);
|
||||||
input_chain = ft_dlst_new(&null, sizeof(char));
|
input_chain = ft_dlst_new(&null, sizeof(char));
|
||||||
|
ft_tc_init(data);
|
||||||
|
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_strequ(buf, g_keys[i].name) == 0)
|
while (g_keys[i].name && ft_strcmp(buf, g_keys[i].name) == 0)
|
||||||
i++;
|
i++;
|
||||||
if (!g_keys[i].f)
|
if (!g_keys[i].f)
|
||||||
continue ;
|
continue ;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_key_basic.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:23 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:23 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_key_basic(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_key_basic(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_key_ctrl_d.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:24 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:24 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_key_ctrl_d(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_key_ctrl_d(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_key_del.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:26 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:26 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_key_del(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_key_del(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_key_enter.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:30 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 14:21:42 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_key_enter(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_key_enter(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_line_down.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:31 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:31 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_line_go_down(t_dlist **input_chain)
|
int ft_line_go_down(t_dlist **input_chain)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_line_end.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:33 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:33 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_line_end(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_line_end(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_line_start.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:34 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:34 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_line_start(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_line_start(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_line_up.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:35 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:35 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_line_go_up(t_dlist **input_chain)
|
int ft_line_go_up(t_dlist **input_chain)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
19
42sh/src/line-editing/ft_prompt.c
Normal file
19
42sh/src/line-editing/ft_prompt.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_prompt.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 14:22:34 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 14:22:48 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
|
int ft_prompt(void)
|
||||||
|
{
|
||||||
|
ft_putstr(SHELL_PROMPT);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
33
42sh/src/line-editing/ft_tc_init.c
Normal file
33
42sh/src/line-editing/ft_tc_init.c
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_tc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 14:27:57 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 14:39:28 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
|
int ft_tc_init(t_data *data)
|
||||||
|
{
|
||||||
|
char *term_name;
|
||||||
|
struct termios term;
|
||||||
|
|
||||||
|
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
|
||||||
|
return (-1);
|
||||||
|
if (tgetent(NULL, term_name) != 1)
|
||||||
|
return (-1);
|
||||||
|
if (tcgetattr(0, &term) == -1)
|
||||||
|
return (-1);
|
||||||
|
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
|
||||||
|
term.c_cc[VMIN] = 1;
|
||||||
|
term.c_cc[VTIME] = 0;
|
||||||
|
if (tcsetattr(0, TCSADRAIN, &term) == -1)
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_word_left.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:36 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:36 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_word_left(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_word_left(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
#include "minishell.h"
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_word_right.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:44:37 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 13:44:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "line_editing.h"
|
||||||
|
|
||||||
int ft_word_right(t_data *data, t_dlist **input_chain, char *buf)
|
int ft_word_right(t_data *data, t_dlist **input_chain, char *buf)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
78
42sh/src/line-editing/includes/line_editing.h
Normal file
78
42sh/src/line-editing/includes/line_editing.h
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* line-editing.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:38:21 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 14:41:23 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LINE_EDITING_H
|
||||||
|
# define LINE_EDITING_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
|
# include <curses.h>
|
||||||
|
# include <term.h>
|
||||||
|
|
||||||
|
# define SHELL_PROMPT "$> "
|
||||||
|
# define BUFF_SIZE 32
|
||||||
|
# define READ_BUF 32
|
||||||
|
# define FT_KEY_C_D "\x4"
|
||||||
|
# define FT_KEY_C_H "\x8"
|
||||||
|
# define FT_KEY_TAB "\x9"
|
||||||
|
# define FT_KEY_ENTER "\xa"
|
||||||
|
# define FT_KEY_C_K "\xb"
|
||||||
|
# define FT_KEY_C_L "\xc"
|
||||||
|
# define FT_KEY_C_U "\x15"
|
||||||
|
# define FT_KEY_ESC "\x1b"
|
||||||
|
# define FT_KEY_UP "\x1b\x5b\x41"
|
||||||
|
# define FT_KEY_DOWN "\x1b\x5b\x42"
|
||||||
|
# define FT_KEY_RIGHT "\x1b\x5b\x43"
|
||||||
|
# define FT_KEY_LEFT "\x1b\x5b\x44"
|
||||||
|
# define FT_KEY_C_UP "\x1b\x4f\x41"
|
||||||
|
# define FT_KEY_C_DOWN "\x1b\x4f\x42"
|
||||||
|
# define FT_KEY_C_RIGHT "\x1b\x4f\x43"
|
||||||
|
# define FT_KEY_C_LEFT "\x1b\x4f\x44"
|
||||||
|
# define FT_KEY_SQUOTE "\x22"
|
||||||
|
# define FT_KEY_DQUOTE "\x27"
|
||||||
|
# define FT_KEY_BSLASH "\x5c"
|
||||||
|
# define FT_KEY_DEL "\x7f"
|
||||||
|
|
||||||
|
typedef struct s_data t_data;
|
||||||
|
|
||||||
|
struct s_data
|
||||||
|
{
|
||||||
|
char **env;
|
||||||
|
t_dlist *history;
|
||||||
|
t_dlist *input_mem;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern t_stof g_keys[];
|
||||||
|
|
||||||
|
int ft_tc_init(t_data *data);
|
||||||
|
int ft_interactive_sh(t_data *data);
|
||||||
|
int ft_prompt(void);
|
||||||
|
int ft_input_is_escaped(t_dlist *input_chain);
|
||||||
|
int ft_history_add(t_data *data, t_dlist *input_chain);
|
||||||
|
|
||||||
|
typedef int key_press(t_data *data, t_dlist **input_chain, 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_basic;
|
||||||
|
key_press ft_key_ctrl_d;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
int ft_prompt(void)
|
|
||||||
{
|
|
||||||
ft_putstr(SHELL_PROMPT);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
int ft_tc_init(t_data *data)
|
|
||||||
{
|
|
||||||
char *term_name;
|
|
||||||
struct termios term;
|
|
||||||
|
|
||||||
if ((term_name = ft_env_getval(data->env, "TERM")) == NULL)
|
|
||||||
return (-1);
|
|
||||||
if (tgetent(NULL, term_name) != 1)
|
|
||||||
return (-1);
|
|
||||||
if (tcgetattr(0, &term) == -1)
|
|
||||||
return (-1);
|
|
||||||
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
|
|
||||||
term.c_cc[VMIN] = 1;
|
|
||||||
term.c_cc[VTIME] = 0;
|
|
||||||
if (tcsetattr(0, TCSADRAIN, &term) == -1)
|
|
||||||
return (-1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +1,49 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:35:14 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 15:43:18 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
int g_mode;
|
int g_mode;
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
t_data data;
|
t_data data;
|
||||||
|
char *cmd;
|
||||||
char **av;
|
char **av;
|
||||||
|
t_list *token;
|
||||||
|
|
||||||
data.env = ft_sstrdup(environ);
|
data.env = ft_sstrdup(environ);
|
||||||
data.history = ft_dlst_new(NULL, 0);
|
token = NULL;
|
||||||
ft_tc_init(&data);
|
|
||||||
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;
|
g_mode = MODE_INPUT;
|
||||||
ft_prompt();
|
|
||||||
if (ft_interactive_sh(&data))
|
if (ft_interactive_sh(&data))
|
||||||
return (1);
|
return (1);
|
||||||
|
cmd = ft_strdup(data.history->prev->content);
|
||||||
g_mode = MODE_EXEC;
|
g_mode = MODE_EXEC;
|
||||||
/* ft_printf("got string:'%s'\n", data.history->prev->content); */
|
|
||||||
av = ft_cmd_getav(data.history->prev->content);
|
/* (void)av; */
|
||||||
if (av && av[0])
|
/* ft_printf("got string:'%s'\n", cmd); */
|
||||||
ft_cmd_process(av, &data.env);
|
|
||||||
|
/* av = ft_cmd_getav(cmd); */
|
||||||
|
/* if (av && av[0]) */
|
||||||
|
/* ft_cmd_process(av, &data.env); */
|
||||||
|
|
||||||
|
(void)av;
|
||||||
|
if (ft_tokenize(&token, cmd))
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ int ft_cmd_process(char **argv, char ***env_p)
|
||||||
execpath = argv[0];
|
execpath = argv[0];
|
||||||
else if (!(execpath = ft_path_findexec(path, argv[0])))
|
else if (!(execpath = ft_path_findexec(path, argv[0])))
|
||||||
return (-1);
|
return (-1);
|
||||||
/* ft_printf("%s @ %s\n", argv[0], execpath); */
|
|
||||||
return (ft_cmd_exec(execpath, argv, env_p));
|
return (ft_cmd_exec(execpath, argv, env_p));
|
||||||
}
|
}
|
||||||
|
|
||||||
39
42sh/src/token/ft_tokenize.c
Normal file
39
42sh/src/token/ft_tokenize.c
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_tokenize.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 17:04:10 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
int ft_tokenize(t_list **alst, char *str)
|
||||||
|
{
|
||||||
|
static int quoted = 0;
|
||||||
|
t_token *token;
|
||||||
|
|
||||||
|
if (!*alst)
|
||||||
|
alst = ft_lstnew(token_init(), sizeof(t_token));
|
||||||
|
else
|
||||||
|
token = (*alst)->content;
|
||||||
|
if (!*str)
|
||||||
|
return (0);
|
||||||
|
else if (token->type == TOKEN_OPERATOR && !quoted)
|
||||||
|
{
|
||||||
|
if (can_be_used_in_op)
|
||||||
|
token_append(token, *str);
|
||||||
|
else
|
||||||
|
ft_tokenize(&(*alst)->next, str);
|
||||||
|
}
|
||||||
|
else if (can_be_first_of_op && !quoted)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
ft_tokenize(&(*alst)->next, str + 1);
|
||||||
|
ft_tokenize(alst, str + 1);
|
||||||
|
}
|
||||||
32
42sh/src/token/includes/token.h
Normal file
32
42sh/src/token/includes/token.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* token.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 15:31:42 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 17:04:12 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef TOKEN_H
|
||||||
|
# define TOKEN_H
|
||||||
|
|
||||||
|
# define TOKEN_WORD 0b000001
|
||||||
|
# define TOKEN_OPERATOR 0b000010
|
||||||
|
|
||||||
|
typedef struct s_token t_token;
|
||||||
|
|
||||||
|
struct s_token
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
char *content;
|
||||||
|
char *size;
|
||||||
|
};
|
||||||
|
|
||||||
|
t_token *token_init();
|
||||||
|
int ft_tokenize(t_list **alst, char *str);
|
||||||
|
int token_recognition(t_list *alst, char *str);
|
||||||
|
|
||||||
|
#endif
|
||||||
24
42sh/src/token/token_init.c
Normal file
24
42sh/src/token/token_init.c
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* token_init.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 16:52:13 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
t_token *token_init(t_list **alst)
|
||||||
|
{
|
||||||
|
t_token *token;
|
||||||
|
|
||||||
|
token = (t_token*)malloc(sizeof(t_token) + 1);
|
||||||
|
token->type = 0;
|
||||||
|
token->size = 10;
|
||||||
|
token->data = ft_strnew(token->size);
|
||||||
|
return (token);
|
||||||
|
}
|
||||||
18
42sh/src/token/token_recognition.c
Normal file
18
42sh/src/token/token_recognition.c
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* token_recognition.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/10 15:37:22 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/10 15:48:45 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
|
int token_recognition(t_list *alst, char *str)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue