Debian Codegraph @

libmve/mvelib.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2024 D2X Project
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <cstring> // for mem* functions
19
20 #include "mvelib.h"cxx . . $ `<file>/libmve/mvelib.h`/
21
22 static const char MVE_HEADERcxx . . $ MVE_HEADER.[] = "Interplay MVE File\x1A";
23 static const short MVE_HDRCONST1cxx . . $ MVE_HDRCONST1. = 0x001A;
24 static const short MVE_HDRCONST2cxx . . $ MVE_HDRCONST2. = 0x0100;
25 static const short MVE_HDRCONST3cxx . . $ MVE_HDRCONST3. = 0x1133;
26
27 mve_cb_Readcxx . . $ mve_cb_Read# mve_readcxx . . $ mve_read.;
28 mve_cb_Alloccxx . . $ mve_cb_Alloc# mve_alloccxx . . $ mve_alloc.;
29 mve_cb_Freecxx . . $ mve_cb_Free# mve_freecxx . . $ mve_free.;
30 mve_cb_ShowFramecxx . . $ mve_cb_ShowFrame# mve_showframecxx . . $ mve_showframe.;
31 mve_cb_SetPalettecxx . . $ mve_cb_SetPalette# mve_setpalettecxx . . $ mve_setpalette.;
32
33 /*
34 * private utility functions
35 */
36 static short _mve_get_shortcxx . . $ _mve_get_short(9e2d0545cb3d9da4).(unsigned char *data);
37 static unsigned short _mve_get_ushortcxx . . $ _mve_get_ushort(e56f59a1c9f445b3).(unsigned char *data);
38
39 /*
40 * private functions for mvefile
41 */
42 static MVEFILEcxx . . $ MVEFILE# *_mvefile_alloccxx . . $ _mvefile_alloc(905748fc52bed99e).();
43 static void _mvefile_freecxx . . $ _mvefile_free(e0260fc6b97b09ea).(MVEFILEcxx . . $ MVEFILE# *movie);
44 static int _mvefile_opencxx . . $ _mvefile_open(2cfb1a8aaf803071).(MVEFILEcxx . . $ MVEFILE# *movie, void *stream);
45 static void _mvefile_resetcxx . . $ _mvefile_reset(e0260fc6b97b09ea).(MVEFILEcxx . . $ MVEFILE# *movie);
46 static int _mvefile_read_headercxx . . $ _mvefile_read_header(1d7e7661686dc57e).(MVEFILEcxx . . $ MVEFILE# *movie);
47 static void _mvefile_set_buffer_sizecxx . . $ _mvefile_set_buffer_size(2701e8ff07fb4637).(MVEFILEcxx . . $ MVEFILE# *movie, int buf_size);
48 static int _mvefile_fetch_next_chunkcxx . . $ _mvefile_fetch_next_chunk(1d7e7661686dc57e).(MVEFILEcxx . . $ MVEFILE# *movie);
49
50 /*
51 * private functions for mvestream
52 */
53 static MVESTREAMcxx . . $ MVESTREAM# *_mvestream_alloccxx . . $ _mvestream_alloc(64e3b3de65826ec6).();
54 static void _mvestream_freecxx . . $ _mvestream_free(322520e409d4025).(MVESTREAMcxx . . $ MVESTREAM# *movie);
55 static int _mvestream_opencxx . . $ _mvestream_open(b026629aad3734ba).(MVESTREAMcxx . . $ MVESTREAM# *movie, void *stream);
56 static void _mvestream_resetcxx . . $ _mvestream_reset(322520e409d4025).(MVESTREAMcxx . . $ MVESTREAM# *movie);
57
58 /************************************************************
59 * public MVEFILE functions
60 ************************************************************/
61
62 /*
63 * open an MVE file
64 */
65 MVEFILEcxx . . $ MVEFILE# *mvefile_opencxx . . $ mvefile_open(d986263c59db9590).(void *stream) {
66 MVEFILEcxx . . $ MVEFILE# *file;
67
68 /* create the file */
69 file = _mvefile_alloccxx . . $ _mvefile_alloc(905748fc52bed99e).();
70 if (!_mvefile_opencxx . . $ _mvefile_open(2cfb1a8aaf803071).(file, stream)) {
71 _mvefile_freecxx . . $ _mvefile_free(e0260fc6b97b09ea).(file);
72 return nullptr;
73 }
74
75 /* initialize the file */
76 _mvefile_set_buffer_sizecxx . . $ _mvefile_set_buffer_size(2701e8ff07fb4637).(file, 1024);
77
78 /* verify the file's header */
79 if (!_mvefile_read_headercxx . . $ _mvefile_read_header(1d7e7661686dc57e).(file)) {
80 _mvefile_freecxx . . $ _mvefile_free(e0260fc6b97b09ea).(file);
81 return nullptr;
82 }
83
84 /* now, prefetch the next chunk */
85 _mvefile_fetch_next_chunkcxx . . $ _mvefile_fetch_next_chunk(1d7e7661686dc57e).(file);
86
87 return file;
88 }
89
90 /*
91 * close a MVE file
92 */
93 void mvefile_closecxx . . $ mvefile_close(e0260fc6b97b09ea).(MVEFILEcxx . . $ MVEFILE# *movie) { _mvefile_freecxx . . $ _mvefile_free(e0260fc6b97b09ea).(movie); }
94
95 /*
96 * reset a MVE file
97 */
98 void mvefile_resetcxx . . $ mvefile_reset(e0260fc6b97b09ea).(MVEFILEcxx . . $ MVEFILE# *file) {
99 _mvefile_resetcxx . . $ _mvefile_reset(e0260fc6b97b09ea).(file);
100
101 /* initialize the file */
102 _mvefile_set_buffer_sizecxx . . $ _mvefile_set_buffer_size(2701e8ff07fb4637).(file, 1024);
103
104 /* verify the file's header */
105 if (!_mvefile_read_headercxx . . $ _mvefile_read_header(1d7e7661686dc57e).(file)) {
106 _mvefile_freecxx . . $ _mvefile_free(e0260fc6b97b09ea).(file);
107 // return NULL;
108 }
109
110 /* now, prefetch the next chunk */
111 _mvefile_fetch_next_chunkcxx . . $ _mvefile_fetch_next_chunk(1d7e7661686dc57e).(file);
112 }
113
114 /*
115 * get the size of the next segment
116 */
117 int mvefile_get_next_segment_sizecxx . . $ mvefile_get_next_segment_size(1d7e7661686dc57e).(MVEFILEcxx . . $ MVEFILE# *movie) {
118 /* if nothing is cached, fail */
119 if (movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. == nullptr || movie->next_segmentcxx . . $ MVEFILE#next_segment. >= movie->cur_fillcxx . . $ MVEFILE#cur_fill.)
120 return -1;
121
122 /* if we don't have enough data to get a segment, fail */
123 if (movie->cur_fillcxx . . $ MVEFILE#cur_fill. - movie->next_segmentcxx . . $ MVEFILE#next_segment. < 4)
124 return -1;
125
126 /* otherwise, get the data length */
127 return _mve_get_shortcxx . . $ _mve_get_short(9e2d0545cb3d9da4).(movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. + movie->next_segmentcxx . . $ MVEFILE#next_segment.);
128 }
129
130 /*
131 * get type of next segment in chunk (0xff if no more segments in chunk)
132 */
133 unsigned char mvefile_get_next_segment_majorcxx . . $ mvefile_get_next_segment_major(23378c90094c51ff).(MVEFILEcxx . . $ MVEFILE# *movie) {
134 /* if nothing is cached, fail */
135 if (movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. == nullptr || movie->next_segmentcxx . . $ MVEFILE#next_segment. >= movie->cur_fillcxx . . $ MVEFILE#cur_fill.)
136 return 0xff;
137
138 /* if we don't have enough data to get a segment, fail */
139 if (movie->cur_fillcxx . . $ MVEFILE#cur_fill. - movie->next_segmentcxx . . $ MVEFILE#next_segment. < 4)
140 return 0xff;
141
142 /* otherwise, get the data length */
143 return movie->cur_chunkcxx . . $ MVEFILE#cur_chunk.[movie->next_segmentcxx . . $ MVEFILE#next_segment. + 2];
144 }
145
146 /*
147 * get subtype (version) of next segment in chunk (0xff if no more segments in
148 * chunk)
149 */
150 unsigned char mvefile_get_next_segment_minorcxx . . $ mvefile_get_next_segment_minor(23378c90094c51ff).(MVEFILEcxx . . $ MVEFILE# *movie) {
151 /* if nothing is cached, fail */
152 if (movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. == nullptr || movie->next_segmentcxx . . $ MVEFILE#next_segment. >= movie->cur_fillcxx . . $ MVEFILE#cur_fill.)
153 return 0xff;
154
155 /* if we don't have enough data to get a segment, fail */
156 if (movie->cur_fillcxx . . $ MVEFILE#cur_fill. - movie->next_segmentcxx . . $ MVEFILE#next_segment. < 4)
157 return 0xff;
158
159 /* otherwise, get the data length */
160 return movie->cur_chunkcxx . . $ MVEFILE#cur_chunk.[movie->next_segmentcxx . . $ MVEFILE#next_segment. + 3];
161 }
162
163 /*
164 * see next segment (return NULL if no next segment)
165 */
166 unsigned char *mvefile_get_next_segmentcxx . . $ mvefile_get_next_segment(84d9daf51fdf2d72).(MVEFILEcxx . . $ MVEFILE# *movie) {
167 /* if nothing is cached, fail */
168 if (movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. == nullptr || movie->next_segmentcxx . . $ MVEFILE#next_segment. >= movie->cur_fillcxx . . $ MVEFILE#cur_fill.)
169 return nullptr;
170
171 /* if we don't have enough data to get a segment, fail */
172 if (movie->cur_fillcxx . . $ MVEFILE#cur_fill. - movie->next_segmentcxx . . $ MVEFILE#next_segment. < 4)
173 return nullptr;
174
175 /* otherwise, get the data length */
176 return movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. + movie->next_segmentcxx . . $ MVEFILE#next_segment. + 4;
177 }
178
179 /*
180 * advance to next segment
181 */
182 void mvefile_advance_segmentcxx . . $ mvefile_advance_segment(e0260fc6b97b09ea).(MVEFILEcxx . . $ MVEFILE# *movie) {
183 /* if nothing is cached, fail */
184 if (movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. == nullptr || movie->next_segmentcxx . . $ MVEFILE#next_segment. >= movie->cur_fillcxx . . $ MVEFILE#cur_fill.)
185 return;
186
187 /* if we don't have enough data to get a segment, fail */
188 if (movie->cur_fillcxx . . $ MVEFILE#cur_fill. - movie->next_segmentcxx . . $ MVEFILE#next_segment. < 4)
189 return;
190
191 /* else, advance to next segment */
192 movie->next_segmentcxx . . $ MVEFILE#next_segment. += (4 + _mve_get_ushortcxx . . $ _mve_get_ushort(e56f59a1c9f445b3).(movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. + movie->next_segmentcxx . . $ MVEFILE#next_segment.));
193 }
194
195 /*
196 * fetch the next chunk (return 0 if at end of stream)
197 */
198 int mvefile_fetch_next_chunkcxx . . $ mvefile_fetch_next_chunk(1d7e7661686dc57e).(MVEFILEcxx . . $ MVEFILE# *movie) { return _mvefile_fetch_next_chunkcxx . . $ _mvefile_fetch_next_chunk(1d7e7661686dc57e).(movie); }
199
200 /************************************************************
201 * public MVESTREAM functions
202 ************************************************************/
203
204 /*
205 * open an MVE stream
206 */
207 MVESTREAMcxx . . $ MVESTREAM# *mve_opencxx . . $ mve_open(773157b047541329).(void *stream) {
208 MVESTREAMcxx . . $ MVESTREAM# *movie;
209
210 /* allocate */
211 movie = _mvestream_alloccxx . . $ _mvestream_alloc(64e3b3de65826ec6).();
212
213 /* open */
214 if (!_mvestream_opencxx . . $ _mvestream_open(b026629aad3734ba).(movie, stream)) {
215 _mvestream_freecxx . . $ _mvestream_free(322520e409d4025).(movie);
216 return nullptr;
217 }
218
219 return movie;
220 }
221
222 /*
223 * close an MVE stream
224 */
225 void mve_closecxx . . $ mve_close(322520e409d4025).(MVESTREAMcxx . . $ MVESTREAM# *movie) { _mvestream_freecxx . . $ _mvestream_free(322520e409d4025).(movie); }
226
227 /*
228 * reset an MVE stream
229 */
230 void mve_resetcxx . . $ mve_reset(322520e409d4025).(MVESTREAMcxx . . $ MVESTREAM# *movie) { _mvestream_resetcxx . . $ _mvestream_reset(322520e409d4025).(movie); }
231
232 /*
233 * set segment type handler
234 */
235 void mve_set_handlercxx . . $ mve_set_handler(208c9697527ebac9).(MVESTREAMcxx . . $ MVESTREAM# *movie, unsigned char major, MVESEGMENTHANDLERcxx . . $ MVESEGMENTHANDLER# handler) {
236 if (major < 32)
237 movie->handlerscxx . . $ MVESTREAM#handlers.[major] = handler;
238 }
239
240 /*
241 * set segment handler context
242 */
243 void mve_set_handler_contextcxx . . $ mve_set_handler_context(e7085631e81cf0a8).(MVESTREAMcxx . . $ MVESTREAM# *movie, void *context) { movie->contextcxx . . $ MVESTREAM#context. = context; }
244
245 /*
246 * play next chunk
247 */
248 int mve_play_next_chunkcxx . . $ mve_play_next_chunk(c6a4a7571c8c3481).(MVESTREAMcxx . . $ MVESTREAM# *movie) {
249 unsigned char major, minor;
250 unsigned char *data;
251 int len;
252
253 /* loop over segments */
254 major = mvefile_get_next_segment_majorcxx . . $ mvefile_get_next_segment_major(23378c90094c51ff).(movie->moviecxx . . $ MVESTREAM#movie.);
255 while (major != 0xff) {
256 /* check whether to handle the segment */
257 if (major < 32 && movie->handlerscxx . . $ MVESTREAM#handlers.[major] != nullptr) {
258 minor = mvefile_get_next_segment_minorcxx . . $ mvefile_get_next_segment_minor(23378c90094c51ff).(movie->moviecxx . . $ MVESTREAM#movie.);
259 len = mvefile_get_next_segment_sizecxx . . $ mvefile_get_next_segment_size(1d7e7661686dc57e).(movie->moviecxx . . $ MVESTREAM#movie.);
260 data = mvefile_get_next_segmentcxx . . $ mvefile_get_next_segment(84d9daf51fdf2d72).(movie->moviecxx . . $ MVESTREAM#movie.);
261
262 if (!movie->handlerscxx . . $ MVESTREAM#handlers.[major](major, minor, data, len, movie->contextcxx . . $ MVESTREAM#context.))
263 return 0;
264 }
265
266 /* advance to next segment */
267 mvefile_advance_segmentcxx . . $ mvefile_advance_segment(e0260fc6b97b09ea).(movie->moviecxx . . $ MVESTREAM#movie.);
268 major = mvefile_get_next_segment_majorcxx . . $ mvefile_get_next_segment_major(23378c90094c51ff).(movie->moviecxx . . $ MVESTREAM#movie.);
269 }
270
271 if (!mvefile_fetch_next_chunkcxx . . $ mvefile_fetch_next_chunk(1d7e7661686dc57e).(movie->moviecxx . . $ MVESTREAM#movie.))
272 return 0;
273
274 /* return status */
275 return 1;
276 }
277
278 /************************************************************
279 * private functions
280 ************************************************************/
281
282 /*
283 * allocate an MVEFILE
284 */
285 static MVEFILEcxx . . $ MVEFILE# *_mvefile_alloccxx . . $ _mvefile_alloc(905748fc52bed99e).() {
286 MVEFILEcxx . . $ MVEFILE# *file = (MVEFILEcxx . . $ MVEFILE# *)mve_alloccxx . . $ mve_alloc.(sizeof(MVEFILEcxx . . $ MVEFILE#));
287 file->streamcxx . . $ MVEFILE#stream. = nullptr;
288 file->cur_chunkcxx . . $ MVEFILE#cur_chunk. = nullptr;
289 file->buf_sizecxx . . $ MVEFILE#buf_size. = 0;
290 file->cur_fillcxx . . $ MVEFILE#cur_fill. = 0;
291 file->next_segmentcxx . . $ MVEFILE#next_segment. = 0;
292
293 return file;
294 }
295
296 /*
297 * free an MVE file
298 */
299 static void _mvefile_freecxx . . $ _mvefile_free(e0260fc6b97b09ea).(MVEFILEcxx . . $ MVEFILE# *movie) {
300 /* free the stream */
301 movie->streamcxx . . $ MVEFILE#stream. = nullptr;
302
303 /* free the buffer */
304 if (movie->cur_chunkcxx . . $ MVEFILE#cur_chunk.)
305 mve_freecxx . . $ mve_free.(movie->cur_chunkcxx . . $ MVEFILE#cur_chunk.);
306 movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. = nullptr;
307
308 /* not strictly necessary */
309 movie->buf_sizecxx . . $ MVEFILE#buf_size. = 0;
310 movie->cur_fillcxx . . $ MVEFILE#cur_fill. = 0;
311 movie->next_segmentcxx . . $ MVEFILE#next_segment. = 0;
312
313 /* free the struct */
314 mve_freecxx . . $ mve_free.(movie);
315 }
316
317 /*
318 * open the file stream in thie object
319 */
320 static int _mvefile_opencxx . . $ _mvefile_open(2cfb1a8aaf803071).(MVEFILEcxx . . $ MVEFILE# *file, void *stream) {
321 file->streamcxx . . $ MVEFILE#stream. = stream;
322 if (!file->streamcxx . . $ MVEFILE#stream.)
323 return 0;
324
325 return 1;
326 }
327
328 /*
329 * allocate an MVEFILE
330 */
331 static void _mvefile_resetcxx . . $ _mvefile_reset(e0260fc6b97b09ea).(MVEFILEcxx . . $ MVEFILE# *file) {
332 fseek((FILE *)file->streamcxx . . $ MVEFILE#stream., 0, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!);
333 file->cur_chunkcxx . . $ MVEFILE#cur_chunk. = nullptr;
334 file->buf_sizecxx . . $ MVEFILE#buf_size. = 0;
335 file->cur_fillcxx . . $ MVEFILE#cur_fill. = 0;
336 file->next_segmentcxx . . $ MVEFILE#next_segment. = 0;
337 }
338
339 /*
340 * read and verify the header of the recently opened file
341 */
342 static int _mvefile_read_headercxx . . $ _mvefile_read_header(1d7e7661686dc57e).(MVEFILEcxx . . $ MVEFILE# *movie) {
343 unsigned char buffer[26];
344
345 /* check the file is open */
346 if (!movie->streamcxx . . $ MVEFILE#stream.)
347 return 0;
348
349 /* check the file is long enough */
350 if (!mve_readcxx . . $ mve_read.(movie->streamcxx . . $ MVEFILE#stream., buffer, 26))
351 return 0;
352
353 /* check the signature */
354 if (memcmp(buffer, MVE_HEADERcxx . . $ MVE_HEADER., 20))
355 return 0;
356
357 /* check the hard-coded constants */
358 if (_mve_get_shortcxx . . $ _mve_get_short(9e2d0545cb3d9da4).(buffer + 20) != MVE_HDRCONST1cxx . . $ MVE_HDRCONST1.)
359 return 0;
360 if (_mve_get_shortcxx . . $ _mve_get_short(9e2d0545cb3d9da4).(buffer + 22) != MVE_HDRCONST2cxx . . $ MVE_HDRCONST2.)
361 return 0;
362 if (_mve_get_shortcxx . . $ _mve_get_short(9e2d0545cb3d9da4).(buffer + 24) != MVE_HDRCONST3cxx . . $ MVE_HDRCONST3.)
363 return 0;
364
365 return 1;
366 }
367
368 static void _mvefile_set_buffer_sizecxx . . $ _mvefile_set_buffer_size(2701e8ff07fb4637).(MVEFILEcxx . . $ MVEFILE# *movie, int buf_size) {
369 unsigned char *new_buffer;
370 int new_len;
371
372 /* check if this would be a redundant operation */
373 if (buf_size <= movie->buf_sizecxx . . $ MVEFILE#buf_size.)
374 return;
375
376 /* allocate new buffer */
377 new_len = 100 + buf_size;
378 new_buffer = (unsigned char *)mve_alloccxx . . $ mve_alloc.(new_len);
379
380 /* copy old data */
381 if (movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. && movie->cur_fillcxx . . $ MVEFILE#cur_fill.)
382 memcpy(new_buffer, movie->cur_chunkcxx . . $ MVEFILE#cur_chunk., movie->cur_fillcxx . . $ MVEFILE#cur_fill.);
383
384 /* free old buffer */
385 if (movie->cur_chunkcxx . . $ MVEFILE#cur_chunk.) {
386 mve_freecxx . . $ mve_free.(movie->cur_chunkcxx . . $ MVEFILE#cur_chunk.);
387 movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. = 0;
388 }
389
390 /* install new buffer */
391 movie->cur_chunkcxx . . $ MVEFILE#cur_chunk. = new_buffer;
392 movie->buf_sizecxx . . $ MVEFILE#buf_size. = new_len;
393 }
394
395 static int _mvefile_fetch_next_chunkcxx . . $ _mvefile_fetch_next_chunk(1d7e7661686dc57e).(MVEFILEcxx . . $ MVEFILE# *movie) {
396 unsigned char buffer[4];
397 unsigned short length;
398
399 /* fail if not open */
400 if (!movie->streamcxx . . $ MVEFILE#stream.)
401 return 0;
402
403 /* fail if we can't read the next segment descriptor */
404 if (!mve_readcxx . . $ mve_read.(movie->streamcxx . . $ MVEFILE#stream., buffer, 4))
405 return 0;
406
407 /* pull out the next length */
408 length = _mve_get_shortcxx . . $ _mve_get_short(9e2d0545cb3d9da4).(buffer);
409
410 /* make sure we've got sufficient space */
411 _mvefile_set_buffer_sizecxx . . $ _mvefile_set_buffer_size(2701e8ff07fb4637).(movie, length);
412
413 /* read the chunk */
414 if (!mve_readcxx . . $ mve_read.(movie->streamcxx . . $ MVEFILE#stream., movie->cur_chunkcxx . . $ MVEFILE#cur_chunk., length))
415 return 0;
416 movie->cur_fillcxx . . $ MVEFILE#cur_fill. = length;
417 movie->next_segmentcxx . . $ MVEFILE#next_segment. = 0;
418
419 return 1;
420 }
421
422 static short _mve_get_shortcxx . . $ _mve_get_short(9e2d0545cb3d9da4).(unsigned char *data) {
423 short value;
424 value = data[0] | (data[1] << 8);
425 return value;
426 }
427
428 static unsigned short _mve_get_ushortcxx . . $ _mve_get_ushort(e56f59a1c9f445b3).(unsigned char *data) {
429 unsigned short value;
430 value = data[0] | (data[1] << 8);
431 return value;
432 }
433
434 /*
435 * allocate an MVESTREAM
436 */
437 static MVESTREAMcxx . . $ MVESTREAM# *_mvestream_alloccxx . . $ _mvestream_alloc(64e3b3de65826ec6).() {
438 MVESTREAMcxx . . $ MVESTREAM# *movie;
439
440 /* allocate and zero-initialize everything */
441 movie = (MVESTREAMcxx . . $ MVESTREAM# *)mve_alloccxx . . $ mve_alloc.(sizeof(MVESTREAMcxx . . $ MVESTREAM#));
442 movie->moviecxx . . $ MVESTREAM#movie. = nullptr;
443 movie->contextcxx . . $ MVESTREAM#context. = 0;
444 memset(movie->handlerscxx . . $ MVESTREAM#handlers., 0, sizeof(movie->handlerscxx . . $ MVESTREAM#handlers.));
445
446 return movie;
447 }
448
449 /*
450 * free an MVESTREAM
451 */
452 static void _mvestream_freecxx . . $ _mvestream_free(322520e409d4025).(MVESTREAMcxx . . $ MVESTREAM# *movie) {
453 /* close MVEFILE */
454 if (movie == nullptr)
455 return;
456 if (movie->moviecxx . . $ MVESTREAM#movie. != nullptr)
457 mvefile_closecxx . . $ mvefile_close(e0260fc6b97b09ea).(movie->moviecxx . . $ MVESTREAM#movie.);
458 movie->moviecxx . . $ MVESTREAM#movie. = nullptr;
459
460 /* clear context and handlers */
461 movie->contextcxx . . $ MVESTREAM#context. = nullptr;
462 memset(movie->handlerscxx . . $ MVESTREAM#handlers., 0, sizeof(movie->handlerscxx . . $ MVESTREAM#handlers.));
463
464 /* free the struct */
465 mve_freecxx . . $ mve_free.(movie);
466 }
467
468 /*
469 * open an MVESTREAM object
470 */
471 static int _mvestream_opencxx . . $ _mvestream_open(b026629aad3734ba).(MVESTREAMcxx . . $ MVESTREAM# *movie, void *stream) {
472 movie->moviecxx . . $ MVESTREAM#movie. = mvefile_opencxx . . $ mvefile_open(d986263c59db9590).(stream);
473
474 return (movie->moviecxx . . $ MVESTREAM#movie. == nullptr) ? 0 : 1;
475 }
476
477 /*
478 * reset an MVESTREAM
479 */
480 static void _mvestream_resetcxx . . $ _mvestream_reset(322520e409d4025).(MVESTREAMcxx . . $ MVESTREAM# *movie) { mvefile_resetcxx . . $ mvefile_reset(e0260fc6b97b09ea).(movie->moviecxx . . $ MVESTREAM#movie.); }