diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-16 10:10:48 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-16 10:11:58 +0200 |
| commit | 46c33fbad5e4965d2d56579e0ce6a97f310b3019 (patch) | |
| tree | 09180cccae5b8e2628dd6f36461db99ae4ddbc0d /src/lexer/trim.c | |
| parent | 28ab60062e26347cb1f28dfea63dbd8090252e4d (diff) | |
| parent | 25ba3ac2ccef9ba8295c3975a1681baa033c5ee6 (diff) | |
| download | minishell-46c33fbad5e4965d2d56579e0ce6a97f310b3019.tar.gz minishell-46c33fbad5e4965d2d56579e0ce6a97f310b3019.tar.bz2 minishell-46c33fbad5e4965d2d56579e0ce6a97f310b3019.zip | |
Merge branch 'parse_cmd' into eval
Diffstat (limited to 'src/lexer/trim.c')
| -rw-r--r-- | src/lexer/trim.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/lexer/trim.c b/src/lexer/trim.c new file mode 100644 index 0000000..ad696a4 --- /dev/null +++ b/src/lexer/trim.c @@ -0,0 +1,64 @@ + +#include "lexer.h" + +char *del_space(t_token *tk) +{ + int i; + char *s; + + i = 0; + while(tk->content[++i] != '\0') + { + if(tk->content[i] == '\\' && tk->content[i + 1] == ' ') + { + i += 2; + if (tk->content[i] == '\0') + tk->tag = tk->tag | TAG_STICK; + } + if(tk->content[i] == ' ') + break; + } + s = ft_strsubf(tk->content, 0, i); + return(s); +} + +char *del_quote(char *str) +{ + int i; + char *s; + + i = 1; + while(str[++i] != '\0') + if (str[i] == '\'' || str[i] == '"') + break; + s = ft_strsubf(str, 1, i - 1); + return (s); +} + +t_ftlst *lexe_trim_out(t_ftlst *lst) +{ + t_ftlst *first; + t_token *tk; + + first = lst; + while(lst != NULL) + { + tk = lst->data; + if (tk->tag >= TAG_STR_DOUBLE || tk->tag >= TAG_STR_SINGLE) + { + tk->content = del_quote(tk->content); + if(lst->next == NULL) + if (tk->tag & TAG_STICK) + tk->tag -= TAG_STICK; + } + else + { + tk->content = del_space(tk); + if(lst->next == NULL) + if (tk->tag & TAG_STICK) + tk->tag -= TAG_STICK; + } + lst = lst->next; + } + return (first); +} |
