2N/A/* list.c - grub list function */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2009 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/list.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/mm.h>
2N/A
2N/Avoid
2N/Agrub_list_push (grub_list_t *head, grub_list_t item)
2N/A{
2N/A item->next = *head;
2N/A *head = item;
2N/A}
2N/A
2N/Avoid
2N/Agrub_list_remove (grub_list_t *head, grub_list_t item)
2N/A{
2N/A grub_list_t *p, q;
2N/A
2N/A for (p = head, q = *p; q; p = &(q->next), q = q->next)
2N/A if (q == item)
2N/A {
2N/A *p = q->next;
2N/A break;
2N/A }
2N/A}
2N/A
2N/Avoid *
2N/Agrub_named_list_find (grub_named_list_t head, const char *name)
2N/A{
2N/A grub_named_list_t item;
2N/A
2N/A FOR_LIST_ELEMENTS (item, head)
2N/A if (grub_strcmp (item->name, name) == 0)
2N/A return item;
2N/A
2N/A return NULL;
2N/A}
2N/A
2N/Avoid
2N/Agrub_prio_list_insert (grub_prio_list_t *head, grub_prio_list_t nitem)
2N/A{
2N/A int inactive = 0;
2N/A
2N/A grub_prio_list_t *p, q;
2N/A
2N/A for (p = head, q = *p; q; p = &(q->next), q = q->next)
2N/A {
2N/A int r;
2N/A
2N/A r = grub_strcmp (nitem->name, q->name);
2N/A if (r < 0)
2N/A break;
2N/A if (r > 0)
2N/A continue;
2N/A
2N/A if (nitem->prio >= (q->prio & GRUB_PRIO_LIST_PRIO_MASK))
2N/A {
2N/A q->prio &= ~GRUB_PRIO_LIST_FLAG_ACTIVE;
2N/A break;
2N/A }
2N/A
2N/A inactive = 1;
2N/A }
2N/A
2N/A *p = nitem;
2N/A nitem->next = q;
2N/A
2N/A if (! inactive)
2N/A nitem->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE;
2N/A}