Posted by: login November 18, 2004
Login in to Rate this Post:
0
?
n = fread(p_la, 1, SW_SIZE + LA_SIZE, f_input) ;
while(n + i == SW_SIZE + LA_SIZE)
{
BiggestMatch(p_sw, p_la, 31) ;
if(p_la >= p_flag)
{
i = 32 - (p_la - p_flag) ;
memcpy(p_start, p_sw, SW_SIZE) ;
p_sw = p_start ;
memcpy((char *)p_la_start, (char *)p_la, i) ;
p_la = p_la_start ;
memset(p_la + i, 0, SW_SIZE + LA_SIZE - i) ;
n = fread(p_la + i, 1, SW_SIZE + LA_SIZE - i, f_input) ;
}
}
p_end = p_la + n + i ;
while(p_la < p_end)
{
if(p_end - p_la <= 31)
BiggestMatch(p_sw, p_la, p_end - p_la - 1) ;
else
BiggestMatch(p_sw, p_la, 31) ;
if(p_la >= p_flag)
{
i = 32 - (p_la - p_flag) ;
memcpy(p_start, p_sw, SW_SIZE) ;
p_sw = p_start ;
memcpy((char *)p_la_start, (char *)p_la, i) ;
p_la = p_la_start ;
memset(p_la + i, 0, SW_SIZE + LA_SIZE - i) ;
p_end = p_la + (LA_SIZE - i) ;
}
}
if(curr_len % 8 != 0) /* if the final inputted char bits does not completly fill
curr_byte ... */
BytesToBits((unsigned char)0, 8 - curr_len) ; /* ... add enough zeros to complete a byte */
printf("\nFinished compressing to file %s\n", outfile_name) ;
break ;
case 'd': case 'D':
printf("\nEnter file to decompress -> ") ;
gets(infile_name) ;
while(infile_name[0] == NULL)
{
printf("\nEnter file to decompress -> ") ;
gets(infile_name) ;
}
f_input = fopen(infile_name,"rb") ; /* opens the test.dat file if it exists */
if(f_input == NULL)
{
printf("\n***FILE NOT FOUND***\n") ;
exit(0) ;
}
printf("\nEnter file to decompress to -> ") ;
gets(outfile_name) ;
while(outfile_name[0] == NULL)
{
printf("\nEnter file to decompress to -> ") ;
gets(outfile_name) ;
}
f_output = fopen(outfile_name,"wb") ;
if(f_output == NULL)
{
printf("\n***ERROR CREATING OUTPUT FILE FOR COMPRESSION***\n") ;
exit(0) ;
}
n = 1 ;
curr_byte = (unsigned char)fgetc(f_input) ;
curr_len = 8 ;
while(n)
{
if(p_la >= p_flag)
{
fwrite(p_la_start, 1, p_la - p_la_start, f_output) ;
memcpy(p_start, p_sw, SW_SIZE) ;
memset(p_la_start, 0, SW_SIZE + LA_SIZE) ;
p_la = p_la_start ;
p_sw = p_start ;
}
n = BitsToBytes(&ch, 1) ;
switch(ch)
{
case 0:
if(ZeroCodeWrite() == 0)
break ;
break ;
case 1:
if(OneCodeWrite() == 0)
break ;
break ;
}
}
fwrite(p_la_start, 1, p_la - p_la_start, f_output) ;
printf("\nFinished uncompressing to file %s\n", outfile_name) ;
break ;
}
fclose(f_input) ;
fclose(f_output) ;
free(p_start) ;
return FAIL ;
}