| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#ifndef _XDELTA3_DECODE_H_ |
|---|
| 20 |
#define _XDELTA3_DECODE_H_ |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
int xd3_decoder_needs_source (xd3_stream *stream) |
|---|
| 27 |
{ |
|---|
| 28 |
return stream->dec_win_ind & VCD_SOURCE; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
static int |
|---|
| 37 |
xd3_decode_init_window (xd3_stream *stream) |
|---|
| 38 |
{ |
|---|
| 39 |
stream->dec_cpylen = 0; |
|---|
| 40 |
stream->dec_cpyoff = 0; |
|---|
| 41 |
stream->dec_cksumbytes = 0; |
|---|
| 42 |
|
|---|
| 43 |
xd3_init_cache (& stream->acache); |
|---|
| 44 |
|
|---|
| 45 |
return 0; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
static int |
|---|
| 51 |
xd3_decode_setup_buffers (xd3_stream *stream) |
|---|
| 52 |
{ |
|---|
| 53 |
|
|---|
| 54 |
if (stream->dec_win_ind & VCD_TARGET) |
|---|
| 55 |
{ |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
if (stream->dec_cpyoff < stream->dec_laststart) |
|---|
| 59 |
{ |
|---|
| 60 |
stream->msg = "unsupported VCD_TARGET offset"; |
|---|
| 61 |
return XD3_INVALID_INPUT; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
if (stream->dec_lastwin == stream->next_out) |
|---|
| 68 |
{ |
|---|
| 69 |
stream->next_out = NULL; |
|---|
| 70 |
stream->space_out = 0; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
stream->dec_cpyaddrbase = stream->dec_lastwin + (usize_t) (stream->dec_cpyoff - stream->dec_laststart); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
if (stream->space_out < stream->dec_tgtlen) |
|---|
| 78 |
{ |
|---|
| 79 |
xd3_free (stream, stream->dec_buffer); |
|---|
| 80 |
|
|---|
| 81 |
stream->space_out = xd3_round_blksize (stream->dec_tgtlen, XD3_ALLOCSIZE); |
|---|
| 82 |
|
|---|
| 83 |
if ((stream->dec_buffer = xd3_alloc (stream, stream->space_out, 1)) == NULL) |
|---|
| 84 |
{ |
|---|
| 85 |
return ENOMEM; |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
stream->next_out = stream->dec_buffer; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
stream->dec_tgtaddrbase = stream->next_out - stream->dec_cpylen; |
|---|
| 95 |
|
|---|
| 96 |
return 0; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
static int |
|---|
| 100 |
xd3_decode_allocate (xd3_stream *stream, |
|---|
| 101 |
usize_t size, |
|---|
| 102 |
uint8_t **buf_ptr, |
|---|
| 103 |
usize_t *buf_alloc) |
|---|
| 104 |
{ |
|---|
| 105 |
if (*buf_ptr != NULL && *buf_alloc < size) |
|---|
| 106 |
{ |
|---|
| 107 |
xd3_free (stream, *buf_ptr); |
|---|
| 108 |
*buf_ptr = NULL; |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
if (*buf_ptr == NULL) |
|---|
| 112 |
{ |
|---|
| 113 |
*buf_alloc = xd3_round_blksize (size, XD3_ALLOCSIZE); |
|---|
| 114 |
|
|---|
| 115 |
if ((*buf_ptr = xd3_alloc (stream, *buf_alloc, 1)) == NULL) |
|---|
| 116 |
{ |
|---|
| 117 |
return ENOMEM; |
|---|
| 118 |
} |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
return 0; |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
static int |
|---|
| 125 |
xd3_decode_section (xd3_stream *stream, |
|---|
| 126 |
xd3_desect *section, |
|---|
| 127 |
xd3_decode_state nstate, |
|---|
| 128 |
int copy) |
|---|
| 129 |
{ |
|---|
| 130 |
XD3_ASSERT (section->pos <= section->size); |
|---|
| 131 |
XD3_ASSERT (stream->dec_state != nstate); |
|---|
| 132 |
|
|---|
| 133 |
if (section->pos < section->size) |
|---|
| 134 |
{ |
|---|
| 135 |
usize_t sect_take; |
|---|
| 136 |
|
|---|
| 137 |
if (stream->avail_in == 0) |
|---|
| 138 |
{ |
|---|
| 139 |
return XD3_INPUT; |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
if ((copy == 0) && (section->pos == 0)) |
|---|
| 143 |
{ |
|---|
| 144 |
|
|---|
| 145 |
section->buf = stream->next_in; |
|---|
| 146 |
sect_take = section->size; |
|---|
| 147 |
} |
|---|
| 148 |
else |
|---|
| 149 |
{ |
|---|
| 150 |
usize_t sect_need = section->size - section->pos; |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
sect_take = min (sect_need, stream->avail_in); |
|---|
| 154 |
|
|---|
| 155 |
if (section->pos == 0) |
|---|
| 156 |
{ |
|---|
| 157 |
int ret; |
|---|
| 158 |
|
|---|
| 159 |
if ((ret = xd3_decode_allocate (stream, |
|---|
| 160 |
section->size, |
|---|
| 161 |
& section->copied1, |
|---|
| 162 |
& section->alloc1))) { return ret; } |
|---|
| 163 |
|
|---|
| 164 |
section->buf = section->copied1; |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
memcpy (section->copied1 + section->pos, |
|---|
| 168 |
stream->next_in, |
|---|
| 169 |
sect_take); |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
section->pos += sect_take; |
|---|
| 173 |
|
|---|
| 174 |
stream->dec_winbytes += sect_take; |
|---|
| 175 |
|
|---|
| 176 |
DECODE_INPUT (sect_take); |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
if (section->pos < section->size) |
|---|
| 180 |
{ |
|---|
| 181 |
stream->msg = "further input required"; |
|---|
| 182 |
return XD3_INPUT; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
XD3_ASSERT (section->pos == section->size); |
|---|
| 186 |
|
|---|
| 187 |
stream->dec_state = nstate; |
|---|
| 188 |
section->buf_max = section->buf + section->size; |
|---|
| 189 |
section->pos = 0; |
|---|
| 190 |
return 0; |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
static int |
|---|
| 198 |
xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst) |
|---|
| 199 |
{ |
|---|
| 200 |
int ret; |
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
if ((inst->size == 0) && |
|---|
| 204 |
(ret = xd3_read_size (stream, |
|---|
| 205 |
& stream->inst_sect.buf, |
|---|
| 206 |
stream->inst_sect.buf_max, |
|---|
| 207 |
& inst->size))) |
|---|
| 208 |
{ |
|---|
| 209 |
return XD3_INVALID_INPUT; |
|---|
| 210 |
} |
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
if (inst->type >= XD3_CPY) |
|---|
| 214 |
{ |
|---|
| 215 |
IF_DEBUG1 ({ |
|---|
| 216 |
static int cnt = 0; |
|---|
| 217 |
DP(RINT "DECODE:%u: COPY at %"Q"u (winoffset %u) size %u winaddr %u\n", |
|---|
| 218 |
cnt++, |
|---|
| 219 |
stream->total_out + (stream->dec_position - stream->dec_cpylen), |
|---|
| 220 |
(stream->dec_position - stream->dec_cpylen), |
|---|
| 221 |
inst->size, |
|---|
| 222 |
inst->addr); |
|---|
| 223 |
}); |
|---|
| 224 |
|
|---|
| 225 |
if ((ret = xd3_decode_address (stream, |
|---|
| 226 |
stream->dec_position, |
|---|
| 227 |
inst->type - XD3_CPY, |
|---|
| 228 |
& stream->addr_sect.buf, |
|---|
| 229 |
stream->addr_sect.buf_max, |
|---|
| 230 |
& inst->addr))) |
|---|
| 231 |
{ |
|---|
| 232 |
return ret; |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
if (inst->addr >= stream->dec_position) |
|---|
| 237 |
{ |
|---|
| 238 |
stream->msg = "address too large"; |
|---|
| 239 |
return XD3_INVALID_INPUT; |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
if (inst->addr < stream->dec_cpylen && inst->addr + inst->size > stream->dec_cpylen) |
|---|
| 245 |
{ |
|---|
| 246 |
stream->msg = "size too large"; |
|---|
| 247 |
return XD3_INVALID_INPUT; |
|---|
| 248 |
} |
|---|
| 249 |
} |
|---|
| 250 |
else |
|---|
| 251 |
{ |
|---|
| 252 |
IF_DEBUG1 ({ |
|---|
| 253 |
if (inst->type == XD3_ADD) |
|---|
| 254 |
{ |
|---|
| 255 |
static int cnt; |
|---|
| 256 |
DP(RINT "DECODE:%d: ADD at %"Q"u (winoffset %u) size %u\n", |
|---|
| 257 |
cnt++, |
|---|
| 258 |
stream->total_out + stream->dec_position - stream->dec_cpylen, |
|---|
| 259 |
stream->dec_position - stream->dec_cpylen, |
|---|
| 260 |
inst->size); |
|---|
| 261 |
} |
|---|
| 262 |
else |
|---|
| 263 |
{ |
|---|
| 264 |
static int cnt; |
|---|
| 265 |
XD3_ASSERT (inst->type == XD3_RUN); |
|---|
| 266 |
DP(RINT "DECODE:%d: RUN at %"Q"u (winoffset %u) size %u\n", |
|---|
| 267 |
cnt++, |
|---|
| 268 |
stream->total_out + stream->dec_position - stream->dec_cpylen, |
|---|
| 269 |
stream->dec_position - stream->dec_cpylen, |
|---|
| 270 |
inst->size); |
|---|
| 271 |
} |
|---|
| 272 |
}); |
|---|
| 273 |
} |
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
if (stream->dec_position + inst->size > stream->dec_maxpos) |
|---|
| 277 |
{ |
|---|
| 278 |
stream->msg = "size too large"; |
|---|
| 279 |
return XD3_INVALID_INPUT; |
|---|
| 280 |
} |
|---|
| 281 |
|
|---|
| 282 |
stream->dec_position += inst->size; |
|---|
| 283 |
return 0; |
|---|
| 284 |
} |
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
static int |
|---|
| 288 |
xd3_decode_instruction (xd3_stream *stream) |
|---|
| 289 |
{ |
|---|
| 290 |
int ret; |
|---|
| 291 |
const xd3_dinst *inst; |
|---|
| 292 |
|
|---|
| 293 |
if (stream->inst_sect.buf == stream->inst_sect.buf_max) |
|---|
| 294 |
{ |
|---|
| 295 |
stream->msg = "instruction underflow"; |
|---|
| 296 |
return XD3_INVALID_INPUT; |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
inst = &stream->code_table[*stream->inst_sect.buf++]; |
|---|
| 300 |
|
|---|
| 301 |
stream->dec_current1.type = inst->type1; |
|---|
| 302 |
stream->dec_current2.type = inst->type2; |
|---|
| 303 |
stream->dec_current1.size = inst->size1; |
|---|
| 304 |
stream->dec_current2.size = inst->size2; |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
if (inst->type1 != XD3_NOOP && (ret = xd3_decode_parse_halfinst (stream, & stream->dec_current1))) |
|---|
| 310 |
{ |
|---|
| 311 |
return ret; |
|---|
| 312 |
} |
|---|
| 313 |
if (inst->type2 != XD3_NOOP && (ret = xd3_decode_parse_halfinst (stream, & stream->dec_current2))) |
|---|
| 314 |
{ |
|---|
| 315 |
return ret; |
|---|
| 316 |
} |
|---|
| 317 |
return 0; |
|---|
| 318 |
} |
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
static int |
|---|
| 322 |
xd3_decode_output_halfinst (xd3_stream *stream, xd3_hinst *inst) |
|---|
| 323 |
{ |
|---|
| 324 |
|
|---|
| 325 |
usize_t take = inst->size; |
|---|
| 326 |
|
|---|
| 327 |
XD3_ASSERT (inst->type != XD3_NOOP); |
|---|
| 328 |
|
|---|
| 329 |
switch (inst->type) |
|---|
| 330 |
{ |
|---|
| 331 |
case XD3_RUN: |
|---|
| 332 |
{ |
|---|
| 333 |
|
|---|
| 334 |
if (stream->data_sect.buf == stream->data_sect.buf_max) |
|---|
| 335 |
{ |
|---|
| 336 |
stream->msg = "data underflow"; |
|---|
| 337 |
return XD3_INVALID_INPUT; |
|---|
| 338 |
} |
|---|
| 339 |
|
|---|
| 340 |
memset (stream->next_out + stream->avail_out, |
|---|
| 341 |
stream->data_sect.buf[0], |
|---|
| 342 |
take); |
|---|
| 343 |
|
|---|
| 344 |
stream->data_sect.buf += 1; |
|---|
| 345 |
stream->avail_out += take; |
|---|
| 346 |
inst->type = XD3_NOOP; |
|---|
| 347 |
break; |
|---|
| 348 |
} |
|---|
| 349 |
case XD3_ADD: |
|---|
| 350 |
{ |
|---|
| 351 |
|
|---|
| 352 |
if (stream->data_sect.buf + take > stream->data_sect.buf_max) |
|---|
| 353 |
{ |
|---|
| 354 |
stream->msg = "data underflow"; |
|---|
| 355 |
return XD3_INVALID_INPUT; |
|---|
| 356 |
} |
|---|
| 357 |
|
|---|
| 358 |
memcpy (stream->next_out + stream->avail_out, |
|---|
| 359 |
stream->data_sect.buf, |
|---|
| 360 |
take); |
|---|
| 361 |
|
|---|
| 362 |
stream->data_sect.buf += take; |
|---|
| 363 |
stream->avail_out += take; |
|---|
| 364 |
inst->type = XD3_NOOP; |
|---|
| 365 |
break; |
|---|
| 366 |
} |
|---|
| 367 |
default: |
|---|
| 368 |
{ |
|---|
| 369 |
usize_t i; |
|---|
| 370 |
const uint8_t *src; |
|---|
| 371 |
uint8_t *dst; |
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
if (inst->addr < stream->dec_cpylen) |
|---|
| 377 |
{ |
|---|
| 378 |
if (stream->dec_win_ind & VCD_TARGET) |
|---|
| 379 |
{ |
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
src = stream->dec_cpyaddrbase + inst->addr; |
|---|
| 383 |
inst->type = XD3_NOOP; |
|---|
| 384 |
inst->size = 0; |
|---|
| 385 |
} |
|---|
| 386 |
else |
|---|
| 387 |
{ |
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
xd3_source *source; |
|---|
| 392 |
xoff_t block; |
|---|
| 393 |
usize_t blkoff; |
|---|
| 394 |
usize_t blksize; |
|---|
| 395 |
int ret; |
|---|
| 396 |
|
|---|
| 397 |
more: |
|---|
| 398 |
|
|---|
| 399 |
source = stream->src; |
|---|
| 400 |
block = source->cpyoff_blocks; |
|---|
| 401 |
blkoff = source->cpyoff_blkoff + inst->addr; |
|---|
| 402 |
blksize = source->blksize; |
|---|
| 403 |
|
|---|
| 404 |
while (blkoff >= blksize) |
|---|
| 405 |
{ |
|---|
| 406 |
block += 1; |
|---|
| 407 |
blkoff -= blksize; |
|---|
| 408 |
} |
|---|
| 409 |
|
|---|
| 410 |
if ((ret = xd3_getblk (stream, block))) |
|---|
| 411 |
{ |
|---|
| 412 |
|
|---|
| 413 |
if (ret == XD3_TOOFARBACK) |
|---|
| 414 |
{ |
|---|
| 415 |
ret = XD3_INTERNAL; |
|---|
| 416 |
} |
|---|
| 417 |
return ret; |
|---|
| 418 |
} |
|---|
| 419 |
|
|---|
| 420 |
src = source->curblk + blkoff; |
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
if ((source->onblk != blksize) && (blkoff + take > source->onblk)) |
|---|
| 425 |
{ |
|---|
| 426 |
stream->msg = "source file too short"; |
|---|
| 427 |
return XD3_INVALID_INPUT; |
|---|
| 428 |
|
|---|
| 429 |
} |
|---|
| 430 |
|
|---|
| 431 |
XD3_ASSERT (blkoff != blksize); |
|---|
| 432 |
|
|---|
| 433 |
if (blkoff + take <= blksize) |
|---|
| 434 |
{ |
|---|
| 435 |
inst->type = XD3_NOOP; |
|---|
| 436 |
inst->size = 0; |
|---|
| 437 |
} |
|---|
| 438 |
else |
|---|
| 439 |
{ |
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
take = blksize - blkoff; |
|---|
| 443 |
inst->size -= take; |
|---|
| 444 |
inst->addr += take; |
|---|
| 445 |
} |
|---|
| 446 |
} |
|---|
| 447 |
} |
|---|
| 448 |
else |
|---|
| 449 |
{ |
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
src = stream->dec_tgtaddrbase + inst->addr; |
|---|
| 454 |
inst->type = XD3_NOOP; |
|---|
| 455 |
inst->size = 0; |
|---|
| 456 |
} |
|---|
| 457 |
|
|---|
| 458 |
dst = stream->next_out + stream->avail_out; |
|---|
| 459 |
|
|---|
| 460 |
stream->avail_out += take; |
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
for (i = take; i != 0; i -= 1) |
|---|
| 464 |
{ |
|---|
| 465 |
*dst++ = *src++; |
|---|
| 466 |
} |
|---|
| 467 |
|
|---|
| 468 |
take = inst->size; |
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
if (inst->type != XD3_NOOP) |
|---|
| 472 |
{ |
|---|
| 473 |
XD3_ASSERT (take > 0); |
|---|
| 474 |
goto more; |
|---|
| 475 |
} |
|---|
| 476 |
else |
|---|
| 477 |
{ |
|---|
| 478 |
XD3_ASSERT (take == 0); |
|---|
| 479 |
} |
|---|
| 480 |
} |
|---|
| 481 |
} |
|---|
| 482 |
|
|---|
| 483 |
return 0; |
|---|
| 484 |
} |
|---|
| 485 |
|
|---|
| 486 |
static int |
|---|
| 487 |
xd3_decode_finish_window (xd3_stream *stream) |
|---|
| 488 |
{ |
|---|
| 489 |
stream->dec_winbytes = 0; |
|---|
| 490 |
stream->dec_state = DEC_FINISH; |
|---|
| 491 |
|
|---|
| 492 |
stream->data_sect.pos = 0; |
|---|
| 493 |
stream->inst_sect.pos = 0; |
|---|
| 494 |
stream->addr_sect.pos = 0; |
|---|
| 495 |
|
|---|
| 496 |
return XD3_OUTPUT; |
|---|
| 497 |
} |
|---|
| 498 |
|
|---|
| 499 |
static int |
|---|
| 500 |
xd3_decode_secondary_sections (xd3_stream *secondary_stream) |
|---|
| 501 |
{ |
|---|
| 502 |
#if SECONDARY_ANY |
|---|
| 503 |
int ret; |
|---|
| 504 |
#define DECODE_SECONDARY_SECTION(UPPER,LOWER) \ |
|---|
| 505 |
((secondary_stream->dec_del_ind & VCD_ ## UPPER ## COMP) && \ |
|---|
| 506 |
(ret = xd3_decode_secondary (secondary_stream, & secondary_stream-> LOWER ## _sect, \ |
|---|
| 507 |
& xd3_sec_ ## LOWER (secondary_stream)))) |
|---|
| 508 |
|
|---|
| 509 |
if (DECODE_SECONDARY_SECTION (DATA, data) || |
|---|
| 510 |
DECODE_SECONDARY_SECTION (INST, inst) || |
|---|
| 511 |
DECODE_SECONDARY_SECTION (ADDR, addr)) |
|---|
| 512 |
{ |
|---|
| 513 |
return ret; |
|---|
| 514 |
} |
|---|
| 515 |
#undef DECODE_SECONDARY_SECTION |
|---|
| 516 |
#endif |
|---|
| 517 |
return 0; |
|---|
| 518 |
} |
|---|
| 519 |
|
|---|
| 520 |
static int |
|---|
| 521 |
xd3_decode_sections (xd3_stream *stream) |
|---|
| 522 |
{ |
|---|
| 523 |
usize_t need, more, take; |
|---|
| 524 |
int copy, ret; |
|---|
| 525 |
|
|---|
| 526 |
if ((stream->flags & XD3_JUST_HDR) != 0) |
|---|
| 527 |
{ |
|---|
| 528 |
|
|---|
| 529 |
return xd3_decode_finish_window (stream); |
|---|
| 530 |
} |
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
need = (stream->inst_sect.size + |
|---|
| 534 |
stream->addr_sect.size + |
|---|
| 535 |
stream->data_sect.size); |
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
XD3_ASSERT (stream->dec_winbytes <= need); |
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
more = (need - stream->dec_winbytes); |
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
take = min (more, stream->avail_in); |
|---|
| 545 |
|
|---|
| 546 |
|
|---|
| 547 |
copy = (take != more); |
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
if ((stream->flags & XD3_SKIP_WINDOW) != 0) |
|---|
| 551 |
{ |
|---|
| 552 |
|
|---|
| 553 |
DECODE_INPUT (take); |
|---|
| 554 |
|
|---|
| 555 |
stream->dec_winbytes += take; |
|---|
| 556 |
|
|---|
| 557 |
if (copy) |
|---|
| 558 |
{ |
|---|
| 559 |
stream->msg = "further input required"; |
|---|
| 560 |
return XD3_INPUT; |
|---|
| 561 |
} |
|---|
| 562 |
|
|---|
| 563 |
return xd3_decode_finish_window (stream); |
|---|
| 564 |
} |
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
switch (stream->dec_state) |
|---|
| 568 |
{ |
|---|
| 569 |
default: |
|---|
| 570 |
stream->msg = "internal error"; |
|---|
| 571 |
return XD3_INVALID_INPUT; |
|---|
| 572 |
|
|---|
| 573 |
case DEC_DATA: |
|---|
| 574 |
if ((ret = xd3_decode_section (stream, & stream->data_sect, DEC_INST, copy))) { return ret; } |
|---|
| 575 |
case DEC_INST: |
|---|
| 576 |
if ((ret = |
|---|