diff options
Diffstat (limited to 'apps/tagtree.c')
-rw-r--r-- | apps/tagtree.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c index 405274c6bd..03673fc653 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c | |||
@@ -69,6 +69,7 @@ enum variables { | |||
69 | static long *uniqbuf; | 69 | static long *uniqbuf; |
70 | 70 | ||
71 | #define MAX_TAGS 5 | 71 | #define MAX_TAGS 5 |
72 | #define MAX_MENU_ID_SIZE 32 | ||
72 | 73 | ||
73 | static struct tagcache_search tcs, tcs2; | 74 | static struct tagcache_search tcs, tcs2; |
74 | static bool sort_inverse; | 75 | static bool sort_inverse; |
@@ -122,9 +123,8 @@ struct menu_entry { | |||
122 | 123 | ||
123 | struct root_menu { | 124 | struct root_menu { |
124 | char title[64]; | 125 | char title[64]; |
125 | char id[32]; | 126 | char id[MAX_MENU_ID_SIZE]; |
126 | int itemcount; | 127 | int itemcount; |
127 | struct root_menu *parent; | ||
128 | struct menu_entry *items[TAGMENU_MAX_ITEMS]; | 128 | struct menu_entry *items[TAGMENU_MAX_ITEMS]; |
129 | }; | 129 | }; |
130 | 130 | ||
@@ -517,6 +517,7 @@ static bool parse_search(struct menu_entry *entry, const char *str) | |||
517 | struct search_instruction *inst = entry->si; | 517 | struct search_instruction *inst = entry->si; |
518 | char buf[MAX_PATH]; | 518 | char buf[MAX_PATH]; |
519 | int i; | 519 | int i; |
520 | struct root_menu *new_menu; | ||
520 | 521 | ||
521 | strp = str; | 522 | strp = str; |
522 | 523 | ||
@@ -542,12 +543,25 @@ static bool parse_search(struct menu_entry *entry, const char *str) | |||
542 | if (!strcasecmp(menus[i]->id, buf)) | 543 | if (!strcasecmp(menus[i]->id, buf)) |
543 | { | 544 | { |
544 | entry->link = i; | 545 | entry->link = i; |
545 | menus[i]->parent = menu; | ||
546 | return true; | 546 | return true; |
547 | } | 547 | } |
548 | } | 548 | } |
549 | 549 | ||
550 | return false; | 550 | if (menu_count >= TAGMENU_MAX_MENUS) |
551 | { | ||
552 | logf("max menucount reached"); | ||
553 | return false; | ||
554 | } | ||
555 | |||
556 | /* Allocate a new menu unless link is found. */ | ||
557 | menus[menu_count] = buffer_alloc(sizeof(struct root_menu)); | ||
558 | new_menu = menus[menu_count]; | ||
559 | memset(new_menu, 0, sizeof(struct root_menu)); | ||
560 | strncpy(new_menu->id, buf, MAX_MENU_ID_SIZE-1); | ||
561 | entry->link = menu_count; | ||
562 | ++menu_count; | ||
563 | |||
564 | return true; | ||
551 | } | 565 | } |
552 | 566 | ||
553 | if (entry->type != menu_next) | 567 | if (entry->type != menu_next) |
@@ -738,7 +752,6 @@ static int parse_line(int n, const char *buf, void *parameters) | |||
738 | if (read_menu) | 752 | if (read_menu) |
739 | { | 753 | { |
740 | /* End the menu */ | 754 | /* End the menu */ |
741 | menu_count++; | ||
742 | read_menu = false; | 755 | read_menu = false; |
743 | } | 756 | } |
744 | return 0; | 757 | return 0; |
@@ -779,21 +792,36 @@ static int parse_line(int n, const char *buf, void *parameters) | |||
779 | return 0; | 792 | return 0; |
780 | } | 793 | } |
781 | 794 | ||
782 | menus[menu_count] = buffer_alloc(sizeof(struct root_menu)); | 795 | if (get_token_str(data, sizeof data) < 0) |
783 | menu = menus[menu_count]; | ||
784 | memset(menu, 0, sizeof(struct root_menu)); | ||
785 | if (get_token_str(menu->id, sizeof(menu->id)) < 0) | ||
786 | { | 796 | { |
787 | logf("%%menu_start id empty"); | 797 | logf("%%menu_start id empty"); |
788 | return 0; | 798 | return 0; |
789 | } | 799 | } |
800 | |||
801 | menu = NULL; | ||
802 | for (i = 0; i < menu_count; i++) | ||
803 | { | ||
804 | if (!strcasecmp(menus[i]->id, data)) | ||
805 | { | ||
806 | menu = menus[i]; | ||
807 | } | ||
808 | } | ||
809 | |||
810 | if (menu == NULL) | ||
811 | { | ||
812 | menus[menu_count] = buffer_alloc(sizeof(struct root_menu)); | ||
813 | menu = menus[menu_count]; | ||
814 | ++menu_count; | ||
815 | memset(menu, 0, sizeof(struct root_menu)); | ||
816 | strncpy(menu->id, data, MAX_MENU_ID_SIZE-1); | ||
817 | } | ||
818 | |||
790 | if (get_token_str(menu->title, sizeof(menu->title)) < 0) | 819 | if (get_token_str(menu->title, sizeof(menu->title)) < 0) |
791 | { | 820 | { |
792 | logf("%%menu_start title empty"); | 821 | logf("%%menu_start title empty"); |
793 | return 0; | 822 | return 0; |
794 | } | 823 | } |
795 | logf("menu: %s", menu->title); | 824 | logf("menu: %s", menu->title); |
796 | menu->itemcount = 0; | ||
797 | read_menu = true; | 825 | read_menu = true; |
798 | break; | 826 | break; |
799 | 827 | ||