diff options
Diffstat (limited to 'src/s_lpipes_split.c')
-rw-r--r-- | src/s_lpipes_split.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/s_lpipes_split.c b/src/s_lpipes_split.c index da23f47..4da4a03 100644 --- a/src/s_lpipes_split.c +++ b/src/s_lpipes_split.c @@ -13,20 +13,54 @@ #include <libft.h> #include <stdlib.h> #include <stdint.h> +#ifdef __linux__ +# include <linux/limits.h> +#else +# include <limits.h> +#endif #include "d_define.h" #include "d_enum.h" +#include "u_parse.h" +#include "u_utils.h" + +void s_set_tmp(char tmp[], size_t pos[], int16_t i, const char word[]) +{ + if (pos[i] != 0) + ft_strlcpy(tmp, + word + ((pos[i - 1] == 0) ? (0) : (pos[i - 1] + 1)), + pos[i] - ((pos[i - 1] == 0) ? (0) : (pos[i - 1])) + + ((pos[i - 1] == 0) ? (1) : (0))); + else + ft_strlcpy(tmp, + word + ((pos[i - 1] == 0) ? (0) : (pos[i - 1] + 1)), + ARG_MAX - pos[i] + 1); +} void s_get_split_pos(size_t pos[], const char word[]) { char *ptr; t_quote_mode mode; - uint8_t i; + uint16_t i; ptr = (char*)word; mode = Q_NONE; - i = 0; - while (*ptr != C_NUL) + i = 1; + while (*ptr != C_NUL && (uint16_t)i < 256) { + if (*ptr == C_PIPE) + { + if (mode == Q_NONE && u_is_not_escaped(word, ptr) == TRUE + && *(ptr + 1) != C_PIPE && *(ptr - 1) != C_PIPE) + { + pos[i] = (ptr - word); + i++; + } + } + if (*ptr == C_DQUOTE) + mode = u_meet_dquote(word, ptr, mode); + else if (*ptr == C_SQUOTE) + mode = u_meet_squote(word, ptr, mode); + ptr++; } } |