From f9019aea8884ff318e14a8069bef994d601380f1 Mon Sep 17 00:00:00 2001 From: wescande Date: Mon, 20 Feb 2017 19:15:19 +0100 Subject: [PATCH] suppression ancien backquote + deplacement command output + modif main sur l'appel a expand_bquote --- 42sh/Makefile | 3 +- 42sh/src/{lexer => glob}/command_getoutput.c | 0 42sh/src/lexer/expand_bquotes.c | 104 ------------------- 42sh/src/main/main.c | 10 +- 4 files changed, 6 insertions(+), 111 deletions(-) rename 42sh/src/{lexer => glob}/command_getoutput.c (100%) delete mode 100644 42sh/src/lexer/expand_bquotes.c diff --git a/42sh/Makefile b/42sh/Makefile index af4c2ff4..f2e697ab 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -83,6 +83,7 @@ exec/redirect_greatand.c\ exec/redirect_less.c\ exec/redirect_lessand.c\ exec/set_exitstatus.c\ +glob/command_getoutput.c\ glob/dir_glob.c\ glob/esc_print.c\ glob/expand_bquote.c\ @@ -151,8 +152,6 @@ job-control/sigint_handler.c\ job-control/sigtstp_handler.c\ job-control/sigttin_handler.c\ job-control/sigttou_handler.c\ -lexer/command_getoutput.c\ -lexer/expand_bquotes.c\ lexer/get_lexer_stack.c\ lexer/get_state_global.c\ lexer/get_state_redir.c\ diff --git a/42sh/src/lexer/command_getoutput.c b/42sh/src/glob/command_getoutput.c similarity index 100% rename from 42sh/src/lexer/command_getoutput.c rename to 42sh/src/glob/command_getoutput.c diff --git a/42sh/src/lexer/expand_bquotes.c b/42sh/src/lexer/expand_bquotes.c deleted file mode 100644 index eec0e93e..00000000 --- a/42sh/src/lexer/expand_bquotes.c +++ /dev/null @@ -1,104 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* expand_bquotes.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/11 16:46:27 by jhalford #+# #+# */ -/* Updated: 2017/02/20 14:17:03 by wescande ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "lexer.h" - -int bquotes_insert_words(t_list *cur_word, char *word, char *after_bq, char *ifs) -{ - t_list *new_word; - t_list *after_word; - t_token *token; - - after_word = cur_word->next; - if (ifs) - word = ft_strtok(word, ifs); - token = cur_word->content; - token_append_str(token, word, 0, 0); - if (ifs) - while ((word = ft_strtok(NULL, ifs))) - { - token = token_init(); - token->type = TK_WORD; - token_append_str(token, word, 0, 0); - new_word = ft_lstnew(token, sizeof(*token)); - cur_word->next = new_word; - new_word->next = after_word; - cur_word = new_word; - } - token = cur_word->content; - ft_strappend(&token->data, after_bq); - return (0); -} - -int bquotes_substitute(t_list *cur_word, char *bq_start, char *bq_end) -{ - char *output; - char *last_char; - char *after_bq; - char *ifs; - t_token *token; - - *bq_start = 0; - *bq_end = 0; - if ((output = command_getoutput(bq_start + 1))) - { - last_char = output + ft_strlen(output) - 1; - while (*last_char == '\n') - *last_char++ = 0; - } - DG("output = [%s]", output); - after_bq = ft_strdup(bq_end + 1); - token = cur_word->content; - ifs = is_char_esc(token->esc, token->data, bq_start) ? - NULL : ft_getenv(data_singleton()->env, "IFS"); - bquotes_insert_words(cur_word, output ? output : "", after_bq, ifs); - ft_strdel(&output); - ft_strdel(&after_bq); - return (0); -} - -int bquotes_expand(t_list **alst) -{ - (void) alst; - /* - t_list *cur_word; - char *bq_start; - char *bq_end; - t_flag tk_word; - t_token *token; - - tk_word = TK_WORD; - cur_word = *alst; - while ((cur_word = ft_lst_find(cur_word, &tk_word, token_cmp_type))) - { - token = cur_word->content; - if (!(bq_start = ft_strchr(token->data, '`')) - || is_char_esc(token->esc2, token->data, bq_start)) - { - cur_word = cur_word->next; - return (0); - } - if (!(bq_end = ft_strchr(bq_start + 1, '`'))) - { - ft_dprintf(2, "{red}%s: parse error near '`'{eoc}\n", SHELL_NAME); - return (-1); - } - if (bquotes_substitute(cur_word, bq_start, bq_end)) - return (-1); - if (!(*token->data)) - ft_lst_delif(alst, cur_word->content, ft_addrcmp, token_free); - cur_word = *alst; - } - */ - return (0); -} - diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index f3bfdf13..a9bb0cec 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/02/20 15:00:31 by wescande ### ########.fr */ +/* Updated: 2017/02/20 19:13:50 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,8 +31,8 @@ int non_interactive_shell(char *command) } while (lexer.str[lexer.pos] == '\n'); if (!token) return (0); - if (bquotes_expand(&token)) - return (1); +// if (bquotes_expand(&token)) +// return (1); //token_print(token); if (ft_parse(&ast, &token)) return (1); @@ -63,8 +63,8 @@ int interactive_shell() return (1); //token_print(token); } while (get_lexer_stack(lexer)); - if (bquotes_expand(&token)) - return (1); +// if (bquotes_expand(&token)) +// return (1); if (!token) return (0); ft_add_str_in_history(lexer.str);