diff options
Diffstat (limited to 'rbutil/rbutilqt/mspack/lzssd.c')
-rw-r--r-- | rbutil/rbutilqt/mspack/lzssd.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/rbutil/rbutilqt/mspack/lzssd.c b/rbutil/rbutilqt/mspack/lzssd.c index f1a47c7a01..63716d414a 100644 --- a/rbutil/rbutilqt/mspack/lzssd.c +++ b/rbutil/rbutilqt/mspack/lzssd.c | |||
@@ -14,31 +14,31 @@ | |||
14 | #include "system-mspack.h" | 14 | #include "system-mspack.h" |
15 | #include "lzss.h" | 15 | #include "lzss.h" |
16 | 16 | ||
17 | #define ENSURE_BYTES do { \ | 17 | #define ENSURE_BYTES do { \ |
18 | if (i_ptr >= i_end) { \ | 18 | if (i_ptr >= i_end) { \ |
19 | read = system->read(input, &inbuf[0], \ | 19 | read = system->read(input, &inbuf[0], \ |
20 | input_buffer_size); \ | 20 | input_buffer_size); \ |
21 | if (read <= 0) { \ | 21 | if (read <= 0) { \ |
22 | system->free(window); \ | 22 | system->free(window); \ |
23 | return (read < 0) ? MSPACK_ERR_READ \ | 23 | return (read < 0) ? MSPACK_ERR_READ \ |
24 | : MSPACK_ERR_OK; \ | 24 | : MSPACK_ERR_OK; \ |
25 | } \ | 25 | } \ |
26 | i_ptr = &inbuf[0]; i_end = &inbuf[read]; \ | 26 | i_ptr = &inbuf[0]; i_end = &inbuf[read]; \ |
27 | } \ | 27 | } \ |
28 | } while (0) | 28 | } while (0) |
29 | 29 | ||
30 | #define WRITE_BYTE do { \ | 30 | #define WRITE_BYTE do { \ |
31 | if (system->write(output, &window[pos], 1) != 1) { \ | 31 | if (system->write(output, &window[pos], 1) != 1) { \ |
32 | system->free(window); \ | 32 | system->free(window); \ |
33 | return MSPACK_ERR_WRITE; \ | 33 | return MSPACK_ERR_WRITE; \ |
34 | } \ | 34 | } \ |
35 | } while (0) | 35 | } while (0) |
36 | 36 | ||
37 | int lzss_decompress(struct mspack_system *system, | 37 | int lzss_decompress(struct mspack_system *system, |
38 | struct mspack_file *input, | 38 | struct mspack_file *input, |
39 | struct mspack_file *output, | 39 | struct mspack_file *output, |
40 | int input_buffer_size, | 40 | int input_buffer_size, |
41 | int mode) | 41 | int mode) |
42 | { | 42 | { |
43 | unsigned char *window, *inbuf, *i_ptr, *i_end; | 43 | unsigned char *window, *inbuf, *i_ptr, *i_end; |
44 | unsigned int pos, i, c, invert, mpos, len; | 44 | unsigned int pos, i, c, invert, mpos, len; |
@@ -48,7 +48,7 @@ int lzss_decompress(struct mspack_system *system, | |||
48 | if (!system || input_buffer_size < 1 || (mode != LZSS_MODE_EXPAND && | 48 | if (!system || input_buffer_size < 1 || (mode != LZSS_MODE_EXPAND && |
49 | mode != LZSS_MODE_MSHELP && mode != LZSS_MODE_QBASIC)) | 49 | mode != LZSS_MODE_MSHELP && mode != LZSS_MODE_QBASIC)) |
50 | { | 50 | { |
51 | return MSPACK_ERR_ARGS; | 51 | return MSPACK_ERR_ARGS; |
52 | } | 52 | } |
53 | 53 | ||
54 | /* allocate memory */ | 54 | /* allocate memory */ |
@@ -64,27 +64,27 @@ int lzss_decompress(struct mspack_system *system, | |||
64 | 64 | ||
65 | /* loop forever; exit condition is in ENSURE_BYTES macro */ | 65 | /* loop forever; exit condition is in ENSURE_BYTES macro */ |
66 | for (;;) { | 66 | for (;;) { |
67 | ENSURE_BYTES; c = *i_ptr++ ^ invert; | 67 | ENSURE_BYTES; c = *i_ptr++ ^ invert; |
68 | for (i = 0x01; i & 0xFF; i <<= 1) { | 68 | for (i = 0x01; i & 0xFF; i <<= 1) { |
69 | if (c & i) { | 69 | if (c & i) { |
70 | /* literal */ | 70 | /* literal */ |
71 | ENSURE_BYTES; window[pos] = *i_ptr++; | 71 | ENSURE_BYTES; window[pos] = *i_ptr++; |
72 | WRITE_BYTE; | 72 | WRITE_BYTE; |
73 | pos++; pos &= LZSS_WINDOW_SIZE - 1; | 73 | pos++; pos &= LZSS_WINDOW_SIZE - 1; |
74 | } | 74 | } |
75 | else { | 75 | else { |
76 | /* match */ | 76 | /* match */ |
77 | ENSURE_BYTES; mpos = *i_ptr++; | 77 | ENSURE_BYTES; mpos = *i_ptr++; |
78 | ENSURE_BYTES; mpos |= (*i_ptr & 0xF0) << 4; | 78 | ENSURE_BYTES; mpos |= (*i_ptr & 0xF0) << 4; |
79 | len = (*i_ptr++ & 0x0F) + 3; | 79 | len = (*i_ptr++ & 0x0F) + 3; |
80 | while (len--) { | 80 | while (len--) { |
81 | window[pos] = window[mpos]; | 81 | window[pos] = window[mpos]; |
82 | WRITE_BYTE; | 82 | WRITE_BYTE; |
83 | pos++; pos &= LZSS_WINDOW_SIZE - 1; | 83 | pos++; pos &= LZSS_WINDOW_SIZE - 1; |
84 | mpos++; mpos &= LZSS_WINDOW_SIZE - 1; | 84 | mpos++; mpos &= LZSS_WINDOW_SIZE - 1; |
85 | } | 85 | } |
86 | } | 86 | } |
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
90 | /* not reached */ | 90 | /* not reached */ |