int my_ls(char *d, char *options) { DIR *dir; t_dirent *file; t_list *list; char *tmp; list = NULL; dir = opendir(d); check_dir_functions(d, dir, 0); while (file = readdir(dir)) { if (file->d_name[0] != '.') { if (find_in_tab(options, 'l') == 0 || find_in_tab(options, 'd') == 0) launch_options(file, options, &list, d); else my_put_in_list(&list, file->d_name, file->d_type, d); } } check_dir_functions(d, dir, 1); if (find_in_tab(options, 'l') == 0) clean_list_syntax(list); my_sort_list(list, options); my_show_long_list(list, options, d); return (0); }
void launch_ls(t_list *f_list, t_list *ptr, char *options, int cpt) { while (cpt < my_list_size(f_list)) { if (my_list_size(f_list) > 2 && find_in_tab(options, 'd') != 0) my_printf("%s:\n", ptr->name); { my_ls(ptr->name, options); } if (cpt + 1 < my_list_size(f_list) && (my_list_size(f_list) > 2 && find_in_tab(options, '1') == 0 && find_in_tab(options, 'd') != 0 || options[0] == '\0')) { my_putstr("\n"); } if (cpt + 1 == my_list_size(f_list) && find_in_tab(options, 'd') == 0 && find_in_tab(options, 'l') != 0) { my_putstr("\n"); } if (cpt + 1 != my_list_size(f_list) && find_in_tab(options, 'l') == 0 && find_in_tab(options, 'd') != 0 && find_in_tab(options, '1') != 0) my_putstr("\n"); ptr = ptr->next; cpt = cpt + 1; } }
int add_to_tab(int *tab, int nb) { int i; int ret; i = 0; if ((ret = find_in_tab(tab, nb, &i)) == 0) { tab[i] = nb; return (1); } else if (ret == 1) return (remove_from_tab(tab, i)); else return (-1); }
int main(int ac, char **av) { char *options; t_list *f_list; t_list *ptr; f_list = NULL; ptr = malloc(sizeof(*ptr)); options = malloc(sizeof(*options) * 4); options = "ldr1"; options = find_options(av, options, 0, 1); f_list = create_list(f_list, av, 0, 1); ptr = f_list; if (my_list_size(f_list) == 1) { my_ls(".", options); if (find_in_tab(options, 'd') == 0) my_putchar('\n'); } else launch_ls(f_list, ptr, options, 1); // free(options); return (0); }