summaryrefslogtreecommitdiffstats
path: root/src/ft_b_echo.c
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-04-27 19:39:19 +0200
committersalad <fmoenne-@student.le-101.fr>2020-04-27 19:39:19 +0200
commitf00e66cd06e678b133cc1d086ff5d1f620ec4941 (patch)
treeb38a42a0ab7e988608b5d402473551c379f654b7 /src/ft_b_echo.c
parentmerge master into fmoenne (diff)
download42-minishell-f00e66cd06e678b133cc1d086ff5d1f620ec4941.tar.gz
42-minishell-f00e66cd06e678b133cc1d086ff5d1f620ec4941.tar.bz2
42-minishell-f00e66cd06e678b133cc1d086ff5d1f620ec4941.tar.xz
42-minishell-f00e66cd06e678b133cc1d086ff5d1f620ec4941.tar.zst
42-minishell-f00e66cd06e678b133cc1d086ff5d1f620ec4941.zip
backslashes as intended, multiline quotes vont me tuer
Diffstat (limited to '')
-rw-r--r--src/ft_b_echo.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/ft_b_echo.c b/src/ft_b_echo.c
index 6b410b3..7d21811 100644
--- a/src/ft_b_echo.c
+++ b/src/ft_b_echo.c
@@ -22,6 +22,22 @@
/* echo kill\nbackslash\nbut\nnot\nn, echo "quoted\nnew\nlines" */
/* Might need to go full buffer */
+void
+ft_e_put(char *str,
+ uint8_t op)
+{
+ size_t i;
+
+ i = -1;
+ if (op == 0)
+ while (str[++i])
+ {
+ if (str[i] == '\\')
+ i++;
+ ft_putchar(str[i]);
+ }
+}
+
char
*ft_e_initb(char *ptr[],
char *str)
@@ -35,14 +51,16 @@ char
{
len += ft_strlen(ptr[i]);
}
- if (!(str = malloc(len * sizeof(char))))
+ if (!(str = (char*)malloc(len * sizeof(char))))
return (NULL);
return (str);
}
void
-ft_e_fill(char *ptr[], char **str)
+ ft_e_fill(char *ptr[], char **str)
{
+ char *bs;
+
ft_sprintf(*str, "%s", *ptr);
ptr++;
while (*ptr)
@@ -50,7 +68,15 @@ ft_e_fill(char *ptr[], char **str)
ft_sprintf(*str + ft_strlen(*str), " %s", *ptr);
ptr++;
}
- *str = ft_strtrim(*str, "\"\'");
+ if (*str[0] == '\"' || *str[0] == '\'')
+ {
+ *str = ft_strtrim(*str, "\"\'");
+ ft_printf("%s", *str);
+ }
+ else if ((bs = ft_strrchr(*str, '\\')))
+ {
+ ft_e_put(*str, 0);
+ }
}
uint8_t
@@ -77,7 +103,6 @@ uint8_t
if (argc - nopt >= 1)
ft_e_fill(ptr, &str);
}
- ft_printf("%s", str);
free(str);
if (nopt == 0)
ft_printf("\n");