while(remaining > 0)
{
/*获取压缩数据中的下一位*/
state = bit_get(compressed,ipos);
ipos++;
if(state == 1)
{
/*处理的是短语标记*/
memset(&offset, 0, sizeof(int));
for(i=0; i<LZ77_WINOFF_BITS; i++)
{
tpos = (sizeof(int)*8) - LZ77_WINOFF_BITS + i;
bit_set((unsigned char *)&offset, tpos, bit_get(compressed,ipos));
ipos++;
}
memset(&length, 0, sizeof(int));
for(i=0; i<LZ77_BUFLEN_BITS; i++)
{
tpos = (sizeof(int)*8) - LZ77_BUFLEN_BITS + i;
bit_set((unsigned char *)&length, tpos, bit_get(compressed,ipos));
ipos++;
}
next = 0x00;
for(i=0; i<LZ77_NEXT_BITS; i++)
{
tpos = (sizeof(unsigned char)*8) - LZ77_NEXT_BITS + i;
bit_set((unsigned char *)&next, tpos, bit_get(compressed,ipos));
ipos++;
}
/*确保偏移和长度对系统有正确的字节排序*/
offset = ntohl(offset);
length = ntohl(length);
/*将短语从滑动窗口写入原始数据缓冲区*/
i=0;
if(opos>0)
{
if((temp = (unsigned char *)realloc(orig,opos+length+1)) == NULL)
{
free(orig);
return 1;
}
orig = temp;
}
else
{
if((orig = (unsigned char *)malloc(length+1)) == NULL)
return -1;
}
while(i<length && remaining>0)
{
orig[opos] = window[offset + i];
opos++;
/*在前向缓冲区中记录每个符号,直到准备更新滑动窗口*/
buffer[i] = window[offset + i];
i++;
/*调整剩余符号总数*/
remaining --;
}