/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parser_process_token.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/05 21:12:15 by qmennen #+# #+# */ /* Updated: 2025/03/05 21:42:44 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" static int parser_should_expand(t_list *value) { t_token *token; char *t_val; int i; token = (t_token *)value->content; if (!token) return (0); i = 0; if (token->type != T_DQWORD && token->type != T_WORD) return (0); while (token->value[i]) { t_val = token->value; if (t_val[i] == '~' && (t_val[i + 1] == '/' || t_val[i + 1] == ' ' || t_val[i + 1] == 0) && token->type == T_WORD) return (1); else if (t_val[i] == '$' && expander_character_valid(t_val[i + 1])) return (1); else if (t_val[i] == '$' && t_val[i + 1] == '?') return (1); i++; } return (0); } //TODO: Make an exception for this `echo hey""you "" test`. here echo actually interprets "" as an extra space. Just check if its empty and surrounded by spaces or sth. Can't be asked rn char *parser_process_token(t_minishell *msh, t_list *prev, t_list *t_head) { char *str; t_token *token; t_token *p_token; if (!t_head) return (NULL); token = (t_token *)t_head->content; p_token = (t_token *)prev->content; str = NULL; if (ft_strcmp(token->value, "") == 0) return (NULL); if (parser_should_expand(t_head)) str = expander_parse_string(token->value, msh); if (!str) str = ft_strdup_safe(msh, token->value); if (str && token->type == T_WORD && ft_strchr(str, '"')) str = parser_sanitize_string(msh, str, '"'); else if (str && token->type == T_WORD && ft_strchr(str, '\'')) str = parser_sanitize_string(msh, str, '\''); return (str); }