aboutsummaryrefslogtreecommitdiff
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
parentf4b7aaff1b397e31925e0701e1342583058178ba (diff)
downloadminishell-39c04561ae4956cb836c6117789cbc7926cfbd65.tar.gz
minishell-39c04561ae4956cb836c6117789cbc7926cfbd65.tar.bz2
minishell-39c04561ae4956cb836c6117789cbc7926cfbd65.zip
chaine_list_ok----rest_tag
-rwxr-xr-xtest_mini/a.outbin17636 -> 17828 bytes
-rw-r--r--test_mini/lexer.c64
-rw-r--r--test_mini/lexer.h1
-rw-r--r--test_mini/lexer_utils.c2
-rw-r--r--test_mini/main.c3
5 files changed, 49 insertions, 21 deletions
diff --git a/test_mini/a.out b/test_mini/a.out
index 4d79529..9b7deeb 100755
--- a/test_mini/a.out
+++ b/test_mini/a.out
Binary files 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 <stdio.h>
# include <stdlib.h>
-# include <libc.h>
# 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';