diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/d_enum.h | 10 | ||||
-rw-r--r-- | src/m_loop_next.c | 16 | ||||
-rw-r--r-- | src/p_args.c | 4 | ||||
-rw-r--r-- | src/p_args_escape.c | 14 | ||||
-rw-r--r-- | src/p_args_quotes.c | 77 | ||||
-rw-r--r-- | src/p_args_quotes.h | 18 |
7 files changed, 26 insertions, 114 deletions
@@ -65,7 +65,6 @@ SRCS_NAME += p_args SRCS_NAME += p_args_next SRCS_NAME += p_args_len SRCS_NAME += p_args_escape -SRCS_NAME += p_args_quotes SRCS_NAME += p_line SRCS_NAME += p_lcom SRCS_NAME += p_lcom_next diff --git a/src/d_enum.h b/src/d_enum.h index 6bd82df..e5078a7 100644 --- a/src/d_enum.h +++ b/src/d_enum.h @@ -32,12 +32,12 @@ enum FT_READ_END }; -enum +typedef enum { - FT_NO_MODE, - FT_SQ_MODE, - FT_DQ_MODE -}; + Q_NONE, + Q_SINGLE, + Q_DOUBLE +} t_quote_mode; enum { diff --git a/src/m_loop_next.c b/src/m_loop_next.c index 31751f2..4bb8f78 100644 --- a/src/m_loop_next.c +++ b/src/m_loop_next.c @@ -158,13 +158,13 @@ static t_bool } static t_bool - m_find_next_quote(char **ptr, char line[], uint8_t mode) + m_find_next_quote(char **ptr, char line[], t_quote_mode mode) { char c; - if (mode == FT_NO_MODE) + if (mode == Q_NONE) return (FALSE); - c = (mode == FT_SQ_MODE) ? (C_SQUOTE) : (C_DQUOTE); + c = (mode == Q_SINGLE) ? (C_SQUOTE) : (C_DQUOTE); (*ptr) += 1; while (**ptr != C_NULL) { @@ -189,11 +189,11 @@ static t_bool static t_bool m_check_missing_quotes(char line[]) { - char *ptr; - uint8_t mode; + char *ptr; + t_quote_mode mode; ptr = line; - mode = FT_NO_MODE; + mode = Q_NONE; while (*ptr != C_NULL) { if (*ptr == C_SQUOTE || *ptr == C_DQUOTE) @@ -202,9 +202,9 @@ static t_bool ((ptr - line) >= 1 && *(ptr - 1) != C_BS) || ((ptr - line) > 1 && *(ptr - 1) == C_BS && *(ptr - 2) == C_BS)) { - mode = (*ptr == C_SQUOTE) ? (FT_SQ_MODE) : (FT_DQ_MODE); + mode = (*ptr == C_SQUOTE) ? (Q_SINGLE) : (Q_DOUBLE); if (m_find_next_quote(&ptr, line, mode) == FALSE) - mode = FT_NO_MODE; + mode = Q_NONE; else return (TRUE); } diff --git a/src/p_args.c b/src/p_args.c index 0ec391c..fa01472 100644 --- a/src/p_args.c +++ b/src/p_args.c @@ -18,7 +18,6 @@ #include "p_args.h" #include "p_args_next.h" #include "p_args_escape.h" -#include "p_args_quotes.h" /* ================= */ /* TODO: DELETE THIS */ @@ -140,8 +139,7 @@ static char p_del_alloced_words(words, to_del); return (NULL); } - p_args_escape_chars(words); - p_args_quotes(words); + p_args_escape_chars_and_quotes(words); p_print(words); return (words); } diff --git a/src/p_args_escape.c b/src/p_args_escape.c index e6c9a24..6052991 100644 --- a/src/p_args_escape.c +++ b/src/p_args_escape.c @@ -12,11 +12,21 @@ #include <stddef.h> +#include "d_define.h" + +static void + p_escape_arg(char *ptr) +{ + while (*ptr != C_NULL) + { + ptr++; + } +} + void p_args_escape_chars(char *words[]) { /* TODO: escape \ */ - /* TODO: escape $vars */ /* TODO: escape $# special vars */ /* TODO: escape my life */ char **ptr; @@ -24,7 +34,7 @@ void ptr = words; while (*ptr != NULL) { - /* if (**ptr != C_SQUOTE) */ + p_escape_arg(*ptr); ptr++; } } diff --git a/src/p_args_quotes.c b/src/p_args_quotes.c deleted file mode 100644 index e6fdd92..0000000 --- a/src/p_args_quotes.c +++ /dev/null @@ -1,77 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* p_args_quotes.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 <stdint.h> - -#include "d_define.h" - -/* static void */ -/* p_arg_squotes(char word[]) */ -/* { */ -/* char *ptr; */ - -/* ptr = word; */ -/* while ((ptr = ft_strchr(ptr, C_SQUOTE)) != NULL) */ -/* { */ -/* ft_memmove(word + (ptr - word), ptr + 1, ft_strlen(ptr + 1) + 1); */ -/* } */ -/* } */ - -static void - p_arg_dquotes(char word[]) -{ - char *ptr; - - ptr = word; - while ((ptr = ft_strchr(ptr, C_DQUOTE)) != NULL) - { - if (ptr - word == 0) - ft_memmove(word, word + 1, ft_strlen(word)); - else if (ptr - word == 1 && *(ptr - 1) == C_BS) - ptr++; - else if (ptr - word > 1 && *(ptr - 1) == C_BS && - *(ptr - 2) != C_BS) - ptr++; - else - ft_memmove(word + (ptr - word), ptr + 1, ft_strlen(ptr + 1) + 1); - } -} - -void - p_args_quotes(char *words[]) -{ - char **ptr; - char *dq_ptr; - char *sq_ptr; - - ptr = words; - dq_ptr = NULL; - sq_ptr = NULL; - while (*ptr != NULL) - { - dq_ptr = ft_strchr(*ptr, C_DQUOTE); - sq_ptr = ft_strchr(*ptr, C_SQUOTE); - if (dq_ptr != NULL && sq_ptr != NULL) - { - if (dq_ptr < sq_ptr) - p_arg_dquotes(*ptr); - } - /* if (**ptr == C_SQUOTE) */ - /* p_arg_squotes(*ptr); */ - /* else if (**ptr == C_DQUOTE) */ - /* p_arg_dquotes(*ptr); */ - ptr++; - dq_ptr = NULL; - sq_ptr = NULL; - } -} diff --git a/src/p_args_quotes.h b/src/p_args_quotes.h deleted file mode 100644 index b902438..0000000 --- a/src/p_args_quotes.h +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* p_args_quotes.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 P_ARGS_QUOTES_H -#define P_ARGS_QUOTES_H - -void p_args_quotes(char *words[]); - -#endif |