t_file *to_tab(const char *name, int opt, DIR *dir, struct dirent *dir_p) { t_file *file; struct stat *f_stat; struct passwd *f_user; if ((file = (t_file*)malloc(sizeof(t_file))) == NULL || (f_stat = (struct stat*)malloc(sizeof(struct stat))) == NULL || (f_user = (struct passwd*)malloc(sizeof(struct passwd))) == NULL) return (NULL); if ((dir_p = readdir(dir)) != NULL) { file->prev = NULL; lstat(name, f_stat); file->type = dir_p->d_type; file->mode = get_mode(f_stat->st_mode); file->lnk_nb = f_stat->st_nlink; f_user = getpwuid(f_stat->st_uid); file->uid = f_user->pw_name; file->modif = f_stat->st_mtime; file->disp_date = ctime((const time_t*)&(f_stat->st_mtime)); file->name = dir_p->d_name; file->next = to_tab(name, opt, dir, dir_p); file->next->prev = file; return (file); } closedir(dir); while (file->prev != NULL) file = file->prev; return (file); }
int display_dir(const char *name, int opt) { DIR *dir; struct dirent *dir_p; t_file *file; if ((dir = opendir(name)) == NULL) { ft_putstr(name); ft_putendl(" : directory can't be opened"); exit (FAILURE); } if (opt == 1 && name[0] == '.' && name[1] == '\0') { while ((dir_p = readdir(dir)) != NULL) { if (dir_p->d_name[0] != '.') ft_putendl(dir_p->d_name); } return (SUCCESS); } dir_p = NULL; file = (opt % 3 == 0) ? to_tab(name, opt, dir, dir_p) : NULL; if (file != NULL) display_long(file, opt); else if (opt % 3 != 0 && opt % 2 == 0) { while ((dir_p = readdir(dir)) != NULL) ft_putendl(dir_p->d_name); } else if (opt % 3 != 0 && opt % 2 == 0) { while ((dir_p = readdir(dir)) != NULL) { if (dir_p->d_name[0] != '.') ft_putendl(dir_p->d_name); } } return (SUCCESS); }
int boucle() { t_mlx ml; int **tab; int count; tab = to_tab(); while (tab[0][count] != 123456789) count++; ml.mlx_ptr = mlx_init(); ml.win_ptr = mlx_new_window(ml.mlx_ptr, 1000, 1000, "Fil de fer"); ml.img = mlx_new_image(ml.mlx_ptr, 1000, 1000); ml.data = mlx_get_data_addr(ml.img, &ml.bpp, &ml.size, &ml.endian); put_quadri(&ml, count, tab); put_quadri_two(&ml, count, tab); mlx_put_image_to_window(ml.mlx_ptr, ml.win_ptr, ml.img, 0, 0); mlx_expose_hook(ml.win_ptr, gere_expose, &ml); mlx_mouse_hook(ml.win_ptr, gere_mouse, &ml); mlx_key_hook(ml.win_ptr, gere_key, &ml); mlx_loop(ml.mlx_ptr); return (0); }