diff --git a/README.md b/README.md index 27e4f4e..b723992 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,30 @@ ## understanding some things : - [how to send EOF to stdin of a shell process](https://unix.stackexchange.com/questions/493578/how-to-send-d-eot-character-to-stdin-of-a-shell-process) - - [get root access 1](https://vitux.com/how-to-become-root-user-in-ubuntu-command-line-using-su-and-sudo/) - - [get root access using sudo su](https://superuser.com/questions/408990/how-do-i-log-out-of-sudo-su) + - [get root access 1](https://vitux.com/how-to-become-root-user-in-ubuntu-command-line-using-su-and-sudo/) + - [get root access using sudo su](https://superuser.com/questions/408990/how-do-i-log-out-of-sudo-su) - [what is a tty](https://www.howtogeek.com/428174/what-is-a-tty-on-linux-and-how-to-use-the-tty-command/) +``` + | BASH | MINISHELL | + ----------------------------------- + | print | action | print | action | +---------------|-----------------|----------------|----------------| + | SIGINT / ctrl-C | ^C | \n | ^C | exit | + prompt> |-----------------|----------------|----------------| + | EOF / ctrl-D | exit | exit | Ø | \n | +---------------|-----------------|----------------|----------------| + | SIGINT / ctrl-C | bla^C | \n | bla^C | exit | +prompt> blabla |-----------------|----------------|----------------| + | EOF / ctrl-D | Ø | Ø | Ø | Ø | +---------------|-----------------|----------------|----------------| + +-> change signal handler for SIGINT, to print a \n instead of exit +-> change when readline receive an EOF and line is empty, to print exit and exit + -> when readline receive an EOF and line is empty, it return NULL + -> if line isn't empty it does nothing + +``` + ## sommaire : --- - [1. todo list :](#markdown-header-1-todo-list) diff --git a/test_rl.c b/test_rl.c deleted file mode 100644 index d0046c7..0000000 --- a/test_rl.c +++ /dev/null @@ -1,92 +0,0 @@ -# include -# include -# include -# include -# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include - -void handler_sigint(int id) -{ - (void)id; - write(1, "\n", 1); -} - -int main(int argc, char *argv[], char *envp[]) -{ - (void)argc; - (void)argv; - char *line_input; - char *prompt; - -// t_cmd **cmd_arr; -// char **envp; -// char *prompt_base; -// char *prompt; -// t_token *token_list; -// int last_exit_status; -// struct termios ori_termios; -// struct termios interactive_termios; -// int termios_changed; -// struct sigaction ori_signal_behaviour; -// struct sigaction signal_behaviour; - - signal(SIGINT, handler_sigint); - line_input = NULL; - prompt = strdup("\e[0;31mtest>\e[0m "); - while (1) - { - if (line_input) - free(line_input); - line_input = readline(prompt); - if (line_input && *line_input) - { - // A faire aprés être sortie du mode interactif - // - Ignorer tout les signaux - // - Remettre ori_termios -// c->signal_behaviour.sa_handler = SIG_IGN; -// sigaction(SIGINT, &c->signal_behaviour, NULL); -// sigaction(SIGQUIT, &c->signal_behaviour, NULL); -// tcsetattr(STDIN_FILENO, TCSANOW, &c->ori_termios); -// if (!fork()) -// { -// char *arg_test[3]; -// -// arg_test[0] = ft_strdup("sleep"); -// arg_test[1] = ft_strdup("3"); -// arg_test[2] = NULL; -// sigaction(SIGQUIT, &c->ori_signal_behaviour, NULL); -// sigaction(SIGINT, &c->ori_signal_behaviour, NULL); -// execve("/bin/sleep", arg_test, c->envp); -// } -// else -// { -// int wait_test; -// wait(&wait_test); -// c->signal_behaviour.sa_handler = sigint_handler; -// sigaction(SIGINT, &c->signal_behaviour, NULL); -// c->signal_behaviour.sa_handler = SIG_IGN; -// sigaction(SIGQUIT, &c->signal_behaviour, NULL); -// tcsetattr(STDIN_FILENO, TCSANOW, &c->interactive_termios); -// } - - printf("%s\n", line_input); - } - else if (!line_input) - write(1, "\n", 1); - } - - return (0); -} diff --git a/test_rl_base.c b/test_rl_base.c new file mode 100644 index 0000000..02d291f --- /dev/null +++ b/test_rl_base.c @@ -0,0 +1,29 @@ +# include +# include +# include + +int main(int argc, char *argv[], char *envp[]) +{ + (void)argc; + (void)argv; + char *line_input; + char *prompt; + + line_input = NULL; + prompt = strdup("\e[0;31mtest>\e[0m "); + while (1) + { + if (line_input) + free(line_input); + line_input = readline(prompt); + if (line_input && *line_input) + { + write(1, line_input, strlen(line_input)); + write(1, "\n", 1); + } + else if (!line_input) + write(1, "\n", 1); + } + + return (0); +} diff --git a/test_rl_modif.c b/test_rl_modif.c new file mode 100644 index 0000000..097cb04 --- /dev/null +++ b/test_rl_modif.c @@ -0,0 +1,43 @@ +# include +# include +# include +# include + +void handler_sigint(int id) +{ + (void)id; + write(1, "\n", 1); + rl_replace_line("", 1); + rl_on_new_line(); + rl_redisplay(); +} + +int main(int argc, char *argv[], char *envp[]) +{ + (void)argc; + (void)argv; + char *line_input; + char *prompt; + + signal(SIGINT, handler_sigint); + line_input = NULL; + prompt = strdup("\e[0;31mtest>\e[0m "); + while (1) + { + if (line_input) + free(line_input); + line_input = readline(prompt); + if (line_input && *line_input) + { + write(1, line_input, strlen(line_input)); + write(1, "\n", 1); + } + else if (!line_input) + { + write(1, "exit\n", 5); + exit(0); + } + } + + return (0); +}