aboutsummaryrefslogtreecommitdiff
path: root/test_mini/lexer.c
diff options
context:
space:
mode:
authornass1pro <nass1pro@gmail.com>2020-06-11 00:28:29 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-13 11:42:43 +0200
commit39c04561ae4956cb836c6117789cbc7926cfbd65 (patch)
treeb07464986ba6a80542c2409a1271c4a9da87a0f4 /test_mini/lexer.c
parentf4b7aaff1b397e31925e0701e1342583058178ba (diff)
downloadminishell-39c04561ae4956cb836c6117789cbc7926cfbd65.tar.gz
minishell-39c04561ae4956cb836c6117789cbc7926cfbd65.tar.bz2
minishell-39c04561ae4956cb836c6117789cbc7926cfbd65.zip
chaine_list_ok----rest_tag
Diffstat (limited to 'test_mini/lexer.c')
-rw-r--r--test_mini/lexer.c64
1 files changed, 46 insertions, 18 deletions
diff --git a/test_mini/lexer.c b/test_mini/lexer.c
index 75197d6..7e4fad2 100644
--- a/test_mini/lexer.c
+++ b/test_mini/lexer.c
@@ -59,7 +59,9 @@ int check_input(char *input)
return(len_is_not_sep(&input[i]));
}
-void check_input_out(char *input)
+
+
+int check_input_out(char *input)
{
int i;
int j;
@@ -72,41 +74,67 @@ void check_input_out(char *input)
j += len_is_not_sep(&input[i]);
if (j != 0)
{
- str = malloc(sizeof(char) * j + 1);
- ft_strlcpy(str, &input[i], j + 1);
- printf("%s%d\n",str, j);
- free(str);
+ return(j);
}
i += j;
j = check_input(&input[i]);
- str = malloc(sizeof(char) * j + 1);
- ft_strlcpy(str, &input[i], j + 1);
- printf("%s%d\n",str, j);
- free(str);
- i += j;
+ return(j);
}
+ return(0);
}
-t_token *create_token_list(void)
+t_token *lexer_lst_token_str(char *input, int i, int j)
{
- t_token *lst_token;
+ t_token *lst_token;
if (!(lst_token = malloc(sizeof(t_token) * 1)))
return (NULL);
- free(lst_token);
+ lst_token->token = 0;
+ lst_token->value = NULL;
+ if (!(lst_token->value = malloc(sizeof(char) * j + 1)))
+ return(0);
+ if (!(ft_strlcpy(lst_token->value, &input[i], j + 1)))
+ {
+ free(lst_token);
+ return(0);
+ }
+ printf("%s\n", lst_token->value);
return (lst_token);
}
+static t_ftlst *create_token_list(char *input, t_ftlst **lst)
+{
+ t_token *lst_token;
+ t_ftlst *new;
+ int i;
+ int j;
+
+ i = 0;
+ while (i < ft_strlen(input))
+ {
+ j = 0;
+ j += check_input(&input[i]);
+ lst_token = lexer_lst_token_str(input,i,j);
+ new = ft_lstnew((void *) lst_token);
+ ft_lstpush_back(lst, new);
+ i += j;
+ }
+ return (*lst);
+}
+
t_ftlst *lexer(char *input)
{
- t_ftlst *lst;
+ t_ftlst **lst;
+ int i;
if (!input)
return (0);
- if(!(lst = malloc(sizeof(t_ftlst) * 1)))
- return(NULL);
-
- check_input_out(input);
+ lst = malloc(sizeof(t_ftlst *) * 1);
+ if (!lst)
+ return(0);
+ *lst = create_token_list(input, lst);
+ i = ft_lstsize(*lst);
+ printf("%d\n", i);
free(lst);
return (0);
}