~ubuntu-branches/debian/stretch/grub2/stretch

« back to all changes in this revision

Viewing changes to kern/list.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2010-06-15 12:45:35 UTC
  • mto: (1.14.1 upstream) (17.3.18 experimental)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20100615124535-9vfbis4kzv0h5bgy
Tags: upstream-1.98+20100614
ImportĀ upstreamĀ versionĀ 1.98+20100614

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
  *head = item;
29
29
}
30
30
 
31
 
void *
32
 
grub_list_pop (grub_list_t *head)
33
 
{
34
 
  grub_list_t item;
35
 
 
36
 
  item = *head;
37
 
  if (item)
38
 
    *head = item->next;
39
 
 
40
 
  return item;
41
 
}
42
 
 
43
31
void
44
32
grub_list_remove (grub_list_t *head, grub_list_t item)
45
33
{
53
41
      }
54
42
}
55
43
 
56
 
int
57
 
grub_list_iterate (grub_list_t head, grub_list_hook_t hook)
58
 
{
59
 
  grub_list_t p;
60
 
 
61
 
  for (p = head; p; p = p->next)
62
 
    if (hook (p))
63
 
      return 1;
64
 
 
65
 
  return 0;
66
 
}
67
 
 
68
 
void
69
 
grub_list_insert (grub_list_t *head, grub_list_t item,
70
 
                  grub_list_test_t test)
71
 
{
72
 
  grub_list_t *p, q;
73
 
 
74
 
  for (p = head, q = *p; q; p = &(q->next), q = q->next)
75
 
    if (test (item, q))
76
 
      break;
77
 
 
78
 
  *p = item;
79
 
  item->next = q;
80
 
}
81
 
 
82
44
void *
83
45
grub_named_list_find (grub_named_list_t head, const char *name)
84
46
{
85
 
  grub_named_list_t result = NULL;
86
 
 
87
 
  auto int list_find (grub_named_list_t item);
88
 
  int list_find (grub_named_list_t item)
89
 
    {
90
 
      if (! grub_strcmp (item->name, name))
91
 
        {
92
 
          result = item;
93
 
          return 1;
94
 
        }
95
 
 
96
 
      return 0;
97
 
    }
98
 
 
99
 
  grub_list_iterate (GRUB_AS_LIST (head), (grub_list_hook_t) list_find);
100
 
  return result;
 
47
  grub_named_list_t item;
 
48
 
 
49
  FOR_LIST_ELEMENTS (item, head)
 
50
    if (grub_strcmp (item->name, name) == 0)
 
51
      return item;
 
52
 
 
53
  return NULL;
101
54
}
102
55
 
103
56
void
105
58
{
106
59
  int inactive = 0;
107
60
 
108
 
  auto int test (grub_prio_list_t new_item, grub_prio_list_t item);
109
 
  int test (grub_prio_list_t new_item, grub_prio_list_t item)
 
61
  grub_prio_list_t *p, q;
 
62
    
 
63
  for (p = head, q = *p; q; p = &(q->next), q = q->next)
110
64
    {
111
65
      int r;
112
66
 
113
 
      r = grub_strcmp (new_item->name, item->name);
114
 
      if (r)
115
 
        return (r < 0);
 
67
      r = grub_strcmp (nitem->name, q->name);
 
68
      if (r < 0)
 
69
        break;
 
70
      if (r > 0)
 
71
        continue;
116
72
 
117
 
      if (new_item->prio >= (item->prio & GRUB_PRIO_LIST_PRIO_MASK))
 
73
      if (nitem->prio >= (q->prio & GRUB_PRIO_LIST_PRIO_MASK))
118
74
        {
119
 
          item->prio &= ~GRUB_PRIO_LIST_FLAG_ACTIVE;
120
 
          return 1;
 
75
          q->prio &= ~GRUB_PRIO_LIST_FLAG_ACTIVE;
 
76
          break;
121
77
        }
122
78
 
123
79
      inactive = 1;
124
 
      return 0;
125
80
    }
126
81
 
127
 
  grub_list_insert (GRUB_AS_LIST_P (head), GRUB_AS_LIST (nitem),
128
 
                    (grub_list_test_t) test);
 
82
  *p = nitem;
 
83
  nitem->next = q;
 
84
 
129
85
  if (! inactive)
130
86
    nitem->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE;
131
87
}