Skip to content

Commit

Permalink
#124 Fix expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroaki-K4 committed Mar 28, 2022
1 parent d2908a5 commit 317e362
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
19 changes: 1 addition & 18 deletions srcs/expand/make_e_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: hkubo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/20 21:25:30 by hkubo #+# #+# */
/* Updated: 2022/02/20 21:25:31 by hkubo ### ########.fr */
/* Updated: 2022/03/28 21:51:46 by hkubo ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -62,20 +62,9 @@ t_expand_state *update_e_state(t_expand_state *e_state, t_list *token_list,
return (e_state);
}

int is_content_empty(t_list *list, char *word)
{
t_token *token;

token = (t_token *)list->content;
if (!ft_strncmp(token->content, word, ft_strlen(token->content) + 1))
return (TRUE);
return (FALSE);
}

t_expand_state *make_e_state(t_list *token_list, t_envs *envs, int exit_status)
{
t_expand_state *e_state;
t_list *last_lst;

e_state = (t_expand_state *)malloc(sizeof(t_expand_state));
if (!e_state)
Expand All @@ -85,11 +74,5 @@ t_expand_state *make_e_state(t_list *token_list, t_envs *envs, int exit_status)
e_state = update_e_state(e_state, token_list, envs, exit_status);
if (!e_state)
return (NULL);
last_lst = ft_lstlast(e_state->token_list);
if (is_content_empty(last_lst, ""))
{
last_lst->prev->next = NULL;
ft_lstdelone_all(last_lst, free);
}
return (e_state);
}
10 changes: 10 additions & 0 deletions test/answer/expand/env_val_without_quote.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ content: echo attr: 0
content: $OUR_MINISHELLa attr: 0
~~~~~After expand~~~~~
content: echo attr: 0
content: attr: 0
minishell> exit
minishell> echo $aOUR_MINISHELL
~~~~~After tokenize~~~~~
content: echo attr: 0
content: $aOUR_MINISHELL attr: 0
~~~~~After expand~~~~~
content: echo attr: 0
content: attr: 0
minishell> exit
minishell> echo a$OUR_MINISHELL
~~~~~After tokenize~~~~~
Expand Down Expand Up @@ -70,3 +72,11 @@ content: $OUR_MINISHELL:minishell attr: 0
content: echo attr: 0
content: Beatiful:minishell attr: 0
minishell> exit
minishell> $HOGE
minishell> exit
minishell> aa$HOGE
minishell> exit
minishell> $OUR_MINISHELL
minishell> exit
minishell> $OUR_MINISHELLaa
minishell> exit
4 changes: 4 additions & 0 deletions test/case/expand/env_val_without_quote.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ echo 'echo a$OUR_MINISHELL' | ./minishell tokenize
echo 'echo a$OUR_MINISHELLa' | ./minishell tokenize
echo 'echo $OUR_MINISHELL$?$OUR_MINISHELL' | ./minishell tokenize
echo 'echo $OUR_MINISHELL:minishell' | ./minishell tokenize
echo '$HOGE' | ./minishell
echo 'aa$HOGE' | ./minishell
echo '$OUR_MINISHELL' | ./minishell
echo '$OUR_MINISHELLaa' | ./minishell

0 comments on commit 317e362

Please sign in to comment.