aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/lexer.h8
m---------libft0
-rw-r--r--src/lexer/lexer.c15
-rw-r--r--src/lexer/trim.c40
-rw-r--r--src/main.c17
5 files changed, 56 insertions, 24 deletions
diff --git a/include/lexer.h b/include/lexer.h
index c477a4f..b1df017 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/13 20:33:53 by charles ### ########.fr */
+/* Updated: 2020/09/14 16:10:44 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
@@ -99,8 +99,8 @@ 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);
-t_tok_lst *lexer(char *input);
-// int check_input_out(char *input);
+int lexer(char *input, t_tok_lst **lst);
+
/*
** utils.c
@@ -117,6 +117,6 @@ int quote_len(char *input, int i);
** trim.c
*/
-void lexer_trim(t_tok_lst *lst);
+int lexer_trim(t_tok_lst *lst);
#endif
diff --git a/libft b/libft
-Subproject 3133f0d4d640abd62287187d13d380d03cce00a
+Subproject 50876fe6b9e369d6b51bac9fa62b790ef5bda9d
diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c
index 79401f2..63e92db 100644
--- a/src/lexer/lexer.c
+++ b/src/lexer/lexer.c
@@ -6,11 +6,12 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:25 by nahaddac #+# #+# */
-/* Updated: 2020/09/14 11:30:24 by nahaddac ### ########.fr */
+/* Updated: 2020/09/14 16:14:51 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
+#include <stdio.h>
// len until meaningful character for non quoted str
int len_until_sep(char *input)
@@ -101,16 +102,20 @@ t_tok_lst *create_token_list(char *input, t_tok_lst **lst)
** \return The created tokens or NULL on error
*/
-t_tok_lst *lexer(char *input)
+int lexer(char *input, t_tok_lst **out)
{
t_tok_lst *lst;
+ int r;
+ r = 0;
if (!input)
- return (NULL);
+ return (1);
lst = NULL;
lst = create_token_list(input, &lst);
- lexer_trim(lst);
- return (lst);
+ r = lexer_trim(lst);
+ *out = lst;
+ return r;
+
}
/* int check_input_out(char *input) */
diff --git a/src/lexer/trim.c b/src/lexer/trim.c
index a01e07e..24eb99f 100644
--- a/src/lexer/trim.c
+++ b/src/lexer/trim.c
@@ -6,12 +6,13 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:36 by nahaddac #+# #+# */
-/* Updated: 2020/09/14 15:13:10 by charles ### ########.fr */
+/* Updated: 2020/09/14 16:23:35 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
+#include <stdio.h>
void del_space(char *str)
{
@@ -31,11 +32,13 @@ void del_space(char *str)
}
}
-void del_quote(char *str)
+int del_quote(char *str)
{
size_t i;
+ int nb_q;
i = 0;
+ nb_q = 1;
if (str[0] == '\'')
{
while (str[i++] != '\0')
@@ -43,7 +46,10 @@ void del_quote(char *str)
if (str[i] == '\\')
i += 2;
if (str[i] == '\'')
+ {
+ nb_q++;
break ;
+ }
}
}
else if (str[0] == '"')
@@ -53,22 +59,39 @@ void del_quote(char *str)
if (str[i] == '\\')
i += 2;
if (str[i] == '"')
+ {
+ nb_q++;
break ;
+ }
}
}
- str[i] = '\0';
- ft_memmove(str, str + 1, ft_strlen(str + 1) + 1);
+ if (nb_q % 2 == 0)
+ {
+ str[i] = '\0';
+ if(!(ft_memmove(str, str + 1, ft_strlen(str + 1) + 1)))
+ return 1;
+ else
+ return 0;
+ }
+ else
+ return 2;
}
-void lexer_trim(t_tok_lst *tokens)
+int lexer_trim(t_tok_lst *tokens)
{
+ int r = 0;
while (tokens != NULL)
{
if (tokens->tag & (TAG_STR_DOUBLE | TAG_STR_SINGLE))
{
- del_quote(tokens->content);
- if (tokens->next == NULL)
- tokens->tag &= ~TAG_STICK;
+ r = del_quote(tokens->content);
+ if (r == 0)
+ {
+ if (tokens->next == NULL)
+ tokens->tag &= ~TAG_STICK;
+ }
+ else
+ return r;
}
else
{
@@ -78,4 +101,5 @@ void lexer_trim(t_tok_lst *tokens)
}
tokens = tokens->next;
}
+ return 0;
}
diff --git a/src/main.c b/src/main.c
index caa4462..daa33f3 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/13 16:11:32 by charles ### ########.fr */
+/* Updated: 2020/09/14 16:13:41 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
@@ -47,7 +47,9 @@ 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};
@@ -101,15 +103,15 @@ int main(int argc, char **argv, char **envp)
if (argc == 3 && ft_strcmp(argv[1], "-l") == 0)
{
- t_tok_lst *lex_out = lexer(argv[2]);
- if (lex_out == NULL)
- return (1);
+ t_tok_lst *lex_out;
+ r = lexer(argv[2], &lex_out);
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 = lexer(argv[2]);
+ t_tok_lst *lex_out;
+ r = lexer(argv[2], &lex_out);
if (lex_out == NULL)
return (1);
@@ -144,11 +146,12 @@ int main(int argc, char **argv, char **envp)
print_prompt();
continue;
}
- t_tok_lst *lex_out = lexer(line);
+ t_tok_lst **lex_out = NULL;
+ r = lexer(line, lex_out);
if (lex_out == NULL)
return (1);
- 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)