Dynamically allocate menu structs.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11052 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2006-09-26 06:40:14 +00:00
parent 3bf676ead3
commit 3ae1c103ed

View file

@ -118,7 +118,7 @@ struct root_menu {
/* Statusbar text of the current view. */ /* Statusbar text of the current view. */
static char current_title[MAX_TAGS][128]; static char current_title[MAX_TAGS][128];
static struct root_menu menus[TAGMENU_MAX_MENUS]; static struct root_menu *menus[TAGMENU_MAX_MENUS];
static struct root_menu *menu; static struct root_menu *menu;
static struct search_instruction *csi; static struct search_instruction *csi;
static const char *strp; static const char *strp;
@ -425,10 +425,10 @@ static bool parse_search(struct menu_entry *entry, const char *str)
/* Find the matching root menu or "create" it */ /* Find the matching root menu or "create" it */
for (i = 0; i < menu_count; i++) for (i = 0; i < menu_count; i++)
{ {
if (!strcasecmp(menus[i].id, buf)) if (!strcasecmp(menus[i]->id, buf))
{ {
entry->link = i; entry->link = i;
menus[i].parent = menu; menus[i]->parent = menu;
return true; return true;
} }
} }
@ -634,7 +634,6 @@ static bool parse_menu(const char *filename)
{ {
/* End the menu */ /* End the menu */
menu_count++; menu_count++;
menu = &menus[menu_count];
read_menu = false; read_menu = false;
} }
continue; continue;
@ -668,6 +667,9 @@ static bool parse_menu(const char *filename)
return false; return false;
} }
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(menu->id, sizeof(menu->id)) < 0)
{ {
logf("%menu_start id empty"); logf("%menu_start id empty");
@ -695,7 +697,7 @@ static bool parse_menu(const char *filename)
for (i = 0; i < menu_count; i++) for (i = 0; i < menu_count; i++)
{ {
if (!strcasecmp(menus[i].id, data)) if (!strcasecmp(menus[i]->id, data))
{ {
root_menu = i; root_menu = i;
} }
@ -733,9 +735,8 @@ static bool parse_menu(const char *filename)
void tagtree_init(void) void tagtree_init(void)
{ {
memset(menus, 0, sizeof menus);
menu_count = 0; menu_count = 0;
menu = &menus[0]; menu = NULL;
root_menu = 0; root_menu = 0;
parse_menu(FILE_SEARCH_INSTRUCTIONS); parse_menu(FILE_SEARCH_INSTRUCTIONS);
@ -1040,7 +1041,9 @@ static int load_root(struct tree_context *c)
if (c->dirlevel == 0) if (c->dirlevel == 0)
c->currextra = root_menu; c->currextra = root_menu;
menu = &menus[c->currextra]; menu = menus[c->currextra];
if (menu == NULL)
return 0;
for (i = 0; i < menu->itemcount; i++) for (i = 0; i < menu->itemcount; i++)
{ {
@ -1142,7 +1145,7 @@ int tagtree_enter(struct tree_context* c)
if (newextra == root) if (newextra == root)
{ {
menu = &menus[seek]; menu = menus[seek];
c->currextra = seek; c->currextra = seek;
} }