multitudes / 42-minishell

This project is about creating a simple shell
MIT License
0 stars 0 forks source link

TESTING #192

Closed multitudes closed 3 months ago

multitudes commented 4 months ago

[FIXED] [edit] $? is fixed ~/Desktop is not currently working [edit] fixed!

And this one is not working....

echo a b | awk -v RS=" " '{print}' | sort

awk: The awk command provided uses the -v option to set the record separator (RS) to a space character " ". In awk, records are usually separated by newlines, meaning awk processes input line by line by default. By setting the record separator to a space, you're telling awk to treat each space-separated string as a separate record instead of each line.

The action {print} simply prints each record. Since the record separator is a space, this awk command will print each space-separated string on a new line.

For example, given the input:

echo a b | awk -v RS=" " '{print}' | sort

The command will output:


a
b

I did a test and the execve in this case expects these args

char *argv_awk[] = {"/usr/bin/awk", "-v", "RS= ", "{print}", NULL};

but what he gets in our minishell is

DEBUG src/executer/executer3.c:execute_command:73: command and args: -/usr/bin/awk- --v- -RS=- - -

we split the "RS=" we expand the space to space and somehow we loose the {print}

any idea?

multitudes commented 4 months ago

[FIXED] We need to remove those error messages perhaps so the minishell behaviour will be the same as bash ans zsh!

minishell $ mkdir aa && mkdir aa/b && cd aa/b && rm -r ../../aa && cd ..
[...]
DEBUG src/executer/executer3.c:execute_list:112: ANDTOKEN
DEBUG src/executer/executer.c:execute_ast:82: 
execute ast (node type: 4)
DEBUG src/analyser/analyser.c:which_ast_node:36: which ast node (ast-type before check: 4)
DEBUG src/analyser/analyser.c:analyse_expand:448: ast-node type after check: 5)
DEBUG src/analyser/analyser.c:expand_tokenlist:426: Token expanded - token type: 2 
DEBUG src/analyser/analyser.c:expand_tokenlist:426: Token expanded - token type: 4 
DEBUG src/builtins/builtins.c:execute_cd_builtin:93: cd builtin

minishell: cd: get old cwd: No such file or directory

DEBUG src/builtins/builtins2.c:execute_cd_tokenlist:39: execute_cd_tokenlist with lexeme ..
DEBUG src/builtins/builtins.c:execute_cd_builtin:102: status: 0

minishell: cd: get new cwd: No such file or directory
minishell: cd: update of OLDPWD failed
minishell: cd: update of PWD failed

DEBUG src/loop.c:restore_fds:440: Restored STDIN: 0, STDOUT: 1, STDERR: 2
DEBUG src/executer/executer3.c:execute_list:120: status now 0
multitudes commented 4 months ago

[FIXED] echo $_ prints echo $_ I think the problem is here

DEBUG src/analyser/analyser.c:replace_dollar_vars:258: replace dollar vars in lexeme: $_
DEBUG src/analyser/analyser.c:replace_dollar_vars:289: new lexeme: echo $_

maybe there is an easy fix

multitudes commented 4 months ago

[FIXED] @ProjektPhoenix I am now updating the exit builtin to this: exit -"100" should return 156 the shell takes the value -100 as unsigned int and then it is modulo 256 Now updated as follows if I have a "exit -100" I will have the 3 tokens exit - 100 so I do atoi of 100 and multiply to -1 and cast to unsigned int modulo 256 to get the same result as bash

multitudes commented 4 months ago

[FIXED] @ProjektPhoenix from the google sheet you ask why the test token is a builtin

for some reason it sets token type "BUILTIN" for "test"

It is a bash builtin like

if test -f "filename"; then
    echo "File exists."
else
    echo "File does not exist."
fi
multitudes commented 4 months ago

[FIXED] @ProjektPhoenix this for the https://github.com/LucasKuhn/minishell_tester in the builtins category Screenshot 2024-07-08 at 7 16 33 PM

