summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-06 17:56:59 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-06 17:56:59 +0200
commitab69117ff18f8b4a2b13adeada00cabd7d997855 (patch)
treeda037207d06d1bb53bd059504ab98c810450ae07
parentI'm lost (diff)
download42-minishell-ab69117ff18f8b4a2b13adeada00cabd7d997855.tar.gz
42-minishell-ab69117ff18f8b4a2b13adeada00cabd7d997855.tar.bz2
42-minishell-ab69117ff18f8b4a2b13adeada00cabd7d997855.tar.xz
42-minishell-ab69117ff18f8b4a2b13adeada00cabd7d997855.tar.zst
42-minishell-ab69117ff18f8b4a2b13adeada00cabd7d997855.zip
Better defines
-rw-r--r--src/d_define.h5
-rw-r--r--src/m_loop_next.c16
-rw-r--r--src/p_args.c5
-rw-r--r--src/p_args_escape.c13
-rw-r--r--src/p_args_len.c18
-rw-r--r--src/u_utils.c4
6 files changed, 32 insertions, 29 deletions
diff --git a/src/d_define.h b/src/d_define.h
index ef980c6..5c10526 100644
--- a/src/d_define.h
+++ b/src/d_define.h
@@ -68,8 +68,9 @@
#define C_SQUOTE 0x27
#define C_DQUOTE 0x22
-#define C_BS 0x5c
-#define C_NULL 0x00
+#define C_BACKS 0x5c
+#define C_NUL 0x00
+#define C_SUB 0x1a
/*
** ====== FILES ======
diff --git a/src/m_loop_next.c b/src/m_loop_next.c
index fb95236..d138206 100644
--- a/src/m_loop_next.c
+++ b/src/m_loop_next.c
@@ -28,7 +28,7 @@ static char
if (fd == STDIN_FILENO)
m_prompt_psx(psx, msh);
get_next_line(fd, &counter_line);
- if (counter_line[0] != C_NULL)
+ if (counter_line[0] != C_NUL)
{
line = ft_nrealloc(line,
ft_strlen(line) + 1,
@@ -49,7 +49,7 @@ static char
if (fd == STDIN_FILENO)
m_prompt_psx(psx, msh);
get_next_line(fd, &counter_line);
- if (counter_line[0] != C_NULL)
+ if (counter_line[0] != C_NUL)
{
line = ft_nrealloc(line,
ft_strlen(line) + 1,
@@ -70,7 +70,7 @@ static char
if (fd == STDIN_FILENO)
m_prompt_psx(psx, msh);
get_next_line(fd, &counter_line);
- if (counter_line[0] != C_NULL)
+ if (counter_line[0] != C_NUL)
{
line = ft_nrealloc(line,
ft_strlen(line) + 1,
@@ -147,8 +147,8 @@ static t_bool
m_check_dquote(char **ptr, char line[])
{
if (((*ptr - line) == 0) ||
- ((*ptr - line) == 1 && *(*ptr - 1) == C_BS) ||
- ((*ptr - line) > 1 && *(*ptr - 1) == C_BS && *(*ptr - 2) != C_BS))
+ ((*ptr - line) == 1 && *(*ptr - 1) == C_BACKS) ||
+ ((*ptr - line) > 1 && *(*ptr - 1) == C_BACKS && *(*ptr - 2) != C_BACKS))
{
return (FALSE);
}
@@ -167,14 +167,14 @@ static t_bool
return (FALSE);
c = (mode == Q_SINGLE) ? (C_SQUOTE) : (C_DQUOTE);
(*ptr) += 1;
- while (**ptr != C_NULL)
+ while (**ptr != C_NUL)
{
if (**ptr == c && c == C_DQUOTE)
{
if (m_check_dquote(ptr, line) == FALSE)
{
(*ptr)++;
- if (**ptr == C_NULL)
+ if (**ptr == C_NUL)
break ;
}
else
@@ -195,7 +195,7 @@ static t_bool
ptr = line;
mode = Q_NONE;
- while (*ptr != C_NULL)
+ while (*ptr != C_NUL)
{
if (*ptr == C_SQUOTE || *ptr == C_DQUOTE)
{
diff --git a/src/p_args.c b/src/p_args.c
index ee2b937..7d5a579 100644
--- a/src/p_args.c
+++ b/src/p_args.c
@@ -96,7 +96,7 @@ static t_bool
static char
*p_skip_whitespace(char *ptr)
{
- while (*ptr != C_NULL && ft_iswhitespace(*ptr))
+ while (*ptr != C_NUL && ft_iswhitespace(*ptr))
ptr++;
return (ptr);
}
@@ -113,8 +113,9 @@ static uint16_t
count = 1;
ptr = p_skip_whitespace(ptr);
start[0] = (ptr - word);
- while (*ptr != C_NULL)
+ while (*ptr != C_NUL)
{
+ if (*ptr == C_BACKS)
if (*ptr == C_DQUOTE)
mode = p_meet_dquote((char*)word, ptr, mode);
else if (*ptr == C_SQUOTE)
diff --git a/src/p_args_escape.c b/src/p_args_escape.c
index 8a2e27f..ae96bb0 100644
--- a/src/p_args_escape.c
+++ b/src/p_args_escape.c
@@ -77,15 +77,16 @@ static void
{
(void)ft_memmove(word + (ptr - word), ptr + 1,
(ft_strlen(ptr + 1) + 1) * sizeof(char));
- if (*ptr == C_BS)
+ if (*ptr == C_BACKS)
{
*(word + (ptr - word)) = 26;
+ ft_printf("%s\n", word);
}
*(p) -= 1;
}
else if (mode == Q_DOUBLE)
{
- if (*(ptr + 1) == C_BS)
+ if (*(ptr + 1) == C_BACKS)
{
(void)ft_memmove(word + (ptr - word), ptr + 1,
(ft_strlen(ptr + 1) + 1) * sizeof(char));
@@ -109,13 +110,13 @@ static void
ptr = word;
mode = Q_NONE;
- while (*ptr != C_NULL)
+ while (*ptr != C_NUL)
{
if (*ptr == C_SQUOTE)
mode = p_escape_squote(ptr, &ptr, word, mode);
else if (*ptr == C_DQUOTE)
mode = p_escape_dquote(ptr, &ptr, word, mode);
- if (*ptr == C_BS)
+ if (*ptr == C_BACKS)
p_escape_bs(ptr, &ptr, word, mode);
ptr++;
}
@@ -124,10 +125,10 @@ static void
static void
p_replace_bs(char *ptr)
{
- while (*ptr != C_NULL)
+ while (*ptr != C_NUL)
{
if (*ptr == 26)
- *ptr = C_BS;
+ *ptr = C_BACKS;
ptr++;
}
}
diff --git a/src/p_args_len.c b/src/p_args_len.c
index c736a3a..801406f 100644
--- a/src/p_args_len.c
+++ b/src/p_args_len.c
@@ -21,18 +21,18 @@ static size_t
end++;
if (word[end] == c)
return (end + 1);
- while (word[end] != C_NULL && word[end] != c)
+ while (word[end] != C_NUL && word[end] != c)
{
end++;
if (word[end] == c && c == C_DQUOTE)
{
- if (word[end - 1] == C_BS && word[end - 2] != C_BS)
+ if (word[end - 1] == C_BACKS && word[end - 2] != C_BACKS)
{
end++;
}
}
}
- if (word[end] != C_NULL)
+ if (word[end] != C_NUL)
{
end++;
}
@@ -42,16 +42,16 @@ static size_t
static size_t
p_skip_unquote(const char word[], size_t end)
{
- while (word[end] != C_NULL && ft_iswhitespace(word[end]) == FALSE)
+ while (word[end] != C_NUL && ft_iswhitespace(word[end]) == FALSE)
{
end++;
if (ft_iswhitespace(word[end]) == TRUE && end == 1 &&
- word[end - 1] == C_BS)
+ word[end - 1] == C_BACKS)
{
end++;
}
else if (ft_iswhitespace(word[end]) == TRUE && end > 1 &&
- word[end - 1] == C_BS && word[end - 2] != C_BS)
+ word[end - 1] == C_BACKS && word[end - 2] != C_BACKS)
{
end++;
}
@@ -62,7 +62,7 @@ static size_t
static size_t
p_skip_quote(const char word[], size_t end)
{
- while (word[end] != C_NULL && ft_iswhitespace(word[end]) == FALSE)
+ while (word[end] != C_NUL && ft_iswhitespace(word[end]) == FALSE)
{
if (word[end] == C_SQUOTE || word[end] == C_DQUOTE)
{
@@ -70,7 +70,7 @@ static size_t
}
else
{
- while (word[end] != C_NULL &&
+ while (word[end] != C_NUL &&
ft_iswhitespace(word[end]) == FALSE)
{
end++;
@@ -87,7 +87,7 @@ size_t
end = start;
if (word[start] != C_SQUOTE && word[start] != C_DQUOTE &&
- word[start] != C_NULL)
+ word[start] != C_NUL)
{
end = p_skip_unquote(word, end);
}
diff --git a/src/u_utils.c b/src/u_utils.c
index fb1dcf6..7f75c4d 100644
--- a/src/u_utils.c
+++ b/src/u_utils.c
@@ -23,8 +23,8 @@ t_bool
u_is_not_escaped(char *head, char *ptr)
{
if (((ptr - head) == 0) ||
- ((ptr - head) >= 1 && *(ptr - 1) != C_BS) ||
- ((ptr - head) > 1 && *(ptr - 1) == C_BS && *(ptr - 2) == C_BS))
+ ((ptr - head) >= 1 && *(ptr - 1) != C_BACKS) ||
+ ((ptr - head) > 1 && *(ptr - 1) == C_BACKS && *(ptr - 2) == C_BACKS))
return (TRUE);
return (FALSE);
}