Lukas Jiriste [Thu, 29 Aug 2024 14:19:07 +0000 (16:19 +0200)]
Add some signal handling for prompt
Signal handling for prompt is mostly done. Only generating a new prompt
when readline gets SIGINT and not erasing ^\ on ctrl-\ on NOLEAKS is
unresolved.
The expected behavior is to output a newline and a new prompt, readline
instead moves the cursor to the start of the current line while
preserving the prompt (so input rewrites the prompt).
Lukas Jiriste [Thu, 29 Aug 2024 08:06:53 +0000 (10:06 +0200)]
Change Makefile to permit usage of sigaction
The C99 standard does not include the sigaction function and structure
as they are (probably) GNU extensions. Using the GNU99 version instead
permits the extension usage.
Lukáš Jiřiště [Wed, 28 Aug 2024 08:34:29 +0000 (10:34 +0200)]
Make variable assignment possible in subshell
Because of ASSIGNMENT_WORD filtering, subshell needs a special rule (the
same as AND_IF, OR_IF) to permit variable assignment to be recognized
imediatelly after subshell starts.
Lukáš Jiřiště [Wed, 28 Aug 2024 07:59:34 +0000 (09:59 +0200)]
Make subshell execute in a new process
Because the OS keeps track of CWDs of its processes, subshell is made to
run in its own process not to change the CWD of main shell.
Also make exit the last executed command in a pipeline and in a program.
Lukáš Jiřiště [Tue, 27 Aug 2024 15:02:44 +0000 (17:02 +0200)]
Remove may_exit member of env
This was implemented to mimic the behaviour of piped exit.
But bash just runs piped commands in separate processes which leads to
piped builtins not having effect on the current session.
So I think it will be more pure without this check and if the bash
behaviour is needed, piping may be delegated to forked processes.
Lukáš Jiřiště [Tue, 27 Aug 2024 14:40:30 +0000 (16:40 +0200)]
Make env initialize properly
The last_was_builtin may be checked in ex_pipeline without
initialization because variable assignment does not run ex_fields
(which sets last_was_builtin).
Lukáš Jiřiště [Tue, 27 Aug 2024 09:37:57 +0000 (11:37 +0200)]
Fix pipeline behaviour
The return value is now set only after pipeline finishes (to the return
value of last command).
The shell also does not wait for each commmand in pipeline to end before
starting the following command (preventing getting stuck on full pipe).
Built-in functions still can get stuck when pipe gets full.
Lukáš Jiřiště [Tue, 27 Aug 2024 08:07:46 +0000 (10:07 +0200)]
Fix setting another value to exported variable
Instead of setting an exported variable to new value with the command of
the form <NAME>=<NEW_VALUE> a new non-exported variable was created and
used for variable expasion. The exported value was passed to child
processes.
This behaviour is fixed by this commit to the expected setting of
exported variable to the new value.
Lukáš Jiřiště [Mon, 26 Aug 2024 14:48:02 +0000 (16:48 +0200)]
Implement pipes and redirection for builtins
The feature is implemented except for error handling. Especially the
restoring of STD*_FILENO should be handled and exit the minishell hwne
they cannot be reopened.
Lukáš Jiřiště [Mon, 26 Aug 2024 14:16:51 +0000 (16:16 +0200)]
Fix tokenization double free
When an unclosed quotes are detected, tokenization fails. This causes
double free because the current_token is appended to tokens (because
current_token.size > 0) and is freed 4 lines below. The double free
happens when the tokens vector frees its memory.
In commit aac1d76 the tokenization was changed to set ASSIGNMENT_WORDs
to WORDs when the ASSIGNMENT_WORD is not in a proper place.
The filter however didn't check whether current token is ASSIGNMENT_WORD
hence other tokens could be changed to WORD also.
Lukas Jiriste [Fri, 23 Aug 2024 16:46:21 +0000 (18:46 +0200)]
Implement the export function, change tokenization
The tokenization had to be changed because "export te=te" was refused by
the parser. The "te=te" part was tokenized as ASSIGNMENT_WORD which can
only occur before command. So any ASSIGNMENT_WORD after command name is
now recognized as WORD.
Lukas Jiriste [Fri, 23 Aug 2024 14:19:22 +0000 (16:19 +0200)]
Fix showing single quotes upon expansion
In order for the wildcard expanded words not to be expanded again as
variables, single quotes were used for variable expansion. This however
caused single quotes to show when variable was expanded inside double
quotes.
The solution is to only quote the variables in wildcard expansion.
Lukas Jiriste [Thu, 22 Aug 2024 15:05:41 +0000 (17:05 +0200)]
Fix issues with patterns of form /*/
When introducing the handling of multiple slashed one after another
(eg. "///*") the handling of "/*/" patterns stopped working because the
asterisk could be assumed to be 0 symbols resulting in // which was
simplified to / effectively skipping a layer of dirs.
Lukas Jiriste [Thu, 22 Aug 2024 11:05:21 +0000 (13:05 +0200)]
Make wildcard expansion quoted
This is done for the expansion not to be expanded further for variable
names. This also prevents files with spae in their name to be split to
multiple tokens.
Lukas Jiriste [Fri, 2 Aug 2024 16:51:44 +0000 (18:51 +0200)]
Make the parsing table structure static
This makes it a little more memory and CPU friendly, because the table
doesn't need to be reallocated and parsed from the text form every
command. The downside itt needs to be cleared at the end of the program.
Lukas Jiriste [Fri, 2 Aug 2024 12:33:51 +0000 (14:33 +0200)]
Add parsing table and rules to the source code
This is done so that minishell does not have to load them from files
preventing minishell from not being able to find the files when being
moved around.
Lukas Jiriste [Thu, 1 Aug 2024 13:53:02 +0000 (15:53 +0200)]
Simplify t_redirection
Due to changes in f561c16753dcf7649b222c9b2e0fe6ca2445b6b9 it is
possible to get rid of created attribute of t_redirection.
It was included because of the same confusion as was talked in that
commit.
Lukas Jiriste [Thu, 1 Aug 2024 12:34:30 +0000 (14:34 +0200)]
Implement pipe duping
The order of closing the ends of pipes in ex_pipeline is done because
the reading end does not receive the eof unless the writting end is
closed. That means all file descriptors pointing to the writting end
have to be closed.
If the minishell itself only closes it after execution of the second
part of a pipe, it gets deadlocked, because minishell waits for the
process end to close the pipe and the process waits for the pipe to be
closed to exit.
Lukas Jiriste [Thu, 1 Aug 2024 07:30:06 +0000 (09:30 +0200)]
Make sure t_vecs are initialized before free
Short circuiting was meant to save the computation resources but causes
assignments not to be initialized when redirections encounter a problem.
This could be solved by initializing assignments outside of
save_assignments or by letting save_assignments initialize the
assignments even though it won't be used. I opted for the later.
This commit makes the project compilable (though it crashes).
It implements the small missing functions in execution.c and integrates
it into the project.
This makes the get_env_var_value unable to fail and the value does not
eed to be changed though pointer, the variable definition as a whole is
replaced during redefinition.
This function traverses the subtree of the command and extracts all
ASSIGNMENT_WORD tokens to the assignments t_vec so that it is in the
same form as the t_vecs in t_vars.
Lukas Jiriste [Sun, 23 Jun 2024 17:08:37 +0000 (19:08 +0200)]
Implement tokenization
The tokenization seems to work now. Thanks to it the parsing can be
tested which shows a leak with the unfreed memory originating from the
follow_rule function.
Lukas Jiriste [Fri, 14 Jun 2024 09:03:26 +0000 (11:03 +0200)]
Repair problems caused by change 2 commit back
The change made was from t_vec<char> to char *.
This change was not made in the function handeling tokens however,
which is rectified with this commit.
The previous 2 commit were made quickly as an exercise in using git
hence the low quality.