void print_dir(t_file *dir, int file) { t_stat *st; t_file *tmp; tmp = dir; st = (t_stat *)malloc(sizeof(t_stat)); g_rec = 1; lstat(dir->path, st); if (g_flags[FLAG_L] == 1 && file == 0) ls_l(dir, 0, st); else { while (dir != NULL) { if (opt_a(dir)) col_print(dir, file, st); dir = dir->next; } } if (tmp->err || !st->st_mode & S_IXUSR) { ft_putstr("ls: "); ft_putstr(get_name(tmp->path)); ft_putendl(": Permission denied"); } free(st); }
int main (int arc, char **argv) { bool key_l = isKey_l(arc, argv); char **path = getPath(arc, argv); int pathCount = getPathCount(arc, argv); bool isFewPathes = false; if (pathCount > 1) isFewPathes = true; int i; for (i=0; i<pathCount; ++i) { //printf("key_l is %d, dir is \"%s\" \n", key_l, path[i]); DIR *directory = opendir(path[i]); if (directory == NULL) { printf("\"%s\" is file or does not exist \n",path[i]); continue; } if (isFewPathes) printf("%s:\n",path[i]); if (key_l == false) ls(directory); else ls_l(directory, path[i]); if (isFewPathes && i!=pathCount-1) printf("%s", "\n"); closedir(directory); } return 0; }
void ls_l(char *arg) { t_file file; t_file **tab; t_llu llu; llu.total = 0; if (!(fill_tab(&tab, arg, &llu))) return ; sort_tab(&tab, &llu); if (!g_d) print_total(&llu); printfilelist(tab, llu.size, arg); llu.i = 0; while (llu.i < llu.size) { file = *((t_file *)tab[llu.i]); if (g_re && S_ISDIR(file.stats.st_mode) && ft_strcmp(file.name, ".") && ft_strcmp(file.name, "..")) llu.total = 0, ft_putchar('\n'), ft_putstr(ft_burger(arg, '/', file.name)), ft_putendl(":"), ls_l(ft_burger(arg, '/', file.name)); llu.i++; } free_ls(tab, &llu); }
void ls_mult_arg(char *argv, int i) { if (i) { ft_putstr(argv); ft_putstr(":\n"); } ls_l(argv); }
void ft_ls(char **av, int ac, char *option) { if (ONLY_BIG_OPT(av[0]) || NO_OPTION_NO_ARG) ls_one(".", option); else if (IS_AN_OPTION) { if (is_only_option(av) && IS_R) recursive(".", option); else if (is_only_option(av) && (IS_L || IS_G || IS_O) && !(PRIORITY)) ls_l(".", option); else if (is_only_option(av) && (IS_A_A || IS_R_2 || IS_T || IS_1 || IS_F || IS_P)) ls_one(".", option); else the_following(&av, option, 1); } else the_following(&av, option, 0); }