URL
https://opencores.org/ocsvn/eco32/eco32/trunk
Go to most recent revision |
Only display areas with differences |
Details |
Blame |
View Log
Rev 4 |
Rev 157 |
#include "c.h"
|
#include "c.h"
|
|
|
static char rcsid[] = "$Id: list.c,v 1.1 2002/08/28 23:12:44 drh Exp $";
|
static char rcsid[] = "$Id: list.c,v 1.1 2002/08/28 23:12:44 drh Exp $";
|
|
|
static List freenodes; /* free list nodes */
|
static List freenodes; /* free list nodes */
|
|
|
/* append - append x to list, return new list */
|
/* append - append x to list, return new list */
|
List append(void *x, List list) {
|
List append(void *x, List list) {
|
List new;
|
List new;
|
|
|
if ((new = freenodes) != NULL)
|
if ((new = freenodes) != NULL)
|
freenodes = freenodes->link;
|
freenodes = freenodes->link;
|
else
|
else
|
NEW(new, PERM);
|
NEW(new, PERM);
|
if (list) {
|
if (list) {
|
new->link = list->link;
|
new->link = list->link;
|
list->link = new;
|
list->link = new;
|
} else
|
} else
|
new->link = new;
|
new->link = new;
|
new->x = x;
|
new->x = x;
|
return new;
|
return new;
|
}
|
}
|
|
|
/* length - # elements in list */
|
/* length - # elements in list */
|
int length(List list) {
|
int length(List list) {
|
int n = 0;
|
int n = 0;
|
|
|
if (list) {
|
if (list) {
|
List lp = list;
|
List lp = list;
|
do
|
do
|
n++;
|
n++;
|
while ((lp = lp->link) != list);
|
while ((lp = lp->link) != list);
|
}
|
}
|
return n;
|
return n;
|
}
|
}
|
|
|
/* ltov - convert list to an NULL-terminated vector allocated in arena */
|
/* ltov - convert list to an NULL-terminated vector allocated in arena */
|
void *ltov(List *list, unsigned arena) {
|
void *ltov(List *list, unsigned arena) {
|
int i = 0;
|
int i = 0;
|
void **array = newarray(length(*list) + 1, sizeof array[0], arena);
|
void **array = newarray(length(*list) + 1, sizeof array[0], arena);
|
|
|
if (*list) {
|
if (*list) {
|
List lp = *list;
|
List lp = *list;
|
do {
|
do {
|
lp = lp->link;
|
lp = lp->link;
|
array[i++] = lp->x;
|
array[i++] = lp->x;
|
} while (lp != *list);
|
} while (lp != *list);
|
#ifndef PURIFY
|
#ifndef PURIFY
|
lp = (*list)->link;
|
lp = (*list)->link;
|
(*list)->link = freenodes;
|
(*list)->link = freenodes;
|
freenodes = lp;
|
freenodes = lp;
|
#endif
|
#endif
|
}
|
}
|
*list = NULL;
|
*list = NULL;
|
array[i] = NULL;
|
array[i] = NULL;
|
return array;
|
return array;
|
}
|
}
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.