/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/08 10:50:26 by ljiriste #+# #+# */
-/* Updated: 2024/08/22 11:30:03 by ljiriste ### ########.fr */
+/* Updated: 2024/08/22 13:02:23 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
if (str[0][1] == '/' || str[0][1] == '\0')
info.path = ft_strdup(get_env_var_value(env, "HOME"));
else
- {
- ft_printf("Advanced tilde expansion not implemented.\n");
return (1);
- }
}
else
info.path = ft_strdup("");
return (res);
}
+int should_be_expanded(const char *word)
+{
+ size_t i;
+ char quote_char;
+
+ quote_char = '\0';
+ i = 0;
+ while (word[i])
+ {
+ if ((word[i] == '*' || word[i] == '?') && quote_char == '\0')
+ return (1);
+ if (word[i] == '"')
+ {
+ if (quote_char == '\0')
+ quote_char = '"';
+ else if (quote_char == '"')
+ quote_char = '\0';
+ }
+ if (word[i] == '\'')
+ {
+ if (quote_char == '\0')
+ quote_char = '\'';
+ else if (quote_char == '\'')
+ quote_char = '\0';
+ }
+ ++i;
+ }
+ return (0);
+}
+
int expand_wildcards(char **input, const t_execution_env *env)
{
char **split;
i = 0;
while (split[i])
{
- if (split[i][0] != '"' && split[i][0] != '\'' && (ft_strchr(split[i], '*') != NULL || ft_strchr(split[i], '?') != NULL))
+ if (should_be_expanded(split[i]))
if (expand_word(split + i, env))
{
ft_free_split(split);