summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-03 14:50:05 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-03 14:50:05 +0200
commit21e8d2c8587aef5717727094d23d87feffeb1f71 (patch)
tree6ecd96827636a02d8362768e59901a654704d343
parentNormed p_subst_alias (diff)
download42-minishell-21e8d2c8587aef5717727094d23d87feffeb1f71.tar.gz
42-minishell-21e8d2c8587aef5717727094d23d87feffeb1f71.tar.bz2
42-minishell-21e8d2c8587aef5717727094d23d87feffeb1f71.tar.xz
42-minishell-21e8d2c8587aef5717727094d23d87feffeb1f71.tar.zst
42-minishell-21e8d2c8587aef5717727094d23d87feffeb1f71.zip
Normed stuff
Diffstat (limited to '')
-rw-r--r--Makefile1
-rw-r--r--src/p_lblock_next.c69
-rw-r--r--src/p_lblock_next.h3
-rw-r--r--src/p_subst_vars.c82
-rw-r--r--src/p_subst_vars.h20
-rw-r--r--src/s_com.c1
6 files changed, 105 insertions, 71 deletions
diff --git a/Makefile b/Makefile
index 4904816..a3b9894 100644
--- a/Makefile
+++ b/Makefile
@@ -82,6 +82,7 @@ SRCS_NAME += p_redirs_heredoc
SRCS_NAME += p_split
SRCS_NAME += p_subst_alias
SRCS_NAME += p_subst_home
+SRCS_NAME += p_subst_vars
SRCS_NAME += u_alias
SRCS_NAME += u_parse
SRCS_NAME += u_path
diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c
index 9def230..485d4ee 100644
--- a/src/p_lblock_next.c
+++ b/src/p_lblock_next.c
@@ -26,75 +26,6 @@
#include "u_vars.h"
#include "u_vars_next.h"
-static char *p_double_them_bs(char varval[])
-{
- char *ptr;
-
- ptr = varval;
- while (*ptr != C_NUL)
- {
- if (*ptr == C_BACKS)
- {
- ptr = ft_memmove(ptr + 1, ptr, ft_strlen(ptr) + 1);
- varval[ptr - varval] = C_BACKS;
- }
- ptr++;
- }
- return (varval);
-}
-
-static void p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh)
-{
- char tmp[ARG_MAX];
- char varval[ARG_MAX];
- char *ptr;
- size_t varlen;
-
- ptr = word;
- varlen = i + 1;
- while (ptr[varlen] != C_NUL &&
- ft_ischarset("$=\\/@%^*+{}[]<>(),.-", ptr[varlen]) == FALSE &&
- ft_iswhitespace(ptr[varlen]) == FALSE)
- varlen += 1;
- ft_strlcpy(tmp, ptr + i, varlen + 1 - i);
- u_get_var_value(varval, tmp, ARG_MAX, msh);
- p_double_them_bs(varval);
- (void)ft_memmove(ptr + (i + ft_strlen(varval)),
- ptr + varlen,
- (ft_strlen(ptr + varlen) + 1) * sizeof(char));
- (void)ft_memmove(word + i, varval, ft_strlen(varval) * sizeof(char));
- *(p) = word + (i + ft_strlen(varval) - 1);
-}
-
-void p_subst_vars(char word[], t_msh *msh)
-{
- char *ptr;
- t_quote_mode mode;
-
- mode = Q_NONE;
- ptr = word;
- while (*ptr != C_NUL)
- {
- if (*ptr == C_DQUOTE)
- mode = u_meet_dquote(word, ptr, mode);
- else if (*ptr == C_SQUOTE)
- mode = u_meet_squote(word, ptr, mode);
- if ((mode == Q_NONE || mode == Q_DOUBLE) && *ptr == C_DOLLAR &&
- u_is_not_escaped(word, ptr) == TRUE)
- {
- p_subst_this_var(&ptr, (ptr - word), word, msh);
- }
- ptr++;
- }
-}
-
-
-
-
-
-
-
-
static char **p_alloc_rewords(char *words[], int64_t j, t_msh *msh)
{
char **rewords;
diff --git a/src/p_lblock_next.h b/src/p_lblock_next.h
index 5d8aeb8..fecb50f 100644
--- a/src/p_lblock_next.h
+++ b/src/p_lblock_next.h
@@ -18,8 +18,7 @@
# include "s_struct.h"
-void p_subst_vars(char word[], t_msh *msh);
-char **p_subst_args(const char word[], int8_t redir);
+/* char **p_subst_args(const char word[], int8_t redir); */
char **p_check_args_equals(char *words[], t_msh *msh);
#endif
diff --git a/src/p_subst_vars.c b/src/p_subst_vars.c
new file mode 100644
index 0000000..47f250b
--- /dev/null
+++ b/src/p_subst_vars.c
@@ -0,0 +1,82 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* p_subst_vars.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 <stddef.h>
+
+#include "d_define.h"
+#include "s_struct.h"
+#include "u_parse.h"
+#include "u_utils.h"
+#include "u_vars.h"
+
+static char *p_double_them_bs(char varval[])
+{
+ char *ptr;
+
+ ptr = varval;
+ while (*ptr != C_NUL)
+ {
+ if (*ptr == C_BACKS)
+ {
+ ptr = ft_memmove(ptr + 1, ptr, ft_strlen(ptr) + 1);
+ varval[ptr - varval] = C_BACKS;
+ }
+ ptr++;
+ }
+ return (varval);
+}
+
+static void p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh)
+{
+ char tmp[ARG_MAX];
+ char varval[ARG_MAX];
+ char *ptr;
+ size_t varlen;
+
+ ptr = word;
+ varlen = i + 1;
+ while (ptr[varlen] != C_NUL &&
+ ft_ischarset("$=\\/@%^*+{}[]<>(),.-", ptr[varlen]) == FALSE
+ && ft_iswhitespace(ptr[varlen]) == FALSE)
+ varlen += 1;
+ ft_strlcpy(tmp, ptr + i, varlen + 1 - i);
+ u_get_var_value(varval, tmp, ARG_MAX, msh);
+ p_double_them_bs(varval);
+ (void)ft_memmove(ptr + (i + ft_strlen(varval)),
+ ptr + varlen,
+ (ft_strlen(ptr + varlen) + 1) * sizeof(char));
+ (void)ft_memmove(word + i, varval, ft_strlen(varval) * sizeof(char));
+ *(p) = word + (i + ft_strlen(varval) - 1);
+}
+
+void p_subst_vars(char word[], t_msh *msh)
+{
+ char *ptr;
+ t_quote_mode mode;
+
+ mode = Q_NONE;
+ ptr = word;
+ while (*ptr != C_NUL)
+ {
+ if (*ptr == C_DQUOTE)
+ mode = u_meet_dquote(word, ptr, mode);
+ else if (*ptr == C_SQUOTE)
+ mode = u_meet_squote(word, ptr, mode);
+ if ((mode == Q_NONE || mode == Q_DOUBLE) && *ptr == C_DOLLAR &&
+ u_is_not_escaped(word, ptr) == TRUE)
+ {
+ p_subst_this_var(&ptr, (ptr - word), word, msh);
+ }
+ ptr++;
+ }
+}
diff --git a/src/p_subst_vars.h b/src/p_subst_vars.h
new file mode 100644
index 0000000..6f6716e
--- /dev/null
+++ b/src/p_subst_vars.h
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* p_subst_vars.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 FT_P_SUBST_VARS_H
+# define FT_P_SUBST_VARS_H
+
+# include "s_struct.h"
+
+void p_subst_vars(char word[], t_msh *msh);
+
+#endif
diff --git a/src/s_com.c b/src/s_com.c
index 2927a51..9dc8309 100644
--- a/src/s_com.c
+++ b/src/s_com.c
@@ -21,6 +21,7 @@
#include "p_lblock_next.h"
#include "p_subst_alias.h"
#include "p_subst_home.h"
+#include "p_subst_vars.h"
#include "p_redirs.h"
#include "s_lredir.h"
#include "s_struct.h"