The only test failing is the

echo "$" 

Interesting also is that

echo "$ $"

prints just one $ Maybe could you check? The problem is in the string tokenizer, I think you miss the DOLLAR token when you tokenize again but we discussed that it would be better to use just one tokenizer and loop on the token to selectively change the types you don't want?

So it is better if I leave it to you :)

The DOLLAR is not allocated in is_complex_dollar_exp or is_simple_dollar_exp for priority reasons...

multitudes commented 3 months ago

[FIXED] @ProjektPhoenix You will be delighted to know that the function new_toknode has been updated to take folldbyspace in the init. t_list *new_toknode(t_tokentype type, const char *lexeme, int *i, bool folldbyspace)

multitudes commented 3 months ago

[FIXED] This is also kinda critical. SEGFAULT! Please look into it when you can @ProjektPhoenix

<*.txt

should give No such file or directory. exit status 1

ProjektPhoenix commented 3 months ago

[FIXED] Update of executer2 seems to have introduced segfaulting (non-fatal) when checking for spaces: ==18483== Invalid read of size 8 ==18483== at 0x40DACF: check_for_spaces (executer2.c:106) ==18483== by 0x40DDCB: get_argv_from_tokenlist (executer2.c:143) ==18483== by 0x40E0C4: execute_command (executer3.c:66) ==18483== by 0x40D7E7: execute_ast (executer.c:108) ==18483== by 0x401E61: loop (loop.c:338) ==18483== by 0x4013B6: main (main.c:29) ==18483== Address 0x0 is not stack'd, malloc'd or (recently) free'd ==18483== ==18483== Process terminating with default action of signal 11 (SIGSEGV) ==18483== Access not within mapped region at address 0x0 ==18483== at 0x40DACF: check_for_spaces (executer2.c:106) ==18483== by 0x40DDCB: get_argv_from_tokenlist (executer2.c:143) ==18483== by 0x40E0C4: execute_command (executer3.c:66) ==18483== by 0x40D7E7: execute_ast (executer.c:108) ==18483== by 0x401E61: loop (loop.c:338) ==18483== by 0x4013B6: main (main.c:29)

ProjektPhoenix commented 3 months ago

[FIXED] And some memory leaks in memory allocation of history file path: ==18483== 14 bytes in 1 blocks are definitely lost in loss record 17 of 93 ==18483== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==18483== by 0x4105F5: ft_strdup (in /home/rpriess/DEVELOPMENT/CORE/minishell.git/minishell) ==18483== by 0x402595: get_history_file_path (history.c:58) ==18483== by 0x40246C: load_history (history.c:28) ==18483== by 0x401DA7: loop (loop.c:322) ==18483== by 0x4013B6: main (main.c:29) ==18483== 14 bytes in 1 blocks are definitely lost in loss record 18 of 93 ==18483== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==18483== by 0x4105F5: ft_strdup (in /home/rpriess/DEVELOPMENT/CORE/minishell.git/minishell) ==18483== by 0x402595: get_history_file_path (history.c:58) ==18483== by 0x402880: add_to_hist_file (history.c:118) ==18483== by 0x402753: handle_history (history.c:94) ==18483== by 0x401E03: loop (loop.c:331) ==18483== by 0x4013B6: main (main.c:29)

ProjektPhoenix commented 3 months ago

[FIXED]

echo $_ prints echo $_ I think the problem is here

DEBUG src/analyser/analyser.c:replace_dollar_vars:258: replace dollar vars in lexeme: $_
DEBUG src/analyser/analyser.c:replace_dollar_vars:289: new lexeme: echo $_

maybe there is an easy fix

