Posted by: login November 18, 2004
Login in to Rate this Post:
0
?
int FindMatch(unsigned char *srch, unsigned char *target, int target_len)
{
offset = 0 ;
while(srch + target_len < target)
{
if(!(memcmp(srch, target, target_len)))
return(target_len) ;
srch++ ;
offset++ ;
}
return FAIL ;
}
int BiggestMatch(unsigned char *srch, unsigned char *target, int target_len)
{
int i ;
for(i = target_len ; i > 1 ; i--)
{
if(FindMatch(srch, target, i))
{
BuildOneCode(i, *(target+i)) ;
p_la += i + 1 ;
p_sw = p_la - SW_SIZE ;
return PASS ;
}
}
BuildZeroCode(*target) ;
p_la++ ;
p_sw = p_la - SW_SIZE ;
return FAIL ;
}
void BuildZeroCode(unsigned char in_char)
{
unsigned char my_char = 0 ;
BytesToBits(my_char, 1) ;
BytesToBits(in_char, 8) ;
}
int BuildOneCode(int len, unsigned char in_char)
{
unsigned char *p_char ;
unsigned char my_char = 1 ;
BytesToBits(my_char, 1) ;
p_char = (unsigned char*)&offset ;
BytesToBits(*p_char, 8) ;
p_char++ ;
BytesToBits(*p_char, 4) ;
p_char = (unsigned char *)&len ;
BytesToBits(*p_char, 5) ;
BytesToBits(in_char, 8) ;
return PASS ;
}
int ZeroCodeWrite(void)
{
unsigned char ch ;
int i ;
i = BitsToBytes(&ch, 8) ;
if(!i)
return FAIL ;
*p_la = ch ;
p_la++ ;
p_sw++ ;
return PASS ;
}
int OneCodeWrite(void)
{
unsigned char ch, *p_ch ;
int i ;
p_ch = (unsigned char *)(&offset) ;
i = BitsToBytes(p_ch, 8) ;
if(!i)
return FAIL ;
i = BitsToBytes(++p_ch, 4) ;
if(!i)
return FAIL ;
p_ch = (unsigned char *)(&len) ;
i = BitsToBytes(p_ch, 5) ;
if(!i)
return FAIL ;
memcpy(p_la, p_sw + offset, len) ;
p_la += len ;
i = BitsToBytes(&ch, 8) ;
*p_la = ch ;
p_la++ ;
p_sw = p_la - SW_SIZE ;
return PASS ;
}