Debian Codegraph @

Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c

raw symbols SCIP
1 /*=========================================================================
2
3 Program: GDCM (Grassroots DICOM). A DICOM library
4
5 Copyright (c) 2006-2011 Mathieu Malaterre
6 All rights reserved.
7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13 =========================================================================*/
14
15 #include "mec_mr3_io.h"cxx . . $ `<file>/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.h`/
16
17 #include "mec_mr3_dict.h"cxx . . $ `<file>/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_dict.h`/
18
19 #include <assert.h>
20 #include <math.h>
21 #include <stdint.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #if defined(_MSC_VER) || defined(__OpenBSD__)
27 #define MEC3_HAS_ICONV 0
28 #else
29 #define MEC3_HAS_ICONVcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:29:9`! 1
30 #endif
31
32 #if MEC3_HAS_ICONVcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:29:9`!
33 #include <iconv.h>
34 #endif
35 #if defined(_MSC_VER) && (_MSC_VER < 1900)
36 #define snprintf _snprintf
37 #endif
38
39 struct streamcxx . . $ stream# {
40 const void *startcxx . . $ stream#start.;
41 const void *endcxx . . $ stream#end.;
42 void *curcxx . . $ stream#cur.;
43 size_t (*readcxx . . $ stream#read.)(void *ptr, size_t size, size_t nmemb, struct streamcxx . . $ stream# *in);
44 };
45
46 static size_t stream_readcxx . . $ stream_read(ba31703fb6d0b4e0).(void *ptr, size_t size, size_t nmemb,
47 struct streamcxx . . $ stream# *in) {
48 char *cur = (char *)in->curcxx . . $ stream#cur.;
49 const char *end = (const char *)in->endcxx . . $ stream#end.;
50 const size_t len = size * nmemb;
51 if (cur + len <= end) {
52 memcpycxx . . $ memcpy(cc817cb175f282d).(ptr, cur, len);
53 in->curcxx . . $ stream#cur. = cur + len;
54 } else {
55 in->curcxx . . $ stream#cur. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
56 return 0;
57 }
58 return nmemb;
59 }
60
61 struct appcxx . . $ app# {
62 struct streamcxx . . $ stream# *incxx . . $ app#in.;
63 #if MEC3_HAS_ICONVcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:29:9`!
64 iconv_tcxx . . $ iconv_t# convcxx . . $ app#conv.;
65 #endif
66 void *shift_jis_buffercxx . . $ app#shift_jis_buffer.;
67 };
68
69 static struct appcxx . . $ app# *create_appcxx . . $ create_app(207586a7460acdf2).(struct appcxx . . $ app# *self, struct streamcxx . . $ stream# *in) {
70 self->incxx . . $ app#in. = in;
71 #if MEC3_HAS_ICONVcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:29:9`!
72 self->convcxx . . $ app#conv. = iconv_opencxx . . $ iconv_open(12e6862c879384a7).("utf-8", "shift-jis");
73 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(self->conv != (iconv_t)-1);
74 #endif
75 self->shift_jis_buffercxx . . $ app#shift_jis_buffer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
76
77 return self;
78 }
79
80 static void setup_buffercxx . . $ setup_buffer(e3d7d4d3917a41c2).(struct appcxx . . $ app# *self, const void *input, const size_t len) {
81 self->incxx . . $ app#in.->curcxx . . $ stream#cur. = (char *)input;
82 self->incxx . . $ app#in.->startcxx . . $ stream#start. = input;
83 self->incxx . . $ app#in.->endcxx . . $ stream#end. = (char *)input + len;
84 self->incxx . . $ app#in.->readcxx . . $ stream#read. = stream_readcxx . . $ stream_read(ba31703fb6d0b4e0).;
85 }
86
87 #define ERROR_RETURNcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:87:9`!(X, Y) \
88 if ((X) != (Y)) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!
89
90 static size_t fread_mirrorcxx . . $ fread_mirror(71e37d83cd1f2ffb).(void *ptr, size_t size, size_t nmemb,
91 struct appcxx . . $ app# *self) {
92 struct streamcxx . . $ stream# *instream = self->incxx . . $ app#in.;
93
94 size_t s = instream->readcxx . . $ stream#read.(ptr, size, nmemb, instream);
95 if (s == nmemb) {
96 return nmemb;
97 }
98 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(0);
99 return s;
100 }
101
102 #if 0
103 static void dump2file(const char *in, int len) {
104 static int debug = 0;
105 char buffer[512];
106 sprintf(buffer, "out%04d", debug);
107 ++debug;
108 FILE *f = fopen(buffer, "wb");
109 fwrite(in, 1, len, f);
110 fclose(f);
111 }
112 #endif
113
114 static size_t is_ascii_string_with_trailing_nullscxx . . $ is_ascii_string_with_trailing_nulls(746566a4864dd891).(const void *ptr, const size_t size) {
115 const unsigned char *byte_ptr = (const unsigned char *)ptr;
116 size_t ret;
117 size_t i = 0;
118
119 // Check for null-terminated C string
120 while (i < size && byte_ptr[i] != '\0') {
121 if (byte_ptr[i] > 127u) {
122 return (size_t)-1;
123 }
124 i++;
125 }
126
127 // If we reached the end without finding a null terminator, it's not a valid
128 // ASCII C string
129 if (i == size) {
130 return (size_t)-1;
131 }
132
133 // Move past the null terminator
134 ret = i;
135 i++;
136
137 // Check that the remaining bytes are all null
138 for (; i < size; ++i) {
139 if (byte_ptr[i] != 0) {
140 return (size_t)-1;
141 }
142 }
143
144 return ret;
145 }
146
147 void print_string_as_hexcxx . . $ print_string_as_hex(85c52e162fed56f9).(const char *str) {
148 printfcxx . . $ printf(581fddd72a8db8fc).(" %%");
149 while (*str) {
150 printfcxx . . $ printf(581fddd72a8db8fc).("%02x ", (unsigned char)*str);
151 str++;
152 }
153 printfcxx . . $ printf(581fddd72a8db8fc).("%% ");
154 }
155
156 // https://stackoverflow.com/questions/28270310/how-to-easily-detect-utf8-encoding-in-the-string
157 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! is_valid_utf8cxx . . $ is_valid_utf8(c5f7da30cbc0f4e9).(const char *string) {
158 if (!string) return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
159
160 const unsigned char *bytes = (const unsigned char *)string;
161 unsigned int cp;
162 int num;
163
164 while (*bytes != 0x00) {
165 if ((*bytes & 0x80) == 0x00) {
166 // U+0000 to U+007F
167 cp = (*bytes & 0x7F);
168 num = 1;
169 } else if ((*bytes & 0xE0) == 0xC0) {
170 // U+0080 to U+07FF
171 cp = (*bytes & 0x1F);
172 num = 2;
173 } else if ((*bytes & 0xF0) == 0xE0) {
174 // U+0800 to U+FFFF
175 cp = (*bytes & 0x0F);
176 num = 3;
177 } else if ((*bytes & 0xF8) == 0xF0) {
178 // U+10000 to U+10FFFF
179 cp = (*bytes & 0x07);
180 num = 4;
181 } else
182 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
183
184 bytes += 1;
185 for (int i = 1; i < num; ++i) {
186 if ((*bytes & 0xC0) != 0x80) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
187 cp = (cp << 6) | (*bytes & 0x3F);
188 bytes += 1;
189 }
190
191 if ((cp > 0x10FFFF) || ((cp >= 0xD800) && (cp <= 0xDFFF)) ||
192 ((cp <= 0x007F) && (num != 1)) ||
193 ((cp >= 0x0080) && (cp <= 0x07FF) && (num != 2)) ||
194 ((cp >= 0x0800) && (cp <= 0xFFFF) && (num != 3)) ||
195 ((cp >= 0x10000) && (cp <= 0x1FFFFF) && (num != 4)))
196 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
197 }
198
199 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
200 }
201
202 enum unicode_typecxx . . $ unicode_type#
203 {
204 kErrorcxx . . $ kError. = -1,
205 kUTF8cxx . . $ kUTF8. = 0,
206 kSHIFT_JIScxx . . $ kSHIFT_JIS. = 1,
207 kEUC_JPcxx . . $ kEUC_JP. = 2
208 };
209
210 const char * unicode_type_as_stringcxx . . $ unicode_type_as_string(f7ae7e56280f18ae).(const int unicode_type)
211 {
212 switch (unicode_type)
213 {
214 case kUTF8cxx . . $ kUTF8.:
215 return "UTF-8";
216 case kSHIFT_JIScxx . . $ kSHIFT_JIS.:
217 return "SHIFT-JIS";
218 case kEUC_JPcxx . . $ kEUC_JP.:
219 return "EUC-JP";
220 default:
221 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(0);
222 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
223 }
224 }
225
226 static int guess_unicode_and_convertcxx . . $ guess_unicode_and_convert(55a978ccac6a7ad7).(struct appcxx . . $ app# *self, const char *str, size_t len) {
227 const size_t guesstimate = len < 128 ? 128 : len * 2;
228 self->shift_jis_buffercxx . . $ app#shift_jis_buffer. = realloccxx . . $ realloc(417ab160f6baadc6).(self->shift_jis_buffercxx . . $ app#shift_jis_buffer., guesstimate);
229 char *dest_str = self->shift_jis_buffercxx . . $ app#shift_jis_buffer.;
230 int utype = kErrorcxx . . $ kError.;
231 #if MEC3_HAS_ICONVcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:29:9`!
232 const char *in_str = str;
233 char *out_str = dest_str;
234 size_t inbytes = len;
235 size_t outbytes = guesstimate;
236 utype = kSHIFT_JIScxx . . $ kSHIFT_JIS.;
237 if (iconvcxx . . $ iconv(df3c92a1a902995d).(self->convcxx . . $ app#conv., (char**)&in_str, &inbytes, &out_str, &outbytes) == (size_t)-1) {
238 #if 0
239 // at this point both gbk_str & inbytes have been modified, prefer original
240 // values:
241 dump2file(str, len);
242 printf("[%.*s]", (int)len, str);
243 fflush(stdout);
244 #endif
245 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(strlen(in_str) <= 3);
246 if (is_valid_utf8cxx . . $ is_valid_utf8(c5f7da30cbc0f4e9).(str)) {
247 utype = kUTF8cxx . . $ kUTF8.;
248 strcpycxx . . $ strcpy(b7b3a83273496486).(dest_str, str);
249 return utype;
250 } else {
251 self->convcxx . . $ app#conv. = iconv_opencxx . . $ iconv_open(12e6862c879384a7).("utf-8", "euc-jp");
252 in_str = str;
253 size_t ret = iconvcxx . . $ iconv(df3c92a1a902995d).(self->convcxx . . $ app#conv., (char**)&in_str, &inbytes, &out_str, &outbytes);
254 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(ret != (size_t)-1);
255 iconv_closecxx . . $ iconv_close(dedf1e9b1c614a07).(self->convcxx . . $ app#conv.);
256 utype = kEUC_JPcxx . . $ kEUC_JP.;
257 self->convcxx . . $ app#conv. = iconv_opencxx . . $ iconv_open(12e6862c879384a7).("utf-8", "shift-jis");
258 }
259 } else
260 {
261 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(inbytes==0);
262 // assert(is_ascii_string_with_trailing_nulls(str, len)!=(size_t)-1);
263 }
264 dest_str[guesstimate - outbytes] = 0;
265 #else
266 (void)str;
267 utype = kError;
268 // guesstimate imply at least 128 bytes:
269 strcpy(dest_str, "No iconv support");
270 #endif
271 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_valid_utf8(dest_str));
272 return utype;
273 }
274
275 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! write_trailercxx . . $ write_trailer(74da70a3f26cd88d).(struct appcxx . . $ app# *self) {
276 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(self->in->cur <= self->in->end);
277 if (self->incxx . . $ app#in.->curcxx . . $ stream#cur. == self->incxx . . $ app#in.->endcxx . . $ stream#end.) return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
278 // else it is missing one byte (nul byte):
279 char padding;
280 const size_t s = fread_mirrorcxx . . $ fread_mirror(71e37d83cd1f2ffb).(&padding, sizeof padding, 1, self);
281 ERROR_RETURNcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:87:9`!(s, 1);
282 ERROR_RETURNcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:87:9`!(padding, 0);
283
284 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
285 }
286
287 struct mec_mr3_infocxx . . $ mec_mr3_info# {
288 uint32_tcxx . . $ uint32_t# keycxx . . $ mec_mr3_info#key.;
289 uint32_tcxx . . $ uint32_t# typecxx . . $ mec_mr3_info#type.;
290 };
291
292 struct mec_mr3_item_datacxx . . $ mec_mr3_item_data# {
293 uint32_tcxx . . $ uint32_t# lencxx . . $ mec_mr3_item_data#len.;
294 void *buffercxx . . $ mec_mr3_item_data#buffer.;
295 size_t sizecxx . . $ mec_mr3_item_data#size.; // aligned/realloc implementation detail
296 };
297
298 static const uint32_tcxx . . $ uint32_t# magic2cxx . . $ magic2.[] = {0, 0, 12, 0, 0};
299
300 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! read_infocxx . . $ read_info(195bdd6644ef5b5b).(struct appcxx . . $ app# *self, const uint8_tcxx . . $ uint8_t# group,
301 struct mec_mr3_infocxx . . $ mec_mr3_info# *info) {
302 (void)group;
303 // read key and type at once:
304 const size_t s = fread_mirrorcxx . . $ fread_mirror(71e37d83cd1f2ffb).(info, sizeof *info, 1, self);
305 ERROR_RETURNcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:87:9`!(s, 1);
306 #ifdef MEC_MR3_IO_DEBUG
307 bool found = check_mec_mr3_info(group, info->key, info->type);
308 ERROR_RETURN(found, true);
309 #endif
310
311 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
312 }
313
314 static void *aligned_alloc_implcxx . . $ aligned_alloc_impl(63a7bf2941bfcd7a).(size_t alignment, size_t size) {
315 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
316 return _aligned_malloc(size, alignment);
317 #else
318 // return aligned_alloc(alignment, size);
319 void *allocPtr;
320 int error = posix_memaligncxx . . $ posix_memalign(e974a8a87fa206f3).(&allocPtr, alignment, size);
321 // posix_memalign() returns zero on success
322 return error == 0 ? allocPtr : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
323 #endif
324 }
325
326 static struct mec_mr3_item_datacxx . . $ mec_mr3_item_data# *mec_mr3_aligned_realloccxx . . $ mec_mr3_aligned_realloc(bbbb938d129dea0a).(struct mec_mr3_item_datacxx . . $ mec_mr3_item_data# *data, const size_t size) {
327 if (!data) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
328 // fast path
329 if (size <= data->sizecxx . . $ mec_mr3_item_data#size.) {
330 return data;
331 }
332 // else need to reallocate
333 const size_t guesstimate = size < 4096 ? 4096 : 2 * size;
334 void *buffer = aligned_alloc_implcxx . . $ aligned_alloc_impl(63a7bf2941bfcd7a).(64u, guesstimate);
335 if (data->buffercxx . . $ mec_mr3_item_data#buffer.) freecxx . . $ free(5d22bdacc48458e8).(data->buffercxx . . $ mec_mr3_item_data#buffer.);
336 if (!buffer) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
337 data->buffercxx . . $ mec_mr3_item_data#buffer. = buffer;
338 data->sizecxx . . $ mec_mr3_item_data#size. = guesstimate;
339 return data;
340 }
341
342 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! is_alignedcxx . . $ is_aligned(d7c96d367a6f87f1).(const void *pointer, const size_t byte_count) {
343 // https://stackoverflow.com/questions/1898153/how-to-determine-if-memory-is-aligned
344 return (uintptr_tcxx . . $ uintptr_t#)pointer % byte_count == 0;
345 }
346
347 enum SignatureTypecxx . . $ SignatureType# { SIG_UNKcxx . . $ SIG_UNK. = 0, SIG_SIMPLEcxx . . $ SIG_SIMPLE. = 1, SIG_COMPLEXcxx . . $ SIG_COMPLEX. = 2 };
348 static enum SignatureTypecxx . . $ SignatureType# compute_signaturecxx . . $ compute_signature(f6af82805ad6e93a).(const uint32_tcxx . . $ uint32_t# sig[5]) {
349 // fast path: {0, 0, 12, 0, 0}
350 const int b = memcmpcxx . . $ memcmp(36f949851efa3055).(sig, magic2cxx . . $ magic2., sizeof(magic2cxx . . $ magic2.));
351 if (b == 0) return SIG_SIMPLEcxx . . $ SIG_SIMPLE.;
352 // check the complex one:
353 // [0,67937544,12,0,235348672] #20
354 // [0,226469240,12,0,235348704] #20
355 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! sig_complex = sig[0] == 0 && sig[2] == 12 && sig[3] == 0;
356 if (sig_complex) return SIG_COMPLEXcxx . . $ SIG_COMPLEX.;
357 return SIG_UNKcxx . . $ SIG_UNK.;
358 }
359
360 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! read_datacxx . . $ read_data(fd1d76ce55b26d10).(struct appcxx . . $ app# *self, const uint8_tcxx . . $ uint8_t# group,
361 const struct mec_mr3_infocxx . . $ mec_mr3_info# *info,
362 struct mec_mr3_item_datacxx . . $ mec_mr3_item_data# *data) {
363 (void)group;
364 (void)info;
365 size_t s = fread_mirrorcxx . . $ fread_mirror(71e37d83cd1f2ffb).(&data->lencxx . . $ mec_mr3_item_data#len., sizeof data->lencxx . . $ mec_mr3_item_data#len., 1, self);
366 ERROR_RETURNcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:87:9`!(s, 1);
367 // in the wild we have: data->len <= 9509
368 uint32_tcxx . . $ uint32_t# separator[5];
369 s = fread_mirrorcxx . . $ fread_mirror(71e37d83cd1f2ffb).(separator, sizeof *separator,
370 sizeof separator / sizeof *separator, self);
371 ERROR_RETURNcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:87:9`!(s, sizeof separator / sizeof *separator);
372 const enum SignatureTypecxx . . $ SignatureType# sig_ok = compute_signaturecxx . . $ compute_signature(f6af82805ad6e93a).(separator);
373 ERROR_RETURNcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:87:9`!(sig_ok != SIG_UNK, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
374 data = mec_mr3_aligned_realloccxx . . $ mec_mr3_aligned_realloc(bbbb938d129dea0a).(data, data->lencxx . . $ mec_mr3_item_data#len.);
375 if (data == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
376 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
377 }
378
379 s = fread_mirrorcxx . . $ fread_mirror(71e37d83cd1f2ffb).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
380 ERROR_RETURNcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:87:9`!(s, data->len);
381
382 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
383 }
384
385 enum Typecxx . . $ Type# {
386 ISO_8859_1_STRINGcxx . . $ ISO_8859_1_STRING. = 0x00000300, // ASCII string / or struct with 'ISO-8859-1' marker
387 FLOAT32_VM2Ncxx . . $ FLOAT32_VM2N. = 0x00000500, // float/32bits VM:2n
388 FLOAT32_VM3Ncxx . . $ FLOAT32_VM3N. = 0x00000600, // float/32bits VM:3n
389 DATETIMEcxx . . $ DATETIME. = 0x00000e00, // Date/Time stored as ASCII VM:1
390 STR40cxx . . $ STR40. = 0x001f4000, // SHIFT-JIS strings x 7
391 STRUCT_136cxx . . $ STRUCT_136. = 0x001f4100, // Fixed struct 136 bytes (struct with ASCII strings)
392 STRUCT_436cxx . . $ STRUCT_436. = 0x001f4300, // Fixed struct 436 bytes (struct with ASCII strings)
393 STRUCT_516cxx . . $ STRUCT_516. = 0x001f4400, // Fixed struct 516 bytes (struct with ASCII strings)
394 STRUCT_325cxx . . $ STRUCT_325. = 0x001f4600, // Fixed struct 325 bytes (struct with ASCII strings)
395 UINT32_VM1cxx . . $ UINT32_VM1. = (int)0xff000400, // uint32_t, range [0, 4] VM:1
396 FLOAT32_VM1cxx . . $ FLOAT32_VM1. = (int)0xff000800, // float/32bits VM:1
397 INT32_VM1Ncxx . . $ INT32_VM1N. = (int)0xff002400, // int32_t (signed) VM:1n
398 FLOAT32_VM1Ncxx . . $ FLOAT32_VM1N. = (int)0xff002800, // float/32bits VM:1n
399 FLOAT64_VM1cxx . . $ FLOAT64_VM1. = (int)0xff002900, // float/64bits VM:1
400 BOOL32_VM1cxx . . $ BOOL32_VM1. = (int)0xff002a00, // bool/32bits VM:1
401 UNICODE_STRINGcxx . . $ UNICODE_STRING. = (int)0xff002c00, // ASCII, UTF-8 or SHIFT-JIS string
402 CHARACTER_SETcxx . . $ CHARACTER_SET. = (int)0xff002300, // 17f2 seems to store the character set used
403 };
404
405 struct buffer19cxx . . $ buffer19# {
406 char sig1cxx . . $ buffer19#sig1.[0x3];
407 unsigned char len2cxx . . $ buffer19#len2.;
408 char sig2cxx . . $ buffer19#sig2.;
409 unsigned char len3cxx . . $ buffer19#len3.;
410 char sig3cxx . . $ buffer19#sig3.;
411 char isocxx . . $ buffer19#iso.[0x9];
412 char sig4cxx . . $ buffer19#sig4.;
413 unsigned char len4cxx . . $ buffer19#len4.;
414 char sig5cxx . . $ buffer19#sig5.;
415 };
416
417 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_isocxx . . $ print_iso(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb, struct appcxx . . $ app# *self) {
418 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
419 static const unsigned char magic[] = {0xdf, 0xff, 0x79};
420 if (nmemb >= sizeof magic && memcmpcxx . . $ memcmp(36f949851efa3055).(ptr, magic, sizeof(magic)) == 0) {
421 // iso
422 struct buffer19cxx . . $ buffer19# b19;
423 if (nmemb < sizeof b19) return 0;
424 memcpycxx . . $ memcpy(cc817cb175f282d).(&b19, ptr, sizeof b19);
425 if (b19.sig2cxx . . $ buffer19#sig2. != 0x1 || b19.sig3cxx . . $ buffer19#sig3. != 0x0 || b19.sig4cxx . . $ buffer19#sig4. != 0x2 ||
426 b19.sig5cxx . . $ buffer19#sig5. != 0x0)
427 return 0;
428 const size_t diff = nmemb - sizeof b19;
429 if (b19.len2cxx . . $ buffer19#len2. != nmemb - 4 || b19.len3cxx . . $ buffer19#len3. != 9 || b19.len4cxx . . $ buffer19#len4. != diff) return 0;
430 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(b19.isocxx . . $ buffer19#iso., "ISO8859-1", 9) != 0) return 0;
431 {
432 const char *str = (char *)ptr + sizeof b19;
433 const int unicode_format = guess_unicode_and_convertcxx . . $ guess_unicode_and_convert(55a978ccac6a7ad7).(self, str, b19.len4cxx . . $ buffer19#len4.);
434 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(unicode_format == kSHIFT_JIS);
435 const char *dest_str = self->shift_jis_buffercxx . . $ app#shift_jis_buffer.;
436 printfcxx . . $ printf(581fddd72a8db8fc).("{%.*s : %s:%s}", 9, b19.isocxx . . $ buffer19#iso., unicode_type_as_stringcxx . . $ unicode_type_as_string(f7ae7e56280f18ae).(unicode_format), dest_str);
437 }
438 } else {
439 // raw string buffer
440 printfcxx . . $ printf(581fddd72a8db8fc).("\"%.*s\"", (int)nmemb, (char *)ptr);
441 }
442 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
443 }
444
445 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_datetimecxx . . $ print_datetime(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
446 struct appcxx . . $ app# *self) {
447 // 11/12/2002,11:27:32
448 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
449 (void)self;
450 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(nmemb == 19 || nmemb == 20);
451 char *str = (char *)ptr;
452 size_t i;
453 const size_t len = strnlencxx . . $ strnlen(ac5a385650b4bde5).(str, nmemb);
454 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(len == 19);
455 for (i = 0; i < len; ++i) {
456 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!((str[i] >= '0' && str[i] <= '9') || str[i] == '/' || str[i] == ',' ||
457 str[i] == ':');
458 }
459
460 printfcxx . . $ printf(581fddd72a8db8fc).("\"%.*s\"", (int)nmemb, str);
461 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
462 }
463
464 typedef char str16cxx . . $ str16#[16 + 1];
465 typedef char str64cxx . . $ str64#[64 + 1];
466
467 struct str40cxx . . $ str40# {
468 uint32_tcxx . . $ uint32_t# indexcxx . . $ str40#index.;
469 char strcxx . . $ str40#str.[7][0x30];
470 };
471
472 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_str40cxx . . $ print_str40(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
473 struct appcxx . . $ app# *self) {
474 const size_t len = nmemb;
475 const char *buffer = ptr;
476 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
477 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(len % 340 == 0);
478 printfcxx . . $ printf(581fddd72a8db8fc).("{");
479 size_t j;
480 for (j = 0; j < len / 340; ++j) {
481 struct str40cxx . . $ str40# a;
482 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(sizeof a == 340);
483 memcpycxx . . $ memcpy(cc817cb175f282d).(&a, buffer + j * 340, sizeof a);
484 if (j)
485 printfcxx . . $ printf(581fddd72a8db8fc).(",");
486 printfcxx . . $ printf(581fddd72a8db8fc).("%u:[", a.indexcxx . . $ str40#index.);
487 int i;
488 for (i = 0; i < 7; ++i) {
489 if (i)
490 printfcxx . . $ printf(581fddd72a8db8fc).(",");
491 const int unicode_format = guess_unicode_and_convertcxx . . $ guess_unicode_and_convert(55a978ccac6a7ad7).(self, a.strcxx . . $ str40#str.[i], sizeof a.strcxx . . $ str40#str.[i]);
492 const char *dest_str = self->shift_jis_buffercxx . . $ app#shift_jis_buffer.;
493 printfcxx . . $ printf(581fddd72a8db8fc).("%s:%s", unicode_type_as_stringcxx . . $ unicode_type_as_string(f7ae7e56280f18ae).(unicode_format), dest_str);
494 }
495 printfcxx . . $ printf(581fddd72a8db8fc).("]");
496 }
497 printfcxx . . $ printf(581fddd72a8db8fc).("}");
498
499 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
500 }
501
502 struct buffer136cxx . . $ buffer136# {
503 uint32_tcxx . . $ uint32_t# zero1cxx . . $ buffer136#zero1.;
504 str64cxx . . $ str64# uid1cxx . . $ buffer136#uid1.; // Detached Study Management SOP Class (1.2.840.10008.3.1.2.3.1) ?
505 str64cxx . . $ str64# uid2cxx . . $ buffer136#uid2.; // 1.2.840.113745.101000.1098000.X.Y.Z
506 uint16_tcxx . . $ uint16_t# zero2cxx . . $ buffer136#zero2.;
507 };
508
509 void print_buffer136cxx . . $ print_buffer136(6acffe5e990cca43).(struct buffer136cxx . . $ buffer136# *b136) {
510 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(b136->zero1 == 0);
511 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(b136->zero2 == 0);
512 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(65 == sizeof b136->uid1);
513 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(65 == sizeof b136->uid2);
514 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b136->uid1, sizeof b136->uid1)!=(size_t)-1);
515 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b136->uid2, sizeof b136->uid2)!=(size_t)-1);
516 printfcxx . . $ printf(581fddd72a8db8fc).("{%u,%s,%s,%hu}", b136->zero1cxx . . $ buffer136#zero1., b136->uid1cxx . . $ buffer136#uid1., b136->uid2cxx . . $ buffer136#uid2., b136->zero2cxx . . $ buffer136#zero2.);
517 }
518
519 struct buffer436cxx . . $ buffer436# {
520 uint32_tcxx . . $ uint32_t# zerocxx . . $ buffer436#zero.;
521 char ivercxx . . $ buffer436#iver.[16 + 1];
522 char idatecxx . . $ buffer436#idate.[8 + 1];
523 char itimecxx . . $ buffer436#itime.[6 + 1 + 6 + 1]; // eg. 113000.000000
524 char junkcxx . . $ buffer436#junk.[29];
525 char buf3cxx . . $ buffer436#buf3.[0x100]; // phi
526 str64cxx . . $ str64# buf4cxx . . $ buffer436#buf4.;
527 str16cxx . . $ str16# buf5cxx . . $ buffer436#buf5.;
528 char modalitycxx . . $ buffer436#modality.[3];
529 char junk2cxx . . $ buffer436#junk2.[21 - 3];
530 uint32_tcxx . . $ uint32_t# valcxx . . $ buffer436#val.;
531 };
532
533 static void print_buffer436cxx . . $ print_buffer436(a3823b17b9c9a446).(struct buffer436cxx . . $ buffer436# *b436) {
534 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(b436->zero == 0);
535 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b436->iver, sizeof b436->iver)!= (size_t)-1);
536 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b436->idate, sizeof b436->idate)!= (size_t)-1);
537 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b436->itime, sizeof b436->itime)!= (size_t)-1);
538 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(*b436->junk == 0);
539 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b436->junk, sizeof b436->junk)!= (size_t)-1);
540 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b436->buf3, sizeof b436->buf3)!= (size_t)-1);
541 #if 0
542 assert(is_ascii_string_with_trailing_nulls(b436->buf4, sizeof b436->buf4));
543 #else
544 const int len4 = strnlencxx . . $ strnlen(ac5a385650b4bde5).(b436->buf4cxx . . $ buffer436#buf4., sizeof b436->buf4cxx . . $ buffer436#buf4.);
545 #endif
546 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b436->buf5, sizeof b436->buf5)!= (size_t)-1);
547 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b436->modality,
548 sizeof b436->modality)!= (size_t)-1);
549 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b436->junk2, sizeof b436->junk2)!= (size_t)-1);
550 #if 0
551 static const char vers1[] = "TM_MR_DCM_V1.0";
552 static const char vers2[] = "TM_MR_DCM_V2.0";
553 static const char vers3[] = "TM_MR_DCM_V1.0_3";
554 static const char vers4[] = "TM_MR1_DCM_V1.0";
555 assert(strcmp(b436->iver, vers1) == 0 || strcmp(b436->iver, vers2) == 0 ||
556 strcmp(b436->iver, vers3) == 0 || strcmp(b436->iver, vers4) == 0);
557 #endif
558 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(strcmp(b436->modality, "MR") == 0);
559 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(b436->val == 0 || b436->val == 1 || b436->val == 3 || b436->val == 4 || b436->val == 6 );
560 printfcxx . . $ printf(581fddd72a8db8fc).("{%u;%s;%s;%s;%s;%.*s;%s;%s;%s;%u}", b436->zerocxx . . $ buffer436#zero., b436->ivercxx . . $ buffer436#iver.,
561 b436->idatecxx . . $ buffer436#idate., b436->itimecxx . . $ buffer436#itime., b436->buf3cxx . . $ buffer436#buf3., len4, b436->buf4cxx . . $ buffer436#buf4., b436->buf5cxx . . $ buffer436#buf5.,
562 b436->modalitycxx . . $ buffer436#modality., b436->junk2cxx . . $ buffer436#junk2., b436->valcxx . . $ buffer436#val.);
563 }
564
565 struct buffer516cxx . . $ buffer516# {
566 str64cxx . . $ str64# zerocxx . . $ buffer516#zero.; // aka 'none'
567 char buf2cxx . . $ buffer516#buf2.[0x15];
568 char buf3cxx . . $ buffer516#buf3.[0x100]; // phi
569 str16cxx . . $ str16# buf4cxx . . $ buffer516#buf4.;
570 str64cxx . . $ str64# buf5cxx . . $ buffer516#buf5.; // Study Instance UID
571 str64cxx . . $ str64# buf6cxx . . $ buffer516#buf6.;
572 uint32_tcxx . . $ uint32_t# boolscxx . . $ buffer516#bools.[6];
573 };
574
575 static void print_buffer516cxx . . $ print_buffer516(e00dd74c137c98fb).(struct buffer516cxx . . $ buffer516# *b516) {
576 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b516->zero, sizeof b516->zero)!= (size_t)-1);
577 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b516->buf2, sizeof b516->buf2)!= (size_t)-1);
578 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b516->buf3, sizeof b516->buf3)!= (size_t)-1);
579 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b516->buf4, sizeof b516->buf4)!= (size_t)-1);
580 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b516->buf5, sizeof b516->buf5)!= (size_t)-1);
581 #if 0
582 assert(is_ascii_string_with_trailing_nulls(b516->buf6, sizeof b516->buf6));
583 #else
584 const int len6 = strnlencxx . . $ strnlen(ac5a385650b4bde5).(b516->buf6cxx . . $ buffer516#buf6., sizeof b516->buf6cxx . . $ buffer516#buf6.);
585 #endif
586 printfcxx . . $ printf(581fddd72a8db8fc).("{%s;%s;%s;%s;%s;%.*s", b516->zerocxx . . $ buffer516#zero., b516->buf2cxx . . $ buffer516#buf2., b516->buf3cxx . . $ buffer516#buf3., b516->buf4cxx . . $ buffer516#buf4.,
587 b516->buf5cxx . . $ buffer516#buf5., len6, b516->buf6cxx . . $ buffer516#buf6.);
588 uint32_tcxx . . $ uint32_t# c;
589 for (c = 0; c < 6; ++c) {
590 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(b516->bools[c] == c % 2);
591 #if 0
592 if (c)
593 printf(",");
594 printf("%d", b516->bools[c]);
595 #endif
596 }
597 printfcxx . . $ printf(581fddd72a8db8fc).("}");
598 }
599
600 struct buffer325cxx . . $ buffer325# {
601 str64cxx . . $ str64# arraycxx . . $ buffer325#array.[5];
602 };
603
604 static void print_buffer325cxx . . $ print_buffer325(3b1c5a67fff74c5c).(struct buffer325cxx . . $ buffer325# *b325) {
605 int c;
606 printfcxx . . $ printf(581fddd72a8db8fc).("{");
607 for (c = 0; c < 5; ++c) {
608 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_ascii_string_with_trailing_nulls(b325->array[c],
609 sizeof b325->array[c])!= (size_t)-1);
610 if (c) printfcxx . . $ printf(581fddd72a8db8fc).(";");
611 printfcxx . . $ printf(581fddd72a8db8fc).("%s", b325->arraycxx . . $ buffer325#array.[c]);
612 }
613 printfcxx . . $ printf(581fddd72a8db8fc).("}");
614 }
615
616 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_structcxx . . $ print_struct(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
617 struct appcxx . . $ app# *self) {
618 (void)self;
619 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
620 const size_t s = nmemb;
621 if (s == 136) {
622 struct buffer136cxx . . $ buffer136# b136;
623 memcpycxx . . $ memcpy(cc817cb175f282d).(&b136, ptr, nmemb);
624 print_buffer136cxx . . $ print_buffer136(6acffe5e990cca43).(&b136);
625 } else if (s == 436) {
626 struct buffer436cxx . . $ buffer436# b436;
627 memcpycxx . . $ memcpy(cc817cb175f282d).(&b436, ptr, nmemb);
628 print_buffer436cxx . . $ print_buffer436(a3823b17b9c9a446).(&b436);
629 } else if (s == 516) {
630 struct buffer516cxx . . $ buffer516# b516;
631 memcpycxx . . $ memcpy(cc817cb175f282d).(&b516, ptr, nmemb);
632 print_buffer516cxx . . $ print_buffer516(e00dd74c137c98fb).(&b516);
633 } else if (s == 325) {
634 struct buffer325cxx . . $ buffer325# b325;
635 memcpycxx . . $ memcpy(cc817cb175f282d).(&b325, ptr, nmemb);
636 print_buffer325cxx . . $ print_buffer325(3b1c5a67fff74c5c).(&b325);
637 } else {
638 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(0); // programmer error
639 return 0;
640 }
641 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
642 }
643
644 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_unicodecxx . . $ print_unicode(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
645 struct appcxx . . $ app# *self) {
646 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
647 const char *str = ptr;
648 const int unicode_format = guess_unicode_and_convertcxx . . $ guess_unicode_and_convert(55a978ccac6a7ad7).(self, str, nmemb);
649 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(unicode_format == kSHIFT_JIS || unicode_format == kUTF8);
650 const char *dest_str = self->shift_jis_buffercxx . . $ app#shift_jis_buffer.;
651 printfcxx . . $ printf(581fddd72a8db8fc).("[%s:%s]", unicode_type_as_stringcxx . . $ unicode_type_as_string(f7ae7e56280f18ae).(unicode_format), dest_str);
652 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
653 }
654
655 static void print_intcxx . . $ print_int(cfb464fe78c8a83b).(const int32_tcxx . . $ int32_t# *buffer, int len) {
656 const int m = sizeof(int32_tcxx . . $ int32_t#);
657 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_aligned(buffer, m));
658 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(len % m == 0);
659 int i;
660 printfcxx . . $ printf(581fddd72a8db8fc).("[");
661 for (i = 0; i < len / m; i++) {
662 if (i) printfcxx . . $ printf(581fddd72a8db8fc).(",");
663 int32_tcxx . . $ int32_t# cur = -1;
664 memcpycxx . . $ memcpy(cc817cb175f282d).(&cur, buffer + i, sizeof cur);
665 printfcxx . . $ printf(581fddd72a8db8fc).("%d", cur);
666 }
667 printfcxx . . $ printf(581fddd72a8db8fc).("]");
668 }
669
670 #if 0
671 static void print_uint(const uint32_t *buffer, int len) {
672 const int m = sizeof(uint32_t);
673 assert(is_aligned(buffer, m));
674 assert(len % m == 0);
675 int i;
676 printf("[");
677 for (i = 0; i < len / m; i++) {
678 if (i)
679 printf(",");
680 uint32_t cur = (uint32_t)-1;
681 memcpy(&cur, buffer + i, sizeof cur);
682 assert(cur == 0x0 || cur == 0x1 || cur == 0x4);
683 printf("%u", cur);
684 }
685 printf("]");
686 }
687 #endif
688
689 static void print_floatcxx . . $ print_float(d97132c3eefc9c07).(const float *buffer, int len) {
690 const int m = sizeof(float);
691 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_aligned(buffer, m));
692 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(len % m == 0);
693 int i;
694 printfcxx . . $ printf(581fddd72a8db8fc).("[");
695 for (i = 0; i < len / m; i++) {
696 if (i) printfcxx . . $ printf(581fddd72a8db8fc).(",");
697 float cur = -1;
698 memcpycxx . . $ memcpy(cc817cb175f282d).(&cur, buffer + i, sizeof cur);
699 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(isfinite(cur) && !isnan(cur));
700 printfcxx . . $ printf(581fddd72a8db8fc).("%f", cur);
701 }
702 printfcxx . . $ printf(581fddd72a8db8fc).("]");
703 }
704
705 static void print_doublecxx . . $ print_double(5007b46494cc5089).(const double *buffer, int len) {
706 const int m = sizeof(double);
707 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_aligned(buffer, m));
708 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(len % m == 0);
709 int i;
710 printfcxx . . $ printf(581fddd72a8db8fc).("[");
711 for (i = 0; i < len / m; i++) {
712 if (i) printfcxx . . $ printf(581fddd72a8db8fc).(",");
713 const double cur = buffer[i];
714 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(isfinite(cur) && !isnan(cur));
715 printfcxx . . $ printf(581fddd72a8db8fc).("%g", cur);
716 }
717 printfcxx . . $ printf(581fddd72a8db8fc).("]");
718 }
719
720 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_int32cxx . . $ print_int32(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
721 struct appcxx . . $ app# *self) {
722 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
723 (void)self;
724 // assert(nmemb == 4 || nmemb == 8 || nmemb == 12 || nmembnmemb == 24 || nmemb
725 // == 32 || nmemb == 48);
726 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(nmemb % 4 == 0);
727 print_intcxx . . $ print_int(cfb464fe78c8a83b).(ptr, nmemb);
728
729 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
730 }
731
732 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_uint32cxx . . $ print_uint32(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
733 struct appcxx . . $ app# *self) {
734 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
735 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_aligned(ptr, 4));
736 (void)self;
737 #if 0
738 assert(nmemb % 4 == 0);
739 print_uint(ptr, nmemb);
740 #else
741 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(nmemb == 4);
742 uint32_tcxx . . $ uint32_t# u;
743 memcpycxx . . $ memcpy(cc817cb175f282d).(&u, ptr, nmemb);
744 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(u == 0x0 || u == 0x1 || u == 0x4);
745 printfcxx . . $ printf(581fddd72a8db8fc).("%u", u);
746 #endif
747
748 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
749 }
750
751 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_float32cxx . . $ print_float32(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
752 struct appcxx . . $ app# *self) {
753 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
754 (void)self;
755 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(nmemb == 4);
756 print_floatcxx . . $ print_float(d97132c3eefc9c07).(ptr, nmemb);
757
758 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
759 }
760
761 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_float32_vm1ncxx . . $ print_float32_vm1n(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
762 struct appcxx . . $ app# *self) {
763 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
764 (void)self;
765 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(nmemb % 4 == 0);
766 print_floatcxx . . $ print_float(d97132c3eefc9c07).(ptr, nmemb);
767
768 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
769 }
770
771 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_float32_vm2ncxx . . $ print_float32_vm2n(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
772 struct appcxx . . $ app# *self) {
773 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
774 (void)self;
775 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!((nmemb / 4) % 2 == 0);
776 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(nmemb == 8 || nmemb == 40 || nmemb == 80 || nmemb == 72 ||
777 nmemb == 88 || nmemb == 64);
778 // FIXME: low/high value for nmemb==40&80 makes them look like double...
779 print_floatcxx . . $ print_float(d97132c3eefc9c07).(ptr, nmemb);
780
781 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
782 }
783
784 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_float32_vm3ncxx . . $ print_float32_vm3n(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
785 struct appcxx . . $ app# *self) {
786 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
787 (void)self;
788 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!((nmemb / 4) % 3 == 0);
789 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(nmemb == 12 || nmemb == 36);
790 print_floatcxx . . $ print_float(d97132c3eefc9c07).(ptr, nmemb);
791
792 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
793 }
794
795 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_float64cxx . . $ print_float64(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
796 struct appcxx . . $ app# *self) {
797 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
798 (void)self;
799 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(nmemb == 8);
800 print_doublecxx . . $ print_double(5007b46494cc5089).(ptr, nmemb);
801 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
802 }
803
804 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! print_bool32cxx . . $ print_bool32(f7495523f7de4d50).(void *ptr, size_t size, size_t nmemb,
805 struct appcxx . . $ app# *self) {
806 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(size == 1);
807 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(is_aligned(ptr, 4));
808 (void)self;
809 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(nmemb == 4);
810 uint32_tcxx . . $ uint32_t# u;
811 memcpycxx . . $ memcpy(cc817cb175f282d).(&u, ptr, nmemb);
812 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(u == 0x0 || u == 0x1);
813 printfcxx . . $ printf(581fddd72a8db8fc).("%s", u ? "true" : "false");
814 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
815 }
816
817 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! printcxx . . $ print(fd1d76ce55b26d10).(struct appcxx . . $ app# *self, const uint8_tcxx . . $ uint8_t# group,
818 const struct mec_mr3_infocxx . . $ mec_mr3_info# *info,
819 struct mec_mr3_item_datacxx . . $ mec_mr3_item_data# *data) {
820 const char *name = get_mec_mr3_info_namecxx . . $ get_mec_mr3_info_name(d1876bf772eec26).(group, info->keycxx . . $ mec_mr3_info#key.);
821 const uint32_tcxx . . $ uint32_t# sign = info->typecxx . . $ mec_mr3_info#type. >> 24;
822 const char symb = sign ? '_' : ' ';
823
824 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! ret = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
825 uint32_tcxx . . $ uint32_t# mult = 1;
826 // print info
827 printfcxx . . $ printf(581fddd72a8db8fc).("(%01x,%05x) %c%04x ", group, info->keycxx . . $ mec_mr3_info#key., symb,
828 (info->typecxx . . $ mec_mr3_info#type. & 0x00ffff00) >> 8);
829 // print data:
830 switch (info->typecxx . . $ mec_mr3_info#type.) {
831 case ISO_8859_1_STRINGcxx . . $ ISO_8859_1_STRING.:
832 ret = print_isocxx . . $ print_iso(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
833 break;
834 case FLOAT32_VM2Ncxx . . $ FLOAT32_VM2N.:
835 ret = print_float32_vm2ncxx . . $ print_float32_vm2n(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
836 break;
837 case FLOAT32_VM3Ncxx . . $ FLOAT32_VM3N.:
838 ret = print_float32_vm3ncxx . . $ print_float32_vm3n(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
839 break;
840 case DATETIMEcxx . . $ DATETIME.:
841 ret = print_datetimecxx . . $ print_datetime(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
842 break;
843 case STR40cxx . . $ STR40.:
844 ret = print_str40cxx . . $ print_str40(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
845 break;
846 case STRUCT_136cxx . . $ STRUCT_136.:
847 case STRUCT_436cxx . . $ STRUCT_436.:
848 case STRUCT_516cxx . . $ STRUCT_516.:
849 case STRUCT_325cxx . . $ STRUCT_325.:
850 ret = print_structcxx . . $ print_struct(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
851 break;
852 case UNICODE_STRINGcxx . . $ UNICODE_STRING.:
853 ret = print_unicodecxx . . $ print_unicode(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
854 break;
855 case FLOAT32_VM1cxx . . $ FLOAT32_VM1.:
856 ret = print_float32cxx . . $ print_float32(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
857 break;
858 case INT32_VM1Ncxx . . $ INT32_VM1N.:
859 ret = print_int32cxx . . $ print_int32(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
860 break;
861 case FLOAT32_VM1Ncxx . . $ FLOAT32_VM1N.:
862 ret = print_float32_vm1ncxx . . $ print_float32_vm1n(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
863 break;
864 case FLOAT64_VM1cxx . . $ FLOAT64_VM1.:
865 ret = print_float64cxx . . $ print_float64(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
866 break;
867 case UINT32_VM1cxx . . $ UINT32_VM1.:
868 ret = print_uint32cxx . . $ print_uint32(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
869 break;
870 case BOOL32_VM1cxx . . $ BOOL32_VM1.:
871 ret = print_bool32cxx . . $ print_bool32(f7495523f7de4d50).(data->buffercxx . . $ mec_mr3_item_data#buffer., 1, data->lencxx . . $ mec_mr3_item_data#len., self);
872 break;
873 case CHARACTER_SETcxx . . $ CHARACTER_SET.:
874 #if 0
875 dump2file(data->buffer, data->len);
876 #endif
877 ret = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
878 break;
879 default:
880 printfcxx . . $ printf(581fddd72a8db8fc).("|NotImplemented|");
881 ret = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
882 }
883 // print key name
884 if (!name) {
885 static char buf[512];
886 (void)snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, sizeof buf, "Missing: {0x%02x, 0x%08x, 0x%08x, \"\"}, //",
887 group, info->keycxx . . $ mec_mr3_info#key., info->typecxx . . $ mec_mr3_info#type.);
888 name = buf;
889 }
890 printfcxx . . $ printf(581fddd72a8db8fc).(" # %u,%u %s\n", data->lencxx . . $ mec_mr3_item_data#len., mult, name);
891
892 return ret;
893 }
894
895 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! read_groupcxx . . $ read_group(ca96d134846bcf02).(struct appcxx . . $ app# *self, uint8_tcxx . . $ uint8_t# group, uint32_tcxx . . $ uint32_t# nitems,
896 struct mec_mr3_infocxx . . $ mec_mr3_info# *info,
897 struct mec_mr3_item_datacxx . . $ mec_mr3_item_data# *data) {
898 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! good = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
899 uint32_tcxx . . $ uint32_t# i;
900 for (i = 0; i < nitems && good; ++i) {
901 good = good && read_infocxx . . $ read_info(195bdd6644ef5b5b).(self, group, info);
902 // lazy evaluation:
903 good = good && read_datacxx . . $ read_data(fd1d76ce55b26d10).(self, group, info, data);
904 good = good && printcxx . . $ print(fd1d76ce55b26d10).(self, group, info, data);
905 }
906 return good;
907 }
908
909 // If we reach group #5, we have to handle the remaining groups magic:
910 #define MAGIC_GROUP_NUMBERcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:910:9`! 5
911
912 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mec_mr3_printcxx . . $ mec_mr3_print(d7c96d367a6f87f1).(const void *input, const size_t len) {
913 if (!input) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
914 struct streamcxx . . $ stream# sin;
915 struct appcxx . . $ app# a;
916 struct appcxx . . $ app# *self = create_appcxx . . $ create_app(207586a7460acdf2).(&a, &sin);
917 setup_buffercxx . . $ setup_buffer(e3d7d4d3917a41c2).(self, input, len);
918
919 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! good = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
920 struct mec_mr3_infocxx . . $ mec_mr3_info# info;
921 struct mec_mr3_item_datacxx . . $ mec_mr3_item_data# data;
922 data.sizecxx . . $ mec_mr3_item_data#size. = data.lencxx . . $ mec_mr3_item_data#len. = 0;
923 data.buffercxx . . $ mec_mr3_item_data#buffer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
924
925 uint32_tcxx . . $ uint32_t# remain = 1;
926 size_t s;
927 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! last_groups = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
928 uint8_tcxx . . $ uint8_t# group = 0;
929 // read until last set of groups found:
930 while (!last_groups && good) {
931 uint32_tcxx . . $ uint32_t# nitems;
932 s = fread_mirrorcxx . . $ fread_mirror(71e37d83cd1f2ffb).(&nitems, sizeof nitems, 1, self);
933 if (s != 1 || nitems == 0) {
934 good = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
935 }
936 if (good && group == MAGIC_GROUP_NUMBERcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:910:9`!) {
937 // special case to handle last groups
938 remain = nitems;
939 last_groups = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
940 s = fread_mirrorcxx . . $ fread_mirror(71e37d83cd1f2ffb).(&nitems, sizeof nitems, 1, self);
941 if (s != 1 || nitems == 0) {
942 good = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
943 }
944 }
945 // lazy evaluation
946 ++group;
947 good = good && read_groupcxx . . $ read_group(ca96d134846bcf02).(self, group, nitems, &info, &data);
948 }
949 // read remaining groups:
950 while (good && --remain != 0) {
951 uint32_tcxx . . $ uint32_t# nitems;
952 s = fread_mirrorcxx . . $ fread_mirror(71e37d83cd1f2ffb).(&nitems, sizeof nitems, 1, self);
953 if (s != 1) {
954 good = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
955 }
956 ++group;
957 good = good && read_groupcxx . . $ read_group(ca96d134846bcf02).(self, group, nitems, &info, &data);
958 }
959 // release memory:
960 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
961 _aligned_free(data.buffer);
962 #else
963 freecxx . . $ free(5d22bdacc48458e8).(data.buffercxx . . $ mec_mr3_item_data#buffer.);
964 #endif
965 #if MEC3_HAS_ICONVcxx . . $ `Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c:29:9`!
966 iconv_closecxx . . $ iconv_close(dedf1e9b1c614a07).(self->convcxx . . $ app#conv.);
967 #endif
968 freecxx . . $ free(5d22bdacc48458e8).(self->shift_jis_buffercxx . . $ app#shift_jis_buffer.);
969 if (!good) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
970
971 // write trailer:
972 if (!write_trailercxx . . $ write_trailer(74da70a3f26cd88d).(self)) {
973 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
974 }
975
976 // make sure the whole input was processed:
977 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(self->in->cur <= self->in->end); // programmer error
978 if (self->incxx . . $ app#in.->curcxx . . $ stream#cur. < self->incxx . . $ app#in.->endcxx . . $ stream#end.) {
979 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
980 }
981 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
982 }