summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libft/src/ft_substr.c2
-rw-r--r--src/ft_b_echo.c33
2 files changed, 29 insertions, 6 deletions
diff --git a/libft/src/ft_substr.c b/libft/src/ft_substr.c
index 947a305..234ddc4 100644
--- a/libft/src/ft_substr.c
+++ b/libft/src/ft_substr.c
@@ -18,9 +18,7 @@ char
*ft_substr(const char *s, unsigned int start, size_t len)
{
char *nstr;
- size_t i;
- i = 0;
if (!(nstr = (char*)malloc((len + 1) * sizeof(char))))
return (NULL);
ft_strlcpy(nstr, s + start, len + 1);
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");