aboutsummaryrefslogtreecommitdiff
path: root/src/lexer/trim.c
diff options
context:
space:
mode:
authornass1pro <nass1pro@gmail.com>2020-06-15 19:24:25 +0200
committernass1pro <nass1pro@gmail.com>2020-06-15 19:24:25 +0200
commit7b383ea28c818441ae5a75ed573dc03e992cd89f (patch)
treef8824d2b4fa6016f15ff11e3483c94ee1cfcb1e3 /src/lexer/trim.c
parent6bb9eafa5fe8de5194801ab5ff3bd898a853c9fb (diff)
downloadminishell-7b383ea28c818441ae5a75ed573dc03e992cd89f.tar.gz
minishell-7b383ea28c818441ae5a75ed573dc03e992cd89f.tar.bz2
minishell-7b383ea28c818441ae5a75ed573dc03e992cd89f.zip
Update lexer
Diffstat (limited to 'src/lexer/trim.c')
-rw-r--r--src/lexer/trim.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/lexer/trim.c b/src/lexer/trim.c
index 9fbb6cc..0f2cde1 100644
--- a/src/lexer/trim.c
+++ b/src/lexer/trim.c
@@ -1,7 +1,60 @@
#include "lexer.h"
+char *del_space(char *str)
+{
+ int i;
+ char *s;
+
+ i = 0;
+ while(str[++i] != '\0')
+ {
+ if(str[i] == '\\' && str[i + 1] == ' ')
+ i += 2;
+ if(str[i] == ' ')
+ break;
+ }
+ s = ft_strsubf(str, 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)
{
- return (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->content);
+ if(lst->next == NULL)
+ if (tk->tag & TAG_STICK)
+ tk->tag -= TAG_STICK;
+ }
+ lst = lst->next;
+ }
+ return (first);
}