pysus 0.4.0__py3.6-linux-x86_64.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. EGG-INFO/PKG-INFO +30 -0
  2. EGG-INFO/SOURCES.txt +75 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/native_libs.txt +2 -0
  5. EGG-INFO/not-zip-safe +1 -0
  6. EGG-INFO/requires.txt +7 -0
  7. EGG-INFO/top_level.txt +2 -0
  8. __pycache__/_readdbc.cpython-36.pyc +0 -0
  9. _readdbc.abi3.so +0 -0
  10. _readdbc.py +7 -0
  11. pysus/__init__.py +2 -0
  12. pysus/__pycache__/__init__.cpython-36.pyc +0 -0
  13. pysus/online_data/CIHA.py +62 -0
  14. pysus/online_data/CNES.py +24 -0
  15. pysus/online_data/SIA.py +92 -0
  16. pysus/online_data/SIH.py +61 -0
  17. pysus/online_data/SIM.py +155 -0
  18. pysus/online_data/__init__.py +22 -0
  19. pysus/online_data/__pycache__/CIHA.cpython-36.pyc +0 -0
  20. pysus/online_data/__pycache__/CNES.cpython-36.pyc +0 -0
  21. pysus/online_data/__pycache__/SIA.cpython-36.pyc +0 -0
  22. pysus/online_data/__pycache__/SIH.cpython-36.pyc +0 -0
  23. pysus/online_data/__pycache__/SIM.cpython-36.pyc +0 -0
  24. pysus/online_data/__pycache__/__init__.cpython-36.pyc +0 -0
  25. pysus/online_data/__pycache__/sinasc.cpython-36.pyc +0 -0
  26. pysus/online_data/sinasc.py +44 -0
  27. pysus/preprocessing/__init__.py +8 -0
  28. pysus/preprocessing/__pycache__/__init__.cpython-36.pyc +0 -0
  29. pysus/preprocessing/__pycache__/decoders.cpython-36.pyc +0 -0
  30. pysus/preprocessing/__pycache__/sinan.cpython-36.pyc +0 -0
  31. pysus/preprocessing/decoders.py +96 -0
  32. pysus/preprocessing/sinan.py +103 -0
  33. pysus/tests/__init__.py +8 -0
  34. pysus/tests/__pycache__/__init__.cpython-36.pyc +0 -0
  35. pysus/tests/__pycache__/test_decoders.cpython-36.pyc +0 -0
  36. pysus/tests/__pycache__/test_sinan.cpython-36.pyc +0 -0
  37. pysus/tests/__pycache__/test_utilities.cpython-36.pyc +0 -0
  38. pysus/tests/test_data/__init__.py +6 -0
  39. pysus/tests/test_data/__pycache__/__init__.cpython-36.pyc +0 -0
  40. pysus/tests/test_data/__pycache__/test_ciha.cpython-36.pyc +0 -0
  41. pysus/tests/test_data/__pycache__/test_sia.cpython-36.pyc +0 -0
  42. pysus/tests/test_data/__pycache__/test_sih.cpython-36.pyc +0 -0
  43. pysus/tests/test_data/__pycache__/test_sim.cpython-36.pyc +0 -0
  44. pysus/tests/test_data/__pycache__/test_sinasc.cpython-36.pyc +0 -0
  45. pysus/tests/test_data/test_ciha.py +23 -0
  46. pysus/tests/test_data/test_sia.py +25 -0
  47. pysus/tests/test_data/test_sih.py +18 -0
  48. pysus/tests/test_data/test_sim.py +41 -0
  49. pysus/tests/test_data/test_sinasc.py +20 -0
  50. pysus/tests/test_decoders.py +38 -0
  51. pysus/tests/test_sinan.py +35 -0
  52. pysus/tests/test_utilities.py +18 -0
  53. pysus/utilities/__init__.py +6 -0
  54. pysus/utilities/__pycache__/__init__.cpython-36.pyc +0 -0
  55. pysus/utilities/__pycache__/_build_readdbc.cpython-36.pyc +0 -0
  56. pysus/utilities/__pycache__/readdbc.cpython-36.pyc +0 -0
  57. pysus/utilities/_build_readdbc.py +32 -0
  58. pysus/utilities/_readdbc.c +897 -0
  59. pysus/utilities/_readdbc.cpython-36m-x86_64-linux-gnu.so +0 -0
  60. pysus/utilities/_readdbc.o +0 -0
  61. pysus/utilities/blast.c +982 -0
  62. pysus/utilities/blast.h +75 -0
  63. pysus/utilities/blast.o +0 -0
  64. pysus/utilities/readdbc.py +52 -0
