Enlightenment CVS committal
Author : onefang
Project : e17
Module : apps/e
Dir : e17/apps/e/src/bin
Modified Files:
e_fdo_menu_to_order.c
Log Message:
*Made this more sane.
*Sped it up a little.
*Hides some hidden stuff, but still shows the .hidden menu if it exists.
*Finds more stuff, although mostly empty menus.
More tweaking at deeper levels needed.
===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_fdo_menu_to_order.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- e_fdo_menu_to_order.c 4 Sep 2006 15:21:15 -0000 1.7
+++ e_fdo_menu_to_order.c 4 Sep 2006 20:00:32 -0000 1.8
@@ -2,26 +2,23 @@
//#define DEBUG 1
-//extern int menu_count, item_count;
+
+struct order_data
+{
+ char order_path[PATH_MAX];
+ Ecore_Sheap *sheap;
+};
static int _e_menu_make_apps(const void *data, Ecore_Desktop_Tree * tree, int
element, int level);
static void _e_menu_dump_each_hash_node(void *value, void *user_data);
-static int _e_search_list(Ecore_List *list, const char *search);
+static void _e_fdo_menu_to_order_add_sheap(Ecore_Sheap *sheap, const char
*order_path, const char *file);
EAPI void
e_fdo_menu_to_order(void)
{
int i;
- /* NEW STRATEGY -
- *
- * if there is no applications.menu
- * try debian-menu.menu instead.
- * if all else fails
- * run debians funky menu generator shit.
- */
char *menu_file;
- /* Should rm -fr ~/.e/e/applications/menu/all to make sure we start from a
clean slate. */
/* Find the main menu file. */
menu_file = ecore_desktop_paths_file_find(ecore_desktop_paths_menus,
"applications.menu", -1,
NULL, NULL);
@@ -30,6 +27,7 @@
/* Try various quirks of various systems. */
menu_file = ecore_desktop_paths_file_find(ecore_desktop_paths_menus,
"debian-menu.menu", -1, NULL,
NULL);
+ /* FIXME: If all else fails, run debians funky menu generator shit. */
}
if (menu_file)
@@ -45,7 +43,12 @@
menus = ecore_desktop_menu_get(menu_file);
if (menus)
{
- /* create the .eap and order files from the menu */
+ char dir[PATH_MAX];
+
+ /* Nuke the old menus. */
+ snprintf(dir, sizeof(dir),
"%s/.e/e/applications/menu/all/", ecore_desktop_home_get());
+ ecore_file_recursive_rm(dir);
+ /* create the .desktop and order files from the menu */
ecore_desktop_tree_foreach(menus, 0, _e_menu_make_apps,
path);
// FIXME: Can't free this just yet, causes major memory corruption.
// ecore_desktop_tree_del(menus);
@@ -64,20 +67,53 @@
{
if (strncmp((char *)tree->elements[element].element, "<MENU ", 6) == 0)
{
+ struct order_data order_data;
char *path;
+ char *name;
Ecore_Hash *apps;
+ path = (char *)tree->elements[element + 1].element;
#ifdef DEBUG
- char *name;
-
name = (char *)tree->elements[element].element;
printf("MAKING MENU - %s \t\t%s\n", path, name);
#endif
- path = (char *)tree->elements[element + 1].element;
// pool = (Ecore_Hash *) tree->elements[element + 2].element;
apps = (Ecore_Hash *) tree->elements[element + 4].element;
-// menu_count++;
- ecore_hash_for_each_node(apps, _e_menu_dump_each_hash_node,
&path[11]);
+
+ order_data.sheap = ecore_sheap_new(ecore_str_compare, 100);
+ if (order_data.sheap)
+ {
+ ecore_sheap_set_free_cb(order_data.sheap, free);
+ snprintf(order_data.order_path,
sizeof(order_data.order_path), "%s/.e/e/applications/menu/all/%s",
ecore_desktop_home_get(), &path[11]);
+ /* Check if we need to create the directory. */
+ if (!ecore_file_exists(order_data.order_path))
+ {
+ const char *temp;
+
+ ecore_file_mkpath(order_data.order_path);
+ /* If we create a dir, we add it to the parents
.order file. */
+ temp = ecore_file_get_dir((const char *)
order_data.order_path);
+ if (temp)
+ {
+
_e_fdo_menu_to_order_add_sheap(order_data.sheap, temp,
ecore_file_get_file(order_data.order_path));
+ free((char *) temp);
+ /* We just used the sheap, but we want it clear
for next time. */
+ ecore_sheap_destroy(order_data.sheap);
+ order_data.sheap =
ecore_sheap_new(ecore_str_compare, 100);
+ ecore_sheap_set_free_cb(order_data.sheap, free);
+ }
+ temp = ecore_file_get_file(order_data.order_path);
+ if (temp)
+ {
+// FIXME: What to do about .directory.eap's when .desktop takes over?
+// create_dir_eap(order_path, temp);
+ }
+ }
+ /* Create the apps. */
+ ecore_hash_for_each_node(apps, _e_menu_dump_each_hash_node,
&order_data);
+ _e_fdo_menu_to_order_add_sheap(order_data.sheap,
order_data.order_path, NULL);
+ ecore_sheap_destroy(order_data.sheap);
+ }
}
}
return 0;
@@ -86,158 +122,80 @@
static void
_e_menu_dump_each_hash_node(void *value, void *user_data)
{
+ struct order_data *order_data;
Ecore_Hash_Node *node;
Ecore_Desktop *desktop;
- const char *file, *path;
+ const char *file, *key;
- path = (char *)user_data;
+ order_data = (struct order_data *)user_data;
node = (Ecore_Hash_Node *) value;
+ key = (char *)node->key;
file = (char *)node->value;
-#ifdef DEBUG
- printf("MAKING MENU ITEM %s -> %s\n", path, file);
-#endif
-// item_count++;
desktop = ecore_desktop_get(file, NULL);
- /* Check If We Process */
+ /* Check if we process */
if ( (!desktop->hidden) && (!desktop->no_display) && ((desktop->type ==
NULL) || (strcmp(desktop->type, "Application") == 0)) )
{
- char order_path[PATH_MAX];
- int length;
- char *buff;
- char buffer[PATH_MAX], path2[PATH_MAX];
- FILE *f;
- Ecore_List *list = NULL;
+ char path2[PATH_MAX];
- snprintf(path2, sizeof(path2), "%s/.e/e/applications/all/%s",
ecore_desktop_home_get(), ecore_file_get_file(file));
+#ifdef DEBUG
+ printf("MAKING MENU ITEM %s -> %s (%s)\n", order_data->order_path,
file, key);
+#endif
+ snprintf(path2, sizeof(path2), "%s/.e/e/applications/all/%s",
ecore_desktop_home_get(), key);
if (!ecore_file_exists(path2))
ecore_file_symlink(file, path2);
- file = ecore_file_get_file(file);
- snprintf(order_path, sizeof(order_path),
"%s/.e/e/applications/menu/all/%s", ecore_desktop_home_get(), path);
- if (!ecore_file_exists(order_path))
- {
- const char *cat;
-
- ecore_file_mkpath(order_path);
-// FIXME: If we create a dir, we should add it to the parents .order file.
- cat = ecore_file_get_file(order_path);
- if (cat)
- {
-// FIXME: What to do about .directory.eap's when .desktop takes over?
-// create_dir_eap(order_path, cat);
- }
- }
-
- snprintf(path2, sizeof(path2), "%s/.order", order_path);
+ ecore_sheap_insert(order_data->sheap, strdup(key));
+ }
+}
-#ifdef DEBUG
- fprintf(stderr, "Modifying Order File %s\n", path2);
-#endif
+static void
+_e_fdo_menu_to_order_add_sheap(Ecore_Sheap *sheap, const char *order_path,
const char *file)
+{
+ char path2[PATH_MAX];
+ FILE *f;
- list = ecore_list_new();
- ecore_list_set_free_cb(list, free);
+ if (file)
+ ecore_sheap_insert(sheap, strdup(file));
+ snprintf(path2, sizeof(path2), "%s/.order", order_path);
+ f = fopen(path2, "r");
+ if (f)
+ {
+ char buffer[PATH_MAX];
- /* Stat .order; Create If Not Found */
- if (!ecore_file_exists(path2))
+ /* Read all entries from existing order file, store in sheap for
sorting. */
+ while (fgets(buffer, sizeof(buffer), f) != NULL)
{
- FILE *f2;
+ int length;
-#ifdef DEBUG
- fprintf(stderr, "Creating Order File %s\n", path2);
-#endif
-
- f2 = fopen(path2, "w");
- if (!f2)
- {
- fprintf(stderr, "ERROR: Cannot Create Order File %s\n",
path2);
- exit(-1);
- }
- fclose(f2);
- /* If We Had To Create This Order Then Just Add The file */
- if (!ecore_list_append(list, strdup(file)))
- {
- fprintf(stderr, "ERROR: Ecore List Append Failed !!\n");
- return;
- }
- }
- else
- {
- /* Open .order File For Parsing */
- f = fopen(path2, "r");
- if (!f)
- {
- fprintf(stderr, "ERROR: Cannot Open Order File %s \n",
path2);
- exit(-1);
- }
-
- /* Read All Entries From Existing Order File, Store In List For
Sorting */
- while (fgets(buffer, sizeof(buffer), f) != NULL)
- {
- /* Strip New Line Char */
- if (buffer[(length = strlen(buffer) - 1)] == '\n')
- buffer[length] = '\0';
- if (!_e_search_list(list, buffer))
- {
- if (!ecore_list_append(list, strdup(buffer)))
- {
- fprintf(stderr, "ERROR: Ecore List Append Failed
!!\n");
- return;
- }
- }
- }
- fclose(f);
- buffer[0] = (char)0;
-
- /* Add This file To List Of Existing ? */
- if (!_e_search_list(list, file))
- {
- if (!ecore_list_append(list, strdup(file)))
- {
- fprintf(stderr, "ERROR: Ecore List Append Failed
!!\n");
- return;
- }
- }
+ /* Strip new line char */
+ if (buffer[(length = strlen(buffer) - 1)] == '\n')
+ buffer[length] = '\0';
+ ecore_sheap_insert(sheap, strdup(buffer));
}
+ fclose(f);
+ }
-#ifdef DEBUG
- fprintf(stderr, "Rewriting Order %s\n", path2);
-#endif
+ f = fopen(path2, "w");
+ if (!f)
+ fprintf(stderr, "ERROR: Cannot Open Order File %s \n", path2);
+ else
+ {
+ char *last = NULL;
+ int i;
- f = fopen(path2, "w");
- if (!f)
+ for (i = 0; i < sheap->size; i++)
{
- fprintf(stderr, "ERROR: Cannot Open Order File %s \n", path2);
- if (list)
- ecore_list_destroy(list);
- return;
- }
+ char *item;
- ecore_list_goto_first(list);
- while ((buff = ecore_list_next(list)) != NULL)
- {
- snprintf(buffer, sizeof(buffer), "%s\n", buff);
- if (buffer != NULL)
- fwrite(buffer, sizeof(char), strlen(buffer), f);
- }
- fclose(f);
-
- if (list)
- ecore_list_destroy(list);
- }
-}
-
-
-static int
-_e_search_list(Ecore_List *list, const char *search)
-{
- char *tmp;
-
- if (!search) return 0;
- if (!list) return 0;
- ecore_list_goto_first(list);
- while ((tmp = (char *)ecore_list_next(list)) != NULL)
- {
- if (!strcmp(tmp, search))
- return 1;
- }
- return 0;
+ item = ecore_sheap_item(sheap, i);
+ if (item)
+ {
+ /* Weed out the dupes. */
+ if ((last) && (strcmp(last, item) == 0))
+ continue;
+ fprintf(f, "%s\n", item);
+ last = item;
+ }
+ }
+ fclose(f);
+ }
}
-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs