int ft_tab(t_data *d) { char *path; DIR *dirp; char **result; char *name; char *tmp; if (!d->line->str || !(path = ft_search_path(d->line->str, d->line->index))) return (1); tmp = ft_preg_replace("\\", "", path); if (!(dirp = opendir(tmp))) { ft_strdel(&path); return (1); } ft_strdel(&tmp); name = ft_get_name(d->line->str, d->line->index); result = ft_search_files(dirp, name); ft_bubble_sort_str(result); ft_completion(d, result, name); closedir(dirp); ft_strdel(&path); ft_strdel(&name); ft_tabdel(&result); return (1); }
static char *ft_strnew_path(char *str, char **envp) { int i; char *tmp; char **path; i = 0; if (access(str, X_OK) != -1) return (str); path = ft_search_path(envp); while (path[i] != NULL) { tmp = ft_file_strjoin(path[i], str); if (access(tmp, X_OK) != -1) { ft_strdel(path); ft_strdel(&str); return (tmp); } i++; ft_strdel(&tmp); } ft_strdel(path); return (NULL); }