Skip to content

Commit

Permalink
fix : echo $'fefe'
Browse files Browse the repository at this point in the history
  • Loading branch information
ggjulio committed Sep 19, 2020
1 parent 186e82e commit ad2ac33
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion includes/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: juligonz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/18 14:06:38 by juligonz #+# #+# */
/* Updated: 2020/09/16 23:30:00 by juligonz ### ########.fr */
/* Updated: 2020/09/19 17:56:46 by juligonz ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -70,6 +70,7 @@ void remove_tokens_type(
*/
int in_simple_quote(t_list *begin_tokens, t_list *to_find);
int in_double_quote(t_list *begin_tokens, t_list *to_find);
int in_quote(t_list *begin_tokens, t_list *to_find);

/*
** tokenizer_variable.c
Expand Down
30 changes: 29 additions & 1 deletion srcs/tokenizer/tokenizer_util_quote.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: juligonz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/21 13:32:18 by juligonz #+# #+# */
/* Updated: 2020/09/16 20:57:05 by juligonz ### ########.fr */
/* Updated: 2020/09/19 18:01:42 by juligonz ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -67,3 +67,31 @@ int in_double_quote(t_list *begin_tokens, t_list *to_find)
}
return (-1);
}

int in_quote(t_list *begin_tokens, t_list *to_find)
{
t_token *actual;
int has_open_quote;
char quote_type;

has_open_quote = 0;
while (begin_tokens)
{
actual = begin_tokens->content;
if (actual->type == Token_quote && !has_open_quote)
{
has_open_quote = 1;
quote_type = actual->str[0];
}
else if (actual->type == Token_quote && quote_type == actual->str[0])
has_open_quote = 0;
if (begin_tokens == to_find)
{
if (has_open_quote)
return (1);
return (0);
}
begin_tokens = begin_tokens->next;
}
return (-1);
}
6 changes: 4 additions & 2 deletions srcs/tokenizer/tokenizer_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: juligonz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/29 22:52:47 by juligonz #+# #+# */
/* Updated: 2020/09/11 21:41:17 by juligonz ### ########.fr */
/* Updated: 2020/09/19 18:29:54 by juligonz ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -81,7 +81,9 @@ void expand_variables(t_list **begin_tokens)
{
if (!in_simple_quote(*begin_tokens, iterator))
{
if (!ft_strcmp(actual->str, "$"))
if (!ft_strcmp(actual->str, "$")
&& (in_quote(*begin_tokens, iterator) || (!iterator->next
|| ((t_token*)(iterator->next->content))->type != Token_quote)))
actual->type = Token_literal;
else if (!ft_strncmp("$?", actual->str, 2))
expand_variables_expand_status(actual);
Expand Down

0 comments on commit ad2ac33

Please sign in to comment.