Enlightenment CVS committal Author : onefang Project : e17 Module : apps/e_utils
Dir : e17/apps/e_utils/src/bin/e17genmenu Modified Files: dumb_tree.c dumb_tree.h fdo_desktops.c fdo_desktops.h fdo_icons.c fdo_menus.c fdo_paths.c fdo_paths.h main.c menus.c Log Message: * Replaced Dumb_Tree usage with Ecore_thingy almost everywhere. The xml and menu code is where Dumb_Tree is really needed, everything else can get by with ordinary ecore stuff. * Doubled the speed of fdo_paths, it really needed it. Still too slow, but it's approaching respectability. * More tweaks to prepare it for the coming APIectomy. Surgery is scheduled for tomorrow. =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/dumb_tree.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- dumb_tree.c 7 Mar 2006 21:58:24 -0000 1.1 +++ dumb_tree.c 10 Aug 2006 07:37:42 -0000 1.2 @@ -7,48 +7,6 @@ static void dumb_tree_dump_each_hash_node(void *value, void *user_data); -/** Split a list of paths into a Dumb_Tree. - * - * The list of paths can use any one of ;:, to seperate the paths. - * You can also escape the :;, with \. - * - * FIXME: The concept here is still buggy, but it should do for now. - * - * @param paths A list of paths. - */ -Dumb_Tree * -dumb_tree_from_paths(char *paths) -{ - Dumb_Tree *tree = NULL; - - tree = dumb_tree_new(paths); - if ((tree) && (tree->buffers)) - { - char *start, *end; - int finished = 0; - - end = tree->buffers[0]; - while (!finished) - { - start = end; - do /* FIXME: There is probably a better way to do this. */ - { - while ((*end != ';') && (*end != ':') && (*end != ',') && (*end != '\0')) - end++; - } - while ((end != tree->buffers[0]) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */ - /* FIXME: We still need to unescape it now. */ - if (*end == '\0') - finished = 1; - *end = '\0'; - if (!dumb_tree_exist(tree, start)) - tree = dumb_tree_add(tree, start); - end++; - } - } - return tree; -} - /* Just a quick and dirty tree implemtation that will likely get replaced by * something much saner at a later date. I wrote most of this while falling * asleep. It will probably scare me when I wake up. B-) =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/dumb_tree.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- dumb_tree.h 7 Mar 2006 21:58:24 -0000 1.1 +++ dumb_tree.h 10 Aug 2006 07:37:42 -0000 1.2 @@ -40,7 +40,6 @@ { # endif - Dumb_Tree *dumb_tree_from_paths(char *paths); Dumb_Tree *dumb_tree_new(char *buffer); Dumb_Tree *dumb_tree_add(Dumb_Tree * tree, char *element); void dumb_tree_track(Dumb_Tree * tree, void *element); =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/fdo_desktops.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- fdo_desktops.c 9 Aug 2006 23:48:00 -0000 1.2 +++ fdo_desktops.c 10 Aug 2006 07:37:42 -0000 1.3 @@ -1,11 +1,12 @@ #include "config.h" #include "global.h" -#include "fdo_icons.h" #include "fdo_desktops.h" +#include "fdo_icons.h" +#include "fdo_paths.h" extern int reject_count, not_over_count; -static void _fdo_desktops_desktop_del(Fdo_Desktop * desktop); +void fdo_desktops_desktop_del(Fdo_Desktop * desktop); static Ecore_Hash *ini_file_cache; static Ecore_Hash *desktop_cache; @@ -129,48 +130,30 @@ { char *value; - value = (char *)ecore_hash_get(result->group, "Name"); - if (value) - result->name = strdup(value); - value = (char *)ecore_hash_get(result->group, "GenericName"); - if (value) - result->generic = strdup(value); - value = (char *)ecore_hash_get(result->group, "Comment"); - if (value) - result->comment = strdup(value); - value = (char *)ecore_hash_get(result->group, "Type"); - if (value) - result->type = strdup(value); - value = (char *)ecore_hash_get(result->group, "Categories"); - if (value) - { - result->categories = strdup(value); - result->Categories = dumb_tree_from_paths(value); - } + result->name = (char *)ecore_hash_get(result->group, "Name"); + result->generic = (char *)ecore_hash_get(result->group, "GenericName"); + result->comment = (char *)ecore_hash_get(result->group, "Comment"); + result->type = (char *)ecore_hash_get(result->group, "Type"); + result->exec = (char *)ecore_hash_get(result->group, "Exec"); + result->window_class = (char *)ecore_hash_get(result->group, "StartupWMClass"); + result->icon = (char *)ecore_hash_get(result->group, "Icon"); + if (result->icon) + result->icon_path = find_icon(result->icon); + result->categories = (char *)ecore_hash_get(result->group, "Categories"); + if (result->categories) + result->Categories = ecore_hash_from_paths(result->categories); value = (char *)ecore_hash_get(result->group, "OnlyShowIn"); if (value) - result->OnlyShowIn = dumb_tree_from_paths(value); + result->OnlyShowIn = ecore_hash_from_paths(value); value = (char *)ecore_hash_get(result->group, "NotShowIn"); if (value) - result->NotShowIn = dumb_tree_from_paths(value); - value = (char *)ecore_hash_get(result->group, "Exec"); - if (value) - result->exec = strdup(value); - value = (char *)ecore_hash_get(result->group, "Icon"); - if (value) - { - result->icon = strdup(value); - result->icon_path = find_icon(result->icon); - } + result->NotShowIn = ecore_hash_from_paths(value); value = (char *)ecore_hash_get(result->group, "X-KDE-StartupNotify"); if (value) result->startup = (!strcmp(value, "true")) ? "1" : "0"; value = (char *)ecore_hash_get(result->group, "StartupNotify"); if (value) result->startup = (!strcmp(value, "true")) ? "1" : "0"; - value = (char *)ecore_hash_get(result->group, "StartupWMClass"); - if (value) - result->window_class = strdup(value); } ecore_hash_set(desktop_cache, strdup(file), result); @@ -204,7 +187,7 @@ if (desktop_cache) { ecore_hash_set_free_key(desktop_cache, free); - ecore_hash_set_free_value(desktop_cache, (Ecore_Free_Cb) _fdo_desktops_desktop_del); + ecore_hash_set_free_value(desktop_cache, (Ecore_Free_Cb) fdo_desktops_destroy); } } } @@ -226,15 +209,15 @@ } -static void -_fdo_desktops_desktop_del(Fdo_Desktop * desktop) +void +fdo_desktops_destroy(Fdo_Desktop * desktop) { if (desktop->NotShowIn) - dumb_tree_del(desktop->NotShowIn); + ecore_hash_destroy(desktop->NotShowIn); if (desktop->OnlyShowIn) - dumb_tree_del(desktop->OnlyShowIn); + ecore_hash_destroy(desktop->OnlyShowIn); if (desktop->Categories) - dumb_tree_del(desktop->Categories); + ecore_hash_destroy(desktop->Categories); free(desktop); } @@ -269,48 +252,33 @@ void parse_desktop_file(char *app, char *menu_path) Desktop *desktop = fdo_desktops_parse_desktop_file(app); - eap->icon_path = find_icon(eap->icon); - void _parse_process_file(app, menu_path, eap); - -void parse_debian_file(char *file) - char *name = _parse_buffer(buffer, "title="); - //char *d = _parse_get_t(t); - eap->icon_path = find_icon(eap->icon); - void _parse_process_file(file, NULL, eap); Desktop *desktop = fdo_desktops_parse_desktop_file(app); result = (Desktop *) ecore_hash_get(desktop_cache, file); Ecore_Hash *result->data = fdo_desktops_parse_ini_file(file); - result->Categories = dumb_tree_from_paths(temp); + eap->icon_path = find_icon(eap->icon); ecore_hash_set(desktop_cache, strdup(file), result); Ecore_Hash *result->data = fdo_desktops_parse_ini_file(file); ecore_hash_set(ini_file_cache, strdup(file), result); -void _parse_process_file(app, menu_path, eap); - write_icon(path, eap); - category = _parse_find_category(eap->categories); - modify_order(order_path, eap->eap_name); - char *find_icon(eap->icon); icon_size = get_icon_size(); icon_theme = get_icon_theme(); static char *find_fdo_icon(char *icon, char *icon_size, char *icon_theme) theme_path = fdo_paths_search_for_file(FDO_PATHS_TYPE_ICON, icn, 1, NULL, NULL); Ecore_Hash *result->data = fdo_desktops_parse_ini_file(theme_path); - directory_paths = dumb_tree_from_paths(directories); found = fdo_paths_search_for_file(FDO_PATHS_TYPE_ICON, path, 0, NULL, NULL); void fdo_desktops_init() ini_file_cache = ecore_hash_new(ecore_str_hash, ecore_str_compare); desktop_cache = ecore_hash_new(ecore_str_hash, ecore_str_compare); - ecore_hash_set_free_value(desktop_cache, (Ecore_Free_Cb) _fdo_desktops_desktop_del); + ecore_hash_set_free_value(desktop_cache, (Ecore_Free_Cb) fdo_desktops_desroy); void fdo_desktops_shutdown() ecore_hash_destroy(ini_file_cache); ecore_hash_destroy(desktop_cache); -static void _fdo_desktops_desktop_del(Desktop * desktop) - dumb_tree_del(desktop->Categories); +static void fdo_desktops_destroy(Desktop * desktop) */ =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/fdo_desktops.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- fdo_desktops.h 9 Aug 2006 23:37:54 -0000 1.1 +++ fdo_desktops.h 10 Aug 2006 07:37:42 -0000 1.2 @@ -10,8 +10,7 @@ typedef struct _Fdo_Desktop Fdo_Desktop; struct _Fdo_Desktop { - Ecore_Hash *data, *group; - Dumb_Tree *Categories, *OnlyShowIn, *NotShowIn; /* FIXME: Better to have these as hashes. */ + Ecore_Hash *data, *group, *Categories, *OnlyShowIn, *NotShowIn; char *name; char *generic; char *comment; @@ -30,5 +29,6 @@ void fdo_desktops_shutdown(void); Ecore_Hash *fdo_desktops_parse_ini_file(char *file); Fdo_Desktop *fdo_desktops_parse_desktop_file(char *file); +void fdo_desktops_destroy(Fdo_Desktop * desktop); #endif =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/fdo_icons.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- fdo_icons.c 9 Aug 2006 23:37:54 -0000 1.1 +++ fdo_icons.c 10 Aug 2006 07:37:42 -0000 1.2 @@ -154,31 +154,34 @@ inherits = (char *)ecore_hash_get(icon_group, "Inherits"); if (directories) { - Dumb_Tree *directory_paths; + Ecore_List *directory_paths; /* Split the directory list. */ #ifdef DEBUG printf("Inherits %s Directories %s\n", inherits, directories); #endif - directory_paths = dumb_tree_from_paths(directories); + directory_paths = ecore_list_from_paths(directories); if (directory_paths) { int wanted_size; int minimal_size = INT_MAX; int i; char *closest = NULL; + char *directory; wanted_size = atoi(icon_size); /* Loop through the themes directories. */ - for (i = 0; i < directory_paths->size; i++) + + ecore_list_goto_first(directory_paths); + while ((directory = ecore_list_next(directory_paths)) != NULL) { Ecore_Hash *sub_group; #ifdef DEBUG - printf("FDO icon path = %s\n", (char *) directory_paths->elements[i].element); + printf("FDO icon path = %s\n", directory_paths); #endif /* Get the details for this theme directory. */ - sub_group = (Ecore_Hash *) ecore_hash_get(theme, directory_paths->elements[i].element); + sub_group = (Ecore_Hash *) ecore_hash_get(theme, directory); if (sub_group) { char *size, *type, *minsize, *maxsize, *threshold; @@ -240,8 +243,7 @@ /* Look for icon with all extensions. */ for (j = 0; ext[j] != NULL; j++) { - snprintf(path, MAX_PATH, "%s/%s/%s%s", icon_theme, - (char *)directory_paths->elements[i].element, icon, ext[j]); + snprintf(path, MAX_PATH, "%s/%s/%s%s", icon_theme, directory, icon, ext[j]); #ifdef DEBUG printf("FDO icon = %s\n", path); #endif @@ -263,7 +265,7 @@ } } - } /* for (i = 0; i < directory_paths->size; i++) */ + } /* while ((directory = ecore_list_next(directory_paths)) != NULL) */ /* Fall back strategy #1, look for closest size in this theme. */ if (closest) =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/fdo_menus.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- fdo_menus.c 9 Aug 2006 23:37:54 -0000 1.7 +++ fdo_menus.c 10 Aug 2006 07:37:42 -0000 1.8 @@ -71,7 +71,7 @@ static int _fdo_menus_legacy_menu(const void *data, char *path); static void _fdo_menus_unxml_rules(Dumb_Tree * rules, Dumb_Tree * tree, char type, char sub_type); static void _fdo_menus_unxml_moves(Dumb_Tree * menu, Dumb_Tree * tree); -static void _fdo_menus_add_dirs(Dumb_Tree * tree, Dumb_Tree * paths, char *pre, char *post, char *extra, int element); +static void _fdo_menus_add_dirs(Dumb_Tree * tree, Ecore_List * paths, char *pre, char *post, char *extra, int element); static int _fdo_menus_expand_apps(struct _fdo_menus_unxml_data *unxml_data, char *app_dir, Ecore_Hash * pool); static int _fdo_menus_check_app(const void *data, char *path); @@ -716,18 +716,18 @@ } static void -_fdo_menus_add_dirs(Dumb_Tree * tree, Dumb_Tree * paths, char *pre, char *post, char *extra, int element) +_fdo_menus_add_dirs(Dumb_Tree * tree, Ecore_List * paths, char *pre, char *post, char *extra, int element) { - int i; - char t[MAX_PATH]; + char t[MAX_PATH], *this_path; /* reverse the order of the dirs. */ - for (i = paths->size - 1; i >= 0; i--) + ecore_list_goto_first(paths); + while ((this_path = ecore_list_next(paths)) != NULL) { if (extra) - sprintf(t, "%s %s%s-merged/", pre, (char *)paths->elements[i].element, extra); + sprintf(t, "%s %s%s-merged/", pre, this_path, extra); else - sprintf(t, "%s %s", pre, (char *)paths->elements[i].element); + sprintf(t, "%s %s", pre, this_path); if (tree) dumb_tree_extend(tree, t); } @@ -1242,16 +1242,19 @@ /* Try to match a category. */ if (desktop->Categories) { - int j; +// int j; + + if (ecore_hash_get(desktop->Categories, &rul[4]) != NULL) + sub_result = TRUE; - for (j = 0; j < desktop->Categories->size; j++) - { - if (strcmp((char *)(desktop->Categories->elements[j].element), &rul[4]) == 0) - { - sub_result = TRUE; - break; - } - } +// for (j = 0; j < desktop->Categories->size; j++) +// { +// if (strcmp((char *)(desktop->Categories->elements[j].element), &rul[4]) == 0) +// { +// sub_result = TRUE; +// break; +// } +// } } break; } =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/fdo_paths.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- fdo_paths.c 7 Mar 2006 21:58:24 -0000 1.1 +++ fdo_paths.c 10 Aug 2006 07:37:42 -0000 1.2 @@ -19,30 +19,48 @@ struct _config_exe_data { char *home; - Dumb_Tree *types; + Ecore_List *paths, *types; int done; }; -static Dumb_Tree *_fdo_paths_get(char *before, char *env_home, char *env, char *env_home_default, char *env_default, char *type, +static Ecore_List *_fdo_paths_get(char *before, char *env_home, char *env, char *env_home_default, char *env_default, char *type, char *gnome_extra, char *kde); static void _fdo_paths_massage_path(char *path, char *home, char *first, char *second); -static void _fdo_paths_check_and_add(Dumb_Tree * paths, char *path); -static void _fdo_paths_exec_config(char *home, Dumb_Tree * extras, char *cmd); +static void _fdo_paths_check_and_add(Ecore_List * paths, char *path); +static void _fdo_paths_exec_config(Ecore_List * paths, char *home, Ecore_List * extras, char *cmd); static int _fdo_paths_cb_exe_exit(void *data, int type, void *event); + +Ecore_Event_Handler *exit_handler = NULL; +Ecore_List *gnome_data = NULL; +char *home; + + void fdo_paths_init() { - if (!fdo_paths_config) - fdo_paths_config = _fdo_paths_get(NULL, "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS", "~/.config", "/etc/xdg", "", NULL, NULL); - if (!fdo_paths_menus) - fdo_paths_menus = - _fdo_paths_get(NULL, "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS", "~/.config", "/etc/xdg", "menus", NULL, "xdgconf-menu"); - if (!fdo_paths_directories) - fdo_paths_directories = - _fdo_paths_get(NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS", - "~/.local/share", "/usr/local/share:/usr/share", "desktop-directories", "gnome/vfolders", "xdgdata-dirs"); + /* FIXME: Keep track of any loose strdups in a list, so that we can free them at shutdown time. */ + + exit_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _fdo_paths_cb_exe_exit, NULL); + gnome_data = ecore_list_new(); + home = get_home(); + if (home) + { + int last; + + /* Strip trailing slash of home. */ + last = strlen(home) - 1; + if ((last >= 0) && (home[last] == '/')) + home[last] = '\0'; + } + + if (exit_handler && gnome_data) + { + ecore_list_set_free_cb(gnome_data, free); + _fdo_paths_exec_config(gnome_data, home, NULL, "gnome-config --datadir"); + } + if (!fdo_paths_desktops) { fdo_paths_desktops = @@ -53,24 +71,36 @@ } if (!fdo_paths_kde_legacy) { - int i; - char temp[MAX_PATH]; + char temp[MAX_PATH], *path; + Ecore_List *temp_list; fdo_paths_kde_legacy = _fdo_paths_get(NULL, NULL, NULL, NULL, NULL, NULL, NULL, "apps"); - for (i = 0; i < fdo_paths_kde_legacy->size; i++) - { - char *path, *t1, *t2; - - path = (char *)fdo_paths_kde_legacy->elements[i].element; - t1 = rindex(path, '/'); - *t1 = '\0'; - t2 = rindex(path, '/'); - *t2 = '\0'; - sprintf(temp, "%s/apps/kappfinder/apps/", path); - *t2 = '/'; - *t1 = '/'; - _fdo_paths_check_and_add(fdo_paths_kde_legacy, temp); - } + if (fdo_paths_kde_legacy) + { + /* Copy it, cause Ecore_List walks can not be nested. */ + temp_list = ecore_list_new(); + if (temp_list) + { + ecore_list_goto_first(fdo_paths_kde_legacy); + while ((path = ecore_list_next(fdo_paths_kde_legacy)) != NULL) + ecore_list_append(temp_list, path); + + ecore_list_goto_first(temp_list); + while ((path = ecore_list_next(temp_list)) != NULL) + { + char *t1, *t2; + + t1 = rindex(path, '/'); + *t1 = '\0'; + t2 = rindex(path, '/'); + *t2 = '\0'; + sprintf(temp, "%s/apps/kappfinder/apps/", path); + *t2 = '/'; + *t1 = '/'; + _fdo_paths_check_and_add(fdo_paths_kde_legacy, temp); + } + } + } } if (!fdo_paths_icons) { @@ -80,19 +110,30 @@ _fdo_paths_get("~/.icons", "XDG_DATA_HOME", "XDG_DATA_DIRS", "~/.local/share", "/usr/local/share:/usr/share", "icons", "dist/icons", "icon:pixmap"); _fdo_paths_check_and_add(fdo_paths_icons, "/usr/share/pixmaps/"); - gnome = getenv("$GNOME_ICON_PATH"); + gnome = getenv("GNOME_ICON_PATH"); if (gnome) _fdo_paths_check_and_add(fdo_paths_icons, gnome); } + if (!fdo_paths_menus) + fdo_paths_menus = + _fdo_paths_get(NULL, "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS", "~/.config", "/etc/xdg", "menus", NULL, "xdgconf-menu"); + if (!fdo_paths_directories) + fdo_paths_directories = + _fdo_paths_get(NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS", + "~/.local/share", "/usr/local/share:/usr/share", "desktop-directories", "gnome/vfolders", "xdgdata-dirs"); + if (!fdo_paths_config) + fdo_paths_config = _fdo_paths_get(NULL, "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS", "~/.config", "/etc/xdg", "", NULL, NULL); + + if (exit_handler) ecore_event_handler_del(exit_handler); } void fdo_paths_shutdown() { - E_FN_DEL(dumb_tree_del, fdo_paths_menus); - E_FN_DEL(dumb_tree_del, fdo_paths_directories); - E_FN_DEL(dumb_tree_del, fdo_paths_desktops); - E_FN_DEL(dumb_tree_del, fdo_paths_icons); + E_FN_DEL(ecore_list_destroy, fdo_paths_menus); + E_FN_DEL(ecore_list_destroy, fdo_paths_directories); + E_FN_DEL(ecore_list_destroy, fdo_paths_desktops); + E_FN_DEL(ecore_list_destroy, fdo_paths_icons); } /** Search for a file in fdo compatible locations. @@ -111,11 +152,10 @@ char * fdo_paths_search_for_file(Fdo_Paths_Type type, char *file, int sub, int (*func) (const void *data, char *path), const void *data) { - int i; - char *path = NULL; + char *path = NULL, *this_path; char temp[MAX_PATH]; struct stat path_stat; - Dumb_Tree *paths = NULL; + Ecore_List *paths = NULL; switch (type) { @@ -133,21 +173,25 @@ break; } - for (i = 0; i < paths->size; i++) - { - sprintf(temp, "%s%s", (char *)paths->elements[i].element, file); - if (stat(temp, &path_stat) == 0) - { - path = strdup(temp); - if (func) - if (func(data, path)) - break; - } - else if (sub) - path = fdo_paths_recursive_search(paths->elements[i].element, file, NULL, func, data); - if (path && (!func)) - break; - } + if (paths) + { + ecore_list_goto_first(paths); + while ((this_path = ecore_list_next(paths)) != NULL) + { + sprintf(temp, "%s%s", this_path, file); + if (stat(temp, &path_stat) == 0) + { + path = strdup(temp); + if (func) + if (func(data, path)) + break; + } + else if (sub) + path = fdo_paths_recursive_search(this_path, file, NULL, func, data); + if (path && (!func)) + break; + } + } return path; } @@ -160,55 +204,45 @@ icons=pathlist */ -static Dumb_Tree * +static Ecore_List * _fdo_paths_get(char *before, char *env_home, char *env, char *env_home_default, char *env_default, char *type, char *gnome_extra, char *kde) { - char *home; - Dumb_Tree *paths = NULL; - Dumb_Tree *types; - Dumb_Tree *gnome_extras; - Dumb_Tree *kdes; - Ecore_Event_Handler *exit_handler; + Ecore_List *paths = NULL; + Ecore_List *types = NULL; + Ecore_List *gnome_extras = NULL; + Ecore_List *kdes = NULL; /* Don't sort them, as they are in preferred order from each source. */ /* Merge the results, there are probably some duplicates. */ - types = dumb_tree_from_paths(type); - gnome_extras = dumb_tree_from_paths(gnome_extra); - kdes = dumb_tree_from_paths(kde); - - home = get_home(); - if (home) - { - int last; - - /* Strip trailing slash of home. */ - last = strlen(home) - 1; - if ((last >= 0) && (home[last] == '/')) - home[last] = '\0'; - } + if (type) types = ecore_list_from_paths(strdup(type)); + if (gnome_extra) gnome_extras = ecore_list_from_paths(strdup(gnome_extra)); + if (kde) kdes = ecore_list_from_paths(strdup(kde)); - paths = dumb_tree_new(NULL); + paths = ecore_list_new(); if (paths) { - int i, j; char path[MAX_PATH]; - Dumb_Tree *env_list; + Ecore_List *env_list; + ecore_list_set_free_cb(paths, free); if (before) { - Dumb_Tree *befores; + Ecore_List *befores; - befores = dumb_tree_from_paths(before); + befores = ecore_list_from_paths(strdup(before)); if (befores) { - for (i = 0; i < befores->size; i++) + char *this_before; + + ecore_list_goto_first(befores); + while ((this_before = ecore_list_next(befores)) != NULL) { - _fdo_paths_massage_path(path, home, befores->elements[i].element, NULL); + _fdo_paths_massage_path(path, home, this_before, NULL); _fdo_paths_check_and_add(paths, path); } - E_FN_DEL(dumb_tree_del, befores); + E_FN_DEL(ecore_list_destroy, befores); } } @@ -219,18 +253,22 @@ value = getenv(env_home); if ((value == NULL) || (value[0] == '\0')) value = env_home_default; - env_list = dumb_tree_from_paths(value); - if (env_list) + env_list = ecore_list_from_paths(strdup(value)); + if (env_list && types) { - for (i = 0; i < env_list->size; i++) + char *this_env, *this_type; + + ecore_list_goto_first(env_list); + while ((this_env = ecore_list_next(env_list)) != NULL) { - for (j = 0; j < types->size; j++) + ecore_list_goto_first(types); + while ((this_type = ecore_list_next(types)) != NULL) { - _fdo_paths_massage_path(path, home, env_list->elements[i].element, types->elements[j].element); + _fdo_paths_massage_path(path, home, this_env, this_type); _fdo_paths_check_and_add(paths, path); } } - E_FN_DEL(dumb_tree_del, env_list); + E_FN_DEL(ecore_list_destroy, env_list); } } @@ -241,52 +279,81 @@ value = getenv(env); if ((value == NULL) || (value[0] == '\0')) value = env_default; - env_list = dumb_tree_from_paths(value); - if (env_list) + env_list = ecore_list_from_paths(value); + if (env_list && types) { - for (i = 0; i < env_list->size; i++) + char *this_env, *this_type; + + ecore_list_goto_first(env_list); + while ((this_env = ecore_list_next(env_list)) != NULL) { - for (j = 0; j < types->size; j++) + ecore_list_goto_first(types); + while ((this_type = ecore_list_next(types)) != NULL) { - _fdo_paths_massage_path(path, home, env_list->elements[i].element, types->elements[j].element); + _fdo_paths_massage_path(path, home, this_env, this_type); _fdo_paths_check_and_add(paths, path); } } - E_FN_DEL(dumb_tree_del, env_list); + E_FN_DEL(ecore_list_destroy, env_list); } } - } - /* - * Get the pathlist from the config file - type=pathlist - * for each path in config - * if it is already in paths, skip it - * if it exists, add it to end of paths - */ - - exit_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _fdo_paths_cb_exe_exit, paths); - if (exit_handler) - { - int i; + /* + * Get the pathlist from the config file - type=pathlist + * for each path in config + * if it is already in paths, skip it + * if it exists, add it to end of paths + */ + + if (gnome_data && types) + { + char *this_gnome, *this_type; - _fdo_paths_exec_config(home, types, "gnome-config --datadir"); - _fdo_paths_exec_config(home, gnome_extras, "gnome-config --datadir"); + ecore_list_goto_first(gnome_data); + while ((this_gnome = ecore_list_next(gnome_data)) != NULL) + { + ecore_list_goto_first(types); + while ((this_type = ecore_list_next(types)) != NULL) + { + _fdo_paths_massage_path(path, home, this_gnome, this_type); + _fdo_paths_check_and_add(paths, path); + } + } + } + if (gnome_data && gnome_extras) + { + char *this_gnome, *this_type; - for (i = 0; i < kdes->size; i++) - { - char cmd[128]; + ecore_list_goto_first(gnome_data); + while ((this_gnome = ecore_list_next(gnome_data)) != NULL) + { + ecore_list_goto_first(gnome_extras); + while ((this_type = ecore_list_next(gnome_extras)) != NULL) + { + _fdo_paths_massage_path(path, home, this_gnome, this_type); + _fdo_paths_check_and_add(paths, path); + } + } + } - sprintf(cmd, "kde-config --path %s", (char *)kdes->elements[i].element); - _fdo_paths_exec_config(home, NULL, cmd); - } + if ((exit_handler != NULL) && (kdes != NULL)) + { + char *this_kde; - ecore_event_handler_del(exit_handler); - } + ecore_list_goto_first(kdes); + while ((this_kde = ecore_list_next(kdes)) != NULL) + { + char cmd[128]; - E_FREE(home); - E_FN_DEL(dumb_tree_del, kdes); - E_FN_DEL(dumb_tree_del, gnome_extras); - E_FN_DEL(dumb_tree_del, types); + sprintf(cmd, "kde-config --path %s", this_kde); + _fdo_paths_exec_config(paths, home, NULL, cmd); + } + } + } + + E_FN_DEL(ecore_list_destroy, kdes); + E_FN_DEL(ecore_list_destroy, gnome_extras); + E_FN_DEL(ecore_list_destroy, types); return paths; } @@ -325,37 +392,43 @@ } } + static void -_fdo_paths_check_and_add(Dumb_Tree * paths, char *path) +_fdo_paths_check_and_add(Ecore_List * paths, char *path) { -#ifdef DEBUG - printf("CHECKING %s", path); -#endif - if (!dumb_tree_exist(paths, path)) - { - struct stat path_stat; + struct stat path_stat; + char *this_path; - /* Check if the path exists. */ - if ((stat(path, &path_stat) == 0) && (S_ISDIR(path_stat.st_mode))) - { -#ifdef DEBUG - printf(" OK"); -#endif - dumb_tree_extend(paths, path); - } - } -#ifdef DEBUG - printf("\n"); -#endif + if (paths == NULL) + { + paths = ecore_list_new(); + if (paths == NULL) + return; + ecore_list_set_free_cb(paths, free); + } + + /* Check if we have it already. */ + ecore_list_goto_first(paths); + while ((this_path = ecore_list_next(paths)) != NULL) + { + if (strcmp(path, this_path) == 0) + return; + } + + /* Check if the path exists. */ + if ((stat(path, &path_stat) == 0) && (S_ISDIR(path_stat.st_mode))) + ecore_list_append(paths, strdup(path)); } + static void -_fdo_paths_exec_config(char *home, Dumb_Tree * extras, char *cmd) +_fdo_paths_exec_config(Ecore_List *paths, char *home, Ecore_List * extras, char *cmd) { Ecore_Exe *exe; struct _config_exe_data ced; ced.home = home; + ced.paths = paths; ced.types = extras; ced.done = 0; exe = ecore_exe_pipe_run(cmd, ECORE_EXE_PIPE_AUTO | ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_READ_LINE_BUFFERED, &ced); @@ -366,6 +439,7 @@ { /* FIXME: raster is paranoid. If too much time passes, give up. * Or find a way to let the usual event loop shit do this without spinning our wheels. + * On the other hand, these are quick commands, and we NEED this data before we can continue. */ ecore_main_loop_iterate(); usleep(10); @@ -438,8 +512,8 @@ _fdo_paths_cb_exe_exit(void *data, int type, void *event) { Ecore_Exe_Event_Del *ev; - Dumb_Tree *paths; - Dumb_Tree *config_list; + Ecore_List *paths; + Ecore_List *config_list; Ecore_Exe_Event_Data *read; struct _config_exe_data *ced; char *value; @@ -451,12 +525,12 @@ value = ecore_exe_tag_get(ev->exe); if ((!value) || (strcmp(value, "genmenu/fdo")) != 0) return 1; - paths = data; - if (!paths) - return 1; ced = ecore_exe_data_get(ev->exe); if (!ced) return 1; + paths = ced->paths; + if (!paths) + return 1; read = ecore_exe_event_data_get(ev->exe, ECORE_EXE_PIPE_READ); if ((read) && (read->lines[0].line)) @@ -464,32 +538,139 @@ value = read->lines[0].line; if (value) { - config_list = dumb_tree_from_paths(value); + config_list = ecore_list_from_paths(value); if (config_list) { - int i, j; + char *this_config, *this_type; - for (i = 0; i < config_list->size; i++) + ecore_list_goto_first(config_list); + while ((this_config = ecore_list_next(config_list)) != NULL) { if (ced->types) { - for (j = 0; j < ced->types->size; j++) + ecore_list_goto_first(ced->types); + while ((this_type = ecore_list_next(ced->types)) != NULL) { - _fdo_paths_massage_path(path, ced->home, config_list->elements[i].element, - ced->types->elements[j].element); + _fdo_paths_massage_path(path, ced->home, this_config, this_type); _fdo_paths_check_and_add(paths, path); } } else { - _fdo_paths_massage_path(path, ced->home, config_list->elements[i].element, NULL); + _fdo_paths_massage_path(path, ced->home, this_config, NULL); _fdo_paths_check_and_add(paths, path); } } - E_FN_DEL(dumb_tree_del, config_list); + E_FN_DEL(ecore_list_destroy, config_list); } } } ced->done = 1; return 1; } + +/** Split a list of paths into an Ecore_Hash. + * + * The list of paths can use any one of ;:, to seperate the paths. + * You can also escape the :;, with \. + * + * FIXME: The concept here is still buggy, but it should do for now. + * Also, it writes to the input string, this may be bad. + * + * @param paths A list of paths. + */ +Ecore_Hash * +ecore_hash_from_paths(char *paths) +{ + Ecore_Hash *result; + + result = ecore_hash_new(ecore_str_hash, ecore_str_compare); + if (result) + { + ecore_hash_set_free_key(result, free); + ecore_hash_set_free_value(result, free); + + if (paths) + { + char *start, *end, temp; + int finished = 0; + + end = paths; + while (!finished) + { + start = end; + do /* FIXME: There is probably a better way to do this. */ + { + while ((*end != ';') && (*end != ':') && (*end != ',') && (*end != '\0')) + end++; + } + while ((end != paths) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */ + /* FIXME: We still need to unescape it now. */ + temp = *end; + if (*end == '\0') + finished = 1; + else + *end = '\0'; + ecore_hash_set(result, strdup(start), strdup(start)); + if ((*end) != temp) + *end = temp; + end++; + } + } + } + return result; +} + + +/** Split a list of paths into an Ecore_Hash. + * + * The list of paths can use any one of ;:, to seperate the paths. + * You can also escape the :;, with \. + * + * FIXME: The concept here is still buggy, but it should do for now. + * Also, it writes to the input string, this may be bad. + * + * @param paths A list of paths. + */ +Ecore_List * +ecore_list_from_paths(char *paths) +{ + Ecore_List *result; + + result = ecore_list_new(); + if (result) + { + ecore_list_set_free_cb(result, free); + + if (paths) + { + char *start, *end, temp; + int finished = 0; + + end = paths; + while (!finished) + { + start = end; + do /* FIXME: There is probably a better way to do this. */ + { + while ((*end != ';') && (*end != ':') && (*end != ',') && (*end != '\0')) + end++; + } + while ((end != paths) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */ + /* FIXME: We still need to unescape it now. */ + temp = *end; + if (*end == '\0') + finished = 1; + else + *end = '\0'; + ecore_list_append(result, strdup(start)); + if ((*end) != temp) + *end = temp; + end++; + } + } + } + return result; +} + + =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/fdo_paths.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- fdo_paths.h 7 Mar 2006 21:58:24 -0000 1.1 +++ fdo_paths.h 10 Aug 2006 07:37:42 -0000 1.2 @@ -1,7 +1,13 @@ #ifndef _FDO_PATHS_H # define _FDO_PATHS_H -#include "dumb_tree.h" +#include <Ecore_Data.h> + +#define E_FN_DEL(_fn, _h) if (_h) { _fn(_h); _h = NULL; } +#define E_REALLOC(p, s, n) p = (s *)realloc(p, sizeof(s) * n) +#define E_NEW(s, n) (s *)calloc(n, sizeof(s)) +#define E_NEW_BIG(s, n) (s *)malloc(n * sizeof(s)) +#define E_FREE(p) { if (p) {free(p); p = NULL;} } enum _Fdo_Paths_Type { @@ -13,12 +19,12 @@ }; typedef enum _Fdo_Paths_Type Fdo_Paths_Type; -Dumb_Tree *fdo_paths_config; -Dumb_Tree *fdo_paths_menus; -Dumb_Tree *fdo_paths_directories; -Dumb_Tree *fdo_paths_desktops; -Dumb_Tree *fdo_paths_icons; -Dumb_Tree *fdo_paths_kde_legacy; +Ecore_List *fdo_paths_config; +Ecore_List *fdo_paths_menus; +Ecore_List *fdo_paths_directories; +Ecore_List *fdo_paths_desktops; +Ecore_List *fdo_paths_icons; +Ecore_List *fdo_paths_kde_legacy; # ifdef __cplusplus extern "C" @@ -31,6 +37,10 @@ char *fdo_paths_recursive_search(char *path, char *d, int (*dir_func) (const void *data, char *path), int (*func) (const void *data, char *path), const void *data); void fdo_paths_shutdown(void); + + Ecore_Hash *ecore_hash_from_paths(char *paths); + Ecore_List *ecore_list_from_paths(char *paths); + # ifdef __cplusplus } =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/main.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- main.c 9 Aug 2006 23:37:54 -0000 1.7 +++ main.c 10 Aug 2006 07:37:42 -0000 1.8 @@ -124,9 +124,9 @@ { char path[MAX_PATH]; double start, begin, paths, gen; -#ifdef DEBUG - int i; -#endif +//#ifdef DEBUG + char *this_path; +//#endif /* Init E Stuff */ _e17genmenu_init(); @@ -144,21 +144,27 @@ paths = ecore_time_get() - begin; fdo_desktops_init(); -#ifdef DEBUG +//#ifdef DEBUG /* You can iterate through the various path lists as needed. */ - for (i = 0; i < fdo_paths_config->size; i++) - printf("FDO config path = %s\n", (char *)fdo_paths_config->elements[i].element); - for (i = 0; i < fdo_paths_menus->size; i++) - printf("FDO menu path = %s\n", (char *)fdo_paths_menus->elements[i].element); - for (i = 0; i < fdo_paths_directories->size; i++) - printf("FDO directory path = %s\n", (char *)fdo_paths_directories->elements[i].element); - for (i = 0; i < fdo_paths_desktops->size; i++) - printf("FDO desktop path = %s\n", (char *)fdo_paths_desktops->elements[i].element); - for (i = 0; i < fdo_paths_icons->size; i++) - printf("FDO icon path = %s\n", (char *)fdo_paths_icons->elements[i].element); - for (i = 0; i < fdo_paths_kde_legacy->size; i++) - printf("FDO kde legacy path = %s\n", (char *)fdo_paths_kde_legacy->elements[i].element); -#endif + ecore_list_goto_first(fdo_paths_config); + while ((this_path = ecore_list_next(fdo_paths_config)) != NULL) + printf("FDO config path = %s\n", this_path); + ecore_list_goto_first(fdo_paths_menus); + while ((this_path = ecore_list_next(fdo_paths_menus)) != NULL) + printf("FDO menu path = %s\n", this_path); + ecore_list_goto_first(fdo_paths_directories); + while ((this_path = ecore_list_next(fdo_paths_directories)) != NULL) + printf("FDO directory path = %s\n", this_path); + ecore_list_goto_first(fdo_paths_desktops); + while ((this_path = ecore_list_next(fdo_paths_desktops)) != NULL) + printf("FDO desktop path = %s\n", this_path); + ecore_list_goto_first(fdo_paths_icons); + while ((this_path = ecore_list_next(fdo_paths_icons)) != NULL) + printf("FDO icon path = %s\n", this_path); + ecore_list_goto_first(fdo_paths_kde_legacy); + while ((this_path = ecore_list_next(fdo_paths_kde_legacy)) != NULL) + printf("FDO kde legacy path = %s\n", this_path); +//#endif /* Just being paranoid, and cause people have removed these during testing. */ =================================================================== RCS file: /cvs/e/e17/apps/e_utils/src/bin/e17genmenu/menus.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- menus.c 26 Apr 2006 08:24:48 -0000 1.4 +++ menus.c 10 Aug 2006 07:37:42 -0000 1.5 @@ -29,7 +29,7 @@ { if (!get_fdo()) { - int i; + char *this_path; printf("Generating menus.\n"); begin = ecore_time_get(); @@ -37,10 +37,13 @@ check_for_dirs(GNOME_DIRS); /* FIXME: probably obsolete. */ check_for_dirs(KDE_DIRS); /* FIXME: probably obsolete. */ check_for_dirs(DEBIAN_DIRS); /* FIXME: may or may not be obsolete. */ - for (i = 0; i < fdo_paths_desktops->size; i++) - check_for_dirs((char *)fdo_paths_desktops->elements[i].element); - for (i = 0; i < fdo_paths_kde_legacy->size; i++) - check_for_dirs((char *)fdo_paths_kde_legacy->elements[i].element); + + ecore_list_goto_first(fdo_paths_desktops); + while ((this_path = ecore_list_next(fdo_paths_desktops)) != NULL) + check_for_dirs(this_path); + ecore_list_goto_first(fdo_paths_kde_legacy); + while ((this_path = ecore_list_next(fdo_paths_kde_legacy)) != NULL) + check_for_dirs(this_path); generate_time = ecore_time_get() - begin; } ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs