Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9 KiB

  1. /*
  2. * decinit.c
  3. *
  4. * Initialisation routines for LZX decoder
  5. */
  6. #include "decoder.h"
  7. #include <memory.h>
  8. #pragma intrinsic(memset)
  9. /*
  10. * Allocate memory for decompression
  11. */
  12. bool NEAR allocate_decompression_memory(t_decoder_context *context)
  13. {
  14. ulong pos_start;
  15. context->dec_num_position_slots = 4;
  16. pos_start = 4;
  17. while (1)
  18. {
  19. pos_start += 1L << dec_extra_bits[context->dec_num_position_slots];
  20. context->dec_num_position_slots++;
  21. if (pos_start >= context->dec_window_size)
  22. break;
  23. }
  24. if (!(context->dec_mem_window = (byte *) context->dec_malloc( context->dec_mallochandle, context->dec_window_size+(MAX_MATCH+4))))
  25. return false;
  26. return true;
  27. }
  28. /*
  29. * Set/reset decoder trees to initial state
  30. */
  31. void NEAR reset_decoder_trees(t_decoder_context *context)
  32. {
  33. memset(context->dec_main_tree_len, 0, MAIN_TREE_ELEMENTS);
  34. memset(context->dec_main_tree_prev_len, 0, MAIN_TREE_ELEMENTS);
  35. memset(context->dec_secondary_length_tree_len, 0, NUM_SECONDARY_LENGTHS);
  36. memset(context->dec_secondary_length_tree_prev_len, 0, NUM_SECONDARY_LENGTHS);
  37. }
  38. /*
  39. * Miscellaneous state initialisations
  40. */
  41. void NEAR decoder_misc_init(t_decoder_context *context)
  42. {
  43. context->dec_last_matchpos_offset[0] = 1;
  44. context->dec_last_matchpos_offset[1] = 1;
  45. context->dec_last_matchpos_offset[2] = 1;
  46. context->dec_bufpos = 0;
  47. context->dec_position_at_start = 0;
  48. context->dec_decoder_state = DEC_STATE_START_NEW_BLOCK;
  49. context->dec_block_size = 0;
  50. /* so that initialise_decoder_bitbuf() will succeed */
  51. context->dec_block_type = BLOCKTYPE_INVALID;
  52. context->dec_first_time_this_group = true;
  53. context->dec_current_file_size = 0;
  54. context->dec_error_condition = false;
  55. }