int gui_main(duc *duc, int argc, char *argv[]) { char *path = "."; if(argc > 0) path = argv[0]; fuzz = opt_fuzz; if(opt_palette) { char c = tolower(opt_palette[0]); if(c == 's') palette = DUC_GRAPH_PALETTE_SIZE; if(c == 'r') palette = DUC_GRAPH_PALETTE_RAINBOW; if(c == 'g') palette = DUC_GRAPH_PALETTE_GREYSCALE; if(c == 'm') palette = DUC_GRAPH_PALETTE_MONOCHROME; } int r = duc_open(duc, opt_database, DUC_OPEN_RO); if(r != DUC_OK) { duc_log(duc, DUC_LOG_FTL, "%s", duc_strerror(duc)); return -1; } dir = duc_dir_open(duc, path); if(dir == NULL) { duc_log(duc, DUC_LOG_FTL, "%s", duc_strerror(duc)); return -1; } dpy = XOpenDisplay(NULL); if(dpy == NULL) { duc_log(duc, DUC_LOG_FTL, "ERROR: Could not open display"); exit(1); } int scr = DefaultScreen(dpy); rootwin = RootWindow(dpy, scr); Window win = XCreateSimpleWindow( dpy, rootwin, 1, 1, win_w, win_h, 0, BlackPixel(dpy, scr), WhitePixel(dpy, scr)); XSelectInput(dpy, win, ExposureMask | ButtonPressMask | StructureNotifyMask | KeyPressMask | PointerMotionMask); XMapWindow(dpy, win); cs = cairo_xlib_surface_create(dpy, win, DefaultVisual(dpy, 0), win_w, win_h); cr = cairo_create(cs); graph = duc_graph_new_cairo(duc, cr); do_gui(duc, graph, dir); duc_dir_close(dir); return 0; }
void br_file_start(duc_graph *g) { struct cairo_backend_data *bd = g->backend_data; switch(bd->fmt) { case DUC_GRAPH_FORMAT_PNG: bd->cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int)g->size, (int)g->size); break; case DUC_GRAPH_FORMAT_SVG: bd->cs = cairo_svg_surface_create_for_stream(cairo_writer, bd->fout, (int)g->size, (int)g->size); break; case DUC_GRAPH_FORMAT_PDF: bd->cs = cairo_pdf_surface_create_for_stream(cairo_writer, bd->fout, (int)g->size, (int)g->size); break; default: duc_log(g->duc, DUC_LOG_FTL, "Image format not handled by cairo backend"); exit(1); } bd->cr = cairo_create(bd->cs); cairo_translate(bd->cr, g->pos_x, g->pos_y); }
int guigl_main(duc *duc, int argc, char *argv[]) { char *path = "."; if(argc > 0) path = argv[0]; fuzz = opt_fuzz; if(opt_palette) { char c = tolower(opt_palette[0]); if(c == 's') palette = DUC_GRAPH_PALETTE_SIZE; if(c == 'r') palette = DUC_GRAPH_PALETTE_RAINBOW; if(c == 'g') palette = DUC_GRAPH_PALETTE_GREYSCALE; if(c == 'm') palette = DUC_GRAPH_PALETTE_MONOCHROME; if(c == 'c') palette = DUC_GRAPH_PALETTE_CLASSIC; } int r = duc_open(duc, opt_database, DUC_OPEN_RO); if(r != DUC_OK) { duc_log(duc, DUC_LOG_FTL, "%s", duc_strerror(duc)); return -1; } dir = duc_dir_open(duc, path); if(dir == NULL) { duc_log(duc, DUC_LOG_FTL, "%s", duc_strerror(duc)); return -1; } if(!glfwInit()) { duc_log(duc, DUC_LOG_FTL, "Error initializen glfw"); return -1; } glfwWindowHint(GLFW_SAMPLES, 4); GLFWwindow* window = window = glfwCreateWindow(640, 480, "Duc", NULL, NULL);; if(window == NULL) { duc_log(duc, DUC_LOG_FTL, "Error creating glfw window"); glfwTerminate(); return -1; } glfwMakeContextCurrent(window); gladLoadGLES2Loader((GLADloadproc) glfwGetProcAddress); glfwGetFramebufferSize(window, &win_w, &win_h); double font_scale = 1.0; sc2fb(window, &font_scale, NULL); graph = duc_graph_new_opengl(duc, font_scale); glfwSetKeyCallback(window, cb_keyboard); glfwSetFramebufferSizeCallback(window, cb_winsize); glfwSetMouseButtonCallback(window, cb_mouse_button); glfwSetCursorPosCallback(window, cb_mouse_motion); glfwSetScrollCallback(window, cb_scroll); while (!glfwWindowShouldClose(window)) { draw(window); glfwWaitEvents(); } glfwTerminate(); return 0; }
static int index_main(duc *duc, int argc, char **argv) { duc_index_flags index_flags = 0; int open_flags = DUC_OPEN_RW | DUC_OPEN_COMPRESS; if(opt_force) open_flags |= DUC_OPEN_FORCE; if(opt_max_depth) duc_index_req_set_maxdepth(req, opt_max_depth); if(opt_one_file_system) index_flags |= DUC_INDEX_XDEV; if(opt_hide_file_names) index_flags |= DUC_INDEX_HIDE_FILE_NAMES; if(opt_check_hard_links) index_flags |= DUC_INDEX_CHECK_HARD_LINKS; if(opt_uncompressed) open_flags &= ~DUC_OPEN_COMPRESS; if(opt_progress) duc_index_req_set_progress_cb(req, progress_cb, NULL); if(argc < 1) { duc_log(duc, DUC_LOG_FTL, "Required index PATH missing."); return -2; } int r = duc_open(duc, opt_database, open_flags); if(r != DUC_OK) { duc_log(duc, DUC_LOG_FTL, "%s", duc_strerror(duc)); return -1; } /* Index all paths passed on the cmdline */ int i; for(i=0; i<argc; i++) { struct duc_index_report *report; report = duc_index(req, argv[i], index_flags); if(report == NULL) { duc_log(duc, DUC_LOG_WRN, "%s", duc_strerror(duc)); continue; } char siz_apparent[32], siz_actual[32]; duc_human_size(&report->size, DUC_SIZE_TYPE_APPARENT, opt_bytes, siz_apparent, sizeof siz_apparent); duc_human_size(&report->size, DUC_SIZE_TYPE_ACTUAL, opt_bytes, siz_actual, sizeof siz_actual); if(r == DUC_OK) { char dur[64]; duc_human_duration(report->time_start, report->time_stop, dur, sizeof dur); duc_log(duc, DUC_LOG_INF, "Indexed %zu files and %zu directories, (%sB apparent, %sB actual) in %s", report->file_count, report->dir_count, siz_apparent, siz_actual, dur); } else { duc_log(duc, DUC_LOG_WRN, "An error occured while indexing: %s", duc_strerror(duc)); } duc_index_report_free(report); } duc_close(duc); duc_index_req_free(req); return 0; }
duc_dir *duc_dir_open(struct duc *duc, const char *path) { /* Canonicalized path */ char *path_canon = duc_canonicalize_path(path); if(!path_canon) { duc->err = DUC_E_PATH_NOT_FOUND; return NULL; } /* Find top path in database */ char *path_try = duc_strdup(path_canon); int l = strlen(path_try); struct duc_devino devino = { 0, 0 }; while(l > 0) { path_try[l] = '\0'; struct duc_index_report *report; report = db_read_report(duc, path_try); if(report) { devino = report->devino; free(report); break; } l--; } free(path_try); if(l == 0) { duc_log(duc, DUC_LOG_FTL, "Path %s not found in database", path_canon); duc->err = DUC_E_PATH_NOT_FOUND; free(path_canon); return NULL; } struct duc_dir *dir; dir = duc_dir_new(duc, &devino); if(dir == NULL) { duc->err = DUC_E_PATH_NOT_FOUND; free(path_canon); return NULL; } char rest[DUC_PATH_MAX]; strncpy(rest, path_canon+l, sizeof rest); char *name = strtok(rest, "/"); while(dir && name) { struct duc_dirent *ent = duc_dir_find_child(dir, name); struct duc_dir *dir_next = NULL; if(ent) { dir_next = duc_dir_openent(dir, ent); } duc_dir_close(dir); dir = dir_next; name = strtok(NULL, "/"); } if(dir) { dir->path = strdup(path_canon); } free(path_canon); return dir; }
duc_dir *duc_dir_open(struct duc *duc, const char *path) { /* Canonicalized path */ char *path_canon = stripdir(path); if(!path_canon) { duc->err = DUC_E_PATH_NOT_FOUND; return NULL; } /* Find top path in database */ int l = strlen(path_canon); dev_t dev = 0; ino_t ino = 0; while(l > 0) { struct duc_index_report *report; size_t report_len; report = db_get(duc->db, path_canon, l, &report_len); if(report && report_len == sizeof(*report)) { dev = report->dev; ino = report->ino; free(report); break; } l--; while(l > 1 && path_canon[l] != '/') l--; } if(l == 0) { duc_log(duc, DUC_LOG_WRN, "Path %s not found in database", path_canon); duc->err = DUC_E_PATH_NOT_FOUND; free(path_canon); return NULL; } struct duc_dir *dir; dir = db_read_dir(duc, dev, ino); if(dir == NULL) { duc->err = DUC_E_PATH_NOT_FOUND; free(path_canon); return NULL; } char rest[PATH_MAX]; strncpy(rest, path_canon+l, sizeof rest); char *name = strtok(rest, "/"); while(dir && name) { struct duc_dirent *ent = duc_dir_find_child(dir, name); struct duc_dir *dir_next = NULL; if(ent) { dir_next = duc_dir_openent(dir, ent); } duc_dir_close(dir); dir = dir_next; name = strtok(NULL, "/"); } if(dir) { dir->path = strdup(path_canon); } return dir; }