backquote expansion checks for splitting
This commit is contained in:
parent
2e0b6102ce
commit
4840051dbd
6 changed files with 31 additions and 21 deletions
|
|
@ -246,7 +246,7 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
|||
@$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196))))
|
||||
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB)))))
|
||||
@printf "\r\e[38;5;11m⌛ MAKE %10.10s : %2d%% \e[48;5;%dm%*s\e[0m%*s\e[48;5;255m \e[0m \e[38;5;11m %*s\e[0m\e[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) "$@"
|
||||
@$(CC) $(FLAGS) -MMD -c $< -o $@\
|
||||
@$(CC) $(FLAGS) $(D_FLAGS) -MMD -c $< -o $@\
|
||||
-I $(INC_DIR)\
|
||||
-I $(LIBFT_INC)
|
||||
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* ft_memrealloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: wescande <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/05 13:44:36 by wescande #+# #+# */
|
||||
/* Updated: 2017/02/10 12:13:23 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/09 17:01:01 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -19,13 +19,16 @@ int expand_bquotes(t_list **alst)
|
|||
t_list *cur_word;
|
||||
t_list *lst;
|
||||
t_token *token;
|
||||
t_token token_buf;
|
||||
t_token *token_buf;
|
||||
char *word;
|
||||
char *ifs;
|
||||
char *output;
|
||||
char *last_char;
|
||||
char *bq_start;
|
||||
char *bq_end;
|
||||
char *after_bq;
|
||||
char **str;
|
||||
t_lexer lexer;
|
||||
t_flag tk;
|
||||
|
||||
tk = TK_WORD;
|
||||
|
|
@ -36,7 +39,6 @@ int expand_bquotes(t_list **alst)
|
|||
after_word = cur_word->next;
|
||||
token = cur_word->content;
|
||||
str = &token->data;
|
||||
DG("found word=[%s]", *str);
|
||||
if (!(bq_start = ft_strchr(*str, '`')))
|
||||
{
|
||||
cur_word = cur_word->next;
|
||||
|
|
@ -49,31 +51,37 @@ int expand_bquotes(t_list **alst)
|
|||
}
|
||||
*bq_end = 0;
|
||||
after_bq = ft_strdup(bq_end + 1);
|
||||
output = command_getoutput(bq_start + 1);
|
||||
word = ft_strtok(output, " \n\t");
|
||||
DG("strtok=[%s]", word);
|
||||
DG("first_tok was [%s]", *str);
|
||||
word = command_getoutput(bq_start + 1);
|
||||
output = word;
|
||||
last_char = word + ft_strlen(word) - 1;
|
||||
while (*last_char == '\n')
|
||||
*last_char++ = 0;
|
||||
ifs = ft_getenv(data_singleton()->env, "IFS");
|
||||
if (ifs)
|
||||
word = ft_strtok(word, ifs);
|
||||
*bq_start = 0;
|
||||
ft_strappend(str, word);
|
||||
DG("first_tok=[%s]", *str);
|
||||
while ((word = ft_strtok(NULL, " \n\t")))
|
||||
while (ifs && (lexer.str = ft_strtok(NULL, ifs)))
|
||||
{
|
||||
DG("strtok=[%s]", word);
|
||||
token_buf.data = ft_strdup(word);
|
||||
token_buf.type = TK_WORD;
|
||||
new_word = ft_lstnew(&token_buf, sizeof(token_buf));
|
||||
lexer.pos = 0;
|
||||
token_buf = token_init();
|
||||
token_buf->type = TK_WORD;
|
||||
while (lexer.str[lexer.pos])
|
||||
{
|
||||
token_append(token_buf, &lexer, 0, 0);
|
||||
lexer.pos++;
|
||||
}
|
||||
new_word = ft_lstnew(token_buf, sizeof(*token_buf));
|
||||
cur_word->next = new_word;
|
||||
new_word->next = after_word;
|
||||
cur_word = new_word;
|
||||
}
|
||||
token = new_word->content;
|
||||
token = cur_word->content;
|
||||
ft_strappend(&token->data, after_bq);
|
||||
ft_strdel(&after_bq);
|
||||
ft_strdel(&output);
|
||||
cur_word = after_word;
|
||||
}
|
||||
token_print(*alst);
|
||||
DG("check end");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@ int lexer_bquote(t_list **alst, t_lexer *lexer)
|
|||
|
||||
token = (*alst)->content;
|
||||
token->type = TK_WORD;
|
||||
token_append(token, lexer, 0, 0);
|
||||
if (lexer->state == DQUOTE_BQUOTE)
|
||||
token_append(token, lexer, 1, 1);
|
||||
else
|
||||
token_append(token, lexer, 0, 0);
|
||||
if (lexer->str[lexer->pos] == '`')
|
||||
{
|
||||
lexer->pos++;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ int lexer_delim(t_list **alst, t_lexer *lexer)
|
|||
t_token *token;
|
||||
|
||||
token = (*alst)->content;
|
||||
DG("DELIM");
|
||||
while (ft_is_delim(lexer->str[lexer->pos]))
|
||||
lexer->pos++;
|
||||
lexer->state = DEFAULT;
|
||||
|
|
|
|||
|
|
@ -67,9 +67,9 @@ int interactive_shell()
|
|||
return (1);
|
||||
DG("check main 0");
|
||||
token_print(token);
|
||||
DG("check main 1");
|
||||
if (ft_parse(&ast, &token))
|
||||
return (1);
|
||||
DG("check main 1");
|
||||
btree_print(STDBUG, ast, &ft_putast);
|
||||
if (ft_exec(&ast))
|
||||
return (1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue