aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorChristopher Uhlig2025-01-25 13:01:10 +0100
committerChristopher Uhlig2025-01-25 13:01:10 +0100
commit87b90103930d83d74baa998866b0995cb8887d51 (patch)
tree0eb876341c2794f2165b83c1d339fb3b38e9f711 /src/parser.c
parent18fb7cb8ae69fc3439266a154aa6b0f947d6805d (diff)
downloadminishell-87b90103930d83d74baa998866b0995cb8887d51.tar.gz
minishell-87b90103930d83d74baa998866b0995cb8887d51.zip
fixed leaks in tokenizer and collectargs also fixed seg for < > and improved value add by $ use
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/parser.c b/src/parser.c
index 68ab372..8393cda 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/29 15:53:29 by dkaiser #+# #+# */
-/* Updated: 2025/01/23 18:00:18 by chuhlig ### ########.fr */
+/* Updated: 2025/01/25 11:38:47 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,28 +21,30 @@ static t_node *parse_statement(t_token *tokens, t_env **env);
t_node *parse(t_token *tokens, t_env **env)
{
- t_node *result;//
+ t_node *result;
- if ((*tokens).type == PIPE_TOKEN)
+ if ((*tokens).type == PIPE_TOKEN
+ || ((*tokens).type == REDIR_TOKEN && !(*tokens).next))
+ {
result = NULL;
+ free_tokens(tokens);
+ }
else
result = parse_statement(tokens, env);
if (result == NULL)
+ {
printf("Parsing error.\n");
- // if (tokens != NULL)
- // print_token_list(tokens);
+ free_tokens(tokens);
+ }
return (result);
}
static t_node *parse_statement(t_token *tokens, t_env **env)
{
t_token *left_side_tokens;
-
- print_token_list(tokens);//until her is fine
- left_side_tokens = split_at_first(&tokens, PIPE_TOKEN);//by pipe usage parse cmd gets reacls so also check there the token list changes
- //leftside toke has the pos of pipe -> next
- //or if we have pipe we return token head and also change the *tokens to after pipe
- if (left_side_tokens == NULL)// we never return NULL exept token is already null
+
+ left_side_tokens = split_at_first(&tokens, PIPE_TOKEN);
+ if (left_side_tokens == NULL)
{
free_tokens(tokens);
tokens = NULL;
@@ -51,13 +53,12 @@ static t_node *parse_statement(t_token *tokens, t_env **env)
else if (tokens != NULL)
{
return (new_pipe_node(parse_cmd(left_side_tokens, env),
- parse_statement(tokens, env)));//here new pipe node
+ parse_statement(tokens, env)));
}
else
{
- print_token_list(left_side_tokens);
- return (parse_cmd(left_side_tokens, env));//here return is cmd node
- }// here he takt left side token so
+ return (parse_cmd(left_side_tokens, env));
+ }
}
t_token *split_at_first(t_token **tokens, int type)
@@ -65,24 +66,21 @@ t_token *split_at_first(t_token **tokens, int type)
t_token *split;
t_token *result;
- split = find_token_by_type(*tokens, type);//split has the pos of where pipe appears// if no pipe in tokenlist 1st if case
+ split = find_token_by_type(*tokens, type);
if (split == NULL)
{
result = *tokens;
- *tokens = NULL;//we are change to pointing token to NULL
+ *tokens = NULL;
return (result);
}
result = *tokens;
- *tokens = split->next;// is this part enought reconnetion
+ *tokens = split->next;
if (result == split)
result = NULL;
- free_token2(split);//why free here? bv would free pipe node but what is with the connection of the tokenlist does this mess up the connection?
+ free_token2(split);
split = NULL;
- return (result);// at this return return is at tokenlist pos of split next and result is the tokenlist before split
+ return (result);
}
-//free token seems not right here even
-// or at least no the right funtion here
-//
static t_token *find_token_by_type(t_token *tokens, int type)
{