Index: apps/tagtree.c
===================================================================
--- apps/tagtree.c	(Revision 13084)
+++ apps/tagtree.c	(Arbeitskopie)
@@ -67,6 +67,7 @@
 static long *uniqbuf;
 
 #define MAX_TAGS 5
+#define MAX_MENU_ID_SIZE 32
 
 static struct tagcache_search tcs, tcs2;
 static bool sort_inverse;
@@ -120,9 +121,8 @@
 
 struct root_menu {
     char title[64];
-    char id[32];
+    char id[MAX_MENU_ID_SIZE];
     int itemcount;
-    struct root_menu *parent;
     struct menu_entry *items[TAGMENU_MAX_ITEMS];
 };
 
@@ -511,6 +511,7 @@
     struct search_instruction *inst = entry->si;
     char buf[MAX_PATH];
     int i;
+    struct root_menu *new_menu;
     
     strp = str;
     
@@ -527,7 +528,7 @@
     
     if (entry->type == menu_load)
     {
-        if (get_token_str(buf, sizeof buf) < 0)
+        if (get_token_str(buf, MAX_MENU_ID_SIZE) < 0)
             return false;
         
         /* Find the matching root menu or "create" it */
@@ -536,12 +537,22 @@
             if (!strcasecmp(menus[i]->id, buf))
             {
                 entry->link = i;
-                menus[i]->parent = menu;
                 return true;
             }
         }
         
-        return false;
+        if (menu_count >= TAGMENU_MAX_MENUS)
+        {
+            logf("max menucount reached");
+            return false;
+        }
+        menus[menu_count] = buffer_alloc(sizeof(struct root_menu));
+        new_menu = menus[menu_count];
+        memset(new_menu, 0, sizeof(struct root_menu));
+        strcpy(new_menu->id, buf);
+        entry->link = menu_count;
+        ++menu_count;
+        return true;
     }
     
     if (entry->type != menu_next)
@@ -732,7 +743,6 @@
         if (read_menu)
         {
             /* End the menu */
-            menu_count++;
             read_menu = false;
         }
         return 0;
@@ -772,22 +782,33 @@
                     logf("max menucount reached");
                     return 0;
                 }
-            
-                menus[menu_count] = buffer_alloc(sizeof(struct root_menu));
-                menu = menus[menu_count];
-                memset(menu, 0, sizeof(struct root_menu));
-                if (get_token_str(menu->id, sizeof(menu->id)) < 0)
+                if (get_token_str(data, MAX_MENU_ID_SIZE) < 0)
                 {
                     logf("%%menu_start id empty");
                     return 0;
                 }
+                menu = NULL;
+                for (i = 0; i < menu_count; i++)
+                {
+                    if (!strcasecmp(menus[i]->id, data))
+                    {
+                        menu = menus[i];
+                    }
+                }
+                if (menu==NULL) 
+                {
+                    menus[menu_count] = buffer_alloc(sizeof(struct root_menu));
+                    menu = menus[menu_count];
+                    ++menu_count;
+                    memset(menu, 0, sizeof(struct root_menu));
+                    strcpy(menu->id, data);
+                }
                 if (get_token_str(menu->title, sizeof(menu->title)) < 0)
                 {
                     logf("%%menu_start title empty");
                     return 0;
                 }
                 logf("menu: %s", menu->title);
-                menu->itemcount = 0;
                 read_menu = true;
                 break;
                 
