/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* s_lpipes_split.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #ifdef __linux__ # include #else # include #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[], short 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; unsigned short i; ptr = (char*)word; mode = Q_NONE; i = 1; while (*ptr != C_NUL && (unsigned short)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++; } }