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.

129 lines
2.7 KiB

  1. /*
  2. * d16align.c
  3. *
  4. * Decoding aligned offset block
  5. */
  6. #include "decoder.h"
  7. int NEAR decode_aligned_offset_block(
  8. t_decoder_context * context,
  9. long bufpos,
  10. int amount_to_decode /* yes, it will equal 32768 */
  11. )
  12. {
  13. ulong match_pos;
  14. ulong temp_pos;
  15. ulong dec_bitbuf;
  16. byte *dec_input_curpos;
  17. byte *dec_end_input_pos;
  18. MATCH match_info;
  19. int match_length;
  20. int c;
  21. char m;
  22. char dec_bitcount;
  23. /*
  24. * Store commonly used variables locally
  25. */
  26. dec_bitcount = context->dec_bitcount;
  27. dec_bitbuf = context->dec_bitbuf;
  28. dec_input_curpos = context->dec_input_curpos;
  29. dec_end_input_pos = context->dec_end_input_pos;
  30. /*
  31. * see comment in d16verb.c about why this is a DO loop,
  32. * and why we allow a signed int to hold the value 32768.
  33. */
  34. do
  35. {
  36. /*
  37. * Decode an item
  38. */
  39. DECODE_MAIN_TREE(c);
  40. if ((c -= NUM_CHARS) < 0)
  41. {
  42. context->DComp_Token_Literal(context, (byte) c);
  43. amount_to_decode--;
  44. }
  45. else
  46. {
  47. /*
  48. * Get match length slot
  49. */
  50. if ((match_length = c & NUM_PRIMARY_LENGTHS) == NUM_PRIMARY_LENGTHS)
  51. {
  52. DECODE_LEN_TREE_NOEOFCHECK(match_length);
  53. }
  54. /*
  55. * Get match position slot
  56. */
  57. m = c >> NL_SHIFT;
  58. if (m > 2)
  59. {
  60. if (dec_extra_bits[ m ] >= 3)
  61. {
  62. if (dec_extra_bits[m]-3)
  63. {
  64. /* no need to getbits17 */
  65. GET_BITS_NOEOFCHECK(dec_extra_bits[ m ] - 3, temp_pos);
  66. }
  67. else
  68. {
  69. temp_pos = 0;
  70. }
  71. match_pos = MP_POS_minus2[m] + (temp_pos << 3);
  72. DECODE_ALIGNED_NOEOFCHECK(temp_pos);
  73. match_pos += temp_pos;
  74. }
  75. else
  76. {
  77. if (dec_extra_bits[m])
  78. {
  79. GET_BITS_NOEOFCHECK(dec_extra_bits[ m ], match_pos);
  80. match_pos += MP_POS_minus2[m];
  81. }
  82. else
  83. {
  84. match_pos = MP_POS_minus2[m];
  85. }
  86. }
  87. context->dec_last_matchpos_offset[2] = context->dec_last_matchpos_offset[1];
  88. context->dec_last_matchpos_offset[1] = context->dec_last_matchpos_offset[0];
  89. context->dec_last_matchpos_offset[0] = match_pos;
  90. }
  91. else
  92. {
  93. match_pos = context->dec_last_matchpos_offset[m];
  94. if (m)
  95. {
  96. context->dec_last_matchpos_offset[m] = context->dec_last_matchpos_offset[0];
  97. context->dec_last_matchpos_offset[0] = match_pos;
  98. }
  99. }
  100. match_length += MIN_MATCH;
  101. match_info.Len = match_length;
  102. match_info.Dist = match_pos;
  103. context->DComp_Token_Match(context, match_info);
  104. amount_to_decode -= match_length;
  105. }
  106. } while (amount_to_decode > 0);
  107. context->dec_bitcount = dec_bitcount;
  108. context->dec_bitbuf = dec_bitbuf;
  109. context->dec_input_curpos = dec_input_curpos;
  110. return 0;
  111. }