/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* p_redirs.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 #include #include "d_define.h" #include "s_lredir.h" #include "s_struct.h" #include "u_parse.h" static int32_t p_get_fd(char word, char *ptr) { char digit[255]; char *tmp; tmp = ptr; while ((tmp - word) > 0 && ft_isdigit(*tmp) == TRUE) tmp--; if ((tmp - word) != 0 && ft_iswhitespace(*tmp) == FALSE) { return (0); } else { while (tmp != ptr) { digit[tmp - word] = *tmp; tmp++; } digit[tmp - word] = C_NUL; } return (ft_atoi(digit)); } static int8_t p_get_redir(char word[], char *ptr, t_com *com) { struct s_lredir *rdr; const int32_t fd = p_get_fd(word, ptr); int8_t redir; redir = (*ptr == '>') ? (1) : (-1); redir = (redir == 1 && *(ptr + 1) == '>') ? (2) : (redir); redir = (redir == -1 && *(ptr + 1) == '<') ? (-2) : (redir); (void)com; (void)rdr; return (0); } int8_t p_redirs(char word[], t_com *com) { struct s_com *com_ptr; char *ptr; t_quote_mode mode; mode = Q_NONE; ptr = (char *)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); else if (mode == Q_NONE && (*ptr == '<' || *ptr == '>') == 1) { if (p_get_redir(word, ptr, com) != 0) return (1); ptr = word; } ptr++; } return (0); }