BATCH MODE WIP

This commit is contained in:
whaffman 2025-02-28 17:04:37 +01:00
parent cfcd59acbd
commit 3106486ae0
4 changed files with 272 additions and 20 deletions

3
.gitignore vendored
View File

@ -7,4 +7,5 @@ obj/
.ms_heredoc
pipetester.c
pipetest
*.txt
result.txt
minishell.log

57
export_test.txt Normal file
View File

@ -0,0 +1,57 @@
export | grep "SHLVL"
export | grep "OLDPWD"
export | grep "PWD"
export TEST
export TEST
export TEST=123
export ___TEST=123
export --TEST=123
export ""=""
export ''=''
export "="="="
export '='='='
export TE\\\ST=100
export TE-ST=100
export -TEST=100
export TEST-=100
export _TEST=100
export TEST
export ==========
export 1TEST=
export TEST
export ""=""
export TES=T=""
export TE+S=T=""
export TES\\\\T=123
export TES.T=123
export TES\\\$T=123
export TES\\\\T
export TES.T=123
export TES+T=123
export TES=T=123
export TES}T=123
export TES{T=123
export TES-T=123
export -TEST=123
export _TEST=123
export TES_T=123
export TEST_=123
export TE*ST=123
export TES#T=123
export TES@T=123
export TES!T=123
export TES$?T=123
export =============123
export +++++++=123
export ________=123
export export
export echo
export pwd
export cd
export export
export unset
export sudo
export TES^T=123
export TES!T=123
export TES\~T=123
export TEST+=100

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */
/* Updated: 2025/02/28 15:25:57 by whaffman ######## odam.nl */
/* Updated: 2025/02/28 17:03:02 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -58,39 +58,55 @@ static void main_loop(t_minishell *msh)
free_minishell_line(msh);
}
}
static void main_loop_from_file(t_minishell *msh, char *file_in, char *file_out)
{
int fd_in;
int fd_out;
fd_in = open(file_in, O_RDONLY);
if (fd_in < 0)
{
error_msg("open", file_in);
return ;
}
static int redirect_stdout_stderr(t_minishell *msh, char *file_out)
{
int fd_out;
int fd_log;
fd_out = open(file_out, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd_out < 0)
{
error_msg("open", file_out);
close(fd_in);
return ;
}
dup2(fd_out, STDOUT_FILENO);
return (error_msg("open", "redirect_stdout"), FAILURE);
fd_log = open("minishell.log", O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd_log < 0)
return (error_msg("open", "redirect_stderr"), FAILURE);
if (dup2(fd_out, STDOUT_FILENO) == -1)
return (error_msg("dup2", "redirect_stdout"), FAILURE);
if (dup2(fd_log, STDERR_FILENO) == -1)
return (error_msg("dup2", "redirect_stderr"), FAILURE);
close(fd_out);
close(fd_log);
return (SUCCESS);
}
static int main_loop_from_file(t_minishell *msh,
char *file_in, char *file_out)
{
int fd_in;
int i;
i = 1;
fd_in = open(file_in, O_RDONLY);
if (fd_in < 0)
return (error_msg("open", "main_loop_from_file"), FAILURE);
if (redirect_stdout_stderr(msh, file_out) == FAILURE)
return (FAILURE);
while (TRUE)
{
msh->line = get_next_line(fd_in);
if (msh->line == NULL)
break ;
printf("%d:> %s", i, msh->line);
fprintf(stderr, "%d:> %s", i, msh->line);
msh->lexer = ft_lexer_new(msh);
msh->tokens = ft_parse_input(msh);
msh->commands = parser_get_commands(msh);
simple_builtins(msh);
free_minishell_line(msh);
i++;
}
close(fd_in);
close(STDOUT_FILENO);
return (SUCCESS);
}
int main(int argc, char **argv, char **envp)
@ -104,7 +120,9 @@ int main(int argc, char **argv, char **envp)
msh = init_minishell();
signal_init_minishell();
environment_parse(msh, envp);
// main_loop(msh);
if (argc == 1)
main_loop(msh);
else if (argc == 3)
main_loop_from_file(msh, argv[1], argv[2]);
free_minishell(&msh);
rl_clear_history();

176
test.txt Normal file
View File

@ -0,0 +1,176 @@
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"
echo oui | cat -e
echo oui | echo non | echo something | grep oui
echo oui | echo non | echo something | grep non
echo oui | echo non | echo something | grep something
cd .. | echo "something"
cd .. | echo "something"
cd / | echo "something"
cd .. | pwd
ifconfig | grep ":"
ifconfig | grep nothing
whoami | grep $USER
whoami | grep $USER > tmp/file
whoami | cat -e | cat -e > tmp/file
cat Makefile | grep "FLAGS"
cat Makefile | cat -e | cat -e
cat Makefile | grep "FLAGS" | grep "FLAGS" | cat -e
export TEST=123 | cat -e | cat -e
unset TEST | cat -e
echo test | cat -e | cat -e | cat -e
whereis ls | cat -e | cat -e > test
echo test | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e
ls -la | grep "."
whereis grep > tmp/file
whereis grep > tmp/file
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