-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_lookup.c
178 lines (124 loc) · 4.74 KB
/
block_lookup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
Copyright (C) 2010, 2011 Christian Klauer
This file is part of OpenRTDynamics, the Real Time Dynamic Toolbox
OpenRTDynamics is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenRTDynamics is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with OpenRTDynamics. If not, see <http://www.gnu.org/licenses/>.
*/
// block_lookup.h
#include <stdlib.h>
#include <stdio.h>
#include "block_lookup.h"
struct lindyn_comp_func_list_head_t * libdyn_new_compfnlist()
{
struct lindyn_comp_func_list_head_t * list_header = (struct lindyn_comp_func_list_head_t *) malloc(sizeof(struct lindyn_comp_func_list_head_t));
list_header->list_head = NULL;
list_header->num_elements = NULL;
list_header->list_tail = NULL;
return list_header; // Grr: The lack of this line was a long living Bug! FIXED at 10. July 2011
}
int libdyn_compfnlist_add(struct lindyn_comp_func_list_head_t *list, int blockid, int comp_fn_type, void *comp_fn)
{
struct lindyn_comp_func_list_ele_t * element = (struct lindyn_comp_func_list_ele_t *) malloc(sizeof(struct lindyn_comp_func_list_ele_t));
element->blockid = blockid;
element->comp_fn = comp_fn;
element->comp_fn_type = comp_fn_type;
if (list->list_head == NULL) { // first element in list
list->list_head = element;
list->list_tail = element;
element->next = NULL;
} else { // add element to list head
element->next = list->list_head;
list->list_head = element;
}
#ifdef EXECUTIONINFO
fprintf(stderr, "mapped block id %d to comp_fn %p\n", blockid, comp_fn);
#endif
return 1;
}
// find computational function pointer based on provided block identification number
struct lindyn_comp_func_list_ele_t * libdyn_compfnlist_find_blockid(struct lindyn_comp_func_list_head_t *list, int blockid)
{
if (list == NULL)
return NULL;
if (list->list_head == NULL)
return NULL;
struct lindyn_comp_func_list_ele_t * current = list->list_head;
do {
if (current->blockid == blockid) {
return current; // found!
}
current = current->next;
} while (current != NULL);
return NULL; // nothing found
}
// find block id based on the computational function pointer
struct lindyn_comp_func_list_ele_t * libdyn_compfnlist_find_comp_fn(struct lindyn_comp_func_list_head_t *list, void *comp_fn)
{
if (list == NULL)
return NULL;
if (list->list_head == NULL)
return NULL;
struct lindyn_comp_func_list_ele_t * current = list->list_head;
do {
if (current->comp_fn == comp_fn) {
return current; // found!
}
current = current->next;
} while (current != NULL);
return NULL; // nothing found
}
void libdyn_compfnlist_Show_comp_fn(struct lindyn_comp_func_list_head_t *list, void *comp_fn)
{
struct lindyn_comp_func_list_ele_t * entr = libdyn_compfnlist_find_comp_fn(list, comp_fn);
if (entr != NULL) {
fprintf(stderr, "Block with comp_fn ptr %p has the blockid %d\n", entr->comp_fn, entr->blockid);
}
}
// find computational function pointer based on provided block identification number
struct lindyn_comp_func_list_ele_t * libdyn_compfnlist_List(struct lindyn_comp_func_list_head_t *list)
{
if (list == NULL)
return NULL;
if (list->list_head == NULL)
return NULL;
fprintf(stderr, " \n");
fprintf(stderr, "List of registered blocks\n");
fprintf(stderr, " \n");
fprintf(stderr, "-------------------------\n");
fprintf(stderr, "-BlockId--|-Comp. fn ptr-\n");
fprintf(stderr, "----------|--------------\n");
struct lindyn_comp_func_list_ele_t * current = list->list_head;
do {
// if (current->blockid == blockid) {
// return current; // found!
// }
fprintf(stderr, "%d | %p\n", current->blockid, current->comp_fn);
current = current->next;
} while (current != NULL);
fprintf(stderr, "----------|--------------\n");
return NULL; // nothing found
}
void libdyn_del_compfnlist(struct lindyn_comp_func_list_head_t *list)
{
if (list->list_head == NULL) {
free(list);
return;
}
struct lindyn_comp_func_list_ele_t * current = list->list_head;
struct lindyn_comp_func_list_ele_t * tmp;
do {
tmp = current->next;
free(current);
current = tmp;
} while (current != NULL);
free(list);
return;
}