/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/02 13:49:31 by dkaiser #+# #+# */
-/* Updated: 2024/09/17 17:24:35 by dkaiser ### ########.fr */
+/* Updated: 2024/09/17 19:24:55 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
{
t_redirection *result;
t_token *cur;
+ int is_redir_only;
cur = *tokens;
result = malloc(sizeof(t_redirection) * 2);
while (cur != NULL && cur->next != NULL)
{
if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN)
+ {
+ is_redir_only = 0;
+ if (cur->previous == NULL && cur->next->next == NULL)
+ is_redir_only = 1;
cur = collect_redir(tokens, result, cur);
+ if (is_redir_only)
+ *tokens = NULL;
+ }
else if (cur->type == REDIR_TOKEN)
- {
- printf("Parsing error.\n");
return (free(result), NULL);
- }
else
cur = cur->next;
}
if (cur && cur->type == REDIR_TOKEN)
- {
- printf("Parsing error.\n");
return (free(result), NULL);
- }
return (result);
}
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 11:21:03 by dkaiser #+# #+# */
-/* Updated: 2024/09/13 16:18:29 by dkaiser ### ########.fr */
+/* Updated: 2024/09/17 18:46:35 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
{
t_node *node;
+ if (left == NULL || right == NULL)
+ return (NULL);
node = new_node(PIPE_NODE);
if (node == NULL)
return (NULL);
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/29 15:53:29 by dkaiser #+# #+# */
-/* Updated: 2024/09/17 15:06:55 by dkaiser ### ########.fr */
+/* Updated: 2024/09/17 19:03:48 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
#include "minishell.h"
#include "token.h"
static t_token *find_token_by_type(t_token *tokens, int type);
t_token *split_at_first(t_token **tokens, int type);
static t_node *parse_statement(t_token *tokens);
-static void free_node_wrapper(void *node);
t_list *parse(t_token *tokens)
{
- t_list *result;
- t_list *current;
- t_token *current_tokens;
+ t_node *result;
- result = NULL;
- current_tokens = split_at_first(&tokens, NEWLINE_TOKEN);
- while (current_tokens != NULL)
- {
- if (result == NULL)
- {
- current = ft_lstnew(parse_statement(current_tokens));
- result = current;
- }
- else
- {
- current->next = ft_lstnew(parse_statement(current_tokens));
- current = current->next;
- }
- if (current == NULL)
- return (ft_lstclear(&result, free_node_wrapper), NULL);
- current_tokens = split_at_first(&tokens, NEWLINE_TOKEN);
- }
- return (result);
+ if ((*tokens).type == PIPE_TOKEN)
+ result = NULL;
+ else
+ result = parse_statement(tokens);
+ if (result == NULL)
+ printf("Parsing error.\n");
+ return (ft_lstnew(result));
}
static t_node *parse_statement(t_token *tokens)
if (left_side_tokens == NULL)
{
free_tokens(tokens);
- printf("Parsing error.\n");
return (NULL);
}
else if (tokens != NULL)
}
return (NULL);
}
-
-static void free_node_wrapper(void *node)
-{
- free_node((t_node *)node);
-}