static void _edje_alias_string(const char *target, Eet_File *ef, const char *base, const char *to) { char buf[1024]; char **match; int count; int i; snprintf(buf, sizeof (buf), "%s/*", base); match = eet_list(ef, buf, &count); snprintf(buf, sizeof (buf), "%s/", base); strcat(buf, "%s"); for (i = 0; i < count && match; ++i) { char name[1024]; char id[1024]; if (sscanf(match[i], buf, &id) != 1) { EINA_LOG_ERR("Wrong fonts section `%s' in `%s'. Discarding it.", match[i], target); continue; } snprintf(name, sizeof (name), "%s/%s", to, id); eet_alias(ef, name, match[i], 1); } free(match); }
static Efreet_Desktop * efreet_util_cache_find(const char *search, const char *what1, const char *what2) { char **keys; int num, i; Efreet_Desktop *ret = NULL; if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL; if ((!what1) && (!what2)) return NULL; keys = eet_list(cache, search, &num); if (!keys) return NULL; for (i = 0; i < num; i++) { const char *data; int size, id; char key[PATH_MAX]; data = eet_read_direct(cache, keys[i], &size); if (!data) continue; if (!((what1 && !strcmp(what1, data)) || (what2 && !strcmp(what2, data)))) continue; id = atoi(keys[i]); snprintf(key, sizeof(key), "%d::op", id); data = eet_read_direct(cache, key, &size); if (!data) continue; ret = efreet_desktop_get(data); if (ret) break; } free(keys); return ret; }
static Eina_List * efreet_util_cache_glob_list(const char *search, const char *what) { char **keys; int num, i; Eina_List *ret = NULL; if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL; if (!what) return NULL; keys = eet_list(cache, search, &num); if (!keys) return NULL; for (i = 0; i < num; i++) { const char *data; int size, id; char key[PATH_MAX]; Efreet_Desktop *desk; data = eet_read_direct(cache, keys[i], &size); if (!data) continue; if (!efreet_util_glob_match(data, what)) continue; id = atoi(keys[i]); snprintf(key, sizeof(key), "%d::op", id); data = eet_read_direct(cache, key, &size); if (!data) continue; desk = efreet_desktop_get(data); if (desk) ret = eina_list_append(ret, desk); } free(keys); return ret; }
int main(int argc, char **argv) { Eet_File *theme_ef; Eina_List *l = NULL; Efreet_Icon_Theme *theme; int i; efreet_cache_update = 0; if (!efreet_init()) return -1; theme_ef = eet_open(efreet_icon_theme_cache_file(), EET_FILE_MODE_READ); if (!theme_ef) return -1; if (argc > 1) { for (i = 1; i < argc; i++) { theme = eet_data_read(theme_ef, efreet_icon_theme_edd(EINA_FALSE), argv[i]); if (theme) l = eina_list_append(l, theme); } } else { char **keys; int num; keys = eet_list(theme_ef, "*", &num); if (keys) { for (i = 0; i < num; i++) { theme = eet_data_read(theme_ef, efreet_icon_theme_edd(EINA_FALSE), keys[i]); if (theme) l = eina_list_append(l, theme); } free(keys); } } EINA_LIST_FREE(l, theme) { void *data; dump(theme); /* free theme */ eina_list_free(theme->paths); eina_list_free(theme->inherits); EINA_LIST_FREE(theme->directories, data) free(data); free(theme); }
void fill_tree_with_db(Etk_Tree *tree) { int num, i; char **entries; char *cover_path; Etk_Tree_Col *col; Etk_Tree_Row *row; Eet_File *ef; char *cover_db_path; asprintf(&cover_db_path, "%s/.e/apps/emphasis/cover.eet", getenv("HOME")); ef = eet_open(cover_db_path, EET_FILE_MODE_READ); if (!ef) { fprintf(stderr, "Can't open %s\n", cover_db_path); free(cover_db_path); exit(-1); } col = etk_tree_col_new(tree, "/artist/album", 0, 0.0); etk_tree_col_model_add(col, etk_tree_model_text_new()); etk_tree_build(tree); etk_tree_freeze(tree); entries = eet_list(ef, "*", &num); for (i=0; i<num; i++) { cover_path = eet_read(ef, entries[i], NULL); row = etk_tree_row_append(tree, NULL, col, entries[i], NULL); if (strcmp("not found", cover_path)) { etk_tree_row_data_set(row, cover_path); } else { etk_tree_row_data_set(row, NULL); } } eet_close(ef); free(cover_db_path); etk_tree_col_sort_set(etk_tree_nth_col_get(tree, 0), tree_sort, NULL); etk_tree_thaw(tree); }
/** * Find all desktops where exec matches a glob pattern * * This list must be freed using EINA_LIST_FREE / efreet_desktop_free * * @param glob the pattern to match * @return a list of desktops */ EAPI Eina_List * efreet_util_desktop_exec_glob_list(const char *glob) { char **keys; int num, i; Eina_List *ret = NULL; if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL; if (!glob) return NULL; keys = eet_list(cache, "*::e", &num); if (!keys) return NULL; for (i = 0; i < num; i++) { const char *data; char *exe; int size, id; char key[PATH_MAX]; Efreet_Desktop *desk; data = eet_read_direct(cache, keys[i], &size); if (!data) continue; exe = ecore_file_app_exe_get(data); if (!exe) continue; if (!efreet_util_glob_match(exe, glob)) { free(exe); continue; } free(exe); id = atoi(keys[i]); snprintf(key, sizeof(key), "%d::op", id); data = eet_read_direct(cache, key, &size); if (!data) continue; desk = efreet_desktop_get(data); if (desk) ret = eina_list_append(ret, desk); } free(keys); return ret; }
/** * Find a desktop by exec * * return value must be freed by efreet_desktop_free * * @param exec the exec name * @return a desktop */ EAPI Efreet_Desktop * efreet_util_desktop_exec_find(const char *exec) { char **keys; int num, i; Efreet_Desktop *ret = NULL; if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL; if (!exec) return NULL; keys = eet_list(cache, "*::e", &num); if (!keys) return NULL; for (i = 0; i < num; i++) { const char *data, *file; char *exe; int size, id; char key[PATH_MAX]; data = eet_read_direct(cache, keys[i], &size); if (!data) continue; exe = ecore_file_app_exe_get(data); if (!exe) continue; file = ecore_file_file_get(exe); if (!file) continue; if (strcmp(exec, exe) && strcmp(exec, file)) { free(exe); continue; } free(exe); id = atoi(keys[i]); snprintf(key, sizeof(key), "%d::op", id); data = eet_read_direct(cache, key, &size); if (!data) continue; ret = efreet_desktop_get(data); if (ret) break; } free(keys); return ret; }
static void dump(Efreet_Icon_Theme *theme) { Eet_File *ef; unsigned int count = 0; double start, avg; char **keys; int num, i; start = ecore_time_get(); ef = eet_open(efreet_icon_cache_file(theme->name.internal), EET_FILE_MODE_READ); printf("open: %s %f\n", theme->name.internal, ecore_time_get() - start); start = ecore_time_get(); keys = eet_list(ef, "*", &num); printf("list: %s %f\n", theme->name.internal, ecore_time_get() - start); if (!keys) return; start = ecore_time_get(); for (i = 0; i < num; i++) { Efreet_Cache_Icon *icon; unsigned int j; icon = eet_data_read(ef, efreet_icon_edd(), keys[i]); if (!icon) continue; for (j = 0; j < icon->icons_count; ++j) count += icon->icons[j]->paths_count; } free(keys); start = ecore_time_get() - start; avg = 0; if (count > 0) avg = start / count; printf("read: %s - %u paths (time: %f) (avg %f)\n", theme->name.internal, count, start, avg); eet_close(ef); eet_clearcache(); }
/** * Find all desktop categories * This list must be freed using EINA_LIST_FREE * * @return an Eina_List of category names (const char *) */ EAPI Eina_List * efreet_util_desktop_categories_list(void) { char **keys; int num, i; Eina_List *ret = NULL; if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL; keys = eet_list(cache, "*::ca", &num); if (!keys) return NULL; for (i = 0; i < num; i++) { const char *data; int size; data = eet_read_direct(cache, keys[i], &size); if (!data) continue; if (eina_list_search_unsorted(ret, EINA_COMPARE_CB(strcmp), data)) continue; ret = eina_list_append(ret, data); } free(keys); return ret; }
int ex_config_read(Extrackt *ex) { Eet_File *ef; char buf[PATH_MAX]; char *home; char **matches; int count; if(ex->config.cd) { /* FIXME: free everything! */ E_FREE(ex->config.cd->cdrom); E_FREE(ex->config.cd); } home = getenv("HOME"); if(!home) return 0; snprintf(buf, sizeof(buf), "%s/.e/extrackt/config.eet", home); if(!ecore_file_exists(buf) || ecore_file_size(buf) == 0) { /* default config values */ return ex_config_defaults_apply(ex); } ef = eet_open(buf, EET_FILE_MODE_READ); if(!ef) { ERROR("Cant open configuration file! Using program defaults."); return ex_config_defaults_apply(ex); } /* Make sure we are compatible - same version numbers */ ex->config.version = NULL; ex->config.version = eet_data_read(ef, _ex_config_version_edd, "config/version"); if(!ex->config.version) { ERROR("Incompatible configuration file! Creating new one."); eet_close(ef); return ex_config_defaults_apply(ex); } else { Ex_Config_Version *v; v = ex_config_version_parse(VERSION); if(ex_config_version_compare(v, ex->config.version) != 0) { ERROR("Your version / configuration of Extrackt is not valid! Overwriting with program defaults"); return ex_config_defaults_apply(ex); } } /* Read config data for cdrom */ ex->config.cd = NULL; ex->config.cd = eet_data_read(ef, _ex_config_cd_edd, "config/cd"); if(!ex->config.cd) { ERROR("Cant read config! Using program defaults."); eet_close(ef); return ex_config_defaults_apply(ex); } /* Read config data for cddb */ ex->config.cddb = NULL; ex->config.cddb = eet_data_read(ef, _ex_config_cddb_edd, "config/cddb"); if(!ex->config.cddb) { ERROR("Cant read config! Using program defaults."); eet_close(ef); return ex_config_defaults_apply(ex); } /* Read config data for rippers */ matches = eet_list(ef, "config/rippers/*", &count); ex->config.rippers = NULL; if(count > 0) { int i; for(i = 0; i < count; i++) { char *match; match = matches[i]; ex->config.rippers = eina_list_append(ex->config.rippers, eet_data_read(ef, _ex_config_exe_edd, match)); } } /* Read config data for encode */ ex->config.encode = NULL; ex->config.encode = eet_data_read(ef, _ex_config_encode_edd, "config/encode"); eet_close(ef); return 1; }
END_TEST START_TEST(eet_test_file_data) { Eet_Data_Descriptor *edd; Eet_Test_Ex_Type *result; Eet_Dictionary *ed; Eet_File *ef; char **list; char *file; Eet_Data_Descriptor_Class eddc; Eet_Test_Ex_Type etbt; int size; int test; int tmpfd; file = strdup("/tmp/eet_suite_testXXXXXX"); eet_init(); eet_test_ex_set(&etbt, 0); etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); etbt.hash = eina_hash_string_superfast_new(NULL); eina_hash_add(etbt.hash, EET_TEST_KEY1, eet_test_ex_set(NULL, 2)); etbt.hash = eina_hash_string_superfast_new(NULL); eina_hash_add(etbt.hash, EET_TEST_KEY2, eet_test_ex_set(NULL, 2)); etbt.ilist = eina_list_prepend(etbt.ilist, &i42); etbt.ilist = eina_list_prepend(etbt.ilist, &i42); etbt.ihash = eina_hash_string_superfast_new(NULL); eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7); etbt.ihash = eina_hash_string_superfast_new(NULL); eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7); etbt.slist = eina_list_prepend(NULL, "test"); etbt.shash = eina_hash_string_superfast_new(NULL); eina_hash_add(etbt.shash, EET_TEST_KEY1, "test"); memset(&etbt.charray, 0, sizeof(etbt.charray)); etbt.charray[0] = "test"; eet_test_setup_eddc(&eddc); eddc.name = "Eet_Test_Ex_Type"; eddc.size = sizeof(Eet_Test_Ex_Type); edd = eet_data_descriptor_file_new(&eddc); fail_if(!edd); eet_build_ex_descriptor(edd, EINA_FALSE); fail_if(-1 == (tmpfd = mkstemp(file))); fail_if(!!close(tmpfd)); /* Insert an error in etbt. */ etbt.i = 0; /* Save the encoded data in a file. */ ef = eet_open(file, EET_FILE_MODE_READ_WRITE); fail_if(!ef); fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); fail_if(!result); fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ_WRITE); /* Test string space. */ ed = eet_dictionary_get(ef); fail_if(!eet_dictionary_string_check(ed, result->str)); fail_if(eet_dictionary_string_check(ed, result->istr)); eet_close(ef); /* Attempt to replace etbt by the correct one. */ etbt.i = EET_TEST_INT; ef = eet_open(file, EET_FILE_MODE_READ_WRITE); fail_if(!ef); fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); fail_if(!result); /* Test the resulting data. */ fail_if(eet_test_ex_check(result, 0, EINA_FALSE) != 0); eet_close(ef); /* Read back the data. */ ef = eet_open(file, EET_FILE_MODE_READ_WRITE); fail_if(!ef); fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY2, &etbt, 0)); result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); fail_if(!result); /* Test string space. */ ed = eet_dictionary_get(ef); fail_if(!ed); fail_if(!eet_dictionary_string_check(ed, result->str)); fail_if(eet_dictionary_string_check(ed, result->istr)); /* Test the resulting data. */ fail_if(eet_test_ex_check(result, 0, EINA_FALSE) != 0); fail_if(eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_FALSE) != 0); fail_if(eina_list_data_get(result->ilist) == NULL); fail_if(*((int *)eina_list_data_get(result->ilist)) != 42); fail_if(eina_list_data_get(result->slist) == NULL); fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0); fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL); fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0); fail_if(strcmp(result->charray[0], "test") != 0); test = 0; if (result->hash) eina_hash_foreach(result->hash, func, &test); fail_if(test != 0); if (result->ihash) eina_hash_foreach(result->ihash, func7, &test); fail_if(test != 0); list = eet_list(ef, "keys/*", &size); fail_if(eet_num_entries(ef) != 2); fail_if(size != 2); fail_if(!(strcmp(list[0], EET_TEST_FILE_KEY1) == 0 && strcmp(list[1], EET_TEST_FILE_KEY2) == 0) && !(strcmp(list[0], EET_TEST_FILE_KEY2) == 0 && strcmp(list[1], EET_TEST_FILE_KEY1) == 0)); free(list); fail_if(eet_delete(ef, NULL) != 0); fail_if(eet_delete(NULL, EET_TEST_FILE_KEY1) != 0); fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0); list = eet_list(ef, "keys/*", &size); fail_if(size != 1); fail_if(eet_num_entries(ef) != 1); /* Test some more wrong case */ fail_if(eet_data_read(ef, edd, "plop") != NULL); fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) != NULL); /* Reinsert and reread data */ fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) == NULL); fail_if(eet_read_direct(ef, EET_TEST_FILE_KEY1, &size) == NULL); eet_close(ef); fail_if(unlink(file) != 0); eet_shutdown(); }
void eli_highscore_init(const char * app) { char buffer[1024]; char * home; Eet_File * ef; eet_init(); edd_entry = eet_data_descriptor_new("Eli_Highscore_Entry", sizeof(Eli_Highscore_Entry), (list_next) eina_list_next, (list_append) eina_list_append, (list_data) eina_list_data_get, (list_free) eina_list_free, (hash_foreach) eina_hash_foreach, (hash_add) eina_hash_add /* FIXME: YOU SHOULD NOT USE EINA_HASH_ADD DIRECTLY */, (hash_free) eina_hash_free); EET_DATA_DESCRIPTOR_ADD_BASIC(edd_entry, Eli_Highscore_Entry, "username", username, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(edd_entry, Eli_Highscore_Entry, "points", points, EET_T_FLOAT); EET_DATA_DESCRIPTOR_ADD_BASIC(edd_entry, Eli_Highscore_Entry, "type", type, EET_T_INT); edd_hiscore = eet_data_descriptor_new("Eli_Highscore", sizeof(Eli_Highscore), (list_next) eina_list_next, (list_append) eina_list_append, (list_data) eina_list_data_get, (list_free) eina_list_free, (hash_foreach) eina_hash_foreach, (hash_add) eina_hash_add /* FIXME: YOU SHOULD NOT USE EINA_HASH_ADD DIRECTLY */, (hash_free) eina_hash_free); EET_DATA_DESCRIPTOR_ADD_LIST(edd_hiscore, Eli_Highscore, "entries", entries, edd_entry); /* this is just a temporally hack, the right path should be * some thing like /var/games/elitaire.score, but * for some reasons eet segv when the directory is not * writable, although the file is */ home = getenv("HOME"); if (!home) home = "/tmp"; snprintf(buffer, sizeof(buffer), "%s/.e/apps/%s/score.eet", home, app); eet_file_name = strdup(buffer); /* * setup the hiscore hash */ hiscore_hash = ecore_hash_new(ecore_str_hash, ecore_str_compare); ecore_hash_free_key_cb_set(hiscore_hash, free); /* * fill the hash */ ef = eet_open(eet_file_name, EET_FILE_MODE_READ); if (ef) { char **list; int num, i; list = eet_list(ef, "*", &num); for(i = 0; i < num; i++) { Eli_Highscore * hiscore; hiscore = eet_data_read(ef, edd_hiscore, list[i]); ecore_hash_set(hiscore_hash, strdup(list[i]), hiscore->entries); } free(list); eet_close(ef); } }