aboutsummaryrefslogtreecommitdiff
path: root/src/lexer
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-23 09:09:17 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-23 10:31:27 +0200
commit11b258841f4a15c514c49af7d378b51cd6a8ab79 (patch)
tree0df3f625f49fc1a8ca0e74f81272120f07a35feb /src/lexer
parent58fc321ec43be4c3f7976769733116232361857a (diff)
downloadminishell-11b258841f4a15c514c49af7d378b51cd6a8ab79.tar.gz
minishell-11b258841f4a15c514c49af7d378b51cd6a8ab79.tar.bz2
minishell-11b258841f4a15c514c49af7d378b51cd6a8ab79.zip
Fixing builtin which needed to not be run in a child process, Added exit builtin
Diffstat (limited to 'src/lexer')
-rw-r--r--src/lexer/lexer.c46
-rw-r--r--src/lexer/token.c13
2 files changed, 33 insertions, 26 deletions
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,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
@@ -14,13 +14,22 @@
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;
if ((token = (t_token*)malloc(sizeof(t_token))) == NULL)
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);