From: <enl...@li...> - 2006-02-18 02:12:30
|
Enlightenment CVS committal Author : onefang Project : e17 Module : apps/e_utils Dir : e17/apps/e_utils/src/bin/e17genmenu/src/bin Modified Files: fdo_menus.c main.c parse.c parse.h Log Message: Major milestone. The internal menu generation step is now complete. This is a major step in the midle of the entire process. Still need to generate the proper .order files from the resulting structure at the end. That comes next. The first major step, the merging of menu files, will be left until last. This is so that I can keep a lid on the amount of test data during these early stages. Remember, my box has thousands of apps installed. =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/fdo_menus.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- fdo_menus.c 17 Feb 2006 14:11:06 -0000 1.10 +++ fdo_menus.c 18 Feb 2006 02:12:25 -0000 1.11 @@ -35,6 +35,7 @@ char *base; char *path; Dumb_List *stack; + int unallocated; }; struct _fdo_menus_generate_data @@ -57,7 +58,7 @@ static int _fdo_menus_generate(const void *data, Dumb_List *list, int element, int level); static void _fdo_menus_inherit_apps(void *value, void *user_data); static void _fdo_menus_select_app(void *value, void *user_data); -static int _fdo_menus_apply_rules(struct _fdo_menus_generate_data *generate_data, Dumb_List *rule, char *key, Ecore_Hash *desktop); +static int _fdo_menus_apply_rules(struct _fdo_menus_generate_data *generate_data, Dumb_List *rule, char *key, Desktop *desktop); Dumb_List * @@ -76,10 +77,14 @@ { dumb_list_foreach(xml, 0, _fdo_menus_unxml, &data); // dumb_list_dump(xml, 0); -// printf("\n\n"); + printf("\n\n"); + data.unallocated = FALSE; + dumb_list_foreach(xml, 0, _fdo_menus_generate, &data); + printf("\n\n"); + data.unallocated = TRUE; dumb_list_foreach(xml, 0, _fdo_menus_generate, &data); // dumb_list_dump(xml, 0); -// printf("\n\n"); + printf("\n\n"); } E_FREE(data.path); E_FREE(data.base); @@ -512,16 +517,12 @@ char *file; file = strdup(path + our_data->length); -// path = strdup(path); if ((file) && (path)) { - char app[MAX_PATH + 2]; - for (i = 0; file[i] != '\0'; i++ ) if (file[i] == '/') file[i] = '-'; - sprintf(app, "U %s", path); - ecore_hash_set(our_data->pool, file, strdup(app)); + ecore_hash_set(our_data->pool, file, strdup(path)); } } } @@ -545,68 +546,43 @@ int i; struct _fdo_menus_generate_data generate_data; - generate_data.unallocated = FALSE; + generate_data.unallocated = unxml_data->unallocated; generate_data.name = (char *) list->elements[element].element; generate_data.path = (char *) list->elements[element + 1].element; generate_data.pool = (Ecore_Hash *) list->elements[element + 2].element; generate_data.rules = (Dumb_List *) list->elements[element + 3].element; generate_data.apps = (Ecore_Hash *) list->elements[element + 4].element; -printf("MAKING MENU - %s \t\t%s\n", generate_data.path, generate_data.name); - /* Inherit the pools. */ - if (unxml_data->stack->size <= level) - { - while (unxml_data->stack->size < level) - dumb_list_add_hash(unxml_data->stack, generate_data.pool); - dumb_list_add_hash(unxml_data->stack, generate_data.pool); - } - else + /* Inherit the pools on the first pass. */ + if (!generate_data.unallocated) { - unxml_data->stack->elements[level].type = DUMB_LIST_ELEMENT_TYPE_HASH; - unxml_data->stack->elements[level].element = generate_data.pool; - } - for (i = level - 1; i >= 0; i--) - { - if (unxml_data->stack->elements[i].type == DUMB_LIST_ELEMENT_TYPE_HASH) - { - Ecore_Hash *ancestor; - - ancestor = (Ecore_Hash *) unxml_data->stack->elements[i].element; - ecore_hash_for_each_node(ancestor, _fdo_menus_inherit_apps, generate_data.pool); - } - } - - /* Process the rules. */ - if (generate_data.name[9] != 'O') - { - for (i = 0; i < generate_data.rules->size; i++) + if (unxml_data->stack->size <= level) + { + while (unxml_data->stack->size < level) + dumb_list_add_hash(unxml_data->stack, generate_data.pool); + dumb_list_add_hash(unxml_data->stack, generate_data.pool); + } + else + { + unxml_data->stack->elements[level].type = DUMB_LIST_ELEMENT_TYPE_HASH; + unxml_data->stack->elements[level].element = generate_data.pool; + } + for (i = level - 1; i >= 0; i--) { - if (generate_data.rules->elements[i].type == DUMB_LIST_ELEMENT_TYPE_LIST) + if (unxml_data->stack->elements[i].type == DUMB_LIST_ELEMENT_TYPE_HASH) { - generate_data.rule = (Dumb_List *) generate_data.rules->elements[i].element; - if (generate_data.rule->size > 0) - { - if ( ((char *) generate_data.rule->elements[0].element)[0] == 'I' ) - { - generate_data.include = TRUE; - ecore_hash_for_each_node(generate_data.pool, _fdo_menus_select_app, &generate_data); - } - else - { - generate_data.include = FALSE; - ecore_hash_for_each_node(generate_data.apps, _fdo_menus_select_app, &generate_data); - } - } + Ecore_Hash *ancestor; + + ancestor = (Ecore_Hash *) unxml_data->stack->elements[i].element; + ecore_hash_for_each_node(ancestor, _fdo_menus_inherit_apps, generate_data.pool); } - else - printf("Fuck, a bug in _fdo_menus.\n"); - } + } } - generate_data.unallocated = TRUE; - /* Process the rules, again. */ - if (generate_data.name[9] == 'O') + /* Process the rules. */ + if (generate_data.name[9] == (generate_data.unallocated ? 'O' : ' ')) { + printf("MAKING MENU - %s \t\t%s\n", generate_data.path, generate_data.name); for (i = 0; i < generate_data.rules->size; i++) { if (generate_data.rules->elements[i].type == DUMB_LIST_ELEMENT_TYPE_LIST) @@ -629,7 +605,7 @@ else printf("Fuck, a bug in _fdo_menus.\n"); } - } + } } } return 0; @@ -654,7 +630,7 @@ _fdo_menus_select_app(void *value, void *user_data) { Ecore_Hash_Node *node; - Ecore_Hash *desktop; + Desktop *desktop; struct _fdo_menus_generate_data *generate_data; char *key, *app; @@ -663,16 +639,17 @@ key = (char *) node->key; app = (char *) node->value; - if ((generate_data->unallocated) && (app[0] == 'A')) + desktop = parse_desktop_ini_file(app); + + if ((generate_data->unallocated) && (desktop->allocated)) return; - desktop = parse_ini_file(&app[2]); if (_fdo_menus_apply_rules(generate_data, generate_data->rule, key, desktop)) { + desktop->allocated = TRUE; if (generate_data->include) { - app[0] = 'A'; - ecore_hash_set(generate_data->apps, key, strdup(&app[2])); + ecore_hash_set(generate_data->apps, key, strdup(app)); printf("INCLUDING %s%s\n", ((generate_data->unallocated) ? "UNALLOCATED " : ""), key); } else @@ -684,7 +661,7 @@ } static int -_fdo_menus_apply_rules(struct _fdo_menus_generate_data *generate_data, Dumb_List *rule, char *key, Ecore_Hash *desktop) +_fdo_menus_apply_rules(struct _fdo_menus_generate_data *generate_data, Dumb_List *rule, char *key, Desktop *desktop) { char type = 'O'; int result = FALSE; @@ -722,7 +699,20 @@ case 'C' : { - /* FIXME: try to match a category. */ + /* Try to match a category. */ + if (desktop->Categories) + { + int j; + + for (j = 0; j < desktop->Categories->size; j++) + { + if (strcmp((char *) (desktop->Categories->elements[j].element), &rul[4]) == 0) + { + sub_result = TRUE; + break; + } + } + } break; } } @@ -816,7 +806,7 @@ * if there are <Deleted> elements that are not ovreridden by a <NotDelete> element * remove this <Menu> element and all it's children. -generate menus +*generate menus * for each <Menu> that is <NotOnlyUnallocated> (which is the default) * for each <AppDir> * for each .desktop @@ -833,7 +823,6 @@ * if rule matches .desktop in pool * add .desktop to menu. * mark it as allocated - * if rule is an <Exclude> * for each .desktop in menu * for each rule =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/main.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -3 -r1.22 -r1.23 --- main.c 17 Feb 2006 14:11:07 -0000 1.22 +++ main.c 18 Feb 2006 02:12:25 -0000 1.23 @@ -59,7 +59,7 @@ char *icon = "tux.png"; Dumb_List *menu_xml = NULL; - printf("Path to %s is %s\n", menu, path); + printf("\n\nPath to %s is %s\n", menu, path); menu_xml = xmlame_get(path);; if (menu_xml) { =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/parse.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- parse.c 17 Feb 2006 06:57:19 -0000 1.11 +++ parse.c 18 Feb 2006 02:12:25 -0000 1.12 @@ -6,6 +6,9 @@ #include "order.h" #include "parse.h" +static void _parse_desktop_del(Desktop *desktop); + + char * get_t(char *icon) { @@ -385,6 +388,15 @@ ecore_hash_set_free_value(ini_file_cache, (Ecore_Free_Cb) ecore_hash_destroy); } } + if (!desktop_cache) + { + desktop_cache = ecore_hash_new(ecore_str_hash, ecore_str_compare); + if (desktop_cache) + { + ecore_hash_set_free_key(desktop_cache, free); + ecore_hash_set_free_value(desktop_cache, (Ecore_Free_Cb) _parse_desktop_del); + } + } } Ecore_Hash * @@ -392,10 +404,6 @@ { Ecore_Hash *result; - result = (Ecore_Hash *) ecore_hash_get(ini_file_cache, file); - if (result) - return result; - result = ecore_hash_new(ecore_str_hash, ecore_str_compare); if (result) { @@ -489,6 +497,54 @@ return result; } +Desktop *parse_desktop_ini_file(char *file) +{ + Desktop *result; + + result = (Desktop *) ecore_hash_get(desktop_cache, file); + if (!result) + { + result = calloc(1, sizeof(Desktop)); + if (result) + { + result->data = parse_ini_file(file); + if (result->data) + { + result->group = (Ecore_Hash *) ecore_hash_get(result->data, "Desktop Entry"); + if (result->group) + { + char *temp; + + temp = (char *) ecore_hash_get(result->group, "Categories"); + if (temp) + result->Categories = dumb_list_from_paths(temp); + temp = (char *) ecore_hash_get(result->group, "OnlyShowIn"); + if (temp) + result->OnlyShowIn = dumb_list_from_paths(temp); + temp = (char *) ecore_hash_get(result->group, "NotShowIn"); + if (temp) + result->NotShowIn = dumb_list_from_paths(temp); + } + ecore_hash_set(desktop_cache, strdup(file), result); + } + else + { + free(result); + result = NULL; + } + } + } + return result; +} + +static void _parse_desktop_del(Desktop *desktop) +{ + if (desktop->NotShowIn) dumb_list_del(desktop->NotShowIn); + if (desktop->OnlyShowIn) dumb_list_del(desktop->OnlyShowIn); + if (desktop->Categories) dumb_list_del(desktop->Categories); + free(desktop); +} + void parse_ini_shutdown() { @@ -497,4 +553,9 @@ ecore_hash_destroy(ini_file_cache); ini_file_cache = NULL; } + if(desktop_cache) + { + ecore_hash_destroy(desktop_cache); + desktop_cache = NULL; + } } =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/parse.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- parse.h 17 Feb 2006 06:57:19 -0000 1.4 +++ parse.h 18 Feb 2006 02:12:25 -0000 1.5 @@ -5,8 +5,19 @@ #include <stdlib.h> #include <unistd.h> #include <Ecore_Data.h> +#include "dumb_list.h" + + +typedef struct _Desktop Desktop; +struct _Desktop +{ + Ecore_Hash *data, *group; + Dumb_List *Categories, *OnlyShowIn, *NotShowIn; /* FIXME: Better to have these as hashes. */ + int NoDisplay, Hidden, allocated; +}; Ecore_Hash *ini_file_cache; +Ecore_Hash *desktop_cache; /* Function Prototypes */ char *get_t(char *icon); @@ -17,6 +28,7 @@ void process_file(char *file, G_Eap *eap); void parse_ini_init(void); Ecore_Hash *parse_ini_file(char *file); +Desktop *parse_desktop_ini_file(char *file); void parse_ini_shutdown(void); #endif |