interactive shell with termcaps
This commit is contained in:
parent
4c0e368997
commit
6359eac19f
46 changed files with 739 additions and 257 deletions
52
42sh/.tags
52
42sh/.tags
|
|
@ -1,15 +1,37 @@
|
|||
Mmain src/main.c /^int main(void)$/
|
||||
builtin_cd src/builtin_cd.c /^int builtin_cd(char **av, char ***env)$/
|
||||
builtin_echo src/builtin_echo.c /^int builtin_echo(char **av, char ***env_p)$/
|
||||
builtin_env src/builtin_env.c /^int builtin_env(char **av, char ***env_p)$/
|
||||
builtin_exit src/builtin_exit.c /^int builtin_exit(char **av, char ***env_p)$/
|
||||
builtin_setenv src/builtin_setenv.c /^int builtin_setenv(char **av, char ***env_p)$/
|
||||
builtin_unsetenv src/builtin_unsetenv.c /^int builtin_unsetenv(char **av, char ***env)$/
|
||||
ft_builtin src/builtin.c /^int ft_builtin(char **av, char ***env_p)$/
|
||||
ft_cmd_exec src/ft_cmd.c /^int ft_cmd_exec(char *execpath, char **argv, char/
|
||||
ft_cmd_getav src/ft_cmd.c /^char **ft_cmd_getav(char *cmd)$/
|
||||
ft_cmd_process src/ft_cmd.c /^int ft_cmd_process(char *cmd)$/
|
||||
ft_env_getval src/lib_env.c /^char *ft_env_getval(char **env, char *key)$/
|
||||
ft_expand_vars src/lib_expansion.c /^void ft_expand_vars(char **av, char **env)$/
|
||||
ft_path_access src/lib_path.c /^int ft_path_access(char *execpath, char *execname/
|
||||
ft_path_findexec src/lib_path.c /^char *ft_path_findexec(char **path, char *execname/
|
||||
HAS_CDOPT_L src/builtin/builtin_cd.c /^#define HAS_CDOPT_L(x) (x & CD_OPT_L)$/
|
||||
HAS_CDOPT_P src/builtin/builtin_cd.c /^#define HAS_CDOPT_P(x) (x & CD_OPT_P)$/
|
||||
Mmain src/main/main.c /^int main(void)$/
|
||||
builtin_cd src/builtin/builtin_cd.c /^int builtin_cd(char **av, char ***env_p)$/
|
||||
builtin_cd_opts src/builtin/builtin_cd.c /^int builtin_cd_opts(char **av, int *opts)$/
|
||||
builtin_cd_special src/builtin/builtin_cd.c /^char *builtin_cd_special(char **av, char **env)$/
|
||||
builtin_echo src/builtin/builtin_echo.c /^int builtin_echo(char **av, char ***env_p)$/
|
||||
builtin_env src/builtin/builtin_env.c /^int builtin_env(char **av, char ***env_p)$/
|
||||
builtin_exit src/builtin/builtin_exit.c /^int builtin_exit(char **av, char ***env_p)$/
|
||||
builtin_setenv src/builtin/builtin_setenv.c /^int builtin_setenv(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_clear_line src/user-interaction/ft_clear_line.c /^int ft_clear_line(t_data *data, t_dlist **input_c/
|
||||
ft_cmd_exec src/user-interaction/ft_cmd.c /^int ft_cmd_exec(char *execpath, char **argv, char/
|
||||
ft_cmd_getav src/user-interaction/ft_cmd.c /^char **ft_cmd_getav(char *cmd)$/
|
||||
ft_cmd_process src/user-interaction/ft_cmd.c /^int ft_cmd_process(char **argv, char ***env_p)$/
|
||||
ft_cursor_left src/user-interaction/ft_cursor_left.c /^int ft_cursor_left(t_data *data, t_dlist **input_/
|
||||
ft_cursor_right src/user-interaction/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_expand_dollar src/main/lib_expansion.c /^void ft_expand_dollar(char **av, char **env)$/
|
||||
ft_history_add src/user-interaction/ft_history_add.c /^int ft_history_add(t_data *data, t_dlist *input_c/
|
||||
ft_history_down src/user-interaction/ft_history_down.c /^int ft_history_down(t_data *data, t_dlist **input/
|
||||
ft_history_up src/user-interaction/ft_history_up.c /^int ft_history_up(t_data *data, t_dlist **input_c/
|
||||
ft_input_is_escaped src/user-interaction/ft_input_is_escaped.c /^int ft_input_is_escaped(t_dlist *input_chain)$/
|
||||
ft_interactive_sh src/user-interaction/ft_interactive_sh.c /^int ft_interactive_sh(t_data *data)$/
|
||||
ft_key_basic src/user-interaction/ft_key_basic.c /^int ft_key_basic(t_data *data, t_dlist **input_cha/
|
||||
ft_key_del src/user-interaction/ft_key_del.c /^int ft_key_del(t_data *data, t_dlist **input_chai/
|
||||
ft_key_enter src/user-interaction/ft_key_enter.c /^int ft_key_enter(t_data *data, t_dlist **input_ch/
|
||||
ft_line_end src/user-interaction/ft_line_end.c /^int ft_line_end(t_data *data, t_dlist **input_cha/
|
||||
ft_line_go_down src/user-interaction/ft_line_down.c /^int ft_line_go_down(t_dlist **input_chain)$/
|
||||
ft_line_go_up src/user-interaction/ft_line_up.c /^int ft_line_go_up(t_dlist **input_chain)$/
|
||||
ft_line_start src/user-interaction/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_findexec src/main/lib_path.c /^char *ft_path_findexec(char **path, char *execname/
|
||||
ft_tc_init src/main/lib_tc.c /^int ft_tc_init(t_data *data)$/
|
||||
ft_word_left src/user-interaction/ft_word_left.c /^int ft_word_left(t_data *data, t_dlist **input_ch/
|
||||
ft_word_right src/user-interaction/ft_word_right.c /^int ft_word_right(t_data *data, t_dlist **input_c/
|
||||
|
|
|
|||
|
|
@ -3,16 +3,23 @@ CC = gcc
|
|||
TAGFILE = .tags
|
||||
|
||||
D_SRC = src
|
||||
F_SRC := $(shell ls -1 $(D_SRC) | grep "\.c$$")
|
||||
DF_SRC := $(addprefix $(D_SRC)/, $(F_SRC))
|
||||
# F_SRC := $(shell ls -1 $(D_SRC) | grep "\.c$$")
|
||||
# F_SRC := $(addprefix $(D_SRC)/, $(F_SRC))
|
||||
F_SRC := $(shell find $(D_SRC) -type f -regex ".*\.c$$")
|
||||
|
||||
D_OBJ = obj
|
||||
F_OBJ = $(F_SRC:.c=.o)
|
||||
F_OBJ = $(notdir $(F_SRC:.c=.o))
|
||||
DF_OBJ := $(addprefix $(D_OBJ)/, $(F_OBJ))
|
||||
|
||||
D_INC = includes libft/includes
|
||||
O_INC = $(addprefix -I, $(D_INC))
|
||||
|
||||
D_SER = libft
|
||||
O_SER = $(addprefix -L, $(D_SER))
|
||||
|
||||
D_LIB = ft ncurses
|
||||
O_LIB = $(addprefix -l, $(D_LIB))
|
||||
|
||||
W_FLAGS = -Wall -Wextra -Werror
|
||||
D_FLAGS =
|
||||
|
||||
|
|
@ -23,11 +30,11 @@ RM = /bin/rm -rf
|
|||
|
||||
all: libft $(NAME) $(TAGFILE)
|
||||
|
||||
$(TAGFILE): $(D_SRC)/*.c
|
||||
@ctags -f $(TAGFILE) $(addprefix $(D_SRC)/, $(F_SRC))
|
||||
$(TAGFILE): $(D_SRC)/*/*.c
|
||||
@ctags -f $(TAGFILE) $(F_SRC)
|
||||
@echo "Making tags..."
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/%.c $(D_INC)
|
||||
$(D_OBJ)/%.o: $(D_SRC)/*/%.c $(D_INC)
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
|
|
@ -36,7 +43,7 @@ libft:
|
|||
@$(MAKE) -C libft/ 2>/dev/null
|
||||
|
||||
$(NAME): $(DF_OBJ) libft/libft.a
|
||||
$(CC) $(O_INC) -Llibft -lft $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS)
|
||||
$(CC) $(O_INC) $(O_SER) $(O_LIB) $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(D_OBJ)
|
||||
|
|
|
|||
210
42sh/Session.vim
210
42sh/Session.vim
|
|
@ -8,36 +8,24 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
|||
let s:wipebuf = bufnr('%')
|
||||
endif
|
||||
set shortmess=aoO
|
||||
badd +1 src/main.c
|
||||
badd +22 src/builtin.c
|
||||
badd +5 src/builtin_cd.c
|
||||
badd +10 src/builtin_echo.c
|
||||
badd +12 src/ft_cmd.c
|
||||
badd +13 includes/minishell.h
|
||||
badd +23 src/lib_path.c
|
||||
badd +9 Makefile
|
||||
badd +6 src/builtin_setenv.c
|
||||
badd +4 src/builtin_unsetenv.c
|
||||
badd +3 src/lib_env.c
|
||||
badd +5 src/builtin_env.c
|
||||
badd +4 src/builtin_exit.c
|
||||
badd +0 src/lib_expansion.c
|
||||
badd +0 includes/minishell.h
|
||||
badd +1 src/user-interaction/ft_word_left.c
|
||||
badd +11 src/user-interaction/ft_cursor_left.c
|
||||
badd +8 src/user-interaction/ft_interactive_sh.c
|
||||
badd +0 src/user-interaction/ft_word_right.c
|
||||
badd +0 src/user-interaction/ft_cursor_right.c
|
||||
badd +7 src/user-interaction/ft_clear_line.c
|
||||
badd +1 src/user-interaction/ft_line_start.c
|
||||
badd +5 src/user-interaction/ft_line_end.c
|
||||
argglobal
|
||||
silent! argdel *
|
||||
argadd src/main.c
|
||||
set stal=2
|
||||
edit includes/minishell.h
|
||||
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 * 79 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
||||
argglobal
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
|
|
@ -48,47 +36,24 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 27 - ((25 * winheight(0) + 19) / 38)
|
||||
let s:l = 47 - ((8 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
27
|
||||
normal! 049|
|
||||
lcd ~/42/minishell
|
||||
wincmd w
|
||||
argglobal
|
||||
edit ~/42/minishell/src/main.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 = 12 - ((10 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
12
|
||||
47
|
||||
normal! 023|
|
||||
lcd ~/42/minishell
|
||||
tabedit src/user-interaction/ft_interactive_sh.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 * 79 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
||||
tabedit ~/42/minishell/src/ft_cmd.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 * 78 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 79 + 79) / 158)
|
||||
argglobal
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
|
|
@ -99,93 +64,46 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 31 - ((12 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
31
|
||||
normal! 0
|
||||
lcd ~/42/minishell
|
||||
wincmd w
|
||||
argglobal
|
||||
edit ~/42/minishell/src/lib_expansion.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 = 6 - ((5 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
6
|
||||
normal! 0
|
||||
lcd ~/42/minishell
|
||||
wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 78 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 79 + 79) / 158)
|
||||
tabedit ~/42/minishell/src/builtin.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 * 78 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 79 + 79) / 158)
|
||||
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 = 20 - ((19 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
20
|
||||
normal! 032|
|
||||
lcd ~/42/minishell
|
||||
wincmd w
|
||||
argglobal
|
||||
edit ~/42/minishell/src/builtin_exit.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 = 8 - ((7 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
8
|
||||
normal! 014|
|
||||
lcd ~/42/minishell
|
||||
normal! 015|
|
||||
wincmd w
|
||||
argglobal
|
||||
edit src/user-interaction/ft_clear_line.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 = 1 - ((0 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
1
|
||||
normal! 0
|
||||
wincmd w
|
||||
2wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 78 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 79 + 79) / 158)
|
||||
tabedit ~/42/minishell/src/lib_env.c
|
||||
exe 'vert 1resize ' . ((&columns * 79 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
||||
tabedit src/user-interaction/ft_word_right.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 * 79 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
||||
argglobal
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
|
|
@ -196,20 +114,40 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 4 - ((3 * winheight(0) + 19) / 38)
|
||||
let s:l = 5 - ((4 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
4
|
||||
normal! 0
|
||||
lcd ~/42/minishell
|
||||
tabnext 3
|
||||
5
|
||||
normal! 013|
|
||||
wincmd w
|
||||
argglobal
|
||||
edit src/user-interaction/ft_cursor_right.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 = 18 - ((17 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
18
|
||||
normal! 013|
|
||||
wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 79 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
||||
tabnext 2
|
||||
set stal=1
|
||||
if exists('s:wipebuf')
|
||||
silent exe 'bwipe ' . s:wipebuf
|
||||
endif
|
||||
unlet! s:wipebuf
|
||||
set winheight=1 winwidth=20 shortmess=filnxtToOc
|
||||
set winheight=1 winwidth=20 shortmess=filnxtToO
|
||||
let s:sx = expand("<sfile>:p:r")."x.vim"
|
||||
if file_readable(s:sx)
|
||||
exe "source " . fnameescape(s:sx)
|
||||
|
|
|
|||
|
|
@ -5,29 +5,82 @@
|
|||
# include <dirent.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/types.h>
|
||||
# define SHELL_PROMPT "$> "
|
||||
# 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_DEL "\x7f"
|
||||
|
||||
typedef struct s_builtin
|
||||
typedef struct s_stof
|
||||
{
|
||||
char *name;
|
||||
int (*f)();
|
||||
} t_builtin;
|
||||
} t_stof;
|
||||
|
||||
extern t_builtin g_builtin[];
|
||||
typedef struct s_data
|
||||
{
|
||||
char **env;
|
||||
t_dlist *history;
|
||||
t_dlist *input_mem;
|
||||
} t_data;
|
||||
|
||||
int ft_cmd_process(char *cmd);
|
||||
extern t_stof g_builtins[];
|
||||
extern t_stof g_keys[];
|
||||
|
||||
typedef int key_press(t_data *data, t_dlist **input_chain, char *buf);
|
||||
|
||||
int ft_tc_init(t_data *data);
|
||||
int ft_interactive_sh(t_data *data);
|
||||
int ft_input_is_escaped(t_dlist *input_chain);
|
||||
int ft_history_add(t_data *data, t_dlist *input_chain);
|
||||
|
||||
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;
|
||||
|
||||
int ft_cmd_process(char **argv, char ***env_p);
|
||||
int ft_cmd_exec(char *execpath, char **argv, char ***env_p);
|
||||
char **ft_cmd_getav(char *cmd);
|
||||
|
||||
int ft_builtin(char **av, char ***env);
|
||||
int builtin_echo(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_setenv(char **av, char ***env);
|
||||
int builtin_unsetenv(char **av, char ***env);
|
||||
int builtin_env(char **av, char ***env);
|
||||
|
||||
void ft_expand_vars(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);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 4e9b9eba0b3c38bba9543590c081c7fd33eeb2f5
|
||||
Subproject commit 87f043154c8e46ae7d0df30ec25ee420ce1b8099
|
||||
BIN
42sh/pdf/21sh.fr.pdf
Normal file
BIN
42sh/pdf/21sh.fr.pdf
Normal file
Binary file not shown.
BIN
42sh/pdf/42sh.pdf
Normal file
BIN
42sh/pdf/42sh.pdf
Normal file
Binary file not shown.
BIN
42sh/pdf/fdf.fr.pdf
Normal file
BIN
42sh/pdf/fdf.fr.pdf
Normal file
Binary file not shown.
3
42sh/script.sh
Normal file
3
42sh/script.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
while [ 1 ]
|
||||
sleep
|
||||
done
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#include "minishell.h"
|
||||
|
||||
t_builtin g_builtin[] = {
|
||||
{"echo", &builtin_echo},
|
||||
{"cd", &builtin_cd},
|
||||
{"setenv", &builtin_setenv},
|
||||
{"unsetenv", &builtin_unsetenv},
|
||||
{"env", &builtin_env},
|
||||
{"exit", &builtin_exit},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
int ft_builtin(char **av, char ***env_p)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (g_builtin[i].name)
|
||||
{
|
||||
if (ft_strcmp(g_builtin[i].name, *av) == 0)
|
||||
{
|
||||
(g_builtin[i].f)(av, env_p);
|
||||
return (1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
36
42sh/src/builtin/builtin.c
Normal file
36
42sh/src/builtin/builtin.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#include "minishell.h"
|
||||
|
||||
t_stof g_builtin[] = {
|
||||
{"echo", &builtin_echo},
|
||||
{"cd", &builtin_cd},
|
||||
{"setenv", &builtin_setenv},
|
||||
{"unsetenv", &builtin_unsetenv},
|
||||
{"env", &builtin_env},
|
||||
{"exit", &builtin_exit},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
int ft_builtin(char **av, char ***env_p)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
char *exitval[2];
|
||||
char **env;
|
||||
|
||||
i = 0;
|
||||
env = *env_p;
|
||||
exitval[0] = ft_strdup("?");
|
||||
while (g_builtin[i].name)
|
||||
{
|
||||
if (ft_strcmp(g_builtin[i].name, *av) == 0)
|
||||
{
|
||||
ret = (g_builtin[i].f)(av, env_p);
|
||||
exitval[1] = ft_strdup(ft_itoa(ret));
|
||||
builtin_setenv(exitval, &env);
|
||||
*env_p = env;
|
||||
return (1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
78
42sh/src/builtin/builtin_cd.c
Normal file
78
42sh/src/builtin/builtin_cd.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#include "minishell.h"
|
||||
#define CDOPT_L 0b001
|
||||
#define CDOPT_P 0b010
|
||||
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
||||
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
||||
#define CDERR_1 "cd: string not in pwd: %s\n"
|
||||
#define CDERR_2 "cd: no such file or directory: %s\n"
|
||||
|
||||
int builtin_cd(char **av, char ***env_p)
|
||||
{
|
||||
int i;
|
||||
int opts;
|
||||
char *target;
|
||||
char *oldpwd[2];
|
||||
char *pwd[2];
|
||||
|
||||
opts = 0;
|
||||
i = builtin_cd_opts(av, &opts);
|
||||
target = builtin_cd_special(av + i, *env_p);
|
||||
oldpwd[0] = ft_strdup("OLDPWD");
|
||||
oldpwd[1] = getcwd(NULL, 0);
|
||||
if (chdir(target))
|
||||
{
|
||||
ft_printf(CDERR_2, target);
|
||||
return (1);
|
||||
}
|
||||
else if (target != av[i])
|
||||
ft_printf("%s\n", target);
|
||||
pwd[0] = ft_strdup("PWD");
|
||||
pwd[1] = getcwd(NULL, 0);
|
||||
builtin_setenv(pwd, env_p);
|
||||
builtin_setenv(oldpwd, env_p);
|
||||
/* { */
|
||||
/* printf(CDERR_1, av[-i]); */
|
||||
/* return (1) */
|
||||
/* } */
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *builtin_cd_special(char **av, char **env)
|
||||
{
|
||||
char *target;
|
||||
|
||||
if (!*av)
|
||||
target = ft_env_getval(env, "HOME");
|
||||
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);
|
||||
}
|
||||
23
42sh/src/builtin/builtin_env.c
Normal file
23
42sh/src/builtin/builtin_env.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int builtin_env(char **av, char ***env_p)
|
||||
{
|
||||
int i;
|
||||
char **env;
|
||||
|
||||
i = 1;
|
||||
env = NULL;
|
||||
if (!av[1])
|
||||
ft_sstrprint(*env_p, '\n');
|
||||
else
|
||||
{
|
||||
while (av[i] && ft_strchr(av[i], '='))
|
||||
{
|
||||
env = ft_sstradd(env, av[i]);
|
||||
i++;
|
||||
}
|
||||
if (av[i])
|
||||
ft_cmd_process(av + i, env_p);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -15,7 +15,6 @@ int builtin_setenv(char **av, char ***env_p)
|
|||
str = ft_str3join(av[0], "=", av[1]);
|
||||
while (*env)
|
||||
{
|
||||
/* ft_printf("%s\n", env[i]); */
|
||||
if (ft_strcmp(*env, av[0]) == '=')
|
||||
{
|
||||
*env = str;
|
||||
25
42sh/src/builtin/builtin_unsetenv.c
Normal file
25
42sh/src/builtin/builtin_unsetenv.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int builtin_unsetenv(char **av, char ***env_p)
|
||||
{
|
||||
char **env;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
env = *env_p;
|
||||
/* ft_printf("builtin: %s\n", av[0]); */
|
||||
i = 1;
|
||||
while (av[i])
|
||||
{
|
||||
j = 0;
|
||||
while (env[j])
|
||||
{
|
||||
if (ft_strcmp(env[j], av[i]) == '=')
|
||||
ft_sstrdel(env, j);
|
||||
else
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int builtin_cd(char **av, char ***env)
|
||||
{
|
||||
(void)env;
|
||||
ft_printf("builtin: %s\n", av[0]);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int builtin_env(char **av, char ***env_p)
|
||||
{
|
||||
(void)env_p;
|
||||
ft_printf("builtin: %s\n", av[0]);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int builtin_unsetenv(char **av, char ***env)
|
||||
{
|
||||
(void)env;
|
||||
ft_printf("builtin: %s\n", av[0]);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#include "minishell.h"
|
||||
|
||||
void ft_expand_vars(char **av, char **env)
|
||||
{
|
||||
while (*av)
|
||||
{
|
||||
if (**av == '$')
|
||||
*av = ft_env_getval(env, *av + 1);
|
||||
av++;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *line;
|
||||
|
||||
while (1)
|
||||
{
|
||||
ft_putstr(SHELL_PROMPT);
|
||||
if (get_next_line(0, &line) == -1)
|
||||
return (1);
|
||||
ft_cmd_process(line);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
char *ft_env_getval(char **env, char *key)
|
||||
{
|
||||
if (!env)
|
||||
return (NULL);
|
||||
while (*env)
|
||||
{
|
||||
/* ft_printf("%s\n", env[i]); */
|
||||
16
42sh/src/main/lib_expansion.c
Normal file
16
42sh/src/main/lib_expansion.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include "minishell.h"
|
||||
|
||||
void ft_expand_dollar(char **av, char **env)
|
||||
{
|
||||
char *dollar;
|
||||
|
||||
while (*av)
|
||||
{
|
||||
if ((dollar = ft_strchr(*av, '$')))
|
||||
{
|
||||
*dollar = '\0';
|
||||
*av = ft_strjoin(*av, ft_env_getval(env, dollar + 1));
|
||||
}
|
||||
av++;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ char *ft_path_findexec(char **path, char *execname)
|
|||
struct dirent *dirent;
|
||||
|
||||
i = -1;
|
||||
while (path[++i])
|
||||
while (path && path[++i])
|
||||
{
|
||||
if (!(dir = opendir(path[i])))
|
||||
continue ;
|
||||
21
42sh/src/main/lib_tc.c
Normal file
21
42sh/src/main/lib_tc.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#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);
|
||||
}
|
||||
24
42sh/src/main/main.c
Normal file
24
42sh/src/main/main.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "minishell.h"
|
||||
extern char **environ;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
t_data data;
|
||||
|
||||
data.env = ft_sstrdup(environ);
|
||||
data.history = ft_dlst_new(NULL, 0);
|
||||
ft_tc_init(&data);
|
||||
while (1)
|
||||
{
|
||||
ft_putstr(SHELL_PROMPT);
|
||||
if (ft_interactive_sh(&data))
|
||||
return (1);
|
||||
ft_printf("got string:'%s'\n", data.history->prev->content);
|
||||
/* return (0); */
|
||||
/* argv = ft_cmd_getav(input); */
|
||||
/* if (argv && argv[0]) */
|
||||
/* ft_cmd_process(argv, &data.env); */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
9
42sh/src/user-interaction/ft_clear_line.c
Normal file
9
42sh/src/user-interaction/ft_clear_line.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_clear_line(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
ft_line_end(data, input_chain, buf);
|
||||
while (ft_key_del(data, input_chain, buf))
|
||||
;
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -1,25 +1,20 @@
|
|||
#include "minishell.h"
|
||||
extern char **environ;
|
||||
|
||||
int ft_cmd_process(char *cmd)
|
||||
int ft_cmd_process(char **argv, char ***env_p)
|
||||
{
|
||||
char **path;
|
||||
char *execpath;
|
||||
char **argv;
|
||||
|
||||
/* path = NULL; */
|
||||
environ = ft_sstrdup(environ);
|
||||
path = ft_strsplit(ft_env_getval(environ, "PATH"), ':');
|
||||
argv = ft_cmd_getav(cmd);
|
||||
ft_expand_vars(argv, environ);
|
||||
if (ft_builtin(argv, &environ))
|
||||
path = ft_strsplit(ft_env_getval(*env_p, "PATH"), ':');
|
||||
ft_expand_dollar(argv, *env_p);
|
||||
if (ft_builtin(argv, env_p))
|
||||
return (0);
|
||||
else if (ft_strchr(argv[0], '/'))
|
||||
execpath = cmd;
|
||||
execpath = argv[0];
|
||||
else if (!(execpath = ft_path_findexec(path, argv[0])))
|
||||
return (-1);
|
||||
ft_printf("%s @ %s\n", argv[0], execpath);
|
||||
return (ft_cmd_exec(execpath, argv, &environ));
|
||||
return (ft_cmd_exec(execpath, argv, env_p));
|
||||
}
|
||||
|
||||
int ft_cmd_exec(char *execpath, char **argv, char ***env_p)
|
||||
19
42sh/src/user-interaction/ft_cursor_left.c
Normal file
19
42sh/src/user-interaction/ft_cursor_left.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_cursor_left(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
char *res;
|
||||
|
||||
res = NULL;
|
||||
(void)buf;
|
||||
(void)data;
|
||||
if (*(char*)(*input_chain)->content == '\n')
|
||||
return (0);
|
||||
if (*(char*)(*input_chain)->content == '\0')
|
||||
return (0);
|
||||
*input_chain = (*input_chain)->prev;
|
||||
if ((res = tgetstr("le", NULL)) == NULL)
|
||||
return (-1);
|
||||
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
|
||||
return (1);
|
||||
}
|
||||
19
42sh/src/user-interaction/ft_cursor_right.c
Normal file
19
42sh/src/user-interaction/ft_cursor_right.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_cursor_right(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
char *res;
|
||||
|
||||
res = NULL;
|
||||
(void)buf;
|
||||
(void)data;
|
||||
if (*(char*)(*input_chain)->content == '\n')
|
||||
return (0);
|
||||
if (!(*input_chain)->next)
|
||||
return (0);
|
||||
*input_chain = (*input_chain)->next;
|
||||
if ((res = tgetstr("nd", NULL)) == NULL)
|
||||
return (-1);
|
||||
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
|
||||
return (1);
|
||||
}
|
||||
21
42sh/src/user-interaction/ft_history_add.c
Normal file
21
42sh/src/user-interaction/ft_history_add.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_history_add(t_data *data, t_dlist *input_chain)
|
||||
{
|
||||
t_dlist *new;
|
||||
char *str;
|
||||
|
||||
str = ft_dlsttostr(input_chain);
|
||||
if (data->history)
|
||||
while (data->history->next)
|
||||
data->history = data->history->next;
|
||||
str = ft_strcut(str, "\\\n");
|
||||
if (!data->history->prev || ft_strcmp(str, (char *)data->history->prev->content))
|
||||
{
|
||||
new = ft_dlst_new(str, sizeof(char) * (ft_strlen(str) + 1));
|
||||
ft_dlst_add_before(&data->history, new);
|
||||
data->history = data->history->next;
|
||||
ft_strdel((char **)&data->history->content);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
23
42sh/src/user-interaction/ft_history_down.c
Normal file
23
42sh/src/user-interaction/ft_history_down.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_history_down(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
(void)buf;
|
||||
if (!data->history)
|
||||
return (0);
|
||||
if (!data->history->next)
|
||||
return (0);
|
||||
data->history = data->history->next;
|
||||
str = data->history->content;
|
||||
*input_chain = ft_dlst_last(*input_chain);
|
||||
/* ft_clear_input(input_chain); */
|
||||
i = 0;
|
||||
while (str[i])
|
||||
ft_key_basic(data, input_chain, str + i++);
|
||||
if (!data->history->next)
|
||||
ft_strdel(&str);
|
||||
return (0);
|
||||
}
|
||||
25
42sh/src/user-interaction/ft_history_up.c
Normal file
25
42sh/src/user-interaction/ft_history_up.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_history_up(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
(void)buf;
|
||||
if (!data->history)
|
||||
return (0);
|
||||
if (!data->history->prev)
|
||||
return (0);
|
||||
if (!data->history->next)
|
||||
data->history->content = ft_dlsttostr(*input_chain);
|
||||
data->history = data->history->prev;
|
||||
str = data->history->content;
|
||||
/* *input_chain = ft_dlst_last(*input_chain); */
|
||||
/* ft_clear_input(input_chain); */
|
||||
i = 0;
|
||||
while (str[i])
|
||||
ft_key_basic(data, input_chain, str + i++);
|
||||
if (!data->history->next)
|
||||
ft_strdel(&str);
|
||||
return (0);
|
||||
}
|
||||
9
42sh/src/user-interaction/ft_input_is_escaped.c
Normal file
9
42sh/src/user-interaction/ft_input_is_escaped.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_input_is_escaped(t_dlist *input_chain)
|
||||
{
|
||||
if (*(char *)input_chain->content == '\\')
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
59
42sh/src/user-interaction/ft_interactive_sh.c
Normal file
59
42sh/src/user-interaction/ft_interactive_sh.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include "minishell.h"
|
||||
|
||||
t_stof g_keys[] = {
|
||||
{FT_KEY_C_D, NULL},
|
||||
{FT_KEY_C_K, NULL},
|
||||
{FT_KEY_TAB, NULL},
|
||||
{FT_KEY_C_H, &ft_line_start},
|
||||
{FT_KEY_C_L, &ft_line_end},
|
||||
{FT_KEY_C_U, &ft_clear_line},
|
||||
{FT_KEY_ESC, NULL},
|
||||
|
||||
/* {FT_KEY_UP, &ft_history_up}, */
|
||||
/* {FT_KEY_DOWN, &ft_history_down}, */
|
||||
{FT_KEY_UP, NULL},
|
||||
{FT_KEY_DOWN, NULL},
|
||||
/* {FT_KEY_C_UP, &ft_line_up}, */
|
||||
/* {FT_KEY_C_DOWN, &ft_line_down}, */
|
||||
{FT_KEY_C_UP, NULL},
|
||||
{FT_KEY_C_DOWN, NULL},
|
||||
|
||||
{FT_KEY_RIGHT, &ft_cursor_right},
|
||||
{FT_KEY_LEFT, &ft_cursor_left},
|
||||
{FT_KEY_C_RIGHT, &ft_word_right},
|
||||
{FT_KEY_C_LEFT, &ft_word_left},
|
||||
|
||||
{FT_KEY_ENTER, &ft_key_enter},
|
||||
{FT_KEY_DEL, &ft_key_del},
|
||||
{NULL, &ft_key_basic},
|
||||
};
|
||||
|
||||
int ft_interactive_sh(t_data *data)
|
||||
{
|
||||
char buf[20];
|
||||
t_dlist *input_chain;
|
||||
char null;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
(void)data;
|
||||
null = '\0';
|
||||
input_chain = ft_dlst_new(&null, sizeof(char));
|
||||
while (1)
|
||||
{
|
||||
ft_bzero(buf, 20);
|
||||
ret = read(0, buf, 20);
|
||||
/* ft_printf("read=%i: %#x,%#x,%#x\n", ret, buf[0], buf[1], buf[2]); */
|
||||
/* continue ; */
|
||||
i = 0;
|
||||
while (g_keys[i].name && ft_strequ(buf, g_keys[i].name) == 0)
|
||||
i++;
|
||||
if (!g_keys[i].f)
|
||||
continue ;
|
||||
ret = (*g_keys[i].f)(data, &input_chain, buf);
|
||||
if (ret < 0)
|
||||
return (-1);
|
||||
else if (ret == 2)
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
19
42sh/src/user-interaction/ft_key_basic.c
Normal file
19
42sh/src/user-interaction/ft_key_basic.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_key_basic(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
t_dlist *new;
|
||||
char *res;
|
||||
|
||||
(void)data;
|
||||
new = ft_dlst_new(&buf[0], sizeof(char));
|
||||
ft_dlst_add_after(input_chain, new);
|
||||
if ((res = tgetstr("IC", NULL)) != NULL)
|
||||
{
|
||||
tputs(tgoto(res, 0, 0), 1, &ft_putchar);
|
||||
ft_putchar(buf[0]);
|
||||
return (0);
|
||||
}
|
||||
ft_putchar(buf[0]);
|
||||
return (0);
|
||||
}
|
||||
27
42sh/src/user-interaction/ft_key_del.c
Normal file
27
42sh/src/user-interaction/ft_key_del.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_key_del(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
char *res;
|
||||
|
||||
(void)data;
|
||||
(void)buf;
|
||||
if (!(*input_chain)->prev)
|
||||
return (0);
|
||||
if (*(char*)(*input_chain)->content == '\n')
|
||||
return (0);
|
||||
ft_dlst_delone(input_chain, &ft_lst_cfree);
|
||||
if ((res = tgetstr("le", NULL)) == NULL)
|
||||
{
|
||||
ft_printf("le error\n");
|
||||
return (-1);
|
||||
}
|
||||
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
|
||||
if ((res = tgetstr("DC", NULL)) == NULL)
|
||||
{
|
||||
ft_printf("DC error\n");
|
||||
return (-1);
|
||||
}
|
||||
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
|
||||
return (1);
|
||||
}
|
||||
14
42sh/src/user-interaction/ft_key_enter.c
Normal file
14
42sh/src/user-interaction/ft_key_enter.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_key_enter(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
if (ft_input_is_escaped(*input_chain))
|
||||
{
|
||||
ft_key_basic(data, input_chain, buf);
|
||||
ft_printf("> ");
|
||||
return (0);
|
||||
}
|
||||
ft_putchar('\n');
|
||||
ft_history_add(data, *input_chain);
|
||||
return (2);
|
||||
}
|
||||
12
42sh/src/user-interaction/ft_line_down.c
Normal file
12
42sh/src/user-interaction/ft_line_down.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_line_go_down(t_dlist **input_chain)
|
||||
{
|
||||
char *res;
|
||||
|
||||
(void)input_chain;
|
||||
if ((res = tgetstr("up", NULL)) == NULL)
|
||||
return (-1);
|
||||
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
|
||||
return (0);
|
||||
}
|
||||
8
42sh/src/user-interaction/ft_line_end.c
Normal file
8
42sh/src/user-interaction/ft_line_end.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_line_end(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
while (ft_cursor_right(data, input_chain, buf))
|
||||
;
|
||||
return (0);
|
||||
}
|
||||
8
42sh/src/user-interaction/ft_line_start.c
Normal file
8
42sh/src/user-interaction/ft_line_start.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_line_start(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
while (ft_cursor_left(data, input_chain, buf))
|
||||
;
|
||||
return (0);
|
||||
}
|
||||
12
42sh/src/user-interaction/ft_line_up.c
Normal file
12
42sh/src/user-interaction/ft_line_up.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_line_go_up(t_dlist **input_chain)
|
||||
{
|
||||
char *res;
|
||||
|
||||
(void)input_chain;
|
||||
if ((res = tgetstr("up", NULL)) == NULL)
|
||||
return (-1);
|
||||
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
|
||||
return (0);
|
||||
}
|
||||
17
42sh/src/user-interaction/ft_word_left.c
Normal file
17
42sh/src/user-interaction/ft_word_left.c
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_word_left(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
ft_cursor_left(data, input_chain, buf);
|
||||
while (FT_WS(*(char *)(*input_chain)->content))
|
||||
{
|
||||
if (!ft_cursor_left(data, input_chain, buf))
|
||||
return (0) ;
|
||||
}
|
||||
while (!FT_WS(*(char *)(*input_chain)->content))
|
||||
{
|
||||
if (!ft_cursor_left(data, input_chain, buf))
|
||||
return (0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
18
42sh/src/user-interaction/ft_word_right.c
Normal file
18
42sh/src/user-interaction/ft_word_right.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_word_right(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
ft_cursor_right(data, input_chain, buf);
|
||||
while (!FT_WS(*(char *)(*input_chain)->content))
|
||||
{
|
||||
if (!ft_cursor_right(data, input_chain, buf))
|
||||
return (0);
|
||||
}
|
||||
while (FT_WS(*(char *)(*input_chain)->content))
|
||||
{
|
||||
if (!ft_cursor_right(data, input_chain, buf))
|
||||
return (0) ;
|
||||
}
|
||||
ft_cursor_left(data, input_chain, buf);
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in a new issue