void ft_ls_sort(t_ls *ls, t_list **list) { ft_lstsort(list, &cmp_asc, &get_name); if (ls->options.is_ordered_by_time) ft_lstsort(list, &time_asc, &get_elem); if (ls->options.is_reverse) ft_lstrev(list); }
void ft_lstsort(t_list **lst, int (*cmp)(t_list *, t_list *)) { t_list *aux; if (*lst) if ((*lst)->next) { aux = lstdiv(*lst); ft_lstsort(lst, cmp); ft_lstsort(&aux, cmp); *lst = lstfus(*lst, aux, cmp); } }
void ft_lstsort(t_list **list, int (*cmp)(void *a_, void *b_), void *(*get_data)(t_list *e)) { t_list *head; t_list *a; t_list *b; head = *list; if ((head == NULL) || (head->next == NULL)) return ; back_split(head, &a, &b); ft_lstsort(&a, cmp, get_data); ft_lstsort(&b, cmp, get_data); *list = sorted_merge(a, b, cmp, get_data); }
int ft_lstsort(t_list **begin, BOOL (*cmp)(void *a, void *b)) { static t_list *head = NULL; t_list *curr; if (!cmp) return (1); if (!head) head = *begin; if (!(curr = *begin) || !curr->next) { head = NULL; return (1); } while (1) { if (!cmp(curr->content, curr->next->content)) { swap(&curr->content, &curr->next->content); if (curr != head) return (0); } if (ft_lstsort(&(curr->next), cmp)) return (1); } }
int main(int ac, char **av) { t_ls ls; ft_ls_init_env(&ls); ft_ls_init_options(&ls); ft_ls_parse_options(&ls, ac, av); ft_ls_parse_files(&ls, ac, av); ls.follow = 0; ft_lstsort(&(ls.errors), &cmp_asc, &get_name); ft_ls_sort(&ls, &ls.non_folders); ft_ls_sort(&ls, &ls.folders); ft_ls_process_files(ls.errors, 0); if (ls.non_folders && ls.options.is_all_files) get_max_values(ls.non_folders); ft_ls_process_files(ls.non_folders, 0); ft_ls_process_files(ls.folders, 1); return (0); }