Remove prio_list

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-02-12 03:52:17 +01:00
parent 78dde88e8c
commit ead2a8822b
7 changed files with 41 additions and 83 deletions

View file

@ -40,7 +40,7 @@ grub_cmd_help (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc,
grub_command_t cmd;
FOR_COMMANDS(cmd)
{
if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE))
if ((cmd->prio & GRUB_COMMAND_FLAG_ACTIVE))
{
struct grub_term_output *term;
const char *summary_translated = _(cmd->summary);
@ -106,7 +106,7 @@ grub_cmd_help (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc,
currarg = args[i];
FOR_COMMANDS(cmd_iter)
{
if (!(cmd_iter->prio & GRUB_PRIO_LIST_FLAG_ACTIVE))
if (!(cmd_iter->prio & GRUB_COMMAND_FLAG_ACTIVE))
continue;
if (grub_strncmp (cmd_iter->name, currarg,

View file

@ -83,8 +83,8 @@ grub_mini_cmd_help (struct grub_command *cmd __attribute__ ((unused)),
for (p = grub_command_list; p; p = p->next)
grub_printf ("%s (%d%c)\t%s\n", p->name,
p->prio & GRUB_PRIO_LIST_PRIO_MASK,
(p->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) ? '+' : '-',
p->prio & GRUB_COMMAND_PRIO_MASK,
(p->prio & GRUB_COMMAND_FLAG_ACTIVE) ? '+' : '-',
p->description);
return 0;

View file

@ -30,6 +30,9 @@ grub_register_command_prio (const char *name,
int prio)
{
grub_command_t cmd;
int inactive = 0;
grub_command_t *p, q;
cmd = (grub_command_t) grub_zalloc (sizeof (*cmd));
if (! cmd)
@ -43,8 +46,33 @@ grub_register_command_prio (const char *name,
cmd->flags = 0;
cmd->prio = prio;
grub_prio_list_insert (GRUB_AS_PRIO_LIST_P (&grub_command_list),
GRUB_AS_PRIO_LIST (cmd));
for (p = &grub_command_list, q = *p; q; p = &(q->next), q = q->next)
{
int r;
r = grub_strcmp (cmd->name, q->name);
if (r < 0)
break;
if (r > 0)
continue;
if (cmd->prio >= (q->prio & GRUB_COMMAND_PRIO_MASK))
{
q->prio &= ~GRUB_COMMAND_FLAG_ACTIVE;
break;
}
inactive = 1;
}
*p = cmd;
cmd->next = q;
if (q)
q->prev = &cmd->next;
cmd->prev = p;
if (! inactive)
cmd->prio |= GRUB_COMMAND_FLAG_ACTIVE;
return cmd;
}
@ -52,6 +80,8 @@ grub_register_command_prio (const char *name,
void
grub_unregister_command (grub_command_t cmd)
{
grub_prio_list_remove (GRUB_AS_PRIO_LIST (cmd));
if ((cmd->prio & GRUB_COMMAND_FLAG_ACTIVE) && (cmd->next))
cmd->next->prio |= GRUB_COMMAND_FLAG_ACTIVE;
grub_list_remove (GRUB_AS_LIST (cmd));
grub_free (cmd);
}

View file

@ -32,39 +32,3 @@ grub_named_list_find (grub_named_list_t head, const char *name)
return NULL;
}
void
grub_prio_list_insert (grub_prio_list_t *head, grub_prio_list_t nitem)
{
int inactive = 0;
grub_prio_list_t *p, q;
for (p = head, q = *p; q; p = &(q->next), q = q->next)
{
int r;
r = grub_strcmp (nitem->name, q->name);
if (r < 0)
break;
if (r > 0)
continue;
if (nitem->prio >= (q->prio & GRUB_PRIO_LIST_PRIO_MASK))
{
q->prio &= ~GRUB_PRIO_LIST_FLAG_ACTIVE;
break;
}
inactive = 1;
}
*p = nitem;
nitem->next = q;
if (q)
q->prev = &nitem->next;
nitem->prev = p;
if (! inactive)
nitem->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE;
}

View file

@ -444,7 +444,7 @@ grub_normal_do_completion (char *buf, int *restore,
grub_command_t cmd;
FOR_COMMANDS(cmd)
{
if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE)
if (cmd->prio & GRUB_COMMAND_FLAG_ACTIVE)
{
if (add_completion (cmd->name, " ", GRUB_COMPLETION_TYPE_COMMAND))
goto fail;

View file

@ -44,6 +44,9 @@ struct grub_command;
typedef grub_err_t (*grub_command_func_t) (struct grub_command *cmd,
int argc, char **argv);
#define GRUB_COMMAND_PRIO_MASK 0xff
#define GRUB_COMMAND_FLAG_ACTIVE 0x100
/* The command description. */
struct grub_command
{

View file

@ -102,43 +102,4 @@ void * EXPORT_FUNC(grub_named_list_find) (grub_named_list_t head,
&& GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \
(grub_named_list_t *) (void *) pptr : (grub_named_list_t *) grub_bad_type_cast ())
#define GRUB_PRIO_LIST_PRIO_MASK 0xff
#define GRUB_PRIO_LIST_FLAG_ACTIVE 0x100
struct grub_prio_list
{
struct grub_prio_list *next;
struct grub_prio_list **prev;
char *name;
int prio;
};
typedef struct grub_prio_list *grub_prio_list_t;
void EXPORT_FUNC(grub_prio_list_insert) (grub_prio_list_t *head,
grub_prio_list_t item);
static inline void
grub_prio_list_remove (grub_prio_list_t item)
{
if ((item->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && (item->next))
item->next->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE;
grub_list_remove (GRUB_AS_LIST (item));
}
#define GRUB_AS_PRIO_LIST(ptr) \
((GRUB_FIELD_MATCH (ptr, grub_prio_list_t, next) \
&& GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prev) \
&& GRUB_FIELD_MATCH (ptr, grub_prio_list_t, name) \
&& GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prio))? \
(grub_prio_list_t) ptr \
: (grub_prio_list_t) grub_bad_type_cast ())
#define GRUB_AS_PRIO_LIST_P(pptr) \
((GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, next) \
&& GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prev) \
&& GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, name) \
&& GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prio)) ? \
(grub_prio_list_t *) (void *) pptr \
: (grub_prio_list_t *) grub_bad_type_cast ())
#endif /* ! GRUB_LIST_HEADER */