summaryrefslogtreecommitdiffstats
path: root/ui/ncurses/nc-menu.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-03-12 14:59:03 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-04-10 11:18:24 +0800
commit1bbd230d618162ccd5ea97540a413c766a07c0cb (patch)
tree8bf596660165d015328d54930ba2f91ed4c4effd /ui/ncurses/nc-menu.c
parente07bd59ad5f4ba9cd113f8dfdcc72e6ca2e69819 (diff)
downloadtalos-petitboot-1bbd230d618162ccd5ea97540a413c766a07c0cb.tar.gz
talos-petitboot-1bbd230d618162ccd5ea97540a413c766a07c0cb.zip
ui/ncurses: Separate menu item creation & initialisation from insertion
Currently, the menu item creation is has two main functions: pmenu_item_alloc and pmenu_item_setup. The latter does initialisation (it sets item->name), and inserts the item into the menu. We have pmenu_item_init to combine this into one, but that means we need to do further initialisation (eg, to set on_execute) after the item has been added to the menu. Instead, this change use a more direct _create and _insert interface. Create does the allocation and initialisation, while _insert does the actual insertion. This means new_item failures will be detected at creation time, rather than during pmenu_insert. Also, we're now insert a completely-populated item into the menu, rather than populating on_edit, on_execute and data after insertion. Because we can detect errors from creation (ie, from new_item failing), we add handling code to cui_boot_option_add and cui_boot_editor_on_exit. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'ui/ncurses/nc-menu.c')
-rw-r--r--ui/ncurses/nc-menu.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
index ef00ff2..5691f42 100644
--- a/ui/ncurses/nc-menu.c
+++ b/ui/ncurses/nc-menu.c
@@ -77,43 +77,39 @@ static void pmenu_resize(struct nc_scr *scr)
}
/**
- * pmenu_item_init - Allocate and initialize a new pmenu_item instance.
+ * pmenu_item_create - Allocate and initialize a new pmenu_item instance.
*
* Returns a pointer the the initialized struct pmenu_item instance or NULL
* on error. The caller is responsible for calling talloc_free() for the
* returned instance.
*/
-
-struct pmenu_item *pmenu_item_alloc(struct pmenu *menu)
+struct pmenu_item *pmenu_item_create(struct pmenu *menu, const char *name)
{
- /* Items go with the menu, not the pointer array. */
-
- struct pmenu_item *i = talloc_zero(menu, struct pmenu_item);
+ struct pmenu_item *item = talloc_zero(menu, struct pmenu_item);
- return i;
-}
-
-struct pmenu_item *pmenu_item_setup(struct pmenu *menu, struct pmenu_item *i,
- unsigned int index, const char *name)
-{
- assert(i);
- assert(name);
+ item->i_sig = pb_item_sig;
+ item->pmenu = menu;
+ item->nci = new_item(name, NULL);
- if (!i)
+ if (!item->nci) {
+ talloc_free(item);
return NULL;
+ }
- i->i_sig = pb_item_sig;
- i->pmenu = menu;
- i->nci = new_item(name, NULL);
-
- if (!i->nci)
- return NULL;
+ set_item_userptr(item->nci, item);
- set_item_userptr(i->nci, i);
+ return item;
+}
- menu->items[index] = i->nci;
+void pmenu_item_insert(struct pmenu *menu, struct pmenu_item *item,
+ unsigned int index)
+{
+ assert(item);
+ assert(index < menu->item_count);
+ assert(menu->items[index] == NULL);
+ assert(menu_items(menu->ncm) == NULL);
- return i;
+ menu->items[index] = item->nci;
}
static int pmenu_item_get_index(const struct pmenu_item *item)
OpenPOWER on IntegriCloud