diff options
| author | nass1pro <nass1pro@gmail.com> | 2020-06-09 19:48:34 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-13 11:25:24 +0200 |
| commit | 19d83149feebaeb99430715242aac352890122cc (patch) | |
| tree | c5b6761db98e27d15bab3fb45ba9e0a646cf06e0 /test_mini/lexer.c | |
| parent | 9fabc25a980550afc6337fd729632462f2680daa (diff) | |
| download | minishell-19d83149feebaeb99430715242aac352890122cc.tar.gz minishell-19d83149feebaeb99430715242aac352890122cc.tar.bz2 minishell-19d83149feebaeb99430715242aac352890122cc.zip | |
lexer_test
single_ok
Diffstat (limited to 'test_mini/lexer.c')
| -rw-r--r-- | test_mini/lexer.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/test_mini/lexer.c b/test_mini/lexer.c new file mode 100644 index 0000000..c847c1d --- /dev/null +++ b/test_mini/lexer.c @@ -0,0 +1,112 @@ + +#include "lexer.h" +#include "parse/parse.h" + + +int len_is_not_sep(char *input) +{ + int i; + + i = -1; + while(input[++i]) + { + if (lexer_sep(input[i])) + { + if (input[i + 1] == ' ') + while(input[++i] == ' ') + ; + return(i); + } + if (input[i] == '\'' || input[i] == '"') + { + i = lexer_verif_entre_cote(input, i); + if (input[i] == ' ') + return(i + 1); + return(i); + } + if (input[i] == ' ') + { + while(input[++i] == ' ') + ; + return (i); + } + } + return(i); +} + +int check_input(char *input) +{ + int i; + + i = 0; + if (lexer_sep(input[i])) + { + while(input[i] == input[i + 1]) + i++; + i += lexe_space(&input[i + 1]); + return (i + 1); + } + if (input[i] == 39 || input[i] == '"') + return(lexer_verif_entre_cote(input, i)); + if (input[i] == ' ') + { + while(input[++i] == ' ') + ; + return (i); + } + return(len_is_not_sep(&input[i])); +} + +void check_input_out(char *input) +{ + int i; + int j; + char *str; + + i = 0; + while(input[i] != '\0') + { + j = 0; + 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); + } + 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; + } + +} + +t_token *create_token_list(void) +{ + t_token *lst_token; + + if (!(lst_token = malloc(sizeof(t_token) * 1))) + return (NULL); + + free(lst_token); + return (lst_token); +} + +t_ftlst *lexer(char *input) +{ + t_ftlst *lst; + + if (!input) + return (0); + if(!(lst = malloc(sizeof(t_ftlst) * 1))) + return(NULL); + + check_input_out(input); + free(lst); + return (0); +} |
