diff options
Diffstat (limited to 'rbutil/rbutilqt/mspack/readbits.h')
-rw-r--r-- | rbutil/rbutilqt/mspack/readbits.h | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/rbutil/rbutilqt/mspack/readbits.h b/rbutil/rbutilqt/mspack/readbits.h index 457cbdd7d4..9b237a3693 100644 --- a/rbutil/rbutilqt/mspack/readbits.h +++ b/rbutil/rbutilqt/mspack/readbits.h | |||
@@ -100,48 +100,48 @@ | |||
100 | #endif | 100 | #endif |
101 | #define BITBUF_WIDTH (sizeof(bit_buffer) * CHAR_BIT) | 101 | #define BITBUF_WIDTH (sizeof(bit_buffer) * CHAR_BIT) |
102 | 102 | ||
103 | #define INIT_BITS do { \ | 103 | #define INIT_BITS do { \ |
104 | BITS_VAR->i_ptr = &BITS_VAR->inbuf[0]; \ | 104 | BITS_VAR->i_ptr = &BITS_VAR->inbuf[0]; \ |
105 | BITS_VAR->i_end = &BITS_VAR->inbuf[0]; \ | 105 | BITS_VAR->i_end = &BITS_VAR->inbuf[0]; \ |
106 | BITS_VAR->bit_buffer = 0; \ | 106 | BITS_VAR->bit_buffer = 0; \ |
107 | BITS_VAR->bits_left = 0; \ | 107 | BITS_VAR->bits_left = 0; \ |
108 | BITS_VAR->input_end = 0; \ | 108 | BITS_VAR->input_end = 0; \ |
109 | } while (0) | 109 | } while (0) |
110 | 110 | ||
111 | #define STORE_BITS do { \ | 111 | #define STORE_BITS do { \ |
112 | BITS_VAR->i_ptr = i_ptr; \ | 112 | BITS_VAR->i_ptr = i_ptr; \ |
113 | BITS_VAR->i_end = i_end; \ | 113 | BITS_VAR->i_end = i_end; \ |
114 | BITS_VAR->bit_buffer = bit_buffer; \ | 114 | BITS_VAR->bit_buffer = bit_buffer; \ |
115 | BITS_VAR->bits_left = bits_left; \ | 115 | BITS_VAR->bits_left = bits_left; \ |
116 | } while (0) | 116 | } while (0) |
117 | 117 | ||
118 | #define RESTORE_BITS do { \ | 118 | #define RESTORE_BITS do { \ |
119 | i_ptr = BITS_VAR->i_ptr; \ | 119 | i_ptr = BITS_VAR->i_ptr; \ |
120 | i_end = BITS_VAR->i_end; \ | 120 | i_end = BITS_VAR->i_end; \ |
121 | bit_buffer = BITS_VAR->bit_buffer; \ | 121 | bit_buffer = BITS_VAR->bit_buffer; \ |
122 | bits_left = BITS_VAR->bits_left; \ | 122 | bits_left = BITS_VAR->bits_left; \ |
123 | } while (0) | 123 | } while (0) |
124 | 124 | ||
125 | #define ENSURE_BITS(nbits) do { \ | 125 | #define ENSURE_BITS(nbits) do { \ |
126 | while (bits_left < (nbits)) READ_BYTES; \ | 126 | while (bits_left < (nbits)) READ_BYTES; \ |
127 | } while (0) | 127 | } while (0) |
128 | 128 | ||
129 | #define READ_BITS(val, nbits) do { \ | 129 | #define READ_BITS(val, nbits) do { \ |
130 | ENSURE_BITS(nbits); \ | 130 | ENSURE_BITS(nbits); \ |
131 | (val) = PEEK_BITS(nbits); \ | 131 | (val) = PEEK_BITS(nbits); \ |
132 | REMOVE_BITS(nbits); \ | 132 | REMOVE_BITS(nbits); \ |
133 | } while (0) | 133 | } while (0) |
134 | 134 | ||
135 | #define READ_MANY_BITS(val, bits) do { \ | 135 | #define READ_MANY_BITS(val, bits) do { \ |
136 | unsigned char needed = (bits), bitrun; \ | 136 | unsigned char needed = (bits), bitrun; \ |
137 | (val) = 0; \ | 137 | (val) = 0; \ |
138 | while (needed > 0) { \ | 138 | while (needed > 0) { \ |
139 | if (bits_left <= (BITBUF_WIDTH - 16)) READ_BYTES; \ | 139 | if (bits_left <= (BITBUF_WIDTH - 16)) READ_BYTES; \ |
140 | bitrun = (bits_left < needed) ? bits_left : needed; \ | 140 | bitrun = (bits_left < needed) ? bits_left : needed; \ |
141 | (val) = ((val) << bitrun) | PEEK_BITS(bitrun); \ | 141 | (val) = ((val) << bitrun) | PEEK_BITS(bitrun); \ |
142 | REMOVE_BITS(bitrun); \ | 142 | REMOVE_BITS(bitrun); \ |
143 | needed -= bitrun; \ | 143 | needed -= bitrun; \ |
144 | } \ | 144 | } \ |
145 | } while (0) | 145 | } while (0) |
146 | 146 | ||
147 | #ifdef BITS_ORDER_MSB | 147 | #ifdef BITS_ORDER_MSB |
@@ -163,21 +163,21 @@ static const unsigned short lsb_bit_mask[17] = { | |||
163 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff | 163 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff |
164 | }; | 164 | }; |
165 | # define PEEK_BITS_T(nbits) (bit_buffer & lsb_bit_mask[(nbits)]) | 165 | # define PEEK_BITS_T(nbits) (bit_buffer & lsb_bit_mask[(nbits)]) |
166 | # define READ_BITS_T(val, nbits) do { \ | 166 | # define READ_BITS_T(val, nbits) do { \ |
167 | ENSURE_BITS(nbits); \ | 167 | ENSURE_BITS(nbits); \ |
168 | (val) = PEEK_BITS_T(nbits); \ | 168 | (val) = PEEK_BITS_T(nbits); \ |
169 | REMOVE_BITS(nbits); \ | 169 | REMOVE_BITS(nbits); \ |
170 | } while (0) | 170 | } while (0) |
171 | #endif | 171 | #endif |
172 | 172 | ||
173 | #ifndef BITS_NO_READ_INPUT | 173 | #ifndef BITS_NO_READ_INPUT |
174 | # define READ_IF_NEEDED do { \ | 174 | # define READ_IF_NEEDED do { \ |
175 | if (i_ptr >= i_end) { \ | 175 | if (i_ptr >= i_end) { \ |
176 | if (read_input(BITS_VAR)) \ | 176 | if (read_input(BITS_VAR)) \ |
177 | return BITS_VAR->error; \ | 177 | return BITS_VAR->error; \ |
178 | i_ptr = BITS_VAR->i_ptr; \ | 178 | i_ptr = BITS_VAR->i_ptr; \ |
179 | i_end = BITS_VAR->i_end; \ | 179 | i_end = BITS_VAR->i_end; \ |
180 | } \ | 180 | } \ |
181 | } while (0) | 181 | } while (0) |
182 | 182 | ||
183 | static int read_input(BITS_TYPE *p) { | 183 | static int read_input(BITS_TYPE *p) { |
@@ -187,15 +187,15 @@ static int read_input(BITS_TYPE *p) { | |||
187 | /* we might overrun the input stream by asking for bits we don't use, | 187 | /* we might overrun the input stream by asking for bits we don't use, |
188 | * so fake 2 more bytes at the end of input */ | 188 | * so fake 2 more bytes at the end of input */ |
189 | if (read == 0) { | 189 | if (read == 0) { |
190 | if (p->input_end) { | 190 | if (p->input_end) { |
191 | D(("out of input bytes")) | 191 | D(("out of input bytes")) |
192 | return p->error = MSPACK_ERR_READ; | 192 | return p->error = MSPACK_ERR_READ; |
193 | } | 193 | } |
194 | else { | 194 | else { |
195 | read = 2; | 195 | read = 2; |
196 | p->inbuf[0] = p->inbuf[1] = 0; | 196 | p->inbuf[0] = p->inbuf[1] = 0; |
197 | p->input_end = 1; | 197 | p->input_end = 1; |
198 | } | 198 | } |
199 | } | 199 | } |
200 | 200 | ||
201 | /* update i_ptr and i_end */ | 201 | /* update i_ptr and i_end */ |