This commit is huge. I did test it a lot on my computer, and it run fine here.

But is so big i fear i could have broken some piece of code. So report any wrong
behaviour to me (cedric on #edevelop).

So moving e17 and efreet to eina_hash. With a little efreet API break so they
must come together.


SVN revision: 38185
This commit is contained in:
Cedric BAIL 2008-12-17 15:33:43 +00:00
parent e33474c92f
commit 35540b3a3b
10 changed files with 438 additions and 370 deletions

View File

@ -12,11 +12,12 @@
#define THEME "Tango"
#define FREE(x) do { free(x); x = NULL; } while (0);
static Eina_Bool _hash_keys(Eina_Hash *hash, const char *key, void *list);
static void ef_icon_theme_themes_find(const char *search_dir,
Ecore_Hash *themes);
Eina_Hash *themes);
static void ef_icons_find(Efreet_Icon_Theme *theme, Ecore_List *themes,
Ecore_Hash *icons);
static void ef_read_dir(const char *dir, Ecore_Hash *icons);
Eina_Hash *icons);
static void ef_read_dir(const char *dir, Eina_Hash *icons);
int
ef_cb_efreet_icon_theme(void)
@ -52,19 +53,27 @@ ef_cb_efreet_icon_theme(void)
return ret;
}
static Eina_Bool
_hash_keys(Eina_Hash *hash, const char *key, void *list)
{
ecore_list_append(list, key);
return EINA_TRUE;
}
int
ef_cb_efreet_icon_theme_list(void)
{
int ret = 1;
Ecore_List *themes;
Ecore_Hash *dirs;
Eina_Hash *dirs;
Eina_Iterator *it;
Efreet_Icon_Theme *theme;
Ecore_List *icon_dirs;
const char *dir;
char buf[PATH_MAX];
void *value;
dirs = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(dirs, free);
dirs = eina_hash_string_superfast_new(free);
icon_dirs = efreet_data_dirs_get();
ecore_list_first_goto(icon_dirs);
@ -81,8 +90,8 @@ ef_cb_efreet_icon_theme_list(void)
ecore_list_first_goto(themes);
while ((theme = ecore_list_next(themes)))
{
if (ecore_hash_get(dirs, theme->name.internal))
ecore_hash_remove(dirs, theme->name.internal);
if ((eina_hash_find(dirs, theme->name.internal)))
eina_hash_del(dirs, theme->name.internal, NULL);
else
{
printf("efreet_icon_theme_list_get() returned %s which we didn't "
@ -92,7 +101,11 @@ ef_cb_efreet_icon_theme_list(void)
}
ecore_list_destroy(themes);
themes = ecore_hash_keys(dirs);
themes = ecore_list_new();
it = eina_hash_iterator_key_new(dirs);
eina_iterator_foreach(it, EINA_EACH(_hash_keys), themes);
eina_iterator_free(it);
if (ecore_list_count(themes) > 0)
{
char *dir;
@ -106,13 +119,13 @@ ef_cb_efreet_icon_theme_list(void)
ret = 0;
}
ecore_list_destroy(themes);
ecore_hash_destroy(dirs);
eina_hash_free(dirs);
return ret;
}
static void
ef_icon_theme_themes_find(const char *search_dir, Ecore_Hash *themes)
ef_icon_theme_themes_find(const char *search_dir, Eina_Hash *themes)
{
Ecore_List *dirs;
char *dir;
@ -127,7 +140,7 @@ ef_icon_theme_themes_find(const char *search_dir, Ecore_Hash *themes)
char p[PATH_MAX];
/* if we've already added the theme we're done */
if (ecore_hash_get(themes, dir))
if (eina_hash_find(themes, dir))
{
free(dir);
continue;
@ -152,7 +165,7 @@ ef_icon_theme_themes_find(const char *search_dir, Ecore_Hash *themes)
if (!skip)
{
d = strdup(dir);
ecore_hash_set(themes, d, d);
eina_hash_add(themes, dir, d);
}
}
free(dir);
@ -425,7 +438,7 @@ int
ef_cb_efreet_icon_match(void)
{
int i, ret = 1;
Ecore_Hash *icon_hash;
Eina_Hash *icon_hash;
Efreet_Icon_Theme *theme;
Ecore_List *themes;
@ -444,9 +457,7 @@ ef_cb_efreet_icon_match(void)
return 1;
}
icon_hash = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(icon_hash, free);
ecore_hash_free_value_cb_set(icon_hash, free);
icon_hash = eina_hash_string_superfast_new(free);
ef_icons_find(theme, themes, icon_hash);
ecore_list_destroy(themes);
@ -461,7 +472,7 @@ ef_cb_efreet_icon_match(void)
if (!path)
{
#if 1
if (ecore_hash_get(icon_hash, icons[i]))
if (eina_hash_find(icon_hash, icons[i]))
{
printf("NOT FOUND %s\n", icons[i]);
ret = 0;
@ -469,7 +480,7 @@ ef_cb_efreet_icon_match(void)
#endif
continue;
}
else if (!ecore_hash_get(icon_hash, icons[i]))
else if (!eina_hash_find(icon_hash, icons[i]))
{
printf("Found icon not in hash: %s\n", icons[i]);
}
@ -487,7 +498,7 @@ ef_cb_efreet_icon_match(void)
free(path);
}
printf("Time: %f\n", (ecore_time_get() - start));
ecore_hash_destroy(icon_hash);
eina_hash_free(icon_hash);
start = ecore_time_get();
for (i = 0; icons[i] != NULL; i++)
@ -516,7 +527,7 @@ ef_cb_efreet_icon_match(void)
}
static void
ef_icons_find(Efreet_Icon_Theme *theme, Ecore_List *themes, Ecore_Hash *icons)
ef_icons_find(Efreet_Icon_Theme *theme, Ecore_List *themes, Eina_Hash *icons)
{
char path[PATH_MAX];
@ -599,7 +610,7 @@ ef_icons_find(Efreet_Icon_Theme *theme, Ecore_List *themes, Ecore_Hash *icons)
}
static void
ef_read_dir(const char *dir, Ecore_Hash *icons)
ef_read_dir(const char *dir, Eina_Hash *icons)
{
Ecore_List *files;
char *file;
@ -624,7 +635,7 @@ ef_read_dir(const char *dir, Ecore_Hash *icons)
{
*p = '\0';
ecore_hash_set(icons, strdup(file), strdup(file));
eina_hash_add(icons, file, strdup(file));
}
FREE(file);

View File

@ -13,7 +13,7 @@ static const char *desktop_environment = NULL;
* A cache of all loaded desktops, hashed by file name.
* Values are Efreet_Desktop structures
*/
static Ecore_Hash *efreet_desktop_cache = NULL;
static Eina_Hash *efreet_desktop_cache = NULL;
/**
* A list of the desktop types available
@ -61,10 +61,14 @@ static int efreet_desktop_generic_fields_parse(Efreet_Desktop *desktop,
Efreet_Ini *ini);
static void efreet_desktop_generic_fields_save(Efreet_Desktop *desktop,
Efreet_Ini *ini);
static void efreet_desktop_x_fields_parse(Ecore_Hash_Node *node,
Efreet_Desktop *desktop);
static void efreet_desktop_x_fields_save(Ecore_Hash_Node *node,
Efreet_Ini *ini);
static Eina_Bool efreet_desktop_x_fields_parse(const Eina_Hash *hash,
const void *key,
void *data,
void *fdata);
static Eina_Bool efreet_desktop_x_fields_save(const Eina_Hash *hash,
const void *key,
void *value,
void *fdata);
static int efreet_desktop_environment_check(Efreet_Ini *ini);
static char *efreet_string_append(char *dest, int *size,
int *len, const char *src);
@ -116,8 +120,7 @@ efreet_desktop_init(void)
if (!eina_stringshare_init()) return --init;
if (!ecore_file_init()) return --init;
efreet_desktop_cache = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(efreet_desktop_cache, ECORE_FREE_CB(free));
efreet_desktop_cache = eina_hash_string_superfast_new(NULL);
efreet_desktop_types = ecore_list_new();
ecore_list_free_cb_set(efreet_desktop_types,
@ -188,7 +191,7 @@ efreet_desktop_get(const char *file)
if (efreet_desktop_cache)
{
desktop = ecore_hash_get(efreet_desktop_cache, file);
desktop = eina_hash_find(efreet_desktop_cache, file);
if (desktop)
{
if (efreet_desktop_cache_check(desktop))
@ -206,14 +209,14 @@ efreet_desktop_get(const char *file)
}
desktop->cached = 0;
ecore_hash_remove(efreet_desktop_cache, file);
eina_hash_del(efreet_desktop_cache, file, NULL);
}
}
desktop = efreet_desktop_new(file);
if (!desktop) return NULL;
ecore_hash_set(efreet_desktop_cache, strdup(file), desktop);
eina_hash_add(efreet_desktop_cache, file, desktop);
desktop->cached = 1;
return desktop;
}
@ -330,8 +333,7 @@ efreet_desktop_read(Efreet_Desktop *desktop)
if (!error && !efreet_desktop_environment_check(ini)) error = 1;
if (!error && !efreet_desktop_generic_fields_parse(desktop, ini)) error = 1;
if (!error)
ecore_hash_for_each_node(ini->section,
ECORE_FOR_EACH(efreet_desktop_x_fields_parse), desktop);
eina_hash_foreach(ini->section, efreet_desktop_x_fields_parse, desktop);
efreet_ini_free(ini);
@ -428,11 +430,12 @@ efreet_desktop_save(Efreet_Desktop *desktop)
if (!efreet_ini_save(ini, desktop->orig_path)) ok = 0;
else
{
if (desktop != ecore_hash_get(efreet_desktop_cache, desktop->orig_path))
if (desktop != eina_hash_find(efreet_desktop_cache, desktop->orig_path))
{
desktop->cached = 1;
ecore_hash_set(efreet_desktop_cache,
strdup(desktop->orig_path), desktop);
eina_hash_del(efreet_desktop_cache, desktop->orig_path, NULL);
eina_hash_add(efreet_desktop_cache, desktop->orig_path,
desktop);
}
}
}
@ -449,10 +452,10 @@ efreet_desktop_save(Efreet_Desktop *desktop)
EAPI int
efreet_desktop_save_as(Efreet_Desktop *desktop, const char *file)
{
if (desktop == ecore_hash_get(efreet_desktop_cache, desktop->orig_path))
if (desktop == eina_hash_find(efreet_desktop_cache, desktop->orig_path))
{
desktop->cached = 0;
ecore_hash_remove(efreet_desktop_cache, desktop->orig_path);
eina_hash_del(efreet_desktop_cache, desktop->orig_path, NULL);
}
FREE(desktop->orig_path);
desktop->orig_path = strdup(file);
@ -474,7 +477,7 @@ efreet_desktop_free(Efreet_Desktop *desktop)
if (desktop->ref > 0) return;
if (desktop->cached && efreet_desktop_cache)
ecore_hash_remove(efreet_desktop_cache, desktop->orig_path);
eina_hash_del(efreet_desktop_cache, desktop->orig_path, NULL);
IF_FREE(desktop->orig_path);
@ -985,9 +988,8 @@ efreet_desktop_generic_fields_save(Efreet_Desktop *desktop, Efreet_Ini *ini)
efreet_ini_boolean_set(ini, "NoDisplay", desktop->no_display);
efreet_ini_boolean_set(ini, "Hidden", desktop->hidden);
if (desktop->x) ecore_hash_for_each_node(desktop->x,
ECORE_FOR_EACH(efreet_desktop_x_fields_save),
ini);
if (desktop->x) eina_hash_foreach(desktop->x, efreet_desktop_x_fields_save,
ini);
}
/**
@ -997,21 +999,19 @@ efreet_desktop_generic_fields_save(Efreet_Desktop *desktop, Efreet_Ini *ini)
* @return Returns no value
* @brief Parses out an X- key from @a node and stores in @a desktop
*/
static void
efreet_desktop_x_fields_parse(Ecore_Hash_Node *node, Efreet_Desktop *desktop)
static Eina_Bool
efreet_desktop_x_fields_parse(const Eina_Hash *hash, const void *key, void *value, void *fdata)
{
if (strncmp(node->key, "X-", 2)) return;
Efreet_Desktop * desktop = fdata;
if (!desktop->x)
{
desktop->x = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(desktop->x,
ECORE_FREE_CB(eina_stringshare_del));
ecore_hash_free_value_cb_set(desktop->x,
ECORE_FREE_CB(eina_stringshare_del));
}
ecore_hash_set(desktop->x, (void *)eina_stringshare_add(node->key),
(void *)eina_stringshare_add(node->value));
if (strncmp(key, "X-", 2)) return EINA_TRUE;
if (desktop && !desktop->x)
desktop->x = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
eina_hash_del(desktop->x, key, NULL);
eina_hash_add(desktop->x, key, (void *)eina_stringshare_add(value));
return EINA_TRUE;
}
/**
@ -1021,10 +1021,13 @@ efreet_desktop_x_fields_parse(Ecore_Hash_Node *node, Efreet_Desktop *desktop)
* @return Returns no value
* @brief Stores an X- key from @a node and stores in @a ini
*/
static void
efreet_desktop_x_fields_save(Ecore_Hash_Node *node, Efreet_Ini *ini)
static Eina_Bool
efreet_desktop_x_fields_save(const Eina_Hash *hash, const void *key, void *value, void *fdata)
{
efreet_ini_string_set(ini, node->key, node->value);
Efreet_Ini *ini = fdata;
efreet_ini_string_set(ini, key, value);
return EINA_TRUE;
}

View File

@ -93,7 +93,7 @@ struct Efreet_Desktop
unsigned char startup_notify:1; /**< The starup notify settings of the app */
unsigned char cached:1; /**< The desktop file is cached by Efreet */
Ecore_Hash *x; /**< Keep track of all user extensions, keys that begin with X- */
Eina_Hash *x; /**< Keep track of all user extensions, keys that begin with X- */
void *type_data; /**< Type specific data for custom types */
};

View File

@ -6,10 +6,10 @@
static char *efreet_icon_deprecated_user_dir = NULL;
static char *efreet_icon_user_dir = NULL;
static Ecore_Hash *efreet_icon_themes = NULL;
static Eina_Hash *efreet_icon_themes = NULL;
static Ecore_List *efreet_icon_extensions = NULL;
static Ecore_List *efreet_extra_icon_dirs = NULL;
static Ecore_Hash *efreet_icon_cache = NULL;
static Eina_Hash *efreet_icon_cache = NULL;
static int efreet_icon_init_count = 0;
@ -110,13 +110,10 @@ efreet_icon_init(void)
for (i = 0; default_exts[i] != NULL; i++)
ecore_list_append(efreet_icon_extensions, strdup(default_exts[i]));
efreet_icon_themes = ecore_hash_new(NULL, NULL);
ecore_hash_free_value_cb_set(efreet_icon_themes,
ECORE_FREE_CB(efreet_icon_theme_free));
efreet_icon_themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_icon_theme_free));
efreet_extra_icon_dirs = ecore_list_new();
efreet_icon_cache = ecore_hash_new(ecore_direct_hash, ecore_direct_compare);
ecore_hash_free_value_cb_set(efreet_icon_cache, ECORE_FREE_CB(ecore_list_destroy));
efreet_icon_cache = eina_hash_pointer_new(EINA_FREE_CB(ecore_list_destroy));
}
return 1;
@ -207,6 +204,12 @@ efreet_icon_extra_list_get(void)
return efreet_extra_icon_dirs;
}
static Eina_Bool
_hash_keys(Eina_Hash *hash, const void *key, void *list)
{
ecore_list_append(list, key);
return EINA_TRUE;
}
/**
* @return Returns a list of Efreet_Icon structs for all the non-hidden icon
* themes
@ -218,6 +221,7 @@ efreet_icon_theme_list_get(void)
{
Ecore_List *list, *theme_list;
char *dir;
Eina_Iterator *it;
/* update the list to include all icon themes */
efreet_icon_theme_dir_scan_all(NULL);
@ -225,13 +229,16 @@ efreet_icon_theme_list_get(void)
/* create the list for the user */
list = ecore_list_new();
theme_list = ecore_hash_keys(efreet_icon_themes);
theme_list = ecore_list_new();
it = eina_hash_iterator_key_new(efreet_icon_themes);
eina_iterator_foreach(it, EINA_EACH(_hash_keys), theme_list);
eina_iterator_free(it);
ecore_list_first_goto(theme_list);
while ((dir = ecore_list_next(theme_list)))
{
Efreet_Icon_Theme *theme;
theme = ecore_hash_get(efreet_icon_themes, dir);
theme = eina_hash_find(efreet_icon_themes, dir);
if (theme->hidden || theme->fake) continue;
#ifndef STRICT_SPEC
if (!theme->name.name) continue;
@ -257,11 +264,11 @@ efreet_icon_theme_find(const char *theme_name)
Efreet_Icon_Theme *theme;
key = eina_stringshare_add(theme_name);
theme = ecore_hash_get(efreet_icon_themes, key);
theme = eina_hash_find(efreet_icon_themes, key);
if (!theme)
{
efreet_icon_theme_dir_scan_all(theme_name);
theme = ecore_hash_get(efreet_icon_themes, key);
theme = eina_hash_find(efreet_icon_themes, key);
}
eina_stringshare_del(key);
@ -319,7 +326,8 @@ efreet_icon_find_theme_check(const char *theme_name)
theme = efreet_icon_theme_new();
theme->fake = 1;
theme->name.internal = eina_stringshare_add(theme_name);
ecore_hash_set(efreet_icon_themes, (void *)theme->name.internal, theme);
eina_hash_del(efreet_icon_themes, (void *)theme->name.internal, NULL);
eina_hash_add(efreet_icon_themes, (void *)theme->name.internal, theme);
}
return theme;
@ -1217,7 +1225,7 @@ efreet_icon_theme_cache_check_dir(Efreet_Icon_Theme *theme, const char *dir)
/* have we modified this directory since our last cache check? */
if (stat(dir, &buf) || (buf.st_mtime > theme->last_cache_check))
{
ecore_hash_remove(efreet_icon_cache, theme);
eina_hash_del(efreet_icon_cache, &theme, NULL);
return 0;
}
@ -1289,14 +1297,14 @@ efreet_icon_theme_dir_scan(const char *search_dir, const char *theme_name)
continue;
key = eina_stringshare_add(dir->d_name);
theme = ecore_hash_get(efreet_icon_themes, key);
theme = eina_hash_find(efreet_icon_themes, key);
if (!theme)
{
theme = efreet_icon_theme_new();
theme->name.internal = key;
ecore_hash_set(efreet_icon_themes,
(void *)theme->name.internal, theme);
eina_hash_add(efreet_icon_themes,
(void *)theme->name.internal, theme);
}
else
{
@ -1323,12 +1331,9 @@ efreet_icon_theme_dir_scan(const char *search_dir, const char *theme_name)
{
Efreet_Icon_Theme *theme;
theme = ecore_hash_get(efreet_icon_themes, theme_name);
theme = eina_hash_find(efreet_icon_themes, theme_name);
if (theme && !theme->valid && !theme->fake)
{
ecore_hash_remove(efreet_icon_themes, theme_name);
efreet_icon_theme_free(theme);
}
eina_hash_del(efreet_icon_themes, theme_name, theme);
}
}
@ -1441,19 +1446,20 @@ efreet_icon_theme_dir_validity_check(void)
{
Ecore_List *keys;
const char *name;
Eina_Iterator *it;
keys = ecore_hash_keys(efreet_icon_themes);
keys = ecore_list_new();
it = eina_hash_iterator_key_new(efreet_icon_themes);
eina_iterator_foreach(it, EINA_EACH(_hash_keys), keys);
eina_iterator_free(it);
ecore_list_first_goto(keys);
while ((name = ecore_list_next(keys)))
{
Efreet_Icon_Theme *theme;
theme = ecore_hash_get(efreet_icon_themes, name);
if (!theme->valid && !theme->fake)
{
ecore_hash_remove(efreet_icon_themes, name);
efreet_icon_theme_free(theme);
}
theme = eina_hash_find(efreet_icon_themes, name);
if (theme && !theme->valid && !theme->fake)
eina_hash_del(efreet_icon_themes, name, theme);
}
ecore_list_destroy(keys);
}
@ -1583,12 +1589,12 @@ efreet_icon_cache_check(Efreet_Icon_Theme *theme, const char *icon, unsigned int
char key[4096];
struct stat st;
list = ecore_hash_get(efreet_icon_cache, theme);
list = eina_hash_find(efreet_icon_cache, &theme);
if (!list)
{
list = ecore_list_new();
ecore_list_free_cb_set(list, ECORE_FREE_CB(efreet_icon_cache_free));
ecore_hash_set(efreet_icon_cache, theme, list);
eina_hash_add(efreet_icon_cache, &theme, list);
return NULL;
}
@ -1620,12 +1626,12 @@ efreet_icon_cache_add(Efreet_Icon_Theme *theme, const char *icon, unsigned int s
char key[4096];
struct stat st;
list = ecore_hash_get(efreet_icon_cache, theme);
list = eina_hash_find(efreet_icon_cache, &theme);
if (!list)
{
list = ecore_list_new();
ecore_list_free_cb_set(list, ECORE_FREE_CB(efreet_icon_cache_free));
ecore_hash_set(efreet_icon_cache, theme, list);
eina_hash_add(efreet_icon_cache, &theme, list);
}
snprintf(key, sizeof(key), "%s %d", icon, size);

View File

@ -2,11 +2,13 @@
#include "Efreet.h"
#include "efreet_private.h"
static Ecore_Hash *efreet_ini_parse(const char *file);
static Eina_Hash *efreet_ini_parse(const char *file);
static char *efreet_ini_unescape(const char *str);
static void efreet_ini_section_save(Ecore_Hash_Node *node, FILE *f);
static void efreet_ini_value_save(Ecore_Hash_Node *node, FILE *f);
static Eina_Bool
efreet_ini_section_save(const Eina_Hash *hash, const void *key, void *data, void *fdata);
static Eina_Bool
efreet_ini_value_save(const Eina_Hash *hash, const void *key, void *data, void *fdata);
/**
* The number of times the Ini subsytem has been initialized
@ -65,16 +67,16 @@ efreet_ini_new(const char *file)
/**
* @internal
* @param file The file to parse
* @return Returns an Ecore_Hash with the contents of @a file, or NULL if the
* @return Returns an Eina_Hash with the contents of @a file, or NULL if the
* file fails to parse or if the file doesn't exist
* @brief Parses the ini file @a file into an Ecore_Hash
* @brief Parses the ini file @a file into an Eina_Hash
*/
static Ecore_Hash *
static Eina_Hash *
efreet_ini_parse(const char *file)
{
const char *buffer, *line_start;
FILE *f;
Ecore_Hash *data, *section = NULL;
Eina_Hash *data, *section = NULL;
struct stat file_stat;
int line_length, left;
@ -100,9 +102,7 @@ efreet_ini_parse(const char *file)
return NULL;
}
data = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(data, ECORE_FREE_CB(eina_stringshare_del));
ecore_hash_free_value_cb_set(data, ECORE_FREE_CB(ecore_hash_destroy));
data = eina_hash_string_small_new(EINA_FREE_CB(eina_hash_free));
line_start = buffer;
while (left > 0)
@ -141,7 +141,7 @@ efreet_ini_parse(const char *file)
if (line_start[header_length] == ']')
{
Ecore_Hash *old;
Eina_Hash *old;
const char *header;
header = alloca(header_length * sizeof(unsigned char));
@ -150,18 +150,13 @@ efreet_ini_parse(const char *file)
memcpy((char*)header, line_start + 1, header_length - 1);
((char*)header)[header_length - 1] = '\0';
section = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(section,
ECORE_FREE_CB(eina_stringshare_del));
ecore_hash_free_value_cb_set(section, ECORE_FREE_CB(free));
section = eina_hash_string_small_new(free);
old = ecore_hash_remove(data, header);
eina_hash_del(data, header, NULL);
// if (old) printf("[efreet] Warning: duplicate section '%s' "
// "in file '%s'\n", header, file);
IF_FREE_HASH(old);
ecore_hash_set(data, (void *)eina_stringshare_add(header),
section);
eina_hash_add(data, header, section);
}
else
{
@ -196,16 +191,16 @@ efreet_ini_parse(const char *file)
if (!isspace(line_start[key_end])) key_end++;
/* trim whitespace from start of value */
for (value_start = sep + 1;
(value_start < line_length) &&
isspace(line_start[value_start]); ++value_start)
for (value_start = sep + 1;
(value_start < line_length) &&
isspace(line_start[value_start]); ++value_start)
;
/* trim \n off of end of value */
for (value_end = line_length;
(value_end > value_start) &&
((line_start[value_end] == '\n') ||
(line_start[value_end] == '\r')); --value_end)
(value_end > value_start) &&
((line_start[value_end] == '\n') ||
(line_start[value_end] == '\r')); --value_end)
;
if (line_start[value_end] != '\n'
@ -233,11 +228,8 @@ efreet_ini_parse(const char *file)
value_end - value_start);
((char*)value)[value_end - value_start] = '\0';
old = ecore_hash_remove(section, key);
IF_FREE(old);
ecore_hash_set(section, (void *)eina_stringshare_add(key),
efreet_ini_unescape(value));
eina_hash_del(section, key, NULL);
eina_hash_add(section, key, efreet_ini_unescape(value));
}
// else
// {
@ -283,7 +275,7 @@ efreet_ini_save(Efreet_Ini *ini, const char *file)
f = fopen(file, "wb");
if (!f) return 0;
ecore_hash_for_each_node(ini->data, ECORE_FOR_EACH(efreet_ini_section_save), f);
eina_hash_foreach(ini->data, efreet_ini_section_save, f);
fclose(f);
return 1;
@ -300,7 +292,7 @@ efreet_ini_section_set(Efreet_Ini *ini, const char *section)
{
if (!ini || !ini->data || !section) return 0;
ini->section = ecore_hash_get(ini->data, section);
ini->section = eina_hash_find(ini->data, section);
return (ini->section ? 1 : 0);
}
@ -313,22 +305,16 @@ efreet_ini_section_set(Efreet_Ini *ini, const char *section)
EAPI void
efreet_ini_section_add(Efreet_Ini *ini, const char *section)
{
Ecore_Hash *hash;
Eina_Hash *hash;
if (!ini || !section) return;
if (!ini->data)
{
ini->data = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(ini->data, ECORE_FREE_CB(eina_stringshare_del));
ecore_hash_free_value_cb_set(ini->data, ECORE_FREE_CB(ecore_hash_destroy));
}
if (ecore_hash_get(ini->data, section)) return;
ini->data = eina_hash_string_small_new(EINA_FREE_CB(eina_hash_free));
if (eina_hash_find(ini->data, section)) return;
hash = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(hash, ECORE_FREE_CB(eina_stringshare_del));
ecore_hash_free_value_cb_set(hash, ECORE_FREE_CB(free));
ecore_hash_set(ini->data, (void *)eina_stringshare_add(section), hash);
hash = eina_hash_string_small_new(free);
eina_hash_add(ini->data, section, hash);
}
/**
@ -343,7 +329,7 @@ efreet_ini_string_get(Efreet_Ini *ini, const char *key)
{
if (!ini || !key || !ini->section) return NULL;
return ecore_hash_get(ini->section, key);
return eina_hash_find(ini->section, key);
}
/**
@ -358,7 +344,8 @@ efreet_ini_string_set(Efreet_Ini *ini, const char *key, const char *value)
{
if (!ini || !key || !ini->section) return;
ecore_hash_set(ini->section, (void *)eina_stringshare_add(key), strdup(value));
eina_hash_del(ini->section, key, NULL);
eina_hash_add(ini->section, key, strdup(value));
}
/**
@ -637,15 +624,21 @@ efreet_ini_unescape(const char *str)
return buf;
}
static void
efreet_ini_section_save(Ecore_Hash_Node *node, FILE *f)
static Eina_Bool
efreet_ini_section_save(const Eina_Hash *hash, const void *key, void *value, void *fdata)
{
fprintf(f, "[%s]\n", (char *)node->key);
ecore_hash_for_each_node(node->value, ECORE_FOR_EACH(efreet_ini_value_save), f);
FILE *f = fdata;
fprintf(f, "[%s]\n", (char *)key);
eina_hash_foreach(value, efreet_ini_value_save, f);
return EINA_TRUE;
}
static void
efreet_ini_value_save(Ecore_Hash_Node *node, FILE *f)
static Eina_Bool
efreet_ini_value_save(const Eina_Hash *hash, const void *key, void *value, void *fdata)
{
fprintf(f, "%s=%s\n", (char *)node->key, (char *)node->value);
FILE *f = fdata;
fprintf(f, "%s=%s\n", (char *)key, (char *)value);
return EINA_TRUE;
}

View File

@ -22,8 +22,8 @@ typedef struct Efreet_Ini Efreet_Ini;
*/
struct Efreet_Ini
{
Ecore_Hash *data; /**< Hash of string => (Hash of string => string) */
Ecore_Hash *section; /**< currently selected section */
Eina_Hash *data; /**< Hash of string => (Hash of string => string) */
Eina_Hash *section; /**< currently selected section */
};
EAPI Efreet_Ini *efreet_ini_new(const char *file);

View File

@ -51,7 +51,7 @@ struct Efreet_Menu_Internal
Ecore_List *applications; /**< applications in this menu */
Ecore_DList *directory_dirs; /**< .directory file directories */
Ecore_Hash *directory_cache; /**< .directory dirs */
Eina_Hash *directory_cache; /**< .directory dirs */
Ecore_List *moves; /**< List of moves to be handled by the menu */
Ecore_List *filters; /**< Include and Exclude filters */
@ -212,13 +212,13 @@ Ecore_List *efreet_menu_kde_legacy_dirs = NULL; /**< The directories to use for
static const char *efreet_tag_menu = NULL;
static char *efreet_menu_file = NULL; /**< A menu file set explicityl as default */
static Ecore_Hash *efreet_merged_menus = NULL;
static Ecore_Hash *efreet_merged_dirs = NULL;
static Eina_Hash *efreet_merged_menus = NULL;
static Eina_Hash *efreet_merged_dirs = NULL;
static Ecore_Hash *efreet_menu_handle_cbs = NULL;
static Ecore_Hash *efreet_menu_filter_cbs = NULL;
static Ecore_Hash *efreet_menu_move_cbs = NULL;
static Ecore_Hash *efreet_menu_layout_cbs = NULL;
static Eina_Hash *efreet_menu_handle_cbs = NULL;
static Eina_Hash *efreet_menu_filter_cbs = NULL;
static Eina_Hash *efreet_menu_move_cbs = NULL;
static Eina_Hash *efreet_menu_layout_cbs = NULL;
static const char *efreet_menu_prefix_get(void);
@ -242,14 +242,14 @@ static int efreet_menu_app_dir_scan(Efreet_Menu_Internal *internal,
int legacy);
static int efreet_menu_directory_dirs_process(Efreet_Menu_Internal *internal);
static int efreet_menu_directory_dir_scan(const char *path,
const char *relative_path,
Ecore_Hash *cache);
const char *relative_path,
Eina_Hash *cache);
static Efreet_Desktop *efreet_menu_directory_get(Efreet_Menu_Internal *internal,
const char *path);
static void efreet_menu_process_filters(Efreet_Menu_Internal *internal,
unsigned int only_unallocated);
static void efreet_menu_process_app_pool(Ecore_List *pool, Ecore_List *applications,
Ecore_Hash *matches,
Eina_Hash *matches,
Efreet_Menu_Filter *filter,
unsigned int only_unallocated);
static int efreet_menu_filter_matches(Efreet_Menu_Filter_Op *op,
@ -439,47 +439,54 @@ efreet_menu_init(void)
if (!eina_stringshare_init()) return 0;
if (!efreet_xml_init()) return 0;
efreet_menu_handle_cbs = ecore_hash_new(NULL, NULL);
efreet_menu_filter_cbs = ecore_hash_new(NULL, NULL);
efreet_menu_move_cbs = ecore_hash_new(NULL, NULL);
efreet_menu_layout_cbs = ecore_hash_new(NULL, NULL);
efreet_menu_handle_cbs = eina_hash_string_superfast_new(NULL);
efreet_menu_filter_cbs = eina_hash_string_superfast_new(NULL);
efreet_menu_move_cbs = eina_hash_string_superfast_new(NULL);
efreet_menu_layout_cbs = eina_hash_string_superfast_new(NULL);
if (!efreet_menu_handle_cbs || !efreet_menu_filter_cbs
|| !efreet_menu_move_cbs || !efreet_menu_layout_cbs)
return 0;
ecore_hash_free_key_cb_set(efreet_menu_handle_cbs,
ECORE_FREE_CB(eina_stringshare_del));
ecore_hash_free_key_cb_set(efreet_menu_filter_cbs,
ECORE_FREE_CB(eina_stringshare_del));
ecore_hash_free_key_cb_set(efreet_menu_move_cbs,
ECORE_FREE_CB(eina_stringshare_del));
ecore_hash_free_key_cb_set(efreet_menu_layout_cbs,
ECORE_FREE_CB(eina_stringshare_del));
/* set Menu into it's own so we can check the XML is valid before trying
* to handle it */
efreet_tag_menu = eina_stringshare_add(menu_cbs[0].key);
for (i = 0; menu_cbs[i].key != NULL; i++)
ecore_hash_set(efreet_menu_handle_cbs,
(void *)eina_stringshare_add(menu_cbs[i].key),
menu_cbs[i].cb);
{
eina_hash_del(efreet_menu_handle_cbs,
menu_cbs[i].key,
NULL);
eina_hash_add(efreet_menu_handle_cbs,
menu_cbs[i].key,
menu_cbs[i].cb);
}
for (i = 0; filter_cbs[i].key != NULL; i++)
ecore_hash_set(efreet_menu_filter_cbs,
(void *)eina_stringshare_add(filter_cbs[i].key),
filter_cbs[i].cb);
{
eina_hash_del(efreet_menu_filter_cbs,
filter_cbs[i].key,
NULL);
eina_hash_add(efreet_menu_filter_cbs,
filter_cbs[i].key,
filter_cbs[i].cb);
}
for (i = 0; move_cbs[i].key != NULL; i++)
ecore_hash_set(efreet_menu_move_cbs,
(void *)eina_stringshare_add(move_cbs[i].key),
move_cbs[i].cb);
{
eina_hash_del(efreet_menu_move_cbs,
move_cbs[i].key,
NULL);
eina_hash_add(efreet_menu_move_cbs,
move_cbs[i].key,
move_cbs[i].cb);
}
for (i = 0; layout_cbs[i].key != NULL; i++)
ecore_hash_set(efreet_menu_layout_cbs,
(void *)eina_stringshare_add(layout_cbs[i].key),
layout_cbs[i].cb);
{
eina_hash_del(efreet_menu_layout_cbs,
layout_cbs[i].key,
NULL);
eina_hash_add(efreet_menu_layout_cbs,
layout_cbs[i].key,
layout_cbs[i].cb);
}
return 1;
}
@ -651,12 +658,10 @@ efreet_menu_parse(const char *path)
}
IF_FREE_HASH(efreet_merged_menus);
efreet_merged_menus = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(efreet_merged_menus, ECORE_FREE_CB(free));
efreet_merged_menus = eina_hash_string_superfast_new(NULL);
IF_FREE_HASH(efreet_merged_dirs);
efreet_merged_dirs = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(efreet_merged_dirs, ECORE_FREE_CB(free));
efreet_merged_dirs = eina_hash_string_superfast_new(NULL);
/* split appart the filename and the path */
internal = efreet_menu_internal_new();
@ -1065,7 +1070,7 @@ efreet_menu_handle_menu(Efreet_Menu_Internal *internal, Efreet_Xml *xml)
ecore_list_last_goto(xml->children);
while ((child = ecore_dlist_previous(xml->children)))
{
cb = ecore_hash_get(efreet_menu_handle_cbs, child->tag);
cb = eina_hash_find(efreet_menu_handle_cbs, child->tag);
if (cb)
{
if (!cb(internal, child))
@ -1649,10 +1654,10 @@ efreet_menu_merge(Efreet_Menu_Internal *parent, Efreet_Xml *xml, const char *pat
}
/* don't merge the same path twice */
if (ecore_hash_get(efreet_merged_menus, realpath))
if (eina_hash_find(efreet_merged_menus, realpath))
return 1;
ecore_hash_set(efreet_merged_menus, strdup(realpath), (void *)1);
eina_hash_add(efreet_merged_menus, realpath, (void *)1);
merge_xml = efreet_xml_new(realpath);
FREE(realpath);
@ -1723,8 +1728,8 @@ efreet_menu_merge_dir(Efreet_Menu_Internal *parent, Efreet_Xml *xml, const char
if (!parent || !xml || !path) return 0;
/* check to see if we've merged this directory already */
if (ecore_hash_get(efreet_merged_dirs, path)) return 1;
ecore_hash_set(efreet_merged_dirs, strdup(path), (void *)1);
if (eina_hash_find(efreet_merged_dirs, path)) return 1;
eina_hash_add(efreet_merged_dirs, path, (void *)1);
files = opendir(path);
if (!files) return 1;
@ -2025,7 +2030,7 @@ efreet_menu_handle_move(Efreet_Menu_Internal *parent, Efreet_Xml *xml)
{
int (*cb)(Efreet_Menu_Internal *parent, Efreet_Xml *xml);
cb = ecore_hash_get(efreet_menu_move_cbs, child->tag);
cb = eina_hash_find(efreet_menu_move_cbs, child->tag);
if (cb)
{
if (!cb(parent, child))
@ -2130,7 +2135,7 @@ efreet_menu_handle_layout(Efreet_Menu_Internal *parent, Efreet_Xml *xml)
{
int (*cb)(Efreet_Menu_Internal *parent, Efreet_Xml *xml, int def);
cb = ecore_hash_get(efreet_menu_layout_cbs, child->tag);
cb = eina_hash_find(efreet_menu_layout_cbs, child->tag);
if (cb)
{
if (!cb(parent, child, 0))
@ -2187,7 +2192,7 @@ efreet_menu_handle_default_layout(Efreet_Menu_Internal *parent, Efreet_Xml *xml)
{
int (*cb)(Efreet_Menu_Internal *parent, Efreet_Xml *xml, int def);
cb = ecore_hash_get(efreet_menu_layout_cbs, child->tag);
cb = eina_hash_find(efreet_menu_layout_cbs, child->tag);
if (cb)
{
if (!cb(parent, child, 1))
@ -2366,7 +2371,7 @@ efreet_menu_handle_filter_op(Efreet_Menu_Filter_Op *op, Efreet_Xml *xml)
{
int (*cb)(Efreet_Menu_Filter_Op *op, Efreet_Xml *xml);
cb = ecore_hash_get(efreet_menu_filter_cbs, child->tag);
cb = eina_hash_find(efreet_menu_filter_cbs, child->tag);
if (cb)
{
if (!cb(op, child))
@ -2683,9 +2688,9 @@ efreet_menu_process_filters(Efreet_Menu_Internal *internal, unsigned int only_un
if (filter->type == EFREET_MENU_FILTER_INCLUDE)
{
Ecore_Hash *matches;
Eina_Hash *matches;
matches = ecore_hash_new(ecore_str_hash, ecore_str_compare);
matches = eina_hash_string_superfast_new(NULL);
efreet_menu_process_app_pool(internal->app_pool, internal->applications,
matches, filter, internal->only_unallocated);
if (internal->parent)
@ -2699,7 +2704,7 @@ efreet_menu_process_filters(Efreet_Menu_Internal *internal, unsigned int only_un
internal->only_unallocated);
} while ((parent = parent->parent));
}
ecore_hash_destroy(matches);
eina_hash_free(matches);
}
else
{
@ -2762,9 +2767,9 @@ efreet_menu_process_filters(Efreet_Menu_Internal *internal, unsigned int only_un
*/
static
void efreet_menu_process_app_pool(Ecore_List *pool, Ecore_List *applications,
Ecore_Hash *matches,
Efreet_Menu_Filter *filter,
unsigned int only_unallocated)
Eina_Hash *matches,
Efreet_Menu_Filter *filter,
unsigned int only_unallocated)
{
Efreet_Menu_Desktop *md;
@ -2773,12 +2778,12 @@ void efreet_menu_process_app_pool(Ecore_List *pool, Ecore_List *applications,
ecore_list_first_goto(pool);
while ((md = ecore_list_next(pool)))
{
if (ecore_hash_get(matches, md->id)) continue;
if (eina_hash_find(matches, md->id)) continue;
if (only_unallocated && md->allocated) continue;
if (efreet_menu_filter_matches(filter->op, md))
{
ecore_list_append(applications, md);
ecore_hash_set(matches, (void *)md->id, md);
eina_hash_add(matches, (void *)md->id, md);
md->allocated = 1;
}
}
@ -3459,9 +3464,8 @@ efreet_menu_directory_dirs_process(Efreet_Menu_Internal *internal)
if (internal->directory_dirs)
{
internal->directory_cache = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(internal->directory_cache, ECORE_FREE_CB(free));
ecore_hash_free_value_cb_set(internal->directory_cache, ECORE_FREE_CB(efreet_desktop_free));
internal->directory_cache =
eina_hash_string_superfast_new(EINA_FREE_CB(efreet_desktop_free));
ecore_dlist_last_goto(internal->directory_dirs);
while ((path = ecore_dlist_previous(internal->directory_dirs)))
@ -3496,7 +3500,7 @@ efreet_menu_directory_dirs_process(Efreet_Menu_Internal *internal)
*/
static int
efreet_menu_directory_dir_scan(const char *path, const char *relative_path,
Ecore_Hash *cache)
Eina_Hash *cache)
{
Efreet_Desktop *desktop;
DIR *files;
@ -3531,7 +3535,8 @@ efreet_menu_directory_dir_scan(const char *path, const char *relative_path,
continue;
}
ecore_hash_set(cache, (void *)strdup(buf2), desktop);
eina_hash_del(cache, buf2, NULL);
eina_hash_add(cache, buf2, desktop);
}
}
closedir(files);
@ -3553,7 +3558,7 @@ efreet_menu_directory_get(Efreet_Menu_Internal *internal, const char *path)
if (internal->directory_cache)
{
dir = ecore_hash_get(internal->directory_cache, path);
dir = eina_hash_find(internal->directory_cache, path);
if (dir) return dir;
}

View File

@ -9,8 +9,8 @@
static Ecore_List *globs = NULL; /* contains Efreet_Mime_Glob structs */
static Ecore_List *magics = NULL; /* contains Efreet_Mime_Magic structs */
static Ecore_Hash *wild = NULL; /* contains *.ext and mime.types globs*/
static Ecore_Hash *monitors = NULL; /* contains file monitors */
static Eina_Hash *wild = NULL; /* contains *.ext and mime.types globs*/
static Eina_Hash *monitors = NULL; /* contains file monitors */
/**
* @internal
@ -111,10 +111,7 @@ efreet_mime_init(void)
efreet_mime_endianess = efreet_mime_endian_check();
monitors = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(monitors, ECORE_FREE_CB(free));
ecore_hash_free_value_cb_set(monitors,
ECORE_FREE_CB(ecore_file_monitor_del));
monitors = eina_hash_string_superfast_new(EINA_FREE_CB(ecore_file_monitor_del));
if (!efreet_mime_init_files())
return 0;
@ -269,7 +266,7 @@ efreet_mime_globs_type_get(const char *file)
while (p)
{
p++;
if (p && (mime = ecore_hash_get(wild, p))) return mime;
if (p && (mime = eina_hash_find(wild, p))) return mime;
p = strchr(p, '.');
}
}
@ -342,11 +339,14 @@ efreet_mime_monitor_add(const char *file)
/* if this is already in our hash then we're already monitoring so no
* reason to re-monitor */
if (ecore_hash_get(monitors, file))
if (eina_hash_find(monitors, file))
return;
if ((fm = ecore_file_monitor_add(file, efreet_mime_cb_update_file, NULL)))
ecore_hash_set(monitors, strdup(file), fm);
{
eina_hash_del(monitors, file, NULL);
eina_hash_add(monitors, file, fm);
}
}
/**
@ -364,10 +364,7 @@ efreet_mime_load_globs(Ecore_List *datadirs, const char *datahome)
const char *datadir = NULL;
IF_FREE_HASH(wild);
wild = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_free_key_cb_set(wild, ECORE_FREE_CB(eina_stringshare_del));
ecore_hash_free_value_cb_set(wild,
ECORE_FREE_CB(eina_stringshare_del));
wild = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
IF_FREE_LIST(globs);
globs = ecore_list_new();
ecore_list_free_cb_set(globs, efreet_mime_glob_free);
@ -688,8 +685,8 @@ efreet_mime_mime_types_load(const char *file)
strncpy(ext, pp, (p - pp));
ext[p - pp] = 0;
ecore_hash_set(wild, (void*)eina_stringshare_add(ext),
(void*)eina_stringshare_add(mimetype));
eina_hash_del(wild, ext, NULL);
eina_hash_add(wild, ext, (void*)eina_stringshare_add(mimetype));
}
while ((*p != '\n') && (*p != 0));
}
@ -746,8 +743,9 @@ efreet_mime_shared_mimeinfo_globs_load(const char *file)
if (ext[0] == '*' && ext[1] == '.')
{
ecore_hash_set(wild, (void*)eina_stringshare_add(&(ext[2])),
(void*)eina_stringshare_add(mimetype));
eina_hash_del(wild, &(ext[2]), NULL);
eina_hash_add(wild, &(ext[2]),
(void*)eina_stringshare_add(mimetype));
}
else
{

View File

@ -94,7 +94,7 @@
*/
#define IF_FREE_HASH(x) do { \
if (x) { \
Ecore_Hash *__tmp; __tmp = (x); (x) = NULL; ecore_hash_destroy(__tmp); \
Eina_Hash *__tmp; __tmp = (x); (x) = NULL; eina_hash_free(__tmp); \
} \
(x) = NULL; \
} while (0)

View File

@ -25,6 +25,7 @@ struct Efreet_Cache_Fill_Dir
struct Efreet_Cache_Search
{
Efreet_Util_Desktop *result;
const char *what1;
const char *what2;
};
@ -56,16 +57,16 @@ static void efreet_util_cache_remove(const char *path, const char *file_id, int
static void efreet_util_cache_reload(const char *path, const char *file_id, int priority);
static void efreet_util_cache_dir_free(void *data);
static void efreet_util_cache_search_mime(void *value, void *data);
static int efreet_util_cache_search_wm_class(const void *value, const void *data);
static int efreet_util_cache_search_exec(const void *value, const void *data);
static int efreet_util_cache_search_name(const void *value, const void *data);
static int efreet_util_cache_search_generic_name(const void *value, const void *data);
static Eina_Bool efreet_util_cache_search_mime(const Eina_Hash *hash, void *value, void *fdata);
static Eina_Bool efreet_util_cache_search_wm_class(const Eina_Hash *hash, void *value, void *fdata);
static Eina_Bool efreet_util_cache_search_exec(const Eina_Hash *hash, void *value, void *fdata);
static Eina_Bool efreet_util_cache_search_name(const Eina_Hash *hash, void *value, void *fdata);
static Eina_Bool efreet_util_cache_search_generic_name(const Eina_Hash *hash, void *value, void *fdata);
static void efreet_util_cache_search_name_glob(void *value, void *data);
static void efreet_util_cache_search_exec_glob(void *value, void *data);
static void efreet_util_cache_search_generic_name_glob(void *value, void *data);
static void efreet_util_cache_search_comment_glob(void *value, void *data);
static Eina_Bool efreet_util_cache_search_name_glob(const Eina_Hash *hash, void *value, void *fdata);