/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/08 10:50:26 by ljiriste #+# #+# */
-/* Updated: 2024/08/08 15:34:37 by ljiriste ### ########.fr */
+/* Updated: 2024/08/22 11:30:03 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
++info->current_expand_char;
return (expand_further(expanded, *info));
}
+ if (*info->current_expand_char == '/' && info->current_entry_char == info->entry)
+ {
+ ++info->current_expand_char;
+ return (add_conformant(expanded, info));
+ }
if ((*info->current_expand_char == '?' && *info->current_entry_char != '\0')
|| *info->current_expand_char == *info->current_entry_char)
{
DIR *dir;
struct dirent *dir_entry;
- dir = opendir(info->path);
+ if (info->path[0] == '\0')
+ dir = opendir("./");
+ else
+ dir = opendir(info->path);
if (!dir)
return (0);
dir_entry = readdir(dir);
str[0][ft_strlen(*str) - 1] = '\0';
if (ft_vec_init(&matched, sizeof(char *)) != success)
return (1);
+ info.to_expand = *str;
if (str[0][0] == '/')
info.path = ft_strdup("/");
- else if (str[0][0] == '~')
- info.path = ft_strjoin(get_env_var_value(env, "HOME"), "/");
+ else if (str[0][0] == '~' && (ft_isalpha(str[0][1]) || str[0][1] == '/' || str[0][1] == '~' || str[0][1] == '+' || str[0][1] == '-'))
+ {
+ 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("./");
+ info.path = ft_strdup("");
if (!info.path)
return (1);
- info.to_expand = *str;
+ if (info.path[0] && ft_strchr("/~", info.path[0]) != NULL)
+ ++info.to_expand;
res = expand_dir(&matched, &info);
res = res || (ft_vec_append(&matched, &nullptr) != success);
res = res || replace_str_by_joint_split(str, matched.vec);