The echo $ appears to be working correctly. I think is related to how and what last command is stored in the env "_" variable. I think this should only be updated after the command has been executed (currently echo $ is directly stored as an empty command in the environment and hence the output of "echo $_" is always just a new line. When executing "env" the update of the last command appears to be happening before env is shown, so env apparently behaves different than other commands/builtins and specifically echo. The new function "update_dollar_underscore()" should probably be called before executing the env builtin, and afterwards for all other builtins and commands.

ProjektPhoenix commented 3 months ago

[FIXED]

This is also kinda critical. SEGFAULT! Please look into it when you can @ProjektPhoenix

<*.txt

should give No such file or directory. exit status 1

resolved. I accidentally worked in and pushed to your current branch.

ProjektPhoenix commented 3 months ago

[FIXED]

mkdir aa && mkdir aa/b && cd aa/b && rm -r ../../aa && cd ..

reduced number of messages in cd builtin. However the function resolve_command_path() may not properly resolve some commands. e.g. just the command "ls" is not resolved properly. Not sure where this error comes from.

ProjektPhoenix commented 3 months ago

[FIXED]

echo a b | awk -v RS=" " '{print}' | sort

[edit] $? is fixed ~/Desktop is not currently working

And this one is not working....

echo a b | awk -v RS=" " '{print}' | sort

awk: The awk command provided uses the -v option to set the record separator (RS) to a space character " ". In awk, records are usually separated by newlines, meaning awk processes input line by line by default. By setting the record separator to a space, you're telling awk to treat each space-separated string as a separate record instead of each line.

The action {print} simply prints each record. Since the record separator is a space, this awk command will print each space-separated string on a new line.

For example, given the input:

echo a b | awk -v RS=" " '{print}' | sort

The command will output:


a
b

I did a test and the execve in this case expects these args

char *argv_awk[] = {"/usr/bin/awk", "-v", "RS= ", "{print}", NULL};

but what he gets in our minishell is

DEBUG src/executer/executer3.c:execute_command:73: command and args: -/usr/bin/awk- --v- -RS=- - -

we split the "RS=" we expand the space to space and somehow we loose the {print}

any idea?

[edit] $? is fixed ~/Desktop is not currently working

And this one is not working....

echo a b | awk -v RS=" " '{print}' | sort

awk: The awk command provided uses the -v option to set the record separator (RS) to a space character " ". In awk, records are usually separated by newlines, meaning awk processes input line by line by default. By setting the record separator to a space, you're telling awk to treat each space-separated string as a separate record instead of each line.

The action {print} simply prints each record. Since the record separator is a space, this awk command will print each space-separated string on a new line.

For example, given the input:

echo a b | awk -v RS=" " '{print}' | sort

The command will output:


a
b

I did a test and the execve in this case expects these args

char *argv_awk[] = {"/usr/bin/awk", "-v", "RS= ", "{print}", NULL};

but what he gets in our minishell is

DEBUG src/executer/executer3.c:execute_command:73: command and args: -/usr/bin/awk- --v- -RS=- - -

we split the "RS=" we expand the space to space and somehow we loose the {print}

any idea?

~/Desktop is fixed and pushed on my branch. With regard to the second issue. I do not see {print} being lost...

ProjektPhoenix commented 3 months ago

[DONE]

@ProjektPhoenix from the google sheet you ask why the test token is a builtin

for some reason it sets token type "BUILTIN" for "test"

It is a bash builtin like

if test -f "filename"; then
    echo "File exists."
else
    echo "File does not exist."
fi

I understand that it is a bash builtin but I wonder how we should deal with it. It appears to not be creating any errors apparently, so we might as well leave it as it is.

ProjektPhoenix commented 3 months ago

[DONE] it works but

echo "$$$$$$$$" 

prints just $ which is fine probably since they get expanded! if ppl want the dollars they just do

echo "$$$$$$$$" 

echo "$" echo "$ $"

is resolved. I simply removed the check for simple DOLLAR token type so to not expand in this case. Also replaced the string_tokenizer with the normal tokenizer function.

BUT: I now see that this makes some tests fail, as the tokenizer performs syntax checks that throw an error but would not be relevant for quoted strings, e.g. minishell tester Test 13: echo "> >> < * ? [ ] | ; [ ] || && ( ) & # $ <<"

multitudes commented 3 months ago

[done!] now works

minishell: *LIC: No such file or directory

===============================

@ProjektPhoenix NEW ISSUE WITH SEGFAULT! THis is ok *LIC doesnt exists

<*LIC 

but this SEGFAULTS

<LIC*
DEBUG src/analyser/analyser.c:expand_tokenlist:440: Token to check for expansion - token type: 21, lexeme: <
DEBUG src/analyser/analyser.c:expand_tokenlist:445: Token expanded - token type: 21, lexeme: <
DEBUG src/analyser/analyser.c:expand_tokenlist:440: Token to check for expansion - token type: 24, lexeme: LIC*
DEBUG src/scanner/token_functions.c:return_lexeme_malloc:67: return_lexeme_malloc: LICENSE
DEBUG src/scanner/token_functions.c:new_toknode:87: token created type 0 -LICENSE-
DEBUG src/analyser/analyser.c:expand_tokenlist:445: Token expanded - token type: 0, lexeme: LICENSE
DEBUG src/analyser/analyser.c:which_ast_node:52: which ast node (ast-type before check: 4)
DEBUG src/analyser/analyser.c:analyse_expand:501: ast-node type after check: 4)
DEBUG src/executer/executer4.c:execute_redirection:119: execute redirection
DEBUG src/executer/executer4.c:execute_redirection:120: ast type before redirection: 4
DEBUG src/executer/executer4.c:setup_redirect:74: setup redirect
DEBUG src/parser/parser_utils2.c:consume_token_and_connect:26: consume token and connect, token to delete: <
DEBUG src/parser/parser_utils2.c:consume_token_and_connect:26: consume token and connect, token to delete: LICENSE
DEBUG src/executer/executer4.c:execute_redirection:147: ast type after redirection: 0
DEBUG src/executer/executer.c:execute_ast:122: Status after execute redirection: 0
Segmentation fault (core dumped)
lbrusa@c4c1c1:~/DEV/minishell$ 

