modifs en cours dans readme

This commit is contained in:
hugogogo
2021-12-15 13:45:16 +01:00
parent 48a3abac15
commit ef490c011e
2 changed files with 32 additions and 227 deletions

257
README.md
View File

@@ -1,224 +1,3 @@
## ENVP vs ENVIRON
- main.c
- free.c
- init.c
- minishell_structs.h
- export.c
- subshell_exec.c
## TESTS SIGNAUX WITH HERE-DOCS :
**bash**
1. dans l'exemple ci-dessous j'ecris ^D a l'emplacement où je le tape, mais en vrai il n'apparait pas dans bash
et j'ai mis a gauche le compte des lignes de heredocs cumulés depuis le debut du process
```text
[zsh]$ bash
[bash]$ echo << EOF
1 > ^D bash: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
2 > ^D bash: warning: here-document at line 2 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
3 > ^D bash: warning: here-document at line 3 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
4 >
5 > ^D bash: warning: here-document at line 4 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
6 > ^D bash: warning: here-document at line 6 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
7 > ^D bash: warning: here-document at line 7 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
8 >
9 >
10 > ^D bash: warning: here-document at line 8 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
11 > ^D bash: warning: here-document at line 11 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
12 >
13 >
14 >
15 > ^D bash: warning: here-document at line 12 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
16 >
17 >
18 >
19 > ^D bash: warning: here-document at line 16 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
20 > ^D bash: warning: here-document at line 20 delimited by end-of-file (wanted `EOF')
[bash]$ echo << EOF
21 > EOF
[bash]$ echo << EOF
22 > ^D bash: warning: here-document at line 23 delimited by end-of-file (wanted `EOF')
[bash]$
```
- le texte de warning ne decrit pas la ligne du heredoc au niveau de laquelle ^D a ete pressé
- il decrit la premiere ligne de chaque heredoc (donc peut importe qu'on ai fait un heredoc de 1 ligne ou de 25 lignes, il donne le numero de la premiere), plus le nombre total de lignes de tous les heredocs depuis le debut du process (j'ai l'impression)
- et quand il rencontre un DELIMITER ca compte pour deux lignes (DELIMITER + '\n' je pense)
2. Ctrl-C quite le mode heredoc a n'importe quel moment, Ctrl-D quite le mode heredoc avec un message, uniquement si le curseur est vide
```text
[bash]$ cat << EOF
> ^C
[bash]$ cat << EOF
> sdfdffs^C
[bash]$ cat << EOF
> ^D bash: warning: here-document at line 3 delimited by end-of-file (wanted `EOF')
[bash]$ cat << EOF
> blablabla^Dblabla^D^D^Dblabla ^D blabla
> ^D bash: warning: here-document at line 5 delimited by end-of-file (wanted `EOF')
[bash]$ cat << EOF
```
3. heredoc avec un echo interrompu par un Ctrl-D saute un ligne avant le nouveau prompt, mais pas heredoc avec un cat :
```text
[bash]$ echo << EOF
> ^C
[bash]$ echo << EOF
> ^D bash: warning: here-document at line 2 delimited by end-of-file (wanted `EOF')
[bash]$ cat << EOF
> ^C
[bash]$ cat << EOF
> ^D bash: warning: here-document at line 4 delimited by end-of-file (wanted `EOF')
[bash]$
```
4. avec une redirection dans un fichier, le heredoc ecrit dans le fichier a la reception du DELIMITER ou bien d'un Ctrl-D, mais pas d'un Ctrl-C :
- avec Ctrl-D :
```text
[bash]$ cat << EOF > file.txt
> hello
> test
> ^D bash: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
[bash]$ cat file.txt
hello
test
```
- avec Ctrl-C
```text
[bash]$ cat << EOF > file.txt
> bonjour
> heredoc a l'appareil
> ^C
[bash]$ cat file.txt
hello
test
```
5. chaque nouvelle ligne doit afficher :
- non pas les characters "> "
- mais le contenu de la variable PS2 (qui par defaut est la chaine de characater "> ")
- (au passage, les characaters "$ " affichés a la fin de chaque prompt devraient etre ceux de la variable PS1)
- [infos ici](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_03)
6. un heredoc interrompu par un Ctrl-D n'arrete pas la pipeline, mais un Ctrl-C si :
```text
[bash]$ echo << EOF | wc
> ^D bash: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
1 0 1
[bash]$ echo << EOF | wc
> ^C
[bash]$
```
7. [force readline return without pressing ctrl-c](https://stackoverflow.com/questions/53165704/readline-c-force-return-of-certain-text-in-readline)
## schema d'execution :
```text
________________________________________________
|LOOP: shell_loop() |
| ______________________________________________ |
||mode interactif ||
|| *signal(SIGINT, handler)* ||
|| readline return line_input ||
||______________________________________________||
| ______________________________________________ |
||mode execution ||
|| *signal(SIGINT, ignore)* ||
|| ____________________________________________ ||
||| lexing |||
|||____________________________________________|||
|| ____________________________________________ ||
||| parsing |||
|||____________________________________________|||
|| ____________________________________________ ||
||| execution |||
|||____________________________________________|||
||______________________________________________||
|________________________________________________|
```
## 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)
- [what is a tty](https://www.howtogeek.com/428174/what-is-a-tty-on-linux-and-how-to-use-the-tty-command/)
- [really handling process](https://stackoverflow.com/questions/47489128/handling-signals-sigstp-sigcont-sigint-with-child-process)
- [signal in a child process](https://stackoverflow.com/questions/55190460/using-signals-in-a-child-process)
- [send signal to process and childs](https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script)
- commande utile pour tester les process parents et enfants : while true ; do ps -o pid,pgid,cmd -C bash ; sleep 0.1 ; echo "\n" ; done
- [exit code status](https://tldp.org/LDP/abs/html/exitcodes.html)
- [`char **s` vs `char *s[]`](https://stackoverflow.com/questions/46830654/what-is-the-difference-between-extern-char-environ-and-extern-char-environ)
- [extern and global](https://stackoverflow.com/questions/2652545/extern-and-global-in-c)
- [on which stream deos bash redirect its prompt](https://unix.stackexchange.com/questions/20826/which-stream-does-bash-write-its-prompt-to)
- [fd redirections &](https://putaindecode.io/articles/maitriser-les-redirections-shell)
- [fd redirections &-](https://wiki.bash-hackers.org/howto/redirection_tutorial)
- [redirect prompt output](https://stackoverflow.com/questions/2559076/how-do-i-redirect-output-to-a-variable-in-shell)
- [read, pipes, process substitution](https://stackoverflow.com/questions/15184358/how-to-avoid-bash-command-substitution-to-remove-the-newline-character)
- [process substitution](https://www.linuxjournal.com/content/shell-process-redirection)
- [read, IFS](https://unix.stackexchange.com/questions/164508/why-do-newline-characters-get-lost-when-using-command-substitution)
- [process substitution](https://www.gnu.org/software/bash/manual/bash.html#Process-Substitution)
- [send one command to two pipes](https://stackoverflow.com/questions/13107783/pipe-output-to-two-different-commands)
- [send two commands to one pipe](https://askubuntu.com/questions/133386/how-to-merge-and-pipe-results-from-two-different-commands-to-single-command)
- ["\[" vs "\[\[" in bash](https://stackoverflow.com/questions/13542832/difference-between-single-and-double-square-brackets-in-bash)
- [redirections in bash](https://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean)
- [bash variable of variable](https://stackoverflow.com/questions/10757380/bash-variable-variables)
```text
| 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 : ## sommaire :
--- ---
- [1. todo list :](#markdown-header-1-todo-list) - [1. todo list :](#markdown-header-1-todo-list)
@@ -241,9 +20,9 @@ prompt> blabla |-----------------|----------------|----------------|
- **global features :** - **global features :**
- `prompt` *show a prompt* - `prompt` *show a prompt*
- `history` **? the command history ?** - `history` *use history with arrows*
- `binaries` *fetch and launch the right executable* - `binaries` *fetch and launch the right executable*
- `'` `"` `;` `\` **? don't interpret special characters and unclosed quotes ?** - `'` `"` `;` `\` *don't interpret special characters and unclosed quotes*
- **pipes :** [video vulgarisation](https://www.youtube.com/watch?v=bKzonnwoR2I) - **pipes :** [video vulgarisation](https://www.youtube.com/watch?v=bKzonnwoR2I)
- `|` *pipes* - `|` *pipes*
- **expensions :** - **expensions :**
@@ -276,8 +55,8 @@ prompt> blabla |-----------------|----------------|----------------|
- `termcap` [man](https://www.gnu.org/software/termutils/manual/termcap-1.3/html_chapter/termcap_toc.html) - `termcap` [man](https://www.gnu.org/software/termutils/manual/termcap-1.3/html_chapter/termcap_toc.html)
- `readline` [man](https://tiswww.case.edu/php/chet/readline/rltop.html) / [second source](https://tiswww.case.edu/php/chet/readline/README) - `readline` [man](https://tiswww.case.edu/php/chet/readline/rltop.html) / [second source](https://tiswww.case.edu/php/chet/readline/README)
*[\go to sommaire](#markdown-header-sommaire)*
*[\go to sommaire](#markdown-header-sommaire)*
## 2. external functions : ## 2. external functions :
--- ---
(extracts of manuals) (extracts of manuals)
@@ -349,9 +128,8 @@ There are three functions to use to get the value of a capability :
- **tcgetattr** : `int tcgetattr(int fildes, struct termios *termptr);` Gets a termios structure, which contains control information for a terminal associated with fildes. It stores that information in a memory location that termptr points to. The contents of a termios structure are described in tcsetattr() - **tcgetattr** : `int tcgetattr(int fildes, struct termios *termptr);` Gets a termios structure, which contains control information for a terminal associated with fildes. It stores that information in a memory location that termptr points to. The contents of a termios structure are described in tcsetattr()
*[\go to sommaire](#markdown-header-sommaire)*
## 3. parsing : ## 3. parsing :
*[\go to sommaire](#markdown-header-sommaire)*
--- ---
### 3.1 methode arbre binaire : ### 3.1 methode arbre binaire :
@@ -781,3 +559,30 @@ Normal si le comportement attendu n'est pas correct (en l'absence de PATH et tou
*[\go to sommaire](#markdown-header-sommaire)* *[\go to sommaire](#markdown-header-sommaire)*
## ressources :
- [send EOF to 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)
- [what is a tty](https://www.howtogeek.com/428174/what-is-a-tty-on-linux-and-how-to-use-the-tty-command/)
- [signal in a child process](https://stackoverflow.com/questions/55190460/using-signals-in-a-child-process)
- [send signal to process and childs](https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script)
- commande utile pour tester les process parents et enfants : while true ; do ps -o pid,pgid,cmd -C bash ; sleep 0.1 ; echo "\n" ; done
- [exit code status](https://tldp.org/LDP/abs/html/exitcodes.html)
- [`char **s` vs `char *s[]`](https://stackoverflow.com/questions/46830654/what-is-the-difference-between-extern-char-environ-and-extern-char-environ)
- [extern and global](https://stackoverflow.com/questions/2652545/extern-and-global-in-c)
### for bash script :
- [on which stream deos bash redirect its prompt](https://unix.stackexchange.com/questions/20826/which-stream-does-bash-write-its-prompt-to)
- [fd redirections &](https://putaindecode.io/articles/maitriser-les-redirections-shell)
- [fd redirections &-](https://wiki.bash-hackers.org/howto/redirection_tutorial)
- [redirect prompt output](https://stackoverflow.com/questions/2559076/how-do-i-redirect-output-to-a-variable-in-shell)
- [read, pipes, process substitution](https://stackoverflow.com/questions/15184358/how-to-avoid-bash-command-substitution-to-remove-the-newline-character)
- [process substitution](https://www.linuxjournal.com/content/shell-process-redirection)
- [read, IFS](https://unix.stackexchange.com/questions/164508/why-do-newline-characters-get-lost-when-using-command-substitution)
- [process substitution](https://www.gnu.org/software/bash/manual/bash.html#Process-Substitution)
- [send one command to two pipes](https://stackoverflow.com/questions/13107783/pipe-output-to-two-different-commands)
- [send two commands to one pipe](https://askubuntu.com/questions/133386/how-to-merge-and-pipe-results-from-two-different-commands-to-single-command)
- ["\[" vs "\[\[" in bash](https://stackoverflow.com/questions/13542832/difference-between-single-and-double-square-brackets-in-bash)
- [redirections in bash](https://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean)
- [bash variable of variable](https://stackoverflow.com/questions/10757380/bash-variable-variables)
- [PS1 variable contain prompt](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_03)
- [force readline return without pressing ctrl-c](https://stackoverflow.com/questions/53165704/readline-c-force-return-of-certain-text-in-readline)