| 287 | } |
| 288 | |
| 289 | static int |
| 290 | GetCode(FILE *fd, int code_size, int flag) |
| 291 | { |
| 292 | static unsigned char buf[280]; |
| 293 | static int curbit, lastbit, done, last_byte; |
| 294 | int i, j, ret; |
| 295 | unsigned char count; |
| 296 | |
| 297 | if (flag) { |
| 298 | curbit = 0; |
| 299 | lastbit = 0; |
| 300 | done = FALSE; |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | if ((curbit + code_size) >= lastbit) { |
| 305 | if (done) { |
| 306 | if (curbit >= lastbit) |
| 307 | Fprintf(stderr, "ran off the end of my bits\n"); |
| 308 | return -1; |
| 309 | } |
| 310 | buf[0] = buf[last_byte - 2]; |
| 311 | buf[1] = buf[last_byte - 1]; |
| 312 | |
| 313 | if ((count = GetDataBlock(fd, &buf[2])) == 0) |
| 314 | done = TRUE; |
| 315 | |
| 316 | last_byte = 2 + count; |
| 317 | curbit = (curbit - lastbit) + 16; |
| 318 | lastbit = (2 + count) * 8; |
| 319 | } |
| 320 | |
| 321 | ret = 0; |
| 322 | for (i = curbit, j = 0; j < code_size; ++i, ++j) |
| 323 | ret |= ((buf[i / 8] & (1 << (i % 8))) != 0) << j; |
| 324 | |
| 325 | curbit += code_size; |
| 326 | |
| 327 | return ret; |
| 328 | } |
| 329 | |
| 330 | static int |
| 331 | LWZReadByte(FILE *fd, int flag) /*, int input_code_size)*/ |
no test coverage detected