Skip to content

Commit

Permalink
Merge pull request #85 from mingxoxo/83-refactor-파싱-과정에서-발생하는-에러에-대한-…
Browse files Browse the repository at this point in the history
…종료-상태-코드-설정

Refactor : #83/parsing error 종료 코드 설정
  • Loading branch information
wonyangs authored Jan 17, 2023
2 parents 73367ed + 0691d8d commit ad8feab
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jeongmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/15 17:20:31 by wonyang #+# #+# */
/* Updated: 2023/01/16 20:58:35 by jeongmin ### ########.fr */
/* Updated: 2023/01/16 23:45:52 by jeongmin ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,6 +15,9 @@
#include "make_tree.h"
#include "ds_tree.h"
#include "libft.h"
#include "minishell.h"

extern t_global g_var;

static void del_t_paren(void *content)
{
Expand All @@ -31,15 +34,39 @@ static void del_t_paren(void *content)
content = NULL;
}

static t_list *pre_processing(char *str)
{
t_list *lst;

lst = tokenization(str);
if (!lst)
return (NULL);
if (!is_correct_syntax(lst->next))
{
ft_lstclear(&lst, &del_t_token);
return (NULL);
}
return (lst);
}

static t_error post_processing(t_tnode *node)
{
if (!node)
return (ERROR);
if (subst(node) == ERROR)
{
g_var.status = 1;
return (ERROR);
}
if (del_quote(node) == ERROR)
{
g_var.status = 1;
return (ERROR);
}
if (wildcard(node) == ERROR)
{
g_var.status = 1;
return (ERROR);
}
if (!node)
return (ERROR);
return (SCS);
}
Expand All @@ -49,24 +76,19 @@ t_tnode *parse_line(char *str)
t_list *lst;
t_tnode *node;

lst = tokenization(str);
lst = pre_processing(str);
if (!lst)
{
free(str);
return (NULL);
}
if (!is_correct_syntax(lst->next))
{
ft_lstclear(&lst, &del_t_token);
free(str);
g_var.status = 1;
return (NULL);
}
node = make_tree(lst->next);
ft_lstclear(&lst, &del_t_paren);
if (post_processing(node) == ERROR)
{
free(str);
clear_node(node, del_t_token);
clear_node(node, &del_t_token);
return (NULL);
}
return (node);
Expand Down

0 comments on commit ad8feab

Please sign in to comment.