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.
Lukas Jiriste [Fri, 3 May 2024 14:11:26 +0000 (16:11 +0200)]
Create the structure for input handling
Create prototypes of some needed types (token, parse tree) and
create the structure of the input processing with empty functions.
Also add a grammar for minishell inside a comment in parsing.h.
This is a simplification of the grammar of Shell programming language
as it is laid out inside
The Open Group Base Specifications Issue 7, 2018 edition
Chapter 2. Shell Command Language
found on site
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
Lukas Jiriste [Thu, 2 May 2024 12:40:05 +0000 (14:40 +0200)]
Add version without history
This version doesn't utilize GNU Readline so it has much lower memory
footprint. The main benefit however is that tracking with valgrind is
made easier with this.
Lukas Jiriste [Thu, 2 May 2024 11:27:09 +0000 (13:27 +0200)]
Implement variables framework, update Libft
So far the variable handling consists of copying the environment
inherited by minishell to separate variable to make changes to it
possible (I suspect that one should not directly change the environ).
The vars struct consists of 2 vectos of strings, one for the exported
variables and one for the others.
This is done so that the exported->vec can be directly passed to execve
instead of contructing it by filtering the exported values from
a common vector.
This is also why the vector is initialized with NULL. The other vec
is constructed the same way so as to be able to reuse the code for
exported.
During work on this commit the function ft_strcat_alloc seemed to be
a great candidate for addition to Libft. That was done and the
function was used in this commit, hence the Libft update.
The minishell is now able to accept input and access history through
the GNU Readline library.
The minishell itself prints prompt with currect directory.
It also handles the "exit" command as well as ctrl-D
so that it can exit. It prints "exit" on exit like bash.