Interestingly this happens only if the file exists. The globbing does find LICENSE

DEBUG src/scanner/token_functions.c:new_toknode:87: token created type 0 -LICENSE-
DEBUG src/scanner/scanner.c:tokenizer:69: token list successfully tokenized === 
DEBUG src/executer/executer.c:execute_ast:107: 
execute ast (node type: 4)
DEBUG src/analyser/analyser.c:expand_tokenlist:440: Token to check for expansion - token type: 21, lexeme: <
DEBUG src/analyser/analyser.c:expand_tokenlist:445: Token expanded - token type: 21, lexeme: <
DEBUG src/analyser/analyser.c:expand_tokenlist:440: Token to check for expansion - token type: 0, lexeme: LICENSE
DEBUG src/analyser/analyser.c:expand_tokenlist:445: Token expanded - token type: 0, lexeme: LICENSE
DEBUG src/analyser/analyser.c:which_ast_node:52: which ast node (ast-type before check: 4)
DEBUG src/analyser/analyser.c:analyse_expand:501: ast-node type after check: 4)
DEBUG src/executer/executer4.c:execute_redirection:119: execute redirection
DEBUG src/executer/executer4.c:execute_redirection:120: ast type before redirection: 4
DEBUG src/executer/executer4.c:setup_redirect:74: setup redirect
DEBUG src/parser/parser_utils2.c:consume_token_and_connect:26: consume token and connect, token to delete: <
DEBUG src/parser/parser_utils2.c:consume_token_and_connect:26: consume token and connect, token to delete: LICENSE
DEBUG src/executer/executer4.c:execute_redirection:147: ast type after redirection: 0
DEBUG src/executer/executer.c:execute_ast:123: Status after execute redirection: 0
Segmentation fault (core dumped)

and then crashes