mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-11 13:44:28 +00:00
ea3e5e56fd
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21441 91177308-0d34-0410-b5e6-96231b3b80d8
76 lines
873 B
C
76 lines
873 B
C
char rcsid_list[] = "$Id$";
|
|
|
|
#include "b.h"
|
|
|
|
IntList
|
|
newIntList(x, next) int x; IntList next;
|
|
{
|
|
IntList l;
|
|
|
|
l = (IntList) zalloc(sizeof(*l));
|
|
assert(l);
|
|
l->x = x;
|
|
l->next = next;
|
|
|
|
return l;
|
|
}
|
|
|
|
List
|
|
newList(x, next) void *x; List next;
|
|
{
|
|
List l;
|
|
|
|
l = (List) zalloc(sizeof(*l));
|
|
assert(l);
|
|
l->x = x;
|
|
l->next = next;
|
|
|
|
return l;
|
|
}
|
|
|
|
List
|
|
appendList(x, l) void *x; List l;
|
|
{
|
|
List last;
|
|
List p;
|
|
|
|
last = 0;
|
|
for (p = l; p; p = p->next) {
|
|
last = p;
|
|
}
|
|
if (last) {
|
|
last->next = newList(x, 0);
|
|
return l;
|
|
} else {
|
|
return newList(x, 0);
|
|
}
|
|
}
|
|
|
|
void
|
|
foreachList(f, l) ListFn f; List l;
|
|
{
|
|
for (; l; l = l->next) {
|
|
(*f)(l->x);
|
|
}
|
|
}
|
|
|
|
void
|
|
reveachList(f, l) ListFn f; List l;
|
|
{
|
|
if (l) {
|
|
reveachList(f, l->next);
|
|
(*f)(l->x);
|
|
}
|
|
}
|
|
|
|
int
|
|
length(l) List l;
|
|
{
|
|
int c = 0;
|
|
|
|
for(; l; l = l->next) {
|
|
c++;
|
|
}
|
|
return c;
|
|
}
|