/** * 根据dirpath指定的路径解析路径目录下的所有文件 * t指定文件类型。 * 返回有向图。 */ digraph* create_digraph(const char* dirpath, src_t t) { base_path = dirpath; switch (t) { case CPP_T: case C_T: parse_fun = parse_c_cpp; break; case JAVA_T: parse_fun = parse_java; break; case CSHARP_T: parse_fun = parse_csharp; break; default: log_err("Unknown src type. %s %d", __FILE__, __LINE__); exit(1); } //初始化目录树 pt = path_tree_init(); path_tree_add(pt, dirpath); int cnt = parse_dir(dirpath); //path_tree_print(pt); buffer_array *all_paths = path_tree_get_all_paths(pt); buffer_array *include_paths; path_tree_node_t *including_ptn; buffer *simple_path; digraph *dg = digraph_init(); size_t i, j; for (i = 0; i < all_paths -> used; ++i) { include_paths = parse_fun(all_paths -> ptr[i] -> ptr); for (j = 0; j < include_paths -> used; ++j) { simple_path = path_tree_simple_path(pt, include_paths -> ptr[j] -> ptr); //log_info("build egde: %s -> %s", all_paths -> ptr[i] -> ptr, include_paths -> ptr[j] -> ptr); if (NULL != simple_path) { digraph_build_edge_string(dg, all_paths -> ptr[i] -> ptr, simple_path -> ptr); } else { digraph_build_edge_string(dg, all_paths -> ptr[i] -> ptr, include_paths -> ptr[j] -> ptr); } buffer_free(simple_path); //digraph_show(dg); } buffer_array_free(include_paths); } buffer_array_free(all_paths); log_info("Return digraph."); return dg; }
/** * 删除缓存, 并释放资源 */ static int cache_delete(size_t pos) { cache_image_t *p; cache_lock(); p = &ccacher.caches[pos]; if (p->data != NULL) { dbg_printf(d, "%s: data 0x%08x", __func__, (unsigned) p->data); free(p->data); p->data = NULL; } if (p->exif_array) { buffer_array_free(p->exif_array); p->exif_array = NULL; } if (p->status == CACHE_OK) { ccacher.memory_usage -= p->width * p->height * sizeof(pixel); } memmove(&ccacher.caches[pos], &ccacher.caches[pos + 1], (ccacher.caches_size - pos - 1) * sizeof(ccacher.caches[0])); ccacher.caches_size--; cache_unlock(); return 0; }
static void cache_clear(void) { int i; cache_lock(); for (i = 0; i < ccacher.caches_size; ++i) { if (ccacher.caches[i].data != NULL) { dbg_printf(d, "%s: %d data 0x%08x", __func__, i, (unsigned) ccacher.caches[i].data); free(ccacher.caches[i].data); ccacher.caches[i].data = NULL; } if (ccacher.caches[i].exif_array) { buffer_array_free(ccacher.caches[i].exif_array); ccacher.caches[i].exif_array = NULL; } if (ccacher.caches[i].status == CACHE_OK) { ccacher.memory_usage -= ccacher.caches[i].width * ccacher.caches[i].height * sizeof(pixel); } } ccacher.caches_size = 0; cacher_cleared = true; cache_unlock(); }
static void free_cache_image(cache_image_t * p) { if (p == NULL) return; if (p->data != NULL) { free(p->data); p->data = NULL; } if (p->exif_array != NULL) { buffer_array_free(p->exif_array); p->exif_array = NULL; } }
dword scene_readimage(dword selidx) { u64 timer_start, timer_end; u64 slide_start, slide_end; width_rotated = 0, height_rotated = 0, thumb_width = 0, thumb_height = 0, paintleft = 0, painttop = 0; imgdata = NULL, imgshow = NULL; oldangle = 0; curtop = 0, curleft = 0, xpos = 0, ypos = 0; img_needrf = true, img_needrc = true, img_needrp = true, showinfo = false, thumb = false; slideshow = false; now = 0, lasttime = 0; imgreading = true; if (config.imginfobar) imgh = PSP_SCREEN_HEIGHT - DISP_FONTSIZE; else imgh = PSP_SCREEN_HEIGHT; if (config.use_image_queue) { cache_setup(config.max_cache_img, &selidx); cache_set_forward(true); cache_on(true); } xrRtcGetCurrentTick(&timer_start); while (1) { u64 dbgnow, dbglasttick; dword key = 0; int ret; if (img_needrf) { int fid; dword ret; fid = freq_enter_hotzone(); xrRtcGetCurrentTick(&dbglasttick); ret = scene_reloadimage(selidx); if (ret == -1) { freq_leave(fid); break; } img_needrf = false; xrRtcGetCurrentTick(&dbgnow); dbg_printf(d, _("装载图像时间: %.2f秒"), pspDiffTime(&dbgnow, &dbglasttick)); freq_leave(fid); } if (img_needrc) { int fid; fid = freq_enter_hotzone(); xrRtcGetCurrentTick(&dbglasttick); scene_rotateimage(); img_needrc = false; xrRtcGetCurrentTick(&dbgnow); dbg_printf(d, _("旋转图像时间: %.2f秒"), pspDiffTime(&dbgnow, &dbglasttick)); freq_leave(fid); } if (img_needrp) { scene_printimage(selidx); img_needrp = false; } now = time(NULL); if (config.thumb == conf_thumb_scroll && thumb) { thumb = false; img_needrp = true; } key = ctrl_read_cont(); ret = image_handle_input(&selidx, key); if (ret == -1 && slideshow && !slideshow_move) { if (key == PSP_CTRL_CIRCLE) { } else if (key != 0 && (key == config.imgkey[1] || key == config.imgkey2[1] || key == CTRL_FORWARD)) { bool should_exit = false; next_image(&selidx, &should_exit); if (should_exit) { break; } } else if (key != 0 && (key == config.imgkey[0] || key == config.imgkey2[0] || key == CTRL_BACK)) { prev_image(&selidx); } else { xrPowerTick(0); if (config.imgpaging == conf_imgpaging_direct || config.imgpaging == conf_imgpaging_updown || config.imgpaging == conf_imgpaging_leftright) { if (now - lasttime >= config.slideinterval) { lasttime = now; ret = scene_slideshow_forward(&selidx); } } else { xrRtcGetCurrentTick(&slide_end); if (pspDiffTime(&slide_end, &slide_start) >= 0.1) { xrRtcGetCurrentTick(&slide_start); } else { lasttime = now; ret = scene_slideshow_forward(&selidx); } } } } if (showinfo && (key & PSP_CTRL_CIRCLE) == 0) { img_needrp = true; showinfo = false; } xrRtcGetCurrentTick(&timer_end); if (pspDiffTime(&timer_end, &timer_start) >= 1.0) { xrRtcGetCurrentTick(&timer_start); secticks++; } if (config.autosleep != 0 && secticks > 60 * config.autosleep) { power_down(); xrPowerRequestSuspend(); secticks = 0; } if (ret != -1) { selidx = ret; break; } scene_image_delay_action(); } reset_image_show_ptr(); if (config.use_image_queue) { cache_on(false); } imgreading = false; if (config.use_image_queue) { } else { if (imgdata != NULL) { free(imgdata); imgdata = NULL; } } if (config.use_image_queue) { // let cacher delete exif data exif_array = NULL; } else { if (exif_array) { buffer_array_free(exif_array); exif_array = NULL; } } return selidx; }