Complete eradication of grub_list_iterate
This commit is contained in:
parent
41e1209827
commit
fda282327f
4 changed files with 37 additions and 67 deletions
|
@ -32,21 +32,17 @@ grub_cmd_handler (struct grub_command *cmd __attribute__ ((unused)),
|
|||
void *curr_item = 0;
|
||||
grub_handler_class_t head;
|
||||
|
||||
auto int list_item (grub_named_list_t item);
|
||||
int list_item (grub_named_list_t item)
|
||||
{
|
||||
if (item == curr_item)
|
||||
grub_putchar ('*');
|
||||
|
||||
grub_printf ("%s\n", item->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
head = grub_handler_class_list;
|
||||
if (argc == 0)
|
||||
{
|
||||
grub_list_iterate (GRUB_AS_LIST (head), (grub_list_hook_t) list_item);
|
||||
grub_handler_class_t item;
|
||||
FOR_LIST_ELEMENTS(item, head)
|
||||
{
|
||||
if (item == curr_item)
|
||||
grub_putchar ('*');
|
||||
|
||||
grub_printf ("%s\n", item->name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -63,9 +59,15 @@ grub_cmd_handler (struct grub_command *cmd __attribute__ ((unused)),
|
|||
|
||||
if (argc == 0)
|
||||
{
|
||||
grub_handler_class_t item;
|
||||
curr_item = class->cur_handler;
|
||||
grub_list_iterate (GRUB_AS_LIST (class->handler_list),
|
||||
(grub_list_hook_t) list_item);
|
||||
FOR_LIST_ELEMENTS(item, head)
|
||||
{
|
||||
if (item == curr_item)
|
||||
grub_putchar ('*');
|
||||
|
||||
grub_printf ("%s\n", item->name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -36,7 +36,6 @@ typedef int (*grub_list_test_t) (grub_list_t new_item, grub_list_t item);
|
|||
void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item);
|
||||
void * EXPORT_FUNC(grub_list_pop) (grub_list_t *head);
|
||||
void EXPORT_FUNC(grub_list_remove) (grub_list_t *head, grub_list_t item);
|
||||
int EXPORT_FUNC(grub_list_iterate) (grub_list_t head, grub_list_hook_t hook);
|
||||
void EXPORT_FUNC(grub_list_insert) (grub_list_t *head, grub_list_t item,
|
||||
grub_list_test_t test);
|
||||
|
||||
|
|
31
kern/list.c
31
kern/list.c
|
@ -53,18 +53,6 @@ grub_list_remove (grub_list_t *head, grub_list_t item)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
grub_list_iterate (grub_list_t head, grub_list_hook_t hook)
|
||||
{
|
||||
grub_list_t p;
|
||||
|
||||
for (p = head; p; p = p->next)
|
||||
if (hook (p))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
grub_list_insert (grub_list_t *head, grub_list_t item,
|
||||
grub_list_test_t test)
|
||||
|
@ -82,22 +70,13 @@ grub_list_insert (grub_list_t *head, grub_list_t item,
|
|||
void *
|
||||
grub_named_list_find (grub_named_list_t head, const char *name)
|
||||
{
|
||||
grub_named_list_t result = NULL;
|
||||
grub_named_list_t item;
|
||||
|
||||
auto int list_find (grub_named_list_t item);
|
||||
int list_find (grub_named_list_t item)
|
||||
{
|
||||
if (! grub_strcmp (item->name, name))
|
||||
{
|
||||
result = item;
|
||||
return 1;
|
||||
}
|
||||
FOR_LIST_ELEMENTS (item, head)
|
||||
if (grub_strcmp (item->name, name) == 0)
|
||||
return item;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_list_iterate (GRUB_AS_LIST (head), (grub_list_hook_t) list_find);
|
||||
return result;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -138,30 +138,6 @@ read_handler_list (void)
|
|||
static int first_time = 1;
|
||||
const char *class_name;
|
||||
|
||||
auto int iterate_handler (grub_handler_t handler);
|
||||
int iterate_handler (grub_handler_t handler)
|
||||
{
|
||||
char name[grub_strlen (class_name) + grub_strlen (handler->name) + 2];
|
||||
|
||||
grub_strcpy (name, class_name);
|
||||
grub_strcat (name, ".");
|
||||
grub_strcat (name, handler->name);
|
||||
|
||||
insert_handler (name, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto int iterate_class (grub_handler_class_t class);
|
||||
int iterate_class (grub_handler_class_t class)
|
||||
{
|
||||
class_name = class->name;
|
||||
grub_list_iterate (GRUB_AS_LIST (class->handler_list),
|
||||
(grub_list_hook_t) iterate_handler);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Make sure that this function does not get executed twice. */
|
||||
if (! first_time)
|
||||
return;
|
||||
|
@ -209,8 +185,22 @@ read_handler_list (void)
|
|||
}
|
||||
}
|
||||
|
||||
grub_list_iterate (GRUB_AS_LIST (grub_handler_class_list),
|
||||
(grub_list_hook_t) iterate_class);
|
||||
grub_handler_class_t class;
|
||||
FOR_LIST_ELEMENTS (class, grub_handler_class_list)
|
||||
{
|
||||
grub_handler_t handler;
|
||||
class_name = class->name;
|
||||
FOR_LIST_ELEMENTS(handler, class->handler_list)
|
||||
{
|
||||
char name[grub_strlen (class_name) + grub_strlen (handler->name) + 2];
|
||||
|
||||
grub_strcpy (name, class_name);
|
||||
grub_strcat (name, ".");
|
||||
grub_strcat (name, handler->name);
|
||||
|
||||
insert_handler (name, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ignore errors. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
|
Loading…
Reference in a new issue