-
Notifications
You must be signed in to change notification settings - Fork 7
/
evp_compat.c
282 lines (264 loc) · 10 KB
/
evp_compat.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#include "config.h"
#include <memory.h>
#undef NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "evpath.h"
#include "cm_internal.h"
struct _CMformat_list {
/*! the name to be associated with this structure */
char *format_name;
/*! the PBIO-style list of fields within this structure */
FMFieldList field_list;
};
typedef struct _CMformat_list CMFormatRec;
typedef CMFormatRec *CMFormatList;
extern int
IOget_array_size_dimen(const char *str, FMFieldList fields, int dimen,
int *control_field);
static int
is_var_array_field(FMFieldList field_list, int field)
{
int done = 0;
int ret = 0;
int dimen_count = 0;
int control_val;
while (!done) {
int static_size = IOget_array_size_dimen(field_list[field].field_type,
field_list, dimen_count,
&control_val);
dimen_count++;
if (static_size == 0) {
done++;
continue;
}
if ((static_size == -1) && (control_val == -1)) {
/* failed validation, errors already delivered */
return -1;
}
if (control_val != -1) {
/* dynamic array */
ret = 1;
}
}
return ret;
}
#define Max(i,j) ((i<j) ? j : i)
extern FMdata_type FMarray_str_to_data_type(const char *str,
long *element_count_ptr);
static
int
struct_size_field_list(FMFieldList list, int pointer_size)
{
int i = 0;
int struct_size = 0;
while (list[i].field_name != NULL) {
int field_size = 0;
if (is_var_array_field(list, i) == 1) {
/* variant array, real_field_size is ioformat->pointer_size */
field_size = pointer_size;
} else {
long elements;
FMarray_str_to_data_type(list[i].field_type, &elements);
field_size = list[i].field_size * elements;
}
assert(field_size > 0);
struct_size = Max(struct_size,
(list[i].field_offset + field_size));
/* printf("i=%d field_name=%s field_type=%s struct_size= %d, offset=%d size=%d\n", i, list[i].field_name, list[i].field_type, struct_size, list[i].field_offset, field_size);*/
i++;
}
return struct_size;
}
extern CMFormat
old_CMregister_format(CManager cm, char *format_name,
FMFieldList field_list, CMFormatList subformat_list)
{
FMStructDescList structs;
int sub_count = 0, i;
if (subformat_list && (subformat_list[sub_count].format_name != NULL)) sub_count++;
structs = malloc(sizeof(structs[0]) * (sub_count + 2));
structs[0].format_name = format_name;
structs[0].field_list = field_list;
structs[0].struct_size = struct_size_field_list(field_list, (int)sizeof(char*));
structs[0].opt_info = NULL;
for (i = 0; i < sub_count; i++) {
structs[i+1].format_name = subformat_list[i].format_name;
structs[i+1].field_list = subformat_list[i].field_list;
structs[i+1].struct_size = struct_size_field_list(structs[i+1].field_list, (int)sizeof(char*));
structs[i+1].opt_info = NULL;
}
structs[sub_count+1].format_name = NULL;
structs[sub_count+1].field_list = NULL;
return CMregister_format(cm, structs);
}
extern EVaction
old_EVassoc_terminal_action(CManager cm, EVstone stone, CMFormatList format_list,
EVSimpleHandlerFunc handler, void* client_data)
{
FMStructDescList structs;
int count = 0, i;
while (format_list && (format_list[count].format_name != NULL)) count++;
structs = malloc(sizeof(structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
structs[i].format_name = format_list[i].format_name;
structs[i].field_list = format_list[i].field_list;
structs[i].struct_size = struct_size_field_list(structs[i].field_list, (int)sizeof(char*));
structs[i].opt_info = NULL;
}
structs[count].format_name = NULL;
structs[count].field_list = NULL;
return EVassoc_terminal_action(cm, stone, structs, handler, client_data);
}
extern EVaction
old_EVassoc_filter_action(CManager cm, EVstone stone, CMFormatList format_list,
EVSimpleHandlerFunc handler, EVstone out_stone, void* client_data)
{
FMStructDescList structs;
int count = 0, i;
while (format_list && (format_list[count].format_name != NULL)) count++;
structs = malloc(sizeof(structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
structs[i].format_name = format_list[i].format_name;
structs[i].field_list = format_list[i].field_list;
structs[i].struct_size = struct_size_field_list(structs[i].field_list, (int)sizeof(char*));
structs[i].opt_info = NULL;
}
structs[count].format_name = NULL;
structs[count].field_list = NULL;
return EVassoc_filter_action(cm, stone, structs, handler, out_stone, client_data);
}
extern EVsource
old_EVcreate_submit_handle(CManager cm, EVstone stone, CMFormatList format_list)
{
FMStructDescList structs;
int count = 0, i;
while (format_list && (format_list[count].format_name != NULL)) count++;
structs = malloc(sizeof(structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
structs[i].format_name = format_list[i].format_name;
structs[i].field_list = format_list[i].field_list;
structs[i].struct_size = struct_size_field_list(structs[i].field_list, (int)sizeof(char*));
structs[i].opt_info = NULL;
}
structs[count].format_name = NULL;
structs[count].field_list = NULL;
return EVcreate_submit_handle(cm, stone, structs);
}
extern EVsource
old_EVcreate_submit_handle_free(CManager cm, EVstone stone, CMFormatList format_list,
EVFreeFunction free_func, void *client_data)
{
FMStructDescList structs;
int count = 0, i;
while (format_list && (format_list[count].format_name != NULL)) count++;
structs = malloc(sizeof(structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
structs[i].format_name = format_list[i].format_name;
structs[i].field_list = format_list[i].field_list;
structs[i].struct_size = struct_size_field_list(structs[i].field_list, (int)sizeof(char*));
structs[i].opt_info = NULL;
}
structs[count].format_name = NULL;
structs[count].field_list = NULL;
return EVcreate_submit_handle_free(cm, stone, structs, free_func, client_data);
}
extern char *
old_create_filter_action_spec(CMFormatList format_list, char *function)
{
FMStructDescList structs;
int count = 0, i;
while (format_list && (format_list[count].format_name != NULL)) count++;
structs = malloc(sizeof(structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
structs[i].format_name = format_list[i].format_name;
structs[i].field_list = format_list[i].field_list;
structs[i].struct_size = struct_size_field_list(structs[i].field_list, (int)sizeof(char*));
structs[i].opt_info = NULL;
}
structs[count].format_name = NULL;
structs[count].field_list = NULL;
return create_filter_action_spec(structs, function);
}
extern char *
old_create_router_action_spec(CMFormatList format_list, char *function)
{
FMStructDescList structs;
int count = 0, i;
while (format_list && (format_list[count].format_name != NULL)) count++;
structs = malloc(sizeof(structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
structs[i].format_name = format_list[i].format_name;
structs[i].field_list = format_list[i].field_list;
structs[i].struct_size = struct_size_field_list(structs[i].field_list, (int)sizeof(char*));
structs[i].opt_info = NULL;
}
structs[count].format_name = NULL;
structs[count].field_list = NULL;
return create_router_action_spec(structs, function);
}
extern char *
old_create_transform_action_spec(CMFormatList format_list, CMFormatList out_format_list, char *function)
{
FMStructDescList structs, out_structs;
int count = 0, i;
while (format_list && (format_list[count].format_name != NULL)) count++;
structs = malloc(sizeof(structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
structs[i].format_name = format_list[i].format_name;
structs[i].field_list = format_list[i].field_list;
structs[i].struct_size = struct_size_field_list(structs[i].field_list, (int)sizeof(char*));
structs[i].opt_info = NULL;
}
structs[count].format_name = NULL;
structs[count].field_list = NULL;
count = 0;
while (out_format_list && (out_format_list[count].format_name != NULL)) count++;
out_structs = malloc(sizeof(out_structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
out_structs[i].format_name = out_format_list[i].format_name;
out_structs[i].field_list = out_format_list[i].field_list;
out_structs[i].struct_size = struct_size_field_list(out_structs[i].field_list, (int)sizeof(char*));
out_structs[i].opt_info = NULL;
}
out_structs[count].format_name = NULL;
out_structs[count].field_list = NULL;
return create_transform_action_spec(structs, out_structs, function);
}
extern char*
old_create_multityped_action_spec(CMFormatList *input_format_lists, CMFormatList out_format_list, char *function)
{
FMStructDescList structs, out_structs, *struct_list;
int struct_count = 0, j;
int count, i;
while (input_format_lists[struct_count] != NULL) struct_count++;
struct_list = malloc(sizeof(struct_list[0]) * (struct_count+1));
for (j = 0; j < struct_count ; j++) {
CMFormatList format_list = input_format_lists[j];
count = 0;
while (format_list && (format_list[count].format_name != NULL)) count++;
structs = malloc(sizeof(structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
structs[i].format_name = format_list[i].format_name;
structs[i].field_list = format_list[i].field_list;
structs[i].struct_size = struct_size_field_list(structs[i].field_list, (int)sizeof(char*));
structs[i].opt_info = NULL;
}
structs[count].format_name = NULL;
structs[count].field_list = NULL;
struct_list[j] = structs;
}
count = 0;
while (out_format_list && (out_format_list[count].format_name != NULL)) count++;
out_structs = malloc(sizeof(out_structs[0]) * (count + 1));
for (i = 0; i < count; i++) {
out_structs[i].format_name = out_format_list[i].format_name;
out_structs[i].field_list = out_format_list[i].field_list;
out_structs[i].struct_size = struct_size_field_list(out_structs[i].field_list, (int)sizeof(char*));
out_structs[i].opt_info = NULL;
}
out_structs[count].format_name = NULL;
out_structs[count].field_list = NULL;
return create_multityped_action_spec(struct_list, function);
}