aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/lexer.h4
m---------libft0
-rw-r--r--src/lexer/lexer.c17
-rw-r--r--src/lexer/trim.c19
-rw-r--r--src/main.c27
5 files changed, 31 insertions, 36 deletions
diff --git a/include/lexer.h b/include/lexer.h
index b1df017..15c5d93 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/19 10:51:26 by nahaddac #+# #+# */
-/* Updated: 2020/09/14 16:10:44 by nahaddac ### ########.fr */
+/* Updated: 2020/09/14 16:28:13 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -99,7 +99,7 @@ t_tok_lst *tok_lst_uncons(t_tok_lst **tokens);
int len_until_sep(char *input);
int tok_len(char *input);
t_tok_lst *create_token_list(char *input, t_tok_lst **lst);
-int lexer(char *input, t_tok_lst **lst);
+int lexer(char *input, t_tok_lst **out);
/*
diff --git a/libft b/libft
-Subproject 50876fe6b9e369d6b51bac9fa62b790ef5bda9d
+Subproject 3133f0d4d640abd62287187d13d380d03cce00a
diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c
index 63e92db..a1d7469 100644
--- a/src/lexer/lexer.c
+++ b/src/lexer/lexer.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:25 by nahaddac #+# #+# */
-/* Updated: 2020/09/14 16:14:51 by nahaddac ### ########.fr */
+/* Updated: 2020/09/14 16:33:58 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -104,17 +104,14 @@ t_tok_lst *create_token_list(char *input, t_tok_lst **lst)
int lexer(char *input, t_tok_lst **out)
{
- t_tok_lst *lst;
- int r;
+ int status;
- r = 0;
if (!input)
- return (1);
- lst = NULL;
- lst = create_token_list(input, &lst);
- r = lexer_trim(lst);
- *out = lst;
- return r;
+ return (2);
+ *out = NULL;
+ *out = create_token_list(input, out);
+ status = lexer_trim(*out);
+ return status;
}
diff --git a/src/lexer/trim.c b/src/lexer/trim.c
index 24eb99f..cffe43a 100644
--- a/src/lexer/trim.c
+++ b/src/lexer/trim.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:36 by nahaddac #+# #+# */
-/* Updated: 2020/09/14 16:23:35 by nahaddac ### ########.fr */
+/* Updated: 2020/09/14 16:33:13 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -79,19 +79,16 @@ int del_quote(char *str)
int lexer_trim(t_tok_lst *tokens)
{
- int r = 0;
+ int status;
+
while (tokens != NULL)
{
if (tokens->tag & (TAG_STR_DOUBLE | TAG_STR_SINGLE))
{
- r = del_quote(tokens->content);
- if (r == 0)
- {
- if (tokens->next == NULL)
- tokens->tag &= ~TAG_STICK;
- }
- else
- return r;
+ if ((status = del_quote(tokens->content)) != 0)
+ return (status);
+ if (tokens->next == NULL)
+ tokens->tag &= ~TAG_STICK;
}
else
{
@@ -101,5 +98,5 @@ int lexer_trim(t_tok_lst *tokens)
}
tokens = tokens->next;
}
- return 0;
+ return (0);
}
diff --git a/src/main.c b/src/main.c
index daa33f3..2e44b0e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */
-/* Updated: 2020/09/14 16:13:41 by nahaddac ### ########.fr */
+/* Updated: 2020/09/14 16:24:30 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -47,9 +47,7 @@ int main(int argc, char **argv, char **envp)
{
t_path path;
t_env env;
- int r;
- r = 0;
env = env_from_array(envp);
char buf[PATH_MAX] = {0};
@@ -104,16 +102,18 @@ int main(int argc, char **argv, char **envp)
if (argc == 3 && ft_strcmp(argv[1], "-l") == 0)
{
t_tok_lst *lex_out;
- r = lexer(argv[2], &lex_out);
+ int status = lexer(argv[2], &lex_out);
+ if (status != 0)
+ return (status);
tok_lst_debug(lex_out);
/* ft_lstiter((t_ftlst*)lex_out, token_debug); */
}
else if (argc == 3 && ft_strcmp(argv[1], "-c") == 0) // put in MINISHELL_TEST
{
t_tok_lst *lex_out;
- r = lexer(argv[2], &lex_out);
- if (lex_out == NULL)
- return (1);
+ int status = lexer(argv[2], &lex_out);
+ if (status != 0)
+ return (status);
t_parsed *parser_out = parse(lex_out);
if (parser_out == NULL || parser_out->syntax_error)
@@ -126,7 +126,7 @@ int main(int argc, char **argv, char **envp)
/* printf("===redirs===\n"); */
/* ft_lstiter(parser_out->ast->redirs, token_debug); */
int fds[2] = {FD_NONE, FD_NONE};
- int status = eval(fds, env, path, parser_out->ast, NULL);
+ status = eval(fds, env, path, parser_out->ast, NULL);
if (status == EVAL_FATAL)
exit(1);
g_last_status = status;
@@ -137,6 +137,7 @@ int main(int argc, char **argv, char **envp)
{
int ret;
char *line;
+ int status;
print_prompt();
while ((ret = ft_getline(STDIN_FILENO, &line)) == FTGL_OK)
@@ -146,12 +147,12 @@ int main(int argc, char **argv, char **envp)
print_prompt();
continue;
}
- t_tok_lst **lex_out = NULL;
- r = lexer(line, lex_out);
- if (lex_out == NULL)
- return (1);
+ t_tok_lst *lex_out;
+ status = lexer(line, &lex_out);
+ if (status != 0)
+ return (status);
- t_parsed *parser_out = parse(*lex_out);
+ t_parsed *parser_out = parse(lex_out);
if (parser_out == NULL)
return (1);
if (parser_out->syntax_error)