Lines Matching full:item
15 * Internally, each item in a menu is represented by a struct menu_item.
45 * An iterator function for menu items. callback will be called for each item
46 * in m, with m, a pointer to the item, and extra being passed to callback. If
50 * item from the list of items.
57 struct menu_item *item; in menu_items_iter() local
61 item = list_entry(pos, struct menu_item, list); in menu_items_iter()
63 ret = callback(m, item, extra); in menu_items_iter()
74 * when creating the menu, call it with a pointer to the item's private data.
75 * Otherwise, print the key of the item.
78 struct menu_item *item, in menu_item_print() argument
82 puts(item->key); in menu_item_print()
85 m->item_data_print(item->data); in menu_item_print()
92 * Free the memory used by a menu item. This includes the memory used by its
96 struct menu_item *item, in menu_item_destroy() argument
99 if (item->key) in menu_item_destroy()
100 free(item->key); in menu_item_destroy()
102 free(item); in menu_item_destroy()
112 * Display a menu so the user can make a choice of an item. First display its
113 * title, if any, and then each item in the menu.
127 * Check if an item's key matches a provided string, pointed to by extra. If
128 * extra is NULL, an item with a NULL key will match. Otherwise, the item's
131 * This is called via menu_items_iter, so it returns a pointer to the item if
135 struct menu_item *item, void *extra) in menu_item_key_match() argument
139 if (!item_key || !item->key) { in menu_item_key_match()
140 if (item_key == item->key) in menu_item_key_match()
141 return item; in menu_item_key_match()
146 if (strcmp(item->key, item_key) == 0) in menu_item_key_match()
147 return item; in menu_item_key_match()
153 * Find the first item with a key matching item_key, if any exists.
162 * Set *choice to point to the default item's data, if any default item was
163 * set, and returns 1. If no default item was set, returns -ENOENT.
176 * Displays the menu and asks the user to choose an item. *choice will point
177 * to the private data of the item the user chooses. The user makes a choice
178 * by inputting a string matching the key of an item. Invalid choices will
232 * key for an existing item in the menu.
234 * Returns 1 if successful, -EINVAL if m is NULL, or -ENOENT if no item with a
239 struct menu_item *item; in menu_default_set() local
244 item = menu_item_by_key(m, item_key); in menu_default_set()
246 if (!item) in menu_default_set()
249 m->default_item = item; in menu_default_set()
262 * menu item. If no item is selected or there is an error, no value will be
281 * menu_item_add() - Adds or replaces a menu item. Note that this replaces the
282 * data of an item if it already exists, but doesn't change the order of the
283 * item.
287 * item_key - Points to a string that will uniquely identify the item. The
291 * item_data - An opaque pointer associated with an item. It is never
293 * will be returned from menu_get_choice if the menu item is selected.
296 * insufficient memory to add the menu item.
300 struct menu_item *item; in menu_item_add() local
305 item = menu_item_by_key(m, item_key); in menu_item_add()
307 if (item) { in menu_item_add()
308 item->data = item_data; in menu_item_add()
312 item = malloc(sizeof *item); in menu_item_add()
313 if (!item) in menu_item_add()
316 item->key = strdup(item_key); in menu_item_add()
318 if (!item->key) { in menu_item_add()
319 free(item); in menu_item_add()
323 item->data = item_data; in menu_item_add()
325 list_add_tail(&item->list, &m->items); in menu_item_add()
344 * item_data_print - If not NULL, will be called for each item when the menu
345 * is displayed, with the pointer to the item's data passed as the argument.
346 * If NULL, each item's key will be printed instead. Since an item's key is
347 * what must be entered to select an item, the item_data_print function should
351 * item. Returns a key string corresponding to the chosen item or NULL if
352 * no item has been selected.