tests ok pour modifier fonctionnement de minishell
This commit is contained in:
25
README.md
25
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)
|
||||
|
||||
92
test_rl.c
92
test_rl.c
@@ -1,92 +0,0 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <readline/readline.h>
|
||||
# include <signal.h>
|
||||
//# include <readline/history.h>
|
||||
//# include <fcntl.h>
|
||||
//# include <sys/ioctl.h>
|
||||
//# include <string.h>
|
||||
//# include <errno.h>
|
||||
//# include <sys/wait.h>
|
||||
//# include <sys/stat.h>
|
||||
//# include <sys/types.h>
|
||||
//# include <sys/time.h>
|
||||
//# include <sys/resource.h>
|
||||
//# include <dirent.h>
|
||||
//# include <termios.h>
|
||||
//# include <curses.h>
|
||||
//# include <term.h>
|
||||
|
||||
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);
|
||||
}
|
||||
29
test_rl_base.c
Normal file
29
test_rl_base.c
Normal file
@@ -0,0 +1,29 @@
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <readline/readline.h>
|
||||
|
||||
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);
|
||||
}
|
||||
43
test_rl_modif.c
Normal file
43
test_rl_modif.c
Normal file
@@ -0,0 +1,43 @@
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <readline/readline.h>
|
||||
# include <signal.h>
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user