/* ** this function will call the compar function with option */ int my_strcmp(t_my_file *s1, t_my_file *s2, char reverse, char *opt) { struct stat *buf1; struct stat *buf2; int res; if (opt[NOTSORT]) return (0); if ((buf1 = malloc(sizeof(*buf1))) == NULL || (buf2 = malloc(sizeof(*buf2))) == NULL) my_puterror(); if ((lstat(my_pathfile(s1->path, s1->name, '\0'), buf1)) == -1) my_puterrno(my_pathfile(s1->path, s1->name, '\0'), errno); if ((lstat(my_pathfile(s2->path, s2->name, '\0'), buf2)) == -1) my_puterrno(my_pathfile(s2->path, s2->name, '\0'), errno); if (opt[TIME]) res = my_strcmp_time(buf1->st_mtime, buf2->st_mtime, reverse); else if (opt[SIZE]) res = my_strcmp_size(buf1->st_size, buf2->st_size, reverse); else res = my_strcmp_name(s1->name, s2->name, reverse); free(buf1); free(buf2); return (res); }
void my_putall_l(char *str, char *path, int *count) { struct stat *buf; if (str[0] != '.') { buf = my_malloc(sizeof(*buf)); if ((lstat(my_pathfile(path, str, '\0'), buf)) == -1) (void)my_puterrno(my_pathfile(path, str, '\0'), errno); else *count += (buf->st_blocks / 2); free(buf); } }
/* ** This functionn will print our file and description */ void my_putfile(char file, t_my_file *files, char *opt, char end) { char *link; t_my_file *tmp; link = NULL; tmp = files; while (files != NULL) { if (!(opt[BACKUP] && files->name[my_strlen(files->name) - 1] == '~') && (file || opt[ALL] || !(files->name[0] == '.'))) { if (opt[LONG]) link = my_opt_l(my_pathfile(files->path, files->name, '\0'), opt); (void)my_putcolor(files->name, files->path, link, opt); } files = files->next; } if (!file && !end) my_printf("\n"); if (opt[RECURSIVE] && !opt[DIRC]) my_opt_R(tmp, opt); free(link); free(tmp); }
/* ** This function will count 1 + 1 if 42 = 13 ** In fact it will add color that all :( */ static char my_putcolor(char *file, char *path, char *link, char *opt) { struct stat *buf; if ((buf = malloc(sizeof(*buf))) == NULL) my_puterror(); if ((lstat(my_pathfile(path, file, '\0'), buf)) == -1) return (my_puterrno(my_pathfile(path, file, '\0'), errno)); my_printf(opt[QUOTE] ? "\"" : "\0"); file = opt[DIRC] && !CURR_P(path) ? my_pathfile(path, file, '\0') : file; if (my_check_color(file, link, buf, opt) == 1) { my_printf("\033[1m\033[36m%s\033[0m", file); my_printf(opt[QUOTE] ? "\" -> " : " -> "); my_putcolor(link, link[0] == '/' ? "\0" : path, NULL, opt); } else my_printf(opt[QUOTE] ? "\"\n" : "\n"); free(buf); return (0); }
void my_opt_R(t_my_file *files, char *opt) { t_my_file *tmp; tmp = files; while (tmp != NULL) { if ((opt[ALL] && !my_check_dir(tmp->name) || tmp->name[0] != '.') && tmp->type == DT_DIR) { my_printf("\n"); my_read_dir(my_pathfile(tmp->path, tmp->name, '/'), opt, 0, 1); } tmp = tmp->next; } free(tmp); }