From 39c04561ae4956cb836c6117789cbc7926cfbd65 Mon Sep 17 00:00:00 2001 From: nass1pro Date: Thu, 11 Jun 2020 00:28:29 +0200 Subject: chaine_list_ok----rest_tag --- test_mini/a.out | Bin 17636 -> 17828 bytes test_mini/lexer.c | 64 ++++++++++++++++++++++++++++++++++-------------- test_mini/lexer.h | 1 - test_mini/lexer_utils.c | 2 +- test_mini/main.c | 3 ++- 5 files changed, 49 insertions(+), 21 deletions(-) diff --git a/test_mini/a.out b/test_mini/a.out index 4d79529..9b7deeb 100755 Binary files a/test_mini/a.out and b/test_mini/a.out differ 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); } diff --git a/test_mini/lexer.h b/test_mini/lexer.h index a8680da..6ae832c 100644 --- a/test_mini/lexer.h +++ b/test_mini/lexer.h @@ -1,7 +1,6 @@ # include # include -# include # include "libft/include/libft_lst.h" # include "libft/include/libft_str.h" diff --git a/test_mini/lexer_utils.c b/test_mini/lexer_utils.c index cef83ae..d7fe8f4 100644 --- a/test_mini/lexer_utils.c +++ b/test_mini/lexer_utils.c @@ -56,7 +56,7 @@ int lexe_space(char *input) return(i); } -int lex_verif_simple_cote(char *input, int i) +static int lex_verif_simple_cote(char *input, int i) { i++; while(input[i] != '\0') diff --git a/test_mini/main.c b/test_mini/main.c index 5f9175f..a0006d5 100644 --- a/test_mini/main.c +++ b/test_mini/main.c @@ -7,7 +7,8 @@ int main(int argc, char **argv) int i = 0; char *input; - input = malloc(sizeof(char) * ft_strlen(argv[1]) + 2); + if (!(input = malloc(sizeof(char) * ft_strlen(argv[1]) + 2))) + return(0); ft_strlcpy(input, argv[1], ft_strlen(argv[1]) + 1); i = ft_strlen(input); input[i + 1] = '\0'; -- cgit