summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-09 16:17:52 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-09 16:17:52 +0200
commitc68b7637d42fac3986857685980e7a7090f5a5aa (patch)
tree85d78b0a187695a7fab0124ae6c02ae12d223e91
parentIn progress (diff)
download42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.tar.gz
42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.tar.bz2
42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.tar.xz
42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.tar.zst
42-minishell-c68b7637d42fac3986857685980e7a7090f5a5aa.zip
In progress
-rw-r--r--Makefile1
-rw-r--r--src/f_fail.h1
-rw-r--r--src/f_parse.c22
-rw-r--r--src/f_parse.h18
-rw-r--r--src/m_loop.c1
-rw-r--r--src/m_minishell.c3
-rw-r--r--src/p_line.c3
-rw-r--r--src/p_split.c42
-rw-r--r--src/u_parse.c7
-rw-r--r--src/u_parse.h4
10 files changed, 82 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 929ffa5..4e890fe 100644
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,7 @@ SRCS_NAME += f_errno
SRCS_NAME += f_exec
SRCS_NAME += f_fail
SRCS_NAME += f_file
+SRCS_NAME += f_parse
SRCS_NAME += f_redir
SRCS_NAME += f_shlvl
SRCS_NAME += m_argv
diff --git a/src/f_fail.h b/src/f_fail.h
index 2e432e2..0046814 100644
--- a/src/f_fail.h
+++ b/src/f_fail.h
@@ -19,6 +19,7 @@
#include "f_errno.h"
#include "f_exec.h"
#include "f_file.h"
+#include "f_parse.h"
#include "f_redir.h"
#include "f_shlvl.h"
#include "s_struct.h"
diff --git a/src/f_parse.c b/src/f_parse.c
new file mode 100644
index 0000000..67a7bf1
--- /dev/null
+++ b/src/f_parse.c
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* f_parse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <unistd.h>
+
+void
+ f_parse_token(char c)
+{
+ ft_dprintf(STDERR_FILENO,
+ "minishell: syntax error near unexpected token `%c'",
+ c);
+}
diff --git a/src/f_parse.h b/src/f_parse.h
new file mode 100644
index 0000000..f6ac496
--- /dev/null
+++ b/src/f_parse.h
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* f_parse.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef F_PARSE_H
+#define F_PARSE_H
+
+void f_parse_token(char c);
+
+#endif
diff --git a/src/m_loop.c b/src/m_loop.c
index b3c06d0..5641686 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -34,7 +34,6 @@ static void
uint8_t previf;
p_line(line, msh);
- ft_memdel((void*)&line);
previf = 0;
ptr = msh->curr;
while (ptr != NULL)
diff --git a/src/m_minishell.c b/src/m_minishell.c
index a538041..6be605a 100644
--- a/src/m_minishell.c
+++ b/src/m_minishell.c
@@ -14,6 +14,7 @@
#include <stdint.h>
#include <unistd.h>
#include <string.h>
+#include <unistd.h>
#include <errno.h>
#include "f_fail.h"
@@ -32,7 +33,7 @@ int
if ((msh = init_msh(argv, envp)) == NULL)
{
- ft_dprintf(2, "%s\n", strerror(errno));
+ ft_dprintf(STDERR_FILENO, "%s\n", strerror(errno));
return (FT_RET_ALLOC);
}
ret = m_argv(argc, argv, msh);
diff --git a/src/p_line.c b/src/p_line.c
index d839154..cdb2fd4 100644
--- a/src/p_line.c
+++ b/src/p_line.c
@@ -59,8 +59,7 @@ static t_bool
}
void
- p_line(char line[],
- t_msh *msh)
+ p_line(char line[], t_msh *msh)
{
p_delete_comments(line);
if (p_check_whitespaces_only(line) == TRUE)
diff --git a/src/p_split.c b/src/p_split.c
index 7e2260d..25f1cc7 100644
--- a/src/p_split.c
+++ b/src/p_split.c
@@ -14,7 +14,9 @@
#include <stdlib.h>
#include <limits.h>
+#include "f_fail.h"
#include "d_define.h"
+#include "s_struct.h"
#include "u_parse.h"
#include "u_utils.h"
@@ -156,16 +158,31 @@ typedef struct s_split
} t_split;
static void
- p_meet_splitter(char *ptr, char line[], t_split sp, t_quote_mode mode)
+ p_meet_splitter(char *ptr,
+ const char line[],
+ t_split *sp,
+ t_quote_mode mode)
{
- const char c = *ptr;
-
- if (c == C_SEMIC && *ptr + 1 != C_SEMIC && *ptr + 1 != C_NUL &&
+ if (mode == Q_NONE && *ptr == C_SEMIC && *(ptr + 1) != C_SEMIC &&
u_is_not_escaped(line, ptr) == TRUE)
{
- sp.pos[sp.count] = (ptr - line);
- sp.nextif[sp.count] = 0;
- sp.count += 1;
+ sp->pos[sp->count] = (ptr - line);
+ sp->nextif[sp->count] = 0;
+ sp->count += 1;
+ }
+ else if (mode == Q_NONE && *ptr == C_AMP && *(ptr + 1) == C_AMP &&
+ (*ptr + 2) != C_PIPE && u_is_not_escaped(line, ptr) == TRUE)
+ {
+ sp->pos[sp->count] = (ptr - line);
+ sp->nextif[sp->count] = 1;
+ sp->count += 1;
+ }
+ else if (mode == Q_NONE && *ptr == C_PIPE && *(ptr + 1) == C_PIPE &&
+ *(ptr + 2) != C_PIPE && u_is_not_escaped(line, ptr) == TRUE)
+ {
+ sp->pos[sp->count] = (ptr - line);
+ sp->nextif[sp->count] = 2;
+ sp->count += 1;
}
}
@@ -180,27 +197,28 @@ static t_split
sp.nextif[0] = 0;
sp.count = 0;
mode = Q_NONE;
- ptr = line;
+ ptr = (char*)line;
while (*ptr != C_NUL)
{
if (*ptr == C_SQUOTE)
- mode = u_meet_squote(ptr, line, mode);
+ mode = u_meet_squote(line, ptr, mode);
else if (*ptr == C_DQUOTE)
- mode = u_meet_dquote(ptr, line, mode);
+ mode = u_meet_dquote(line, ptr, mode);
else if (*ptr == C_SEMIC || *ptr == C_AMP || *ptr == C_PIPE)
- p_meet_splitter(ptr, line, sp, mode);
+ p_meet_splitter(ptr, line, &sp, mode);
ptr++;
}
return (sp);
}
char
- **p_split_line(const char line[])
+ **p_split_line(char line[])
{
t_split sp;
char **words;
words = NULL;
sp = p_fill_sp(line);
+ ft_memdel((void*)&line);
return (words);
}
diff --git a/src/u_parse.c b/src/u_parse.c
index ade8dd7..b49e6ba 100644
--- a/src/u_parse.c
+++ b/src/u_parse.c
@@ -10,10 +10,13 @@
/* */
/* ************************************************************************** */
+#include <libft.h>
+
+#include "u_utils.h"
#include "d_define.h"
t_quote_mode
- u_meet_dquote(char *head, char *ptr, t_quote_mode mode)
+ u_meet_dquote(const char *head, char *ptr, t_quote_mode mode)
{
if (mode == Q_NONE)
{
@@ -34,7 +37,7 @@ t_quote_mode
}
t_quote_mode
- u_meet_squote(char *head, char *ptr, t_quote_mode mode)
+ u_meet_squote(const char *head, char *ptr, t_quote_mode mode)
{
if (mode == Q_NONE)
{
diff --git a/src/u_parse.h b/src/u_parse.h
index 631468e..8542f80 100644
--- a/src/u_parse.h
+++ b/src/u_parse.h
@@ -15,7 +15,7 @@
#include "d_define.h"
-t_quote_mode u_meet_dquote(char *head, char *ptr, t_quote_mode mode);
-t_quote_mode u_meet_squote(char *head, char *ptr, t_quote_mode mode);
+t_quote_mode u_meet_dquote(const char *head, char *ptr, t_quote_mode mode);
+t_quote_mode u_meet_squote(const char *head, char *ptr, t_quote_mode mode);
#endif