last push before starting 42
This commit is contained in:
parent
6359eac19f
commit
94cdecd642
27 changed files with 116 additions and 73 deletions
43
42sh/.tags
43
42sh/.tags
|
|
@ -10,28 +10,31 @@ builtin_exit src/builtin/builtin_exit.c /^int builtin_exit(char **av, char ***e
|
|||
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_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_getav src/main/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_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_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_history_add src/line-editing/ft_history_add.c /^int ft_history_add(t_data *data, t_dlist *input_c/
|
||||
ft_history_down src/line-editing/ft_history_down.c /^int ft_history_down(t_data *data, t_dlist **input/
|
||||
ft_history_up src/line-editing/ft_history_up.c /^int ft_history_up(t_data *data, t_dlist **input_c/
|
||||
ft_input_is_escaped src/line-editing/ft_input_is_escaped.c /^int ft_input_is_escaped(t_dlist *input_chain)$/
|
||||
ft_interactive_sh src/line-editing/ft_interactive_sh.c /^int ft_interactive_sh(t_data *data)$/
|
||||
ft_key_basic src/line-editing/ft_key_basic.c /^int ft_key_basic(t_data *data, t_dlist **input_cha/
|
||||
ft_key_ctrl_d src/line-editing/ft_key_ctrl_d.c /^int ft_key_ctrl_d(t_data *data, t_dlist **input_c/
|
||||
ft_key_del src/line-editing/ft_key_del.c /^int ft_key_del(t_data *data, t_dlist **input_chai/
|
||||
ft_key_enter src/line-editing/ft_key_enter.c /^int ft_key_enter(t_data *data, t_dlist **input_ch/
|
||||
ft_line_end src/line-editing/ft_line_end.c /^int ft_line_end(t_data *data, t_dlist **input_cha/
|
||||
ft_line_go_down src/line-editing/ft_line_down.c /^int ft_line_go_down(t_dlist **input_chain)$/
|
||||
ft_line_go_up src/line-editing/ft_line_up.c /^int ft_line_go_up(t_dlist **input_chain)$/
|
||||
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_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_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/
|
||||
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/
|
||||
sig_handler src/main/sig_handler.c /^void sig_handler(int signo)$/
|
||||
|
|
|
|||
|
|
@ -8,42 +8,30 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
|||
let s:wipebuf = bufnr('%')
|
||||
endif
|
||||
set shortmess=aoO
|
||||
badd +0 includes/minishell.h
|
||||
badd +47 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 +5 src/user-interaction/ft_word_right.c
|
||||
badd +18 src/user-interaction/ft_cursor_right.c
|
||||
badd +7 src/user-interaction/ft_clear_line.c
|
||||
badd +1 src/user-interaction/ft_line_start.c
|
||||
badd +5 src/user-interaction/ft_line_end.c
|
||||
badd +21 src/main/main.c
|
||||
badd +12 src/builtin/builtin_exit.c
|
||||
badd +0 src/user-interaction/ft_cmd.c
|
||||
badd +8 src/line-editing/ft_cmd.c
|
||||
badd +2 src/main/ft_cmd.c
|
||||
badd +13 src/main/sig_handler.c
|
||||
badd +1 src/main/prompt.c
|
||||
badd +3 src/main/ft_prompt.c
|
||||
badd +1 src/line-editing/ft_interactive_sh.c
|
||||
badd +7 src/line-editing/ft_key_ctrl_d.c
|
||||
argglobal
|
||||
silent! argdel *
|
||||
set stal=2
|
||||
edit includes/minishell.h
|
||||
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 = 47 - ((8 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
47
|
||||
normal! 023|
|
||||
tabedit src/user-interaction/ft_interactive_sh.c
|
||||
set splitbelow splitright
|
||||
wincmd _ | wincmd |
|
||||
vsplit
|
||||
1wincmd h
|
||||
|
|
@ -64,15 +52,15 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 8 - ((7 * winheight(0) + 19) / 38)
|
||||
let s:l = 68 - ((22 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
8
|
||||
normal! 015|
|
||||
68
|
||||
normal! 025|
|
||||
wincmd w
|
||||
argglobal
|
||||
edit src/user-interaction/ft_clear_line.c
|
||||
edit src/main/main.c
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
setlocal fmr={{{,}}}
|
||||
|
|
@ -82,17 +70,16 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 1 - ((0 * winheight(0) + 19) / 38)
|
||||
let s:l = 9 - ((8 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
1
|
||||
9
|
||||
normal! 0
|
||||
wincmd w
|
||||
2wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 79 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
||||
tabedit src/user-interaction/ft_word_right.c
|
||||
tabedit src/line-editing/ft_interactive_sh.c
|
||||
set splitbelow splitright
|
||||
wincmd _ | wincmd |
|
||||
vsplit
|
||||
|
|
@ -114,15 +101,15 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 5 - ((4 * winheight(0) + 19) / 38)
|
||||
let s:l = 36 - ((16 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
5
|
||||
normal! 013|
|
||||
36
|
||||
normal! 05|
|
||||
wincmd w
|
||||
argglobal
|
||||
edit src/user-interaction/ft_cursor_right.c
|
||||
edit src/main/sig_handler.c
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
setlocal fmr={{{,}}}
|
||||
|
|
@ -132,13 +119,14 @@ setlocal fml=1
|
|||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let s:l = 18 - ((17 * winheight(0) + 19) / 38)
|
||||
let s:l = 13 - ((12 * winheight(0) + 19) / 38)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
exe s:l
|
||||
normal! zt
|
||||
18
|
||||
normal! 013|
|
||||
13
|
||||
normal! 022|
|
||||
wincmd w
|
||||
2wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 79 + 79) / 158)
|
||||
exe 'vert 2resize ' . ((&columns * 78 + 79) / 158)
|
||||
tabnext 2
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
# include <sys/types.h>
|
||||
# include <curses.h>
|
||||
# include <term.h>
|
||||
# include <signal.h>
|
||||
|
||||
# define SHELL_PROMPT "$> "
|
||||
# define BUFF_SIZE 32
|
||||
# define READ_BUF 32
|
||||
|
|
@ -43,14 +45,21 @@ typedef struct s_data
|
|||
|
||||
extern t_stof g_builtins[];
|
||||
extern t_stof g_keys[];
|
||||
extern pid_t g_pid;
|
||||
extern int g_mode;
|
||||
|
||||
void sig_handler(int signo);
|
||||
#define MODE_INPUT 0b0001
|
||||
#define MODE_EXEC 0b0010
|
||||
|
||||
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_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;
|
||||
|
|
@ -65,6 +74,7 @@ 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_exec(char *execpath, char **argv, char ***env_p);
|
||||
|
|
|
|||
4
42sh/script.sh
Normal file → Executable file
4
42sh/script.sh
Normal file → Executable file
|
|
@ -1,3 +1,3 @@
|
|||
while [ 1 ]
|
||||
sleep
|
||||
while [ 1 ]; do
|
||||
sleep 1
|
||||
done
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ int builtin_exit(char **av, char ***env_p)
|
|||
status = ft_atoi(av[1]);
|
||||
else
|
||||
status = ft_atoi(ft_env_getval(*env_p, "?"));
|
||||
printf("exit status %i", status);
|
||||
exit(status);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#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},
|
||||
|
|
@ -25,6 +24,7 @@ t_stof g_keys[] = {
|
|||
|
||||
{FT_KEY_ENTER, &ft_key_enter},
|
||||
{FT_KEY_DEL, &ft_key_del},
|
||||
{FT_KEY_C_D, &ft_key_ctrl_d},
|
||||
{NULL, &ft_key_basic},
|
||||
};
|
||||
|
||||
10
42sh/src/line-editing/ft_key_ctrl_d.c
Normal file
10
42sh/src/line-editing/ft_key_ctrl_d.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_key_ctrl_d(t_data *data, t_dlist **input_chain, char *buf)
|
||||
{
|
||||
(void)data;
|
||||
(void)input_chain;
|
||||
(void)buf;
|
||||
ft_putendl("exit");
|
||||
exit(0);
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#include "minishell.h"
|
||||
extern pid_t g_pid;
|
||||
|
||||
int ft_cmd_process(char **argv, char ***env_p)
|
||||
{
|
||||
|
|
@ -13,7 +14,7 @@ int ft_cmd_process(char **argv, char ***env_p)
|
|||
execpath = argv[0];
|
||||
else if (!(execpath = ft_path_findexec(path, argv[0])))
|
||||
return (-1);
|
||||
ft_printf("%s @ %s\n", argv[0], execpath);
|
||||
/* ft_printf("%s @ %s\n", argv[0], execpath); */
|
||||
return (ft_cmd_exec(execpath, argv, env_p));
|
||||
}
|
||||
|
||||
|
|
@ -36,6 +37,7 @@ int ft_cmd_exec(char *execpath, char **argv, char ***env_p)
|
|||
}
|
||||
else
|
||||
{
|
||||
g_pid = pid;
|
||||
wait(&status);
|
||||
sstr = ft_sstradd(sstr, "?");
|
||||
sstr = ft_sstradd(sstr, ft_itoa(status));
|
||||
7
42sh/src/main/ft_prompt.c
Normal file
7
42sh/src/main/ft_prompt.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include "minishell.h"
|
||||
|
||||
int ft_prompt(void)
|
||||
{
|
||||
ft_putstr(SHELL_PROMPT);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,23 +1,28 @@
|
|||
#include "minishell.h"
|
||||
extern char **environ;
|
||||
int g_mode;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
t_data data;
|
||||
char **av;
|
||||
|
||||
data.env = ft_sstrdup(environ);
|
||||
data.history = ft_dlst_new(NULL, 0);
|
||||
ft_tc_init(&data);
|
||||
if (signal(SIGINT, sig_handler) == SIG_ERR)
|
||||
ft_printf("\ncan't catch SIGINT\n");
|
||||
while (1)
|
||||
{
|
||||
ft_putstr(SHELL_PROMPT);
|
||||
g_mode = MODE_INPUT;
|
||||
ft_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); */
|
||||
g_mode = MODE_EXEC;
|
||||
/* ft_printf("got string:'%s'\n", data.history->prev->content); */
|
||||
av = ft_cmd_getav(data.history->prev->content);
|
||||
if (av && av[0])
|
||||
ft_cmd_process(av, &data.env);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
19
42sh/src/main/sig_handler.c
Normal file
19
42sh/src/main/sig_handler.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "minishell.h"
|
||||
pid_t g_pid;
|
||||
int g_mode;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
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)
|
||||
kill(g_pid, SIGINT);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue