OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [src/] [list.c] - Blame information for rev 109

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
#include "c.h"
2
 
3
static char rcsid[] = "$Id: list.c,v 1.1 2002/08/28 23:12:44 drh Exp $";
4
 
5
static List freenodes;          /* free list nodes */
6
 
7
/* append - append x to list, return new list */
8
List append(void *x, List list) {
9
        List new;
10
 
11
        if ((new = freenodes) != NULL)
12
                freenodes = freenodes->link;
13
        else
14
                NEW(new, PERM);
15
        if (list) {
16
                new->link = list->link;
17
                list->link = new;
18
        } else
19
                new->link = new;
20
        new->x = x;
21
        return new;
22
}
23
 
24
/* length - # elements in list */
25
int length(List list) {
26
        int n = 0;
27
 
28
        if (list) {
29
                List lp = list;
30
                do
31
                        n++;
32
                while ((lp = lp->link) != list);
33
        }
34
        return n;
35
}
36
 
37
/* ltov - convert list to an NULL-terminated vector allocated in arena */
38
void *ltov(List *list, unsigned arena) {
39
        int i = 0;
40
        void **array = newarray(length(*list) + 1, sizeof array[0], arena);
41
 
42
        if (*list) {
43
                List lp = *list;
44
                do {
45
                        lp = lp->link;
46
                        array[i++] = lp->x;
47
                } while (lp != *list);
48
#ifndef PURIFY
49
                lp = (*list)->link;
50
                (*list)->link = freenodes;
51
                freenodes = lp;
52
#endif
53
        }
54
        *list = NULL;
55
        array[i] = NULL;
56
        return array;
57
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.