aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDominik Kaiser2024-08-11 12:15:40 +0200
committerDominik Kaiser2024-08-11 12:15:40 +0200
commitf53acc629b1b3e7f4097eef1e26841ef0b9b24c6 (patch)
treec66db435ce50b68f47de47ec632d767b118112ed /src
parent8cf2aec82f98094d8175c5e5daaaa115f9b64fc2 (diff)
downloadminishell-f53acc629b1b3e7f4097eef1e26841ef0b9b24c6.tar.gz
minishell-f53acc629b1b3e7f4097eef1e26841ef0b9b24c6.zip
Fix parser bugs
Diffstat (limited to 'src')
-rw-r--r--src/collect_redirs.c13
-rw-r--r--src/parse_cmd.c10
-rw-r--r--src/tokenizer.c4
3 files changed, 16 insertions, 11 deletions
diff --git a/src/collect_redirs.c b/src/collect_redirs.c
index 76b08da..d50bec4 100644
--- a/src/collect_redirs.c
+++ b/src/collect_redirs.c
@@ -6,13 +6,13 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/02 13:49:31 by dkaiser #+# #+# */
-/* Updated: 2024/08/02 15:21:04 by dkaiser ### ########.fr */
+/* Updated: 2024/08/11 12:12:16 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
-static void collect_redir(t_token **tokens, t_redirection *result,
+static t_token *collect_redir(t_token **tokens, t_redirection *result,
t_token *cur);
static void set_redir(t_redirection *redir, int type, char *specifier);
static int is_output_redir(int i);
@@ -31,7 +31,7 @@ t_redirection *collect_redirs(t_token **tokens)
while (cur != NULL && cur->next != NULL)
{
if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN)
- collect_redir(tokens, result, cur);
+ cur = collect_redir(tokens, result, cur);
else if (cur->type == REDIR_TOKEN)
{
dbg("TODO: Add parsing errmsg");
@@ -43,7 +43,8 @@ t_redirection *collect_redirs(t_token **tokens)
return (result);
}
-static void collect_redir(t_token **tokens, t_redirection *result, t_token *cur)
+static t_token *collect_redir(t_token **tokens, t_redirection *result,
+ t_token *cur)
{
set_redir(&result[is_output_redir(cur->content.redir_type)],
cur->content.redir_type, cur->next->content.string);
@@ -57,7 +58,11 @@ static void collect_redir(t_token **tokens, t_redirection *result, t_token *cur)
free_token_and_connect(cur->previous);
}
else
+ {
free_token(cur);
+ return (NULL);
+ }
+ return (cur);
}
static void set_redir(t_redirection *redir, int type, char *specifier)
diff --git a/src/parse_cmd.c b/src/parse_cmd.c
index 068a4c1..eb70f0d 100644
--- a/src/parse_cmd.c
+++ b/src/parse_cmd.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2024/08/02 14:22:32 by dkaiser ### ########.fr */
+/* Updated: 2024/08/11 12:14:11 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -34,11 +34,8 @@ static char **collect_args(t_token **tokens)
cur = *tokens;
i = 0;
- while (cur != NULL)
- {
- i++;
+ while (cur != NULL && ++i)
cur = cur->next;
- }
result = malloc(sizeof(char *) * (i + 1));
if (result == NULL)
return (free_tokens(*tokens), NULL);
@@ -46,10 +43,11 @@ static char **collect_args(t_token **tokens)
i = 0;
while (cur != NULL && cur->type == STRING_TOKEN)
{
+ if (cur->previous)
+ free_token(cur->previous);
result[i] = cur->content.string;
i++;
cur = cur->next;
- free_token(cur->previous);
}
result[i] = NULL;
return (result);
diff --git a/src/tokenizer.c b/src/tokenizer.c
index 34685ac..efbf723 100644
--- a/src/tokenizer.c
+++ b/src/tokenizer.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */
-/* Updated: 2024/08/09 15:40:00 by chuhlig ### ########.fr */
+/* Updated: 2024/08/11 11:40:35 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -110,4 +110,6 @@ void tokenizer(char *s, t_token **token_list)
pos = i + 1;
}
}
+ while ((*token_list)->previous)
+ *token_list = (*token_list)->previous;
}