From 11b258841f4a15c514c49af7d378b51cd6a8ab79 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 23 Jun 2020 09:09:17 +0200 Subject: Fixing builtin which needed to not be run in a child process, Added exit builtin --- src/lexer/lexer.c | 46 ++++++++++++++++++++++------------------------ src/lexer/token.c | 13 +++++++++++-- 2 files changed, 33 insertions(+), 26 deletions(-) (limited to 'src/lexer') diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 9b43616..dd34654 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -69,24 +69,24 @@ int check_input_out(char *input) return(0); } -t_token *lexer_lst_token_str(char *input, int i, int j) -{ - t_token *lst_token; - - if (!(lst_token = malloc(sizeof(t_token) * 1))) - return (NULL); - lst_token->tag = 0; - lst_token->content = NULL; - if (!(lst_token->content = malloc(sizeof(char) * j + 1))) - return(0); - if (!(ft_strlcpy(lst_token->content, &input[i], j + 1))) - { - free(lst_token); - return(0); - } - - return (lst_token); -} +/* t_token *lexer_lst_token_str(char *input, int i, int j) */ +/* { */ +/* t_token *lst_token; */ +/* */ +/* if (!(lst_token = malloc(sizeof(t_token) * 1))) */ +/* return (NULL); */ +/* lst_token->tag = 0; */ +/* lst_token->content = NULL; */ +/* if (!(lst_token->content = malloc(sizeof(char) * j + 1))) */ +/* return(0); */ +/* if (!(ft_strlcpy(lst_token->content, &input[i], j + 1))) */ +/* { */ +/* free(lst_token); */ +/* return(0); */ +/* } */ +/* */ +/* return (lst_token); */ +/* } */ enum e_token_tag token_verif_stick(t_token *lst_token) { @@ -151,9 +151,10 @@ static t_ftlst *create_token_list(char *input, t_ftlst **lst) { j = 0; j += check_input(&input[i]); - lst_token = lexer_lst_token_str(input,i,j); + /* lst_token = lexer_lst_token_str(input,i,j); */ + lst_token = token_new_until(0, input + i, j); lst_token = push_token_enum(lst_token); - new = ft_lstnew((void *) lst_token); + new = ft_lstnew(lst_token); ft_lstpush_back(lst, new); i += j; } @@ -165,10 +166,7 @@ t_ftlst *lexer(char *input) t_ftlst *lst; if (!input) - return (0); - lst = malloc(sizeof(t_ftlst ) * 1); - if (!lst) - return(0); + return (NULL); lst = NULL; lst = create_token_list(input, &lst); lst = lexe_trim_out(lst); diff --git a/src/lexer/token.c b/src/lexer/token.c index 966a443..5465b6b 100644 --- a/src/lexer/token.c +++ b/src/lexer/token.c @@ -6,13 +6,22 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/09 13:38:08 by charles #+# #+# */ -/* Updated: 2020/06/15 11:38:24 by charles ### ########.fr */ +/* Updated: 2020/06/23 08:55:32 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "lexer.h" t_token *token_new(enum e_token_tag tag, char *content) +{ + size_t len; + + if (content != NULL) + len = ft_strlen(content); + return (token_new_until(tag, content, len)); +} + +t_token *token_new_until(enum e_token_tag tag, char *content, int n) { t_token *token; @@ -20,7 +29,7 @@ t_token *token_new(enum e_token_tag tag, char *content) return (NULL); if (content == NULL) token->content = NULL; - else if ((token->content = ft_strdup(content)) == NULL) + else if ((token->content = ft_strndup(content, n)) == NULL) { free(token); return (NULL); -- cgit