Merge branch 'willem' into quinten

This commit is contained in:
Quinten Mennen 2025-03-06 16:22:56 +01:00
commit 046e8d320b
12 changed files with 227 additions and 162 deletions

View File

@ -6,13 +6,13 @@
# By: qmennen <qmennen@student.codam.nl> +#+ #
# +#+ #
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
# Updated: 2025/03/04 18:26:26 by whaffman ######## odam.nl #
# Updated: 2025/03/06 15:56:12 by whaffman ######## odam.nl #
# #
# **************************************************************************** #
NAME = minishell
# FLAGS=-DNOCOLORS -DNOBANNER -DNOPROMPT
FLAGS=-DNOBANNER
FLAGS=-DNOCOLORS -DNOBANNER -DNOPROMPT -DSHELL_NAME=\"bash\"
# FLAGS=-DNOBANNER
SRC_PATH = src
INC_PATH = inc

View File

@ -16,6 +16,8 @@ A lot of amazing shell stuff
- `cat $PWD/test` should expand,
- `cd -` : `bash: cd: OLDPWD not set`
- `cd ~` : does not expand ?
- ~ does expand in bash but not in any quotes
- `echo a '' b` = "a b" ipv "a b"
## Tester
- [minishell_tester](https://github.com/LucasKuhn/minishell_tester)
@ -31,6 +33,42 @@ A lot of amazing shell stuff
- [ ] CTRL+\ during `sleep 5` should do nothing, but returns a new prompt
- [ ] echo "hello" > /root/protected.txt gives the error but still prints
- [ ] cat < filenoexit returns `minishell: minishell: unable to write to temp file: No such file or directory` but we're not writin
- [x] Find absolute path for command input ('/', './', 'cmd')
- [x]Add heredoc to tokenizer
- [x] Environment to `t_list`
- [x] Get environment array (export)
- [x] Set environment variable (export)
- [x] Simple builtin export
- [x] builtins
- [x] Preliminary signals
- [x] Define struct for commands, something like (
```c
typedef struct s_command
{
char *command;
char *path;
char **args;
int fd_in;
int fd_out;
} t_command;
```
)
- [x] Make the `executor`, run a command
- [x] Make a parser to create a command list
- [x] Add redirects, appends, pipe etc. File descriptor functions
a command can have multiple redirects but only the last is used for stdout
Redirects take precedence over pipes, but pipes are still created and managed.
should it close the unused pipe-end?
all redirects are opened and closed, but only last fd is used.
multiple HEREDOCs can be nested, only last is used.
- [x] Expand \$ vars & support \$ ~?
* [x] $var
* [x] $?
* [ ] ~
- [x] export without arguments
- [ ] ft_free_arr_safe in environment mess
- [x] builtins not first in pipeline? wtf is happening HAHAHAHAHAH its not using builtin, but core-utils
- CB command to change banner
- __Bonus:__ Command tree for &&, ||, *
## Signals

View File

@ -6,13 +6,17 @@
/* By: marvin <marvin@student.42.fr> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:13 by whaffman #+# #+# */
/* Updated: 2025/03/02 22:12:12 by whaffman ######## odam.nl */
/* Updated: 2025/03/06 15:55:50 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# ifndef SHELL_NAME
# define SHELL_NAME "minishell"
# endif // SHELL_NAME
# include "allowed.h"
# include "libft.h"
# include "typedef.h"

View File

@ -6,12 +6,11 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 17:03:13 by whaffman #+# #+# */
/* Updated: 2025/03/03 21:20:09 by whaffman ######## odam.nl */
/* Updated: 2025/03/06 15:36:30 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
#define SHELL_NAME "minishell"
void error_msg(char *func, char *msg)
{

View File

@ -1,17 +1,36 @@
#!/bin/bash
minishell_output=$(../minishell -c "$1")
minishell_exit_code=$?
compare_shells() {
minishell_output=$(../minishell -c "$1" 2>&1)
minishell_exit_code=$?
bash_output=$(bash -c "$1")
bash_exit_code=$?
bash_output=$(bash -c "$1" 2>&1 | sed 's/ line 1://g')
bash_exit_code=$?
paste <(echo -e "Minishell:\n$minishell_output") <(echo -e "Bash:\n$bash_output") | column -t -s $'\t'
echo "Minishell exit code: $minishell_exit_code"
echo "Bash exit code: $bash_exit_code"
echo -e "\e[33m$1\e[0m"
echo "==================================="
if [ $minishell_exit_code -eq $bash_exit_code ]; then
echo "Exit codes match."
else
echo "Exit codes do not match."
fi
if [ "$minishell_output" != "$bash_output" ]; then
paste <(echo -e "Minishell:\n$minishell_output" | cat -e) <(echo -e "Bash:\n$bash_output" | cat -e) | column -t -s $'\t'
else
echo -e "\e[32mstdout: Ok!\e[0m"
fi
if [ $minishell_exit_code -ne $bash_exit_code ]; then
echo "Minishell exit code: $minishell_exit_code"
echo "Bash exit code: $bash_exit_code"
echo "Exit codes do not match."
else
echo -e "\e[32mexit code: Ok!\e[0m"
fi
}
if [ -z "$1" ]; then
echo "Usage: $0 <file>"
exit 1
fi
while IFS= read -r line; do
compare_shells "$line"
done < "$1"

View File

@ -1,85 +1,6 @@
cd
cd ..
cd .
cd /Users
cd //
cd '//'
cd //////
cd ./././
cd /
cd '/etc'
cd '/var'
cd "$PWD/prompt"
cd "doesntexist"
cd "doesntexist" 2>/dev/null
cd ../../..
cd ..
cd ..
cd ?
cd +
cd _
cd bark bark
cd '/'
cd $PWD/file_tests
cd $OLDPWD/builtins
echo
echo echo
eCho
eChO
eCHO
echo $
echo $ $
ECHO
echo rhobebou
echo stop barking
echo "bonjour"
echo bonjour
echo 'bonjour'
echo -n bonjour
echo -nn bonjour
echo -n -n -n bonjour
echo "-n" bonjour
echo -n"-n" bonjour
echo "-nnnn" bonjour
echo "-nnnn" -n bonjour
echo "-n -n -n"-n bonjour
echo "-n '-n'" bonjour
echo $USER
echo "$USER"
echo "'$USER'"
echo " '$USER' "
echo text"$USER"
echo text"'$USER'" ' $USER '
echo "text" "$USER" "$USER"
echo ' $USER '
echo text "$USER" "$USER"text
echo ''''''''''$USER''''''''''
echo """"""""$USER""""""""
echo $USER'$USER'text oui oui oui oui $USER oui $USER ''
echo $USER '' $USER $USER '' $USER '' $USER -n $USER
echo ' \' ' \'
echo '\" ' " \"\""
echo \\\" \\\" \\\" \\\"\\\"\\\" \\\'\\\'\\\'
echo "$USER""$USER""$USER"
echo text"$USER"test
echo '$USER' "$USER" "text \' text"
echo '$USER'
echo $USER " "
echo "$USER""Users/$USER/file""'$USER'"'$USER'
echo "$USER$USER$USER"
echo '$USER'"$USER"'$USER'
echo '"$USER"''$USER'"""$USER"
echo " $USER "'$PWD'
echo " $USER \$ "'$PWD'
echo $USER=4
echo $USER=thallard
echo $USER
echo $?
echo $PWD/file
echo "$PWD/file"
echo "text" "text$USER" ... "$USER"
echo $PWD
env | grep "_="
env | grep "_="
env | grep "SHLVL"
@ -111,66 +32,7 @@ ls -la > tmp/file
ls -la > tmp/file
unset
export TEST=100
unset doesntexist
unset PWD
unset PWD
unset OLDPWD
unset PATH
unset PATH
unset PATH
unset TES\\\\T
unset TES;T
unset TES.T
unset TES+T
unset TES=T
unset TES}T
unset TES{T
unset TES-T
unset -TEST
unset _TEST
unset TES_T
unset TEST_
unset TE*ST
unset TES#T
unset TES@T
unset TES!T
unset TES$?T
unset ============
unset +++++++
unset ________
unset export
unset echo
unset pwd
unset cd
unset unset
unset sudo
unset TES^T
unset TES!T
unset TES\~T
echo $PWD
echo $PWD|cat -e
echo $PWD hallo | cat -e
echo '$PWD hallo | cat -e'
echo "$PWD hallo | cat -e"
wc < Makefile -l | cat -e > outfile | echo hello | rev > outfile2
< test.txt < Makefile<README.md wc -l|cat -e | rev
< Makefile cat > out | < README.md cat -e
< README.md cat -e | <Makefile cat
< in1 cat -e | < in2 cat
< in1 cat -e > out1 | < in2 cat
env | rev | head -5 | cat -e | rev
< in1 <in2 <in3 < Makefile rev | head -5 | cat -e | rev > out > out2 > out3 >> out4
echo ok"hello"ok1"mfg" == echo ok'hello'ok1'mfg'
echo okhellook1"mfg" == echo okhellook1'mfg'
echo "o""k "hellook1 == echo 'o''k 'hellook1
echo '"***hello***"'
echo "'***hello***'"
echo ok"'hello'"ok1"hello1"ok2
echo "text" "$USER" "$USER"
echo """"""""$USER""""""""
echo "-n -n -n"-n bonjour
echo "'$USER'"
echo "$PWD "a
echo " $PWD"
exit

25
tests/test_cd.txt Normal file
View File

@ -0,0 +1,25 @@
cd ; pwd
cd .. ; pwd
cd . ; pwd
cd /Users ; pwd
cd // ; pwd
cd '//' ; pwd
cd ////// ; pwd
cd ./././ ; pwd
cd / ; pwd
cd '/etc' ; pwd
cd '/var' ; pwd
cd "$PWD/prompt" ; pwd
cd "doesntexist" ; pwd
cd "doesntexist" 2>/dev/null ; pwd
cd ../../.. ; pwd
cd .. ; pwd
cd .. ; pwd
cd ? ; pwd
cd + ; pwd
cd _ ; pwd
cd bark bark ; pwd
cd '/' ; pwd
cd $PWD/file_tests ; pwd
cd $OLDPWD/builtins ; pwd
cd ~ ; pwd

81
tests/test_echo.txt Normal file
View File

@ -0,0 +1,81 @@
echo
echo echo
eCho
eChO
eCHO
echo $
echo $ $
ECHO
echo rhobebou
echo stop barking
echo "bonjour"
echo bonjour
echo 'bonjour'
echo -n bonjour
echo -nn bonjour
echo -n -n -n bonjour
echo "-n" bonjour
echo -n"-n" bonjour
echo "-nnnn" bonjour
echo "-nnnn" -n bonjour
echo "-n -n -n"-n bonjour
echo "-n '-n'" bonjour
echo $USER
echo "$USER"
echo "'$USER'"
echo " '$USER' "
echo text"$USER"
echo text"'$USER'" ' $USER '
echo "text" "$USER" "$USER"
echo ' $USER '
echo text "$USER" "$USER"text
echo ''''''''''$USER''''''''''
echo """"""""$USER""""""""
echo $USER'$USER'text oui oui oui oui $USER oui $USER ''
echo $USER '' $USER $USER '' $USER '' $USER -n $USER
echo ' \' ' \'
echo '\" ' " \"\""
echo \\\" \\\" \\\" \\\"\\\"\\\" \\\'\\\'\\\'
echo "$USER""$USER""$USER"
echo text"$USER"test
echo '$USER' "$USER" "text \' text"
echo '$USER'
echo $USER " "
echo "$USER""Users/$USER/file""'$USER'"'$USER'
echo "$USER$USER$USER"
echo '$USER'"$USER"'$USER'
echo '"$USER"''$USER'"""$USER"
echo " $USER "'$PWD'
echo " $USER \$ "'$PWD'
echo $USER=4
echo $USER=thallard
echo $USER
echo $?
echo $PWD/file
echo "$PWD/file"
echo "text" "text$USER" ... "$USER"
echo $PWD
echo $PWD|cat -e
echo $PWD hallo | cat -e
echo '$PWD hallo | cat -e'
echo "$PWD hallo | cat -e"
wc < Makefile -l | cat -e > outfile | echo hello | rev > outfile2
< test.txt < Makefile<README.md wc -l|cat -e | rev
< Makefile cat > out | < README.md cat -e
< README.md cat -e | <Makefile cat
< in1 cat -e | < in2 cat
< in1 cat -e > out1 | < in2 cat
env | rev | head -5 | cat -e | rev
< in1 <in2 <in3 < Makefile rev | head -5 | cat -e | rev > out > out2 > out3 >> out4
echo ok"hello"ok1"mfg" == echo ok'hello'ok1'mfg'
echo okhellook1"mfg" == echo okhellook1'mfg'
echo "o""k "hellook1 == echo 'o''k 'hellook1
echo '"***hello***"'
echo "'***hello***'"
echo ok"'hello'"ok1"hello1"ok2
echo "text" "$USER" "$USER"
echo """"""""$USER""""""""
echo "-n -n -n"-n bonjour
echo "'$USER'"
echo "$PWD "a
echo " $PWD"

3
tests/test_env.txt Normal file
View File

@ -0,0 +1,3 @@
env | grep "_="
env | grep "_="
env | grep "SHLVL"

View File

@ -1,2 +0,0 @@
echo "yeah"
exit

36
tests/test_unset.txt Normal file
View File

@ -0,0 +1,36 @@
unset doesntexist
unset PWD
unset PWD
unset OLDPWD
unset PATH
unset PATH
unset PATH
unset TES\\\\T
unset TES;T
unset TES.T
unset TES+T
unset TES=T
unset TES}T
unset TES{T
unset TES-T
unset -TEST
unset _TEST
unset TES_T
unset TEST_
unset TE*ST
unset TES#T
unset TES@T
unset TES!T
unset TES$?T
unset ============
unset +++++++
unset ________
unset export
unset echo
unset pwd
unset cd
unset unset
unset sudo
unset TES^T
unset TES!T
unset TES\~T