extern uint32_t lzma_mf_bt3_find(lzma_mf *mf, lzma_match *matches) { header_find(true, 3); hash_3_calc(); const uint32_t delta2 = pos - mf->hash[hash_2_value]; const uint32_t cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value]; mf->hash[hash_2_value] = pos; mf->hash[FIX_3_HASH_SIZE + hash_value] = pos; uint32_t len_best = 2; if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) { for ( ; len_best != len_limit; ++len_best) if (*(cur + len_best - delta2) != cur[len_best]) break; matches[0].len = len_best; matches[0].dist = delta2 - 1; matches_count = 1; if (len_best == len_limit) { bt_skip(); return 1; // matches_count } } bt_find(len_best); }
/* find a particular header - return the content */ char *header_content(char *label) { struct header *h = header_find(label); if (h) return h->content; return NULL; }
extern uint32_t lzma_mf_bt2_find(lzma_mf *mf, lzma_match *matches) { header_find(true, 2); hash_2_calc(); const uint32_t cur_match = mf->hash[hash_value]; mf->hash[hash_value] = pos; bt_find(1); }
void header_remove(char *label) { struct header *h = header_find(label); if (!h) return; free(h->label); free(h->content); DLIST_REMOVE(headers, h); free(h); num_headers--; }
extern uint32_t lzma_mf_bt4_find(lzma_mf *mf, lzma_match *matches) { header_find(true, 4); hash_4_calc(); uint32_t delta2 = pos - mf->hash[hash_2_value]; const uint32_t delta3 = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value]; const uint32_t cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value]; mf->hash[hash_2_value] = pos; mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos; mf->hash[FIX_4_HASH_SIZE + hash_value] = pos; uint32_t len_best = 1; if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) { len_best = 2; matches[0].len = 2; matches[0].dist = delta2 - 1; matches_count = 1; } if (delta2 != delta3 && delta3 < mf->cyclic_size && *(cur - delta3) == *cur) { len_best = 3; matches[matches_count++].dist = delta3 - 1; delta2 = delta3; } if (matches_count != 0) { for ( ; len_best != len_limit; ++len_best) if (*(cur + len_best - delta2) != cur[len_best]) break; matches[matches_count - 1].len = len_best; if (len_best == len_limit) { bt_skip(); return matches_count; } } if (len_best < 3) len_best = 3; bt_find(len_best); }
/* add a element to a header list */ void header_add_list(char *label, char *content) { struct header *h = header_find(label); char *p; if (!h) { header_add(label, content); return; } p = (char *)xmalloc(strlen(h->content) + strlen(content) + 3); strcpy(p, h->content); strcat(p, ", "); strcat(p, content); free(h->content); h->content = p; }
/* remove a particular element from a header list */ void header_remove_list(char *label, char *content) { struct header *h = header_find(label); char *p; if (!h) return; p = strstr(h->content, content); if (!p) return; if (!strchr(h->content,',')) { header_remove(label); return; } string_sub(h->content, content, ""); string_sub(h->content, ", ,", ","); trim_string(h->content," ", " "); trim_string(h->content,",", ","); }