/*将不匹配的符号写入原始数据缓冲区*/
if(remaining > 0)
{
orig[opos] = next;
opos++;
/*仍需在前向缓冲区中记录此符号*/
buffer[i] = next;
/*调整剩余字符总数*/
remaining--;
}
/*调整短语长度*/
length++;
}
else
{
/*处理的是字符标记*/
next = 0x00;
for(i=0; i<LZ77_NEXT_BITS; i++)
{
tpos = (sizeof(unsigned char)*8) - LZ77_NEXT_BITS + i;
bit_get((unsigned char *)&next, tpos,bit_get(compressed,ipos));
ipos++;
}
/*将字符写入原始数据缓冲区*/
if(opos > 0)
{
if((temp = (unsigned char*)realloc(orig,opos+1)) == NULL)
{
free(orig);
return -1;
}
orig = temp;
}
else
{
if((orig = (unsigned char *)malloc(1)) == NULL)
return -1;
}
orig[opos] = next;
opos++;
/*在前向缓冲区中记录当前字符*/
if(remaining > 0)
buffer[0] = next;
/*调整剩余数量*/
remaining--;
/*设置短语长度为1*/
length = 1;
}
/*复制前向缓冲中的数据到滑动窗口*/
memmove(&window[0], &window[length],LZ7_WINDOW_BITS - length);
memmove(&window[LZ77_WINDOW_SIZE - length], &buffer[0], length);
}
/*指向原始数据缓冲区*/
*original = orig;
/*返回解压缩的原始数据中的字节数*/
return opos;
}
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx