Lines Matching +full:last +full:- +full:level

3 /*-
4 * SPDX-License-Identifier: BSD-2-Clause
36 * 00, 01 - Signature (US, RS), we already validated it earlier.
37 * 02..05 - Uncompressed size
38 * 06 - Level for the huffman tree (<=24)
41 * tree levels, each level would consume 1 byte (See [1]).
55 * last level symbol count by 2 which makes it a number in
67 * and store pointers to each level's first symbol. In addition to
68 * that, maintain two counts for each level: inner nodes count and
76 * level */
78 * each level */
83 * first symbol of each tree level */
102 free(unpackd->symbolsin); in unpack_descriptor_fini()
103 free(unpackd->inodesin); in unpack_descriptor_fini()
104 free(unpackd->symbol); in unpack_descriptor_fini()
105 free(unpackd->tree); in unpack_descriptor_fini()
107 fclose(unpackd->fpIn); in unpack_descriptor_fini()
108 fclose(unpackd->fpOut); in unpack_descriptor_fini()
115 unpackd_fill_inodesin(const unpack_descriptor_t *unpackd, int level) in unpackd_fill_inodesin() argument
120 * leaf nodes in the next level. For the last level there in unpackd_fill_inodesin()
123 if (level < unpackd->treelevels) { in unpackd_fill_inodesin()
124 unpackd_fill_inodesin(unpackd, level + 1); in unpackd_fill_inodesin()
125 unpackd->inodesin[level] = (unpackd->inodesin[level + 1] + in unpackd_fill_inodesin()
126 unpackd->symbolsin[level + 1]) / 2; in unpackd_fill_inodesin()
128 unpackd->inodesin[level] = 0; in unpackd_fill_inodesin()
161 bytesread = read(in, hdr + prelen, PACK_HEADER_LENGTH - prelen); in unpack_parse_header()
169 unpackd->uncompressed_size = 0; in unpack_parse_header()
171 unpackd->uncompressed_size <<= 8; in unpack_parse_header()
172 unpackd->uncompressed_size |= hdr[i]; in unpack_parse_header()
176 unpackd->treelevels = hdr[6]; in unpack_parse_header()
177 if (unpackd->treelevels > HTREE_MAXLEVEL || unpackd->treelevels < 1) in unpack_parse_header()
181 if ((unpackd->fpIn = fdopen(in, "r")) == NULL) in unpack_parse_header()
183 if ((unpackd->fpOut = fdopen(out, "w")) == NULL) in unpack_parse_header()
187 unpackd->inodesin = in unpack_parse_header()
188 calloc(unpackd->treelevels, sizeof(*(unpackd->inodesin))); in unpack_parse_header()
189 unpackd->symbolsin = in unpack_parse_header()
190 calloc(unpackd->treelevels, sizeof(*(unpackd->symbolsin))); in unpack_parse_header()
191 unpackd->tree = in unpack_parse_header()
192 calloc(unpackd->treelevels, (sizeof(*(unpackd->tree)))); in unpack_parse_header()
193 if (unpackd->inodesin == NULL || unpackd->symbolsin == NULL || in unpack_parse_header()
194 unpackd->tree == NULL) in unpack_parse_header()
198 unpackd->treelevels--; in unpack_parse_header()
201 unpackd->symbol_size = 1; /* EOB */ in unpack_parse_header()
202 for (i = 0; i <= unpackd->treelevels; i++) { in unpack_parse_header()
203 if ((thisbyte = fgetc(unpackd->fpIn)) == EOF) in unpack_parse_header()
205 unpackd->symbolsin[i] = (unsigned char)thisbyte; in unpack_parse_header()
206 unpackd->symbol_size += unpackd->symbolsin[i]; in unpack_parse_header()
208 accepted_bytes(bytes_in, unpackd->treelevels); in unpack_parse_header()
209 if (unpackd->symbol_size > 256) in unpack_parse_header()
211 infile_newdata(unpackd->treelevels); in unpack_parse_header()
214 unpackd->symbol_eob = unpackd->symbol = calloc(1, unpackd->symbol_size); in unpack_parse_header()
215 if (unpackd->symbol == NULL) in unpack_parse_header()
221 * it by reducing 2 from the actual number from the last level. in unpack_parse_header()
223 * We adjust the last level's symbol count by 1 here, because in unpack_parse_header()
227 unpackd->symbolsin[unpackd->treelevels]++; in unpack_parse_header()
228 for (i = 0; i <= unpackd->treelevels; i++) { in unpack_parse_header()
229 unpackd->tree[i] = unpackd->symbol_eob; in unpack_parse_header()
230 for (j = 0; j < unpackd->symbolsin[i]; j++) { in unpack_parse_header()
231 if ((thisbyte = fgetc(unpackd->fpIn)) == EOF) in unpack_parse_header()
233 *unpackd->symbol_eob++ = (char)thisbyte; in unpack_parse_header()
235 infile_newdata(unpackd->symbolsin[i]); in unpack_parse_header()
236 accepted_bytes(bytes_in, unpackd->symbolsin[i]); in unpack_parse_header()
240 unpackd->symbolsin[unpackd->treelevels]++; in unpack_parse_header()
262 * into 'thiscode' bit-by-bit, then output the symbol we got in unpack_decode()
271 while ((thisbyte = fgetc(unpackd->fpIn)) != EOF) { in unpack_decode()
281 for (i = 7; i >= 0; i--) { in unpack_decode()
285 if (thiscode >= unpackd->inodesin[thislevel]) { in unpack_decode()
287 thiscode - unpackd->inodesin[thislevel]; in unpack_decode()
288 if (inlevelindex > unpackd->symbolsin[thislevel]) in unpack_decode()
292 &(unpackd->tree[thislevel][inlevelindex]); in unpack_decode()
293 if ((thissymbol == unpackd->symbol_eob) && in unpack_decode()
294 (bytes_out == unpackd->uncompressed_size)) in unpack_decode()
297 fputc((*thissymbol), unpackd->fpOut); in unpack_decode()
304 if (thislevel > unpackd->treelevels) in unpack_decode()
311 if (bytes_out != unpackd->uncompressed_size) in unpack_decode()
322 if (in == -1) in unpack()
325 if (out == -1) in unpack()