@@ -0,0 +1,897 @@
1
+ #define _CFFI_
2
+ #include <Python.h>
3
+ #ifdef __cplusplus
4
+ extern "C" {
5
+ #endif
6
+ #include <stddef.h>
7
+
8
+ /* This part is from file 'cffi/parse_c_type.h'. It is copied at the
9
+ beginning of C sources generated by CFFI's ffi.set_source(). */
10
+
11
+ typedef void *_cffi_opcode_t;
12
+
13
+ #define _CFFI_OP(opcode, arg) (_cffi_opcode_t)(opcode | (((uintptr_t)(arg)) << 8))
14
+ #define _CFFI_GETOP(cffi_opcode) ((unsigned char)(uintptr_t)cffi_opcode)
15
+ #define _CFFI_GETARG(cffi_opcode) (((intptr_t)cffi_opcode) >> 8)
16
+
17
+ #define _CFFI_OP_PRIMITIVE 1
18
+ #define _CFFI_OP_POINTER 3
19
+ #define _CFFI_OP_ARRAY 5
20
+ #define _CFFI_OP_OPEN_ARRAY 7
21
+ #define _CFFI_OP_STRUCT_UNION 9
22
+ #define _CFFI_OP_ENUM 11
23
+ #define _CFFI_OP_FUNCTION 13
24
+ #define _CFFI_OP_FUNCTION_END 15
25
+ #define _CFFI_OP_NOOP 17
26
+ #define _CFFI_OP_BITFIELD 19
27
+ #define _CFFI_OP_TYPENAME 21
28
+ #define _CFFI_OP_CPYTHON_BLTN_V 23 // varargs
29
+ #define _CFFI_OP_CPYTHON_BLTN_N 25 // noargs
30
+ #define _CFFI_OP_CPYTHON_BLTN_O 27 // O (i.e. a single arg)
31
+ #define _CFFI_OP_CONSTANT 29
32
+ #define _CFFI_OP_CONSTANT_INT 31
33
+ #define _CFFI_OP_GLOBAL_VAR 33
34
+ #define _CFFI_OP_DLOPEN_FUNC 35
35
+ #define _CFFI_OP_DLOPEN_CONST 37
36
+ #define _CFFI_OP_GLOBAL_VAR_F 39
37
+ #define _CFFI_OP_EXTERN_PYTHON 41
38
+
39
+ #define _CFFI_PRIM_VOID 0
40
+ #define _CFFI_PRIM_BOOL 1
41
+ #define _CFFI_PRIM_CHAR 2
42
+ #define _CFFI_PRIM_SCHAR 3
43
+ #define _CFFI_PRIM_UCHAR 4
44
+ #define _CFFI_PRIM_SHORT 5
45
+ #define _CFFI_PRIM_USHORT 6
46
+ #define _CFFI_PRIM_INT 7
47
+ #define _CFFI_PRIM_UINT 8
48
+ #define _CFFI_PRIM_LONG 9
49
+ #define _CFFI_PRIM_ULONG 10
50
+ #define _CFFI_PRIM_LONGLONG 11
51
+ #define _CFFI_PRIM_ULONGLONG 12
52
+ #define _CFFI_PRIM_FLOAT 13
53
+ #define _CFFI_PRIM_DOUBLE 14
54
+ #define _CFFI_PRIM_LONGDOUBLE 15
55
+
56
+ #define _CFFI_PRIM_WCHAR 16
57
+ #define _CFFI_PRIM_INT8 17
58
+ #define _CFFI_PRIM_UINT8 18
59
+ #define _CFFI_PRIM_INT16 19
60
+ #define _CFFI_PRIM_UINT16 20
61
+ #define _CFFI_PRIM_INT32 21
62
+ #define _CFFI_PRIM_UINT32 22
63
+ #define _CFFI_PRIM_INT64 23
64
+ #define _CFFI_PRIM_UINT64 24
65
+ #define _CFFI_PRIM_INTPTR 25
66
+ #define _CFFI_PRIM_UINTPTR 26
67
+ #define _CFFI_PRIM_PTRDIFF 27
68
+ #define _CFFI_PRIM_SIZE 28
69
+ #define _CFFI_PRIM_SSIZE 29
70
+ #define _CFFI_PRIM_INT_LEAST8 30
71
+ #define _CFFI_PRIM_UINT_LEAST8 31
72
+ #define _CFFI_PRIM_INT_LEAST16 32
73
+ #define _CFFI_PRIM_UINT_LEAST16 33
74
+ #define _CFFI_PRIM_INT_LEAST32 34
75
+ #define _CFFI_PRIM_UINT_LEAST32 35
76
+ #define _CFFI_PRIM_INT_LEAST64 36
77
+ #define _CFFI_PRIM_UINT_LEAST64 37
78
+ #define _CFFI_PRIM_INT_FAST8 38
79
+ #define _CFFI_PRIM_UINT_FAST8 39
80
+ #define _CFFI_PRIM_INT_FAST16 40
81
+ #define _CFFI_PRIM_UINT_FAST16 41
82
+ #define _CFFI_PRIM_INT_FAST32 42
83
+ #define _CFFI_PRIM_UINT_FAST32 43
84
+ #define _CFFI_PRIM_INT_FAST64 44
85
+ #define _CFFI_PRIM_UINT_FAST64 45
86
+ #define _CFFI_PRIM_INTMAX 46
87
+ #define _CFFI_PRIM_UINTMAX 47
88
+
89
+ #define _CFFI__NUM_PRIM 48
90
+ #define _CFFI__UNKNOWN_PRIM (-1)
91
+ #define _CFFI__UNKNOWN_FLOAT_PRIM (-2)
92
+ #define _CFFI__UNKNOWN_LONG_DOUBLE (-3)
93
+
94
+ #define _CFFI__IO_FILE_STRUCT (-1)
95
+
96
+
97
+ struct _cffi_global_s {
98
+ const char *name;
99
+ void *address;
100
+ _cffi_opcode_t type_op;
101
+ void *size_or_direct_fn; // OP_GLOBAL_VAR: size, or 0 if unknown
102
+ // OP_CPYTHON_BLTN_*: addr of direct function
103
+ };
104
+
105
+ struct _cffi_getconst_s {
106
+ unsigned long long value;
107
+ const struct _cffi_type_context_s *ctx;
108
+ int gindex;
109
+ };
110
+
111
+ struct _cffi_struct_union_s {
112
+ const char *name;
113
+ int type_index; // -> _cffi_types, on a OP_STRUCT_UNION
114
+ int flags; // _CFFI_F_* flags below
115
+ size_t size;
116
+ int alignment;
117
+ int first_field_index; // -> _cffi_fields array
118
+ int num_fields;
119
+ };
120
+ #define _CFFI_F_UNION 0x01 // is a union, not a struct
121
+ #define _CFFI_F_CHECK_FIELDS 0x02 // complain if fields are not in the
122
+ // "standard layout" or if some are missing
123
+ #define _CFFI_F_PACKED 0x04 // for CHECK_FIELDS, assume a packed struct
124
+ #define _CFFI_F_EXTERNAL 0x08 // in some other ffi.include()
125
+ #define _CFFI_F_OPAQUE 0x10 // opaque
126
+
127
+ struct _cffi_field_s {
128
+ const char *name;
129
+ size_t field_offset;
130
+ size_t field_size;
131
+ _cffi_opcode_t field_type_op;
132
+ };
133
+
134
+ struct _cffi_enum_s {
135
+ const char *name;
136
+ int type_index; // -> _cffi_types, on a OP_ENUM
137
+ int type_prim; // _CFFI_PRIM_xxx
138
+ const char *enumerators; // comma-delimited string
139
+ };
140
+
141
+ struct _cffi_typename_s {
142
+ const char *name;
143
+ int type_index; /* if opaque, points to a possibly artificial
144
+ OP_STRUCT which is itself opaque */
145
+ };
146
+
147
+ struct _cffi_type_context_s {
148
+ _cffi_opcode_t *types;
149
+ const struct _cffi_global_s *globals;
150
+ const struct _cffi_field_s *fields;
151
+ const struct _cffi_struct_union_s *struct_unions;
152
+ const struct _cffi_enum_s *enums;
153
+ const struct _cffi_typename_s *typenames;
154
+ int num_globals;
155
+ int num_struct_unions;
156
+ int num_enums;
157
+ int num_typenames;
158
+ const char *const *includes;
159
+ int num_types;
160
+ int flags; /* future extension */
161
+ };
162
+
163
+ struct _cffi_parse_info_s {
164
+ const struct _cffi_type_context_s *ctx;
165
+ _cffi_opcode_t *output;
166
+ unsigned int output_size;
167
+ size_t error_location;
168
+ const char *error_message;
169
+ };
170
+
171
+ struct _cffi_externpy_s {
172
+ const char *name;
173
+ size_t size_of_result;
174
+ void *reserved1, *reserved2;
175
+ };
176
+
177
+ #ifdef _CFFI_INTERNAL
178
+ static int parse_c_type(struct _cffi_parse_info_s *info, const char *input);
179
+ static int search_in_globals(const struct _cffi_type_context_s *ctx,
180
+ const char *search, size_t search_len);
181
+ static int search_in_struct_unions(const struct _cffi_type_context_s *ctx,
182
+ const char *search, size_t search_len);
183
+ #endif
184
+
185
+ /* this block of #ifs should be kept exactly identical between
186
+ c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py
187
+ and cffi/_cffi_include.h */
188
+ #if defined(_MSC_VER)
189
+ # include <malloc.h> /* for alloca() */
190
+ # if _MSC_VER < 1600 /* MSVC < 2010 */
191
+ typedef __int8 int8_t;
192
+ typedef __int16 int16_t;
193
+ typedef __int32 int32_t;
194
+ typedef __int64 int64_t;
195
+ typedef unsigned __int8 uint8_t;
196
+ typedef unsigned __int16 uint16_t;
197
+ typedef unsigned __int32 uint32_t;
198
+ typedef unsigned __int64 uint64_t;
199
+ typedef __int8 int_least8_t;
200
+ typedef __int16 int_least16_t;
201
+ typedef __int32 int_least32_t;
202
+ typedef __int64 int_least64_t;
203
+ typedef unsigned __int8 uint_least8_t;
204
+ typedef unsigned __int16 uint_least16_t;
205
+ typedef unsigned __int32 uint_least32_t;
206
+ typedef unsigned __int64 uint_least64_t;
207
+ typedef __int8 int_fast8_t;
208
+ typedef __int16 int_fast16_t;
209
+ typedef __int32 int_fast32_t;
210
+ typedef __int64 int_fast64_t;
211
+ typedef unsigned __int8 uint_fast8_t;
212
+ typedef unsigned __int16 uint_fast16_t;
213
+ typedef unsigned __int32 uint_fast32_t;
214
+ typedef unsigned __int64 uint_fast64_t;
215
+ typedef __int64 intmax_t;
216
+ typedef unsigned __int64 uintmax_t;
217
+ # else
218
+ # include <stdint.h>
219
+ # endif
220
+ # if _MSC_VER < 1800 /* MSVC < 2013 */
221
+ typedef unsigned char _Bool;
222
+ # endif
223
+ #else
224
+ # include <stdint.h>
225
+ # if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
226
+ # include <alloca.h>
227
+ # endif
228
+ #endif
229
+
230
+ #ifdef __GNUC__
231
+ # define _CFFI_UNUSED_FN __attribute__((unused))
232
+ #else
233
+ # define _CFFI_UNUSED_FN /* nothing */
234
+ #endif
235
+
236
+ #ifdef __cplusplus
237
+ # ifndef _Bool
238
+ # define _Bool bool /* semi-hackish: C++ has no _Bool; bool is builtin */
239
+ # endif
240
+ #endif
241
+
242
+ /********** CPython-specific section **********/
243
+ #ifndef PYPY_VERSION
244
+
245
+
246
+ #if PY_MAJOR_VERSION >= 3
247
+ # define PyInt_FromLong PyLong_FromLong
248
+ #endif
249
+
250
+ #define _cffi_from_c_double PyFloat_FromDouble
251
+ #define _cffi_from_c_float PyFloat_FromDouble
252
+ #define _cffi_from_c_long PyInt_FromLong
253
+ #define _cffi_from_c_ulong PyLong_FromUnsignedLong
254
+ #define _cffi_from_c_longlong PyLong_FromLongLong
255
+ #define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong
256
+
257
+ #define _cffi_to_c_double PyFloat_AsDouble
258
+ #define _cffi_to_c_float PyFloat_AsDouble
259
+
260
+ #define _cffi_from_c_int(x, type) \
261
+ (((type)-1) > 0 ? /* unsigned */ \
262
+ (sizeof(type) < sizeof(long) ? \
263
+ PyInt_FromLong((long)x) : \
264
+ sizeof(type) == sizeof(long) ? \
265
+ PyLong_FromUnsignedLong((unsigned long)x) : \
266
+ PyLong_FromUnsignedLongLong((unsigned long long)x)) : \
267
+ (sizeof(type) <= sizeof(long) ? \
268
+ PyInt_FromLong((long)x) : \
269
+ PyLong_FromLongLong((long long)x)))
270
+
271
+ #define _cffi_to_c_int(o, type) \
272
+ ((type)( \
273
+ sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \
274
+ : (type)_cffi_to_c_i8(o)) : \
275
+ sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \
276
+ : (type)_cffi_to_c_i16(o)) : \
277
+ sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \
278
+ : (type)_cffi_to_c_i32(o)) : \
279
+ sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \
280
+ : (type)_cffi_to_c_i64(o)) : \
281
+ (Py_FatalError("unsupported size for type " #type), (type)0)))
282
+
283
+ #define _cffi_to_c_i8 \
284
+ ((int(*)(PyObject *))_cffi_exports[1])
285
+ #define _cffi_to_c_u8 \
286
+ ((int(*)(PyObject *))_cffi_exports[2])
287
+ #define _cffi_to_c_i16 \
288
+ ((int(*)(PyObject *))_cffi_exports[3])
289
+ #define _cffi_to_c_u16 \
290
+ ((int(*)(PyObject *))_cffi_exports[4])
291
+ #define _cffi_to_c_i32 \
292
+ ((int(*)(PyObject *))_cffi_exports[5])
293
+ #define _cffi_to_c_u32 \
294
+ ((unsigned int(*)(PyObject *))_cffi_exports[6])
295
+ #define _cffi_to_c_i64 \
296
+ ((long long(*)(PyObject *))_cffi_exports[7])
297
+ #define _cffi_to_c_u64 \
298
+ ((unsigned long long(*)(PyObject *))_cffi_exports[8])
299
+ #define _cffi_to_c_char \
300
+ ((int(*)(PyObject *))_cffi_exports[9])
301
+ #define _cffi_from_c_pointer \
302
+ ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[10])
303
+ #define _cffi_to_c_pointer \
304
+ ((char *(*)(PyObject *, CTypeDescrObject *))_cffi_exports[11])
305
+ #define _cffi_get_struct_layout \
306
+ not used any more
307
+ #define _cffi_restore_errno \
308
+ ((void(*)(void))_cffi_exports[13])
309
+ #define _cffi_save_errno \
310
+ ((void(*)(void))_cffi_exports[14])
311
+ #define _cffi_from_c_char \
312
+ ((PyObject *(*)(char))_cffi_exports[15])
313
+ #define _cffi_from_c_deref \
314
+ ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[16])
315
+ #define _cffi_to_c \
316
+ ((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[17])
317
+ #define _cffi_from_c_struct \
318
+ ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[18])
319
+ #define _cffi_to_c_wchar_t \
320
+ ((wchar_t(*)(PyObject *))_cffi_exports[19])
321
+ #define _cffi_from_c_wchar_t \
322
+ ((PyObject *(*)(wchar_t))_cffi_exports[20])
323
+ #define _cffi_to_c_long_double \
324
+ ((long double(*)(PyObject *))_cffi_exports[21])
325
+ #define _cffi_to_c__Bool \
326
+ ((_Bool(*)(PyObject *))_cffi_exports[22])
327
+ #define _cffi_prepare_pointer_call_argument \
328
+ ((Py_ssize_t(*)(CTypeDescrObject *, PyObject *, char **))_cffi_exports[23])
329
+ #define _cffi_convert_array_from_object \
330
+ ((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[24])
331
+ #define _CFFI_CPIDX 25
332
+ #define _cffi_call_python \
333
+ ((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[_CFFI_CPIDX])
334
+ #define _CFFI_NUM_EXPORTS 26
335
+
336
+ typedef struct _ctypedescr CTypeDescrObject;
337
+
338
+ static void *_cffi_exports[_CFFI_NUM_EXPORTS];
339
+
340
+ #define _cffi_type(index) ( \
341
+ assert((((uintptr_t)_cffi_types[index]) & 1) == 0), \
342
+ (CTypeDescrObject *)_cffi_types[index])
343
+
344
+ static PyObject *_cffi_init(const char *module_name, Py_ssize_t version,
345
+ const struct _cffi_type_context_s *ctx)
346
+ {
347
+ PyObject *module, *o_arg, *new_module;
348
+ void *raw[] = {
349
+ (void *)module_name,
350
+ (void *)version,
351
+ (void *)_cffi_exports,
352
+ (void *)ctx,
353
+ };
354
+
355
+ module = PyImport_ImportModule("_cffi_backend");
356
+ if (module == NULL)
357
+ goto failure;
358
+
359
+ o_arg = PyLong_FromVoidPtr((void *)raw);
360
+ if (o_arg == NULL)
361
+ goto failure;
362
+
363
+ new_module = PyObject_CallMethod(
364
+ module, (char *)"_init_cffi_1_0_external_module", (char *)"O", o_arg);
365
+
366
+ Py_DECREF(o_arg);
367
+ Py_DECREF(module);
368
+ return new_module;
369
+
370
+ failure:
371
+ Py_XDECREF(module);
372
+ return NULL;
373
+ }
374
+
375
+ _CFFI_UNUSED_FN
376
+ static PyObject **_cffi_unpack_args(PyObject *args_tuple, Py_ssize_t expected,
377
+ const char *fnname)
378
+ {
379
+ if (PyTuple_GET_SIZE(args_tuple) != expected) {
380
+ PyErr_Format(PyExc_TypeError,
381
+ "%.150s() takes exactly %zd arguments (%zd given)",
382
+ fnname, expected, PyTuple_GET_SIZE(args_tuple));
383
+ return NULL;
384
+ }
385
+ return &PyTuple_GET_ITEM(args_tuple, 0); /* pointer to the first item,
386
+ the others follow */
387
+ }
388
+
389
+ /********** end CPython-specific section **********/
390
+ #else
391
+ _CFFI_UNUSED_FN
392
+ static void (*_cffi_call_python_org)(struct _cffi_externpy_s *, char *);
393
+ # define _cffi_call_python _cffi_call_python_org
394
+ #endif
395
+
396
+
397
+ #define _cffi_array_len(array) (sizeof(array) / sizeof((array)[0]))
398
+
399
+ #define _cffi_prim_int(size, sign) \
400
+ ((size) == 1 ? ((sign) ? _CFFI_PRIM_INT8 : _CFFI_PRIM_UINT8) : \
401
+ (size) == 2 ? ((sign) ? _CFFI_PRIM_INT16 : _CFFI_PRIM_UINT16) : \
402
+ (size) == 4 ? ((sign) ? _CFFI_PRIM_INT32 : _CFFI_PRIM_UINT32) : \
403
+ (size) == 8 ? ((sign) ? _CFFI_PRIM_INT64 : _CFFI_PRIM_UINT64) : \
404
+ _CFFI__UNKNOWN_PRIM)
405
+
406
+ #define _cffi_prim_float(size) \
407
+ ((size) == sizeof(float) ? _CFFI_PRIM_FLOAT : \
408
+ (size) == sizeof(double) ? _CFFI_PRIM_DOUBLE : \
409
+ (size) == sizeof(long double) ? _CFFI__UNKNOWN_LONG_DOUBLE : \
410
+ _CFFI__UNKNOWN_FLOAT_PRIM)
411
+
412
+ #define _cffi_check_int(got, got_nonpos, expected) \
413
+ ((got_nonpos) == (expected <= 0) && \
414
+ (got) == (unsigned long long)expected)
415
+
416
+ #ifdef MS_WIN32
417
+ # define _cffi_stdcall __stdcall
418
+ #else
419
+ # define _cffi_stdcall /* nothing */
420
+ #endif
421
+
422
+ #ifdef __cplusplus
423
+ }
424
+ #endif
425
+
426
+ /************************************************************/
427
+
428
+ /* dbc2dbf.c
429
+
430
+ Copyright (C) 2016 Daniela Petruzalek
431
+ Version 1.0, 22 May 2016
432
+
433
+ This program is free software: you can redistribute it and/or modify
434
+ it under the terms of the GNU Affero General Public License as published
435
+ by the Free Software Foundation, either version 3 of the License, or
436
+ (at your option) any later version.
437
+
438
+ This program is distributed in the hope that it will be useful,
439
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
440
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
441
+ GNU Affero General Public License for more details.
442
+
443
+ You should have received a copy of the GNU Affero General Public License
444
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
445
+
446
+ */
447
+
448
+ /*
449
+ Author Notes
450
+ ============
451
+
452
+ This program decompresses .dbc files to .dbf. This code is based on the work
453
+ of Mark Adler <madler@alumni.caltech.edu> (zlib/blast) and Pablo Fonseca
454
+ (https://github.com/eaglebh/blast-dbf).
455
+ */
456
+
457
+ #include <stdio.h>
458
+ #include <stdlib.h>
459
+ #include <unistd.h>
460
+ #include <errno.h>
461
+ #include <string.h>
462
+ #include <stdint.h>
463
+ // #include <R.h>
464
+
465
+ #include "blast.h"
466
+
467
+ #define CHUNK 4096
468
+
469
+ /* Input file helper function */
470
+ static unsigned inf(void *how, unsigned char **buf)
471
+ {
472
+ static unsigned char hold[CHUNK];
473
+
474
+ *buf = hold;
475
+ return fread(hold, 1, CHUNK, (FILE *)how);
476
+ }
477
+
478
+ /* Output file helper function */
479
+ static int outf(void *how, unsigned char *buf, unsigned len)
480
+ {
481
+ return fwrite(buf, 1, len, (FILE *)how) != len;
482
+ }
483
+
484
+ /*
485
+ dbc2dbf(char** input_file, char** output_file)
486
+ This function decompresses a given .dbc input file into the corresponding .dbf.
487
+
488
+ Please provide fully qualified names, including file extension.
489
+ */
490
+ void dbc2dbf(char** input_file, char** output_file) {
491
+ FILE *input = 0, *output = 0;
492
+ int ret = 0;
493
+ unsigned char rawHeader[2];
494
+ uint16_t header = 0;
495
+
496
+ /* Open input file */
497
+ input = fopen(input_file[0], "rb");
498
+ if(input == NULL) {
499
+ error("Error reading input file %s: %s", input_file[0], strerror(errno));
500
+ return;
501
+ }
502
+
503
+ /* Open output file */
504
+ output = fopen(output_file[0], "wb");
505
+ if(output == NULL) {
506
+ error("Error reading output file %s: %s", output_file[0], strerror(errno));
507
+ return;
508
+ }
509
+
510
+ /* Process file header - skip 8 bytes */
511
+ if( fseek(input, 8, SEEK_SET) ) {
512
+ error("Error processing input file %s: %s", input_file[0], strerror(errno));
513
+ return;
514
+ }
515
+
516
+ /* Reads two bytes from the header = header size */
517
+ ret = fread(rawHeader, 2, 1, input);
518
+ if( ferror(input) ) {
519
+ error("Error reading input file %s: %s", input_file[0], strerror(errno));
520
+ return;
521
+ }
522
+
523
+ /* Platform independent code (header is stored in little endian format) */
524
+ header = rawHeader[0] + (rawHeader[1] << 8);
525
+
526
+ /* Reset file pointer */
527
+ rewind(input);
528
+
529
+ /* Copy file header from input to output */
530
+ unsigned char buf[header];
531
+
532
+ ret = fread(buf, 1, header, input);
533
+ if( ferror(input) ) {
534
+ error("Error reading input file %s: %s", input_file[0], strerror(errno));
535
+ return;
536
+ }
537
+
538
+ ret = fwrite(buf, 1, header, output);
539
+ if( ferror(output) ) {
540
+ error("Error writing output file %s: %s", output_file[0], strerror(errno));
541
+ return;
542
+ }
543
+
544
+ /* Jump to the data (Skip CRC32) */
545
+ if( fseek(input, header + 4, SEEK_SET) ) {
546
+ error("Error processing input file %s: %s", input_file[0], strerror(errno));
547
+ return;
548
+ }
549
+
550
+ /* decompress */
551
+ ret = blast(inf, input, outf, output);
552
+ if( ret ) error("blast error code: %d", ret);
553
+
554
+ /* see if there are any leftover bytes */
555
+ int n = 0;
556
+ while (fgetc(input) != EOF) n++;
557
+ if (n) error("blast warning: %d unused bytes of input\n", n);
558
+
559
+ fclose(input);
560
+ fclose(output);
561
+ }
562
+
563
+
564
+ /************************************************************/
565
+
566
+ static void *_cffi_types[] = {
567
+ /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 21), // int()(unsigned int(*)(void *, unsigned char * *), void *, int(*)(void *, unsigned char *, unsigned int), void *)
568
+ /* 1 */ _CFFI_OP(_CFFI_OP_POINTER, 11), // unsigned int(*)(void *, unsigned char * *)
569
+ /* 2 */ _CFFI_OP(_CFFI_OP_POINTER, 23), // void *
570
+ /* 3 */ _CFFI_OP(_CFFI_OP_POINTER, 6), // int(*)(void *, unsigned char *, unsigned int)
571
+ /* 4 */ _CFFI_OP(_CFFI_OP_NOOP, 2),
572
+ /* 5 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
573
+ /* 6 */ _CFFI_OP(_CFFI_OP_FUNCTION, 21), // int()(void *, unsigned char *, unsigned int)
574
+ /* 7 */ _CFFI_OP(_CFFI_OP_NOOP, 2),
575
+ /* 8 */ _CFFI_OP(_CFFI_OP_POINTER, 22), // unsigned char *
576
+ /* 9 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 8), // unsigned int
577
+ /* 10 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
578
+ /* 11 */ _CFFI_OP(_CFFI_OP_FUNCTION, 9), // unsigned int()(void *, unsigned char * *)
579
+ /* 12 */ _CFFI_OP(_CFFI_OP_NOOP, 2),
580
+ /* 13 */ _CFFI_OP(_CFFI_OP_POINTER, 8), // unsigned char * *
581
+ /* 14 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
582
+ /* 15 */ _CFFI_OP(_CFFI_OP_FUNCTION, 23), // void()(char * *, char * *)
583
+ /* 16 */ _CFFI_OP(_CFFI_OP_POINTER, 19), // char * *
584
+ /* 17 */ _CFFI_OP(_CFFI_OP_NOOP, 16),
585
+ /* 18 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
586
+ /* 19 */ _CFFI_OP(_CFFI_OP_POINTER, 20), // char *
587
+ /* 20 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 2), // char
588
+ /* 21 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), // int
589
+ /* 22 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 4), // unsigned char
590
+ /* 23 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 0), // void
591
+ };
592
+
593
+ static int _cffi_d_blast(unsigned int(* x0)(void *, unsigned char * *), void * x1, int(* x2)(void *, unsigned char *, unsigned int), void * x3)
594
+ {
595
+ return blast(x0, x1, x2, x3);
596
+ }
597
+ #ifndef PYPY_VERSION
598
+ static PyObject *
599
+ _cffi_f_blast(PyObject *self, PyObject *args)
600
+ {
601
+ unsigned int(* x0)(void *, unsigned char * *);
602
+ void * x1;
603
+ int(* x2)(void *, unsigned char *, unsigned int);
604
+ void * x3;
605
+ Py_ssize_t datasize;
606
+ int result;
607
+ PyObject *arg0;
608
+ PyObject *arg1;
609
+ PyObject *arg2;
610
+ PyObject *arg3;
611
+ PyObject **aa;
612
+
613
+ aa = _cffi_unpack_args(args, 4, "blast");
614
+ if (aa == NULL)
615
+ return NULL;
616
+ arg0 = aa[0];
617
+ arg1 = aa[1];
618
+ arg2 = aa[2];
619
+ arg3 = aa[3];
620
+
621
+ x0 = (unsigned int(*)(void *, unsigned char * *))_cffi_to_c_pointer(arg0, _cffi_type(1));
622
+ if (x0 == (unsigned int(*)(void *, unsigned char * *))NULL && PyErr_Occurred())
623
+ return NULL;
624
+
625
+ datasize = _cffi_prepare_pointer_call_argument(
626
+ _cffi_type(2), arg1, (char **)&x1);
627
+ if (datasize != 0) {
628
+ if (datasize < 0)
629
+ return NULL;
630
+ x1 = (void *)alloca((size_t)datasize);
631
+ memset((void *)x1, 0, (size_t)datasize);
632
+ if (_cffi_convert_array_from_object((char *)x1, _cffi_type(2), arg1) < 0)
633
+ return NULL;
634
+ }
635
+
636
+ x2 = (int(*)(void *, unsigned char *, unsigned int))_cffi_to_c_pointer(arg2, _cffi_type(3));
637
+ if (x2 == (int(*)(void *, unsigned char *, unsigned int))NULL && PyErr_Occurred())
638
+ return NULL;
639
+
640
+ datasize = _cffi_prepare_pointer_call_argument(
641
+ _cffi_type(2), arg3, (char **)&x3);
642
+ if (datasize != 0) {
643
+ if (datasize < 0)
644
+ return NULL;
645
+ x3 = (void *)alloca((size_t)datasize);
646
+ memset((void *)x3, 0, (size_t)datasize);
647
+ if (_cffi_convert_array_from_object((char *)x3, _cffi_type(2), arg3) < 0)
648
+ return NULL;
649
+ }
650
+
651
+ Py_BEGIN_ALLOW_THREADS
652
+ _cffi_restore_errno();
653
+ { result = blast(x0, x1, x2, x3); }
654
+ _cffi_save_errno();
655
+ Py_END_ALLOW_THREADS
656
+
657
+ (void)self; /* unused */
658
+ return _cffi_from_c_int(result, int);
659
+ }
660
+ #else
661
+ # define _cffi_f_blast _cffi_d_blast
662
+ #endif
663
+
664
+ static void _cffi_d_dbc2dbf(char * * x0, char * * x1)
665
+ {
666
+ dbc2dbf(x0, x1);
667
+ }
668
+ #ifndef PYPY_VERSION
669
+ static PyObject *
670
+ _cffi_f_dbc2dbf(PyObject *self, PyObject *args)
671
+ {
672
+ char * * x0;
673
+ char * * x1;
674
+ Py_ssize_t datasize;
675
+ PyObject *arg0;
676
+ PyObject *arg1;
677
+ PyObject **aa;
678
+
679
+ aa = _cffi_unpack_args(args, 2, "dbc2dbf");
680
+ if (aa == NULL)
681
+ return NULL;
682
+ arg0 = aa[0];
683
+ arg1 = aa[1];
684
+
685
+ datasize = _cffi_prepare_pointer_call_argument(
686
+ _cffi_type(16), arg0, (char **)&x0);
687
+ if (datasize != 0) {
688
+ if (datasize < 0)
689
+ return NULL;
690
+ x0 = (char * *)alloca((size_t)datasize);
691
+ memset((void *)x0, 0, (size_t)datasize);
692
+ if (_cffi_convert_array_from_object((char *)x0, _cffi_type(16), arg0) < 0)
693
+ return NULL;
694
+ }
695
+
696
+ datasize = _cffi_prepare_pointer_call_argument(
697
+ _cffi_type(16), arg1, (char **)&x1);
698
+ if (datasize != 0) {
699
+ if (datasize < 0)
700
+ return NULL;
701
+ x1 = (char * *)alloca((size_t)datasize);
702
+ memset((void *)x1, 0, (size_t)datasize);
703
+ if (_cffi_convert_array_from_object((char *)x1, _cffi_type(16), arg1) < 0)
704
+ return NULL;
705
+ }
706
+
707
+ Py_BEGIN_ALLOW_THREADS
708
+ _cffi_restore_errno();
709
+ { dbc2dbf(x0, x1); }
710
+ _cffi_save_errno();
711
+ Py_END_ALLOW_THREADS
712
+
713
+ (void)self; /* unused */
714
+ Py_INCREF(Py_None);
715
+ return Py_None;
716
+ }
717
+ #else
718
+ # define _cffi_f_dbc2dbf _cffi_d_dbc2dbf
719
+ #endif
720
+
721
+ static unsigned int _cffi_d_inf(void * x0, unsigned char * * x1)
722
+ {
723
+ return inf(x0, x1);
724
+ }
725
+ #ifndef PYPY_VERSION
726
+ static PyObject *
727
+ _cffi_f_inf(PyObject *self, PyObject *args)
728
+ {
729
+ void * x0;
730
+ unsigned char * * x1;
731
+ Py_ssize_t datasize;
732
+ unsigned int result;
733
+ PyObject *arg0;
734
+ PyObject *arg1;
735
+ PyObject **aa;
736
+
737
+ aa = _cffi_unpack_args(args, 2, "inf");
738
+ if (aa == NULL)
739
+ return NULL;
740
+ arg0 = aa[0];
741
+ arg1 = aa[1];
742
+
743
+ datasize = _cffi_prepare_pointer_call_argument(
744
+ _cffi_type(2), arg0, (char **)&x0);
745
+ if (datasize != 0) {
746
+ if (datasize < 0)
747
+ return NULL;
748
+ x0 = (void *)alloca((size_t)datasize);
749
+ memset((void *)x0, 0, (size_t)datasize);
750
+ if (_cffi_convert_array_from_object((char *)x0, _cffi_type(2), arg0) < 0)
751
+ return NULL;
752
+ }
753
+
754
+ datasize = _cffi_prepare_pointer_call_argument(
755
+ _cffi_type(13), arg1, (char **)&x1);
756
+ if (datasize != 0) {
757
+ if (datasize < 0)
758
+ return NULL;
759
+ x1 = (unsigned char * *)alloca((size_t)datasize);
760
+ memset((void *)x1, 0, (size_t)datasize);
761
+ if (_cffi_convert_array_from_object((char *)x1, _cffi_type(13), arg1) < 0)
762
+ return NULL;
763
+ }
764
+
765
+ Py_BEGIN_ALLOW_THREADS
766
+ _cffi_restore_errno();
767
+ { result = inf(x0, x1); }
768
+ _cffi_save_errno();
769
+ Py_END_ALLOW_THREADS
770
+
771
+ (void)self; /* unused */
772
+ return _cffi_from_c_int(result, unsigned int);
773
+ }
774
+ #else
775
+ # define _cffi_f_inf _cffi_d_inf
776
+ #endif
777
+
778
+ static int _cffi_d_outf(void * x0, unsigned char * x1, unsigned int x2)
779
+ {
780
+ return outf(x0, x1, x2);
781
+ }
782
+ #ifndef PYPY_VERSION
783
+ static PyObject *
784
+ _cffi_f_outf(PyObject *self, PyObject *args)
785
+ {
786
+ void * x0;
787
+ unsigned char * x1;
788
+ unsigned int x2;
789
+ Py_ssize_t datasize;
790
+ int result;
791
+ PyObject *arg0;
792
+ PyObject *arg1;
793
+ PyObject *arg2;
794
+ PyObject **aa;
795
+
796
+ aa = _cffi_unpack_args(args, 3, "outf");
797
+ if (aa == NULL)
798
+ return NULL;
799
+ arg0 = aa[0];
800
+ arg1 = aa[1];
801
+ arg2 = aa[2];
802
+
803
+ datasize = _cffi_prepare_pointer_call_argument(
804
+ _cffi_type(2), arg0, (char **)&x0);
805
+ if (datasize != 0) {
806
+ if (datasize < 0)
807
+ return NULL;
808
+ x0 = (void *)alloca((size_t)datasize);
809
+ memset((void *)x0, 0, (size_t)datasize);
810
+ if (_cffi_convert_array_from_object((char *)x0, _cffi_type(2), arg0) < 0)
811
+ return NULL;
812
+ }
813
+
814
+ datasize = _cffi_prepare_pointer_call_argument(
815
+ _cffi_type(8), arg1, (char **)&x1);
816
+ if (datasize != 0) {
817
+ if (datasize < 0)
818
+ return NULL;
819
+ x1 = (unsigned char *)alloca((size_t)datasize);
820
+ memset((void *)x1, 0, (size_t)datasize);
821
+ if (_cffi_convert_array_from_object((char *)x1, _cffi_type(8), arg1) < 0)
822
+ return NULL;
823
+ }
824
+
825
+ x2 = _cffi_to_c_int(arg2, unsigned int);
826
+ if (x2 == (unsigned int)-1 && PyErr_Occurred())
827
+ return NULL;
828
+
829
+ Py_BEGIN_ALLOW_THREADS
830
+ _cffi_restore_errno();
831
+ { result = outf(x0, x1, x2); }
832
+ _cffi_save_errno();
833
+ Py_END_ALLOW_THREADS
834
+
835
+ (void)self; /* unused */
836
+ return _cffi_from_c_int(result, int);
837
+ }
838
+ #else
839
+ # define _cffi_f_outf _cffi_d_outf
840
+ #endif
841
+
842
+ static const struct _cffi_global_s _cffi_globals[] = {
843
+ { "blast", (void *)_cffi_f_blast, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 0), (void *)_cffi_d_blast },
844
+ { "dbc2dbf", (void *)_cffi_f_dbc2dbf, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 15), (void *)_cffi_d_dbc2dbf },
845
+ { "inf", (void *)_cffi_f_inf, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 11), (void *)_cffi_d_inf },
846
+ { "outf", (void *)_cffi_f_outf, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 6), (void *)_cffi_d_outf },
847
+ };
848
+
849
+ static const struct _cffi_typename_s _cffi_typenames[] = {
850
+ { "blast_in", 1 },
851
+ { "blast_out", 3 },
852
+ };
853
+
854
+ static const struct _cffi_type_context_s _cffi_type_context = {
855
+ _cffi_types,
856
+ _cffi_globals,
857
+ NULL, /* no fields */
858
+ NULL, /* no struct_unions */
859
+ NULL, /* no enums */
860
+ _cffi_typenames,
861
+ 4, /* num_globals */
862
+ 0, /* num_struct_unions */
863
+ 0, /* num_enums */
864
+ 2, /* num_typenames */
865
+ NULL, /* no includes */
866
+ 24, /* num_types */
867
+ 0, /* flags */
868
+ };
869
+
870
+ #ifdef PYPY_VERSION
871
+ PyMODINIT_FUNC
872
+ _cffi_pypyinit__readdbc(const void *p[])
873
+ {
874
+ p[0] = (const void *)0x2601;
875
+ p[1] = &_cffi_type_context;
876
+ }
877
+ # ifdef _MSC_VER
878
+ PyMODINIT_FUNC
879
+ # if PY_MAJOR_VERSION >= 3
880
+ PyInit__readdbc(void) { return NULL; }
881
+ # else
882
+ init_readdbc(void) { }
883
+ # endif
884
+ # endif
885
+ #elif PY_MAJOR_VERSION >= 3
886
+ PyMODINIT_FUNC
887
+ PyInit__readdbc(void)
888
+ {
889
+ return _cffi_init("_readdbc", 0x2601, &_cffi_type_context);
890
+ }
891
+ #else
892
+ PyMODINIT_FUNC
893
+ init_readdbc(void)
894
+ {
895
+ _cffi_init("_readdbc", 0x2601, &_cffi_type_context);
896
+ }
897
+ #endif