-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from mingxoxo/83-refactor-파싱-과정에서-발생하는-에러에-대한-…
…종료-상태-코드-설정 Refactor : #83/parsing error 종료 코드 설정
- Loading branch information
Showing
1 changed file
with
33 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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) | ||
{ | ||
|
@@ -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); | ||
} | ||
|
@@ -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); | ||
|