Subversion Repositories Games.Carmageddon

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 pmbaty 1
#include "brlists.h"
2
#include "harness/trace.h"
3
#include <assert.h>
4
#include <stdio.h>
5
 
6
 
7
// IDA: void __cdecl BrNewList(br_list *list)
8
void BrNewList(br_list* list) {
9
    LOG_TRACE10("(%p)", list);
10
 
11
    list->head = (br_node*)&list->_null;
12
    list->_null = NULL;
13
    list->tail = (br_node*)list;
14
}
15
 
16
// IDA: void __cdecl BrAddHead(br_list *list, br_node *node)
17
void BrAddHead(br_list* list, br_node* node) {
18
    LOG_TRACE10("(%p, %p)", list, node);
19
    assert(node != NULL);
20
    assert(list != NULL);
21
    assert(list->head != NULL);
22
 
23
    //node->prev = (br_node*)list;
24
    node->prev = (br_node*)&(list->head);
25
    node->next = list->head;
26
    list->head->prev = node;
27
    list->head = node;
28
}
29
 
30
// IDA: void __cdecl BrAddTail(br_list *list, br_node *node)
31
void BrAddTail(br_list* list, br_node* node) {
32
    LOG_TRACE10("(%p, %p)", list, node);
33
 
34
    node->next = (br_node*)&list->_null;
35
    node->prev = list->tail;
36
    list->tail->next = node;
37
    list->tail = node;
38
}
39
 
40
// IDA: br_node* __cdecl BrRemHead(br_list *list)
41
br_node* BrRemHead(br_list* list) {
42
    br_node* n;
43
    LOG_TRACE10("(%p)", list);
44
 
45
    n = list->head;
46
    if (n == (br_node*)&list->_null) {
47
        return NULL;
48
    }
49
    list->head = n->next;
50
    n->next->prev = (br_node*)&list->head;
51
    return n;
52
}
53
 
54
// IDA: br_node* __cdecl BrRemTail(br_list *list)
55
br_node* BrRemTail(br_list* list) {
56
    br_node* n;
57
    LOG_TRACE10("(%p)", list);
58
 
59
    n = list->tail;
60
    if (n == (br_node*)&list->head) {
61
        return NULL;
62
    }
63
    list->tail = n->prev;
64
    n->prev->next = (br_node*)&list->_null;
65
    return n;
66
}
67
 
68
// IDA: void __cdecl BrInsert(br_list *list, br_node *here, br_node *node)
69
void BrInsert(br_list* list, br_node* here, br_node* node) {
70
    LOG_TRACE10("(%p, %p, %p)", list, here, node);
71
 
72
    node->prev = here;
73
    node->next = here->next;
74
    here->next->prev = node;
75
    here->next = node;
76
}
77
 
78
// IDA: br_node* __cdecl BrRemove(br_node *node)
79
br_node* BrRemove(br_node* node) {
80
    LOG_TRACE10("(%p)", node);
81
 
82
    node->next->prev = node->prev;
83
    node->prev->next = node->next;
84
    return node;
85
}
86
 
87
// IDA: void __cdecl BrSimpleNewList(br_simple_list *list)
88
void BrSimpleNewList(br_simple_list* list) {
89
    LOG_TRACE10("(%p)", list);
90
 
91
    list->head = NULL;
92
}
93
 
94
// IDA: void __cdecl BrSimpleAddHead(br_simple_list *list, br_simple_node *node)
95
void BrSimpleAddHead(br_simple_list* list, br_simple_node* node) {
96
    LOG_TRACE10("(%p, %p)", list, node);
97
 
98
    node->next = list->head;
99
    node->prev = (br_simple_node**)&list->head;
100
    if (list->head != NULL) {
101
        list->head->prev = &node->next;
102
    }
103
    list->head = node;
104
}
105
 
106
// IDA: br_simple_node* __cdecl BrSimpleRemHead(br_simple_list *list)
107
br_simple_node* BrSimpleRemHead(br_simple_list* list) {
108
    br_simple_node* node;
109
    LOG_TRACE10("(%p)", list);
110
 
111
    node = list->head;
112
    if (node != NULL) {
113
        *node->prev = node->next;
114
        if (node->next != NULL) {
115
            node->next->prev = node->prev;
116
        }
117
        node->prev = NULL;
118
        node->next = NULL;
119
    }
120
    return node;
121
}
122
 
123
// IDA: void __cdecl BrSimpleInsert(br_simple_list *list, br_simple_node *here, br_simple_node *node)
124
void BrSimpleInsert(br_simple_list* list, br_simple_node* here, br_simple_node* node) {
125
    LOG_TRACE10("(%p, %p, %p)", list, here, node);
126
 
127
    node->prev = &here->next;
128
    node->next = here->next;
129
    if (here->next != NULL) {
130
        here->next->prev = &node->next;
131
    }
132
    here->next = node;
133
}
134
 
135
// IDA: br_simple_node* __cdecl BrSimpleRemove(br_simple_node *node)
136
br_simple_node* BrSimpleRemove(br_simple_node* node) {
137
    LOG_TRACE10("(%p)", node);
138
 
139
    *node->prev = node->next;
140
    if (node->next != NULL) {
141
        node->next->prev = node->prev;
142
    }
143
    node->next = NULL;
144
    node->prev = NULL;
145
    return node;
146
}