Category : Files from Magazines
Archive   : DDJ0589.ZIP
Filename : RLE.ASC
by Phil Daley
[LISTING ONE]
/*****************************************************************************
* PROGRAM RLE.C *
* written by Phil Daley *
* February 3, 1989 *
*****************************************************************************/
int main(void);
int uncompress(unsigned char *,int,unsigned char *) ;
int compress(unsigned char *,int,unsigned char *) ;
int process_comp(unsigned char *,int,int) ;
int process_uncomp(unsigned char *,int,int) ;
#include
#include
unsigned char screen[24][80] = {
"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»",
"º º",
"º º",
"º º",
"º o This is a sample screen that would be typical of the type º",
"º that would present information to a user for instructions º",
"º or a help screen, etc. º",
"º º",
"º º",
"º o While it contains a lot of unique characters in the text º",
"º lines, it also contains a lot of white space in empty lines º",
"º and margins. º",
"º º",
"º º",
"º o It would be unusual for the compression algorithm used º",
"º here to find any repeated characters other than spaces º",
"º and the border. º",
"º º",
"º º",
"º º",
"º º",
"º º",
"º º",
"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"} ;
unsigned char new[2000] ;
/********************** main ***********************/
int main() /* this is a demo main */
{
int orig_length = 1920 ;
int compressed_length ;
int i, j ;
compressed_length = compress(screen[0],orig_length,new) ;
printf("The original screen (1920) compressed to %d bytes\n",compressed_length) ;
memset(screen,0,1920) ; /* erase the orig */
orig_length = uncompress(new,compressed_length,screen[0]) ;
printf("And back to the original (%d) length\n",orig_length) ;
for (i = 0; i < 24; i++)
for (j = 0; j < 80; j++) /* show it */
printf("%c",screen[i][j]) ;
return(0) ;
}
/*********************** compress ****************************/
compress(in_array,in_size,out_array)
unsigned char *in_array ;
int in_size ;
unsigned char *out_array ;
{
register int i = 0 ;
register int j = 0 ;
register int k ;
register int l ;
while (i < in_size) {
if (in_array[i] == in_array[i + 1] && in_array[i + 1] == in_array[i + 2]) {
k = process_comp(in_array,i,in_size) ;
out_array[j++] = (unsigned char)k | 0x80 ;
out_array[j++] = in_array[i] ;
i += k ;
}
else {
k = process_uncomp(in_array,i,in_size) ;
out_array[j++] = (unsigned char)k ;
for (l = 0; l < k; l++)
out_array[j++] = in_array[i++] ;
}
}
return(j) ;
}
/*********************** process_comp ****************************/
process_comp(in_array,i,in_size)
unsigned char *in_array ;
int i ;
int in_size ;
{
register int len = 0 ;
while (in_array[i] == in_array[i + 1] && i < in_size) {
len++ ;
i++ ;
if (len == 126)
break ;
}
return(len + 1) ;
}
/*********************** process_uncomp ****************************/
process_uncomp(in_array,i,in_size)
unsigned char *in_array ;
int i ;
int in_size ;
{
register int len = 0 ;
while ((in_array[i] != in_array[i + 1] || in_array[i] != in_array[i + 2]) && i < in_size) {
len++ ;
i++ ;
if (len == 127)
break ;
}
return(len) ;
}
/********************** uncompress ***********************/
uncompress(in_array,in_size,out_array)
unsigned char *in_array ;
int in_size ;
unsigned char *out_array ;
{
register int i ;
register int j ;
register int k=0 ;
register int l ;
for (i = 0; i < in_size;) {
j = in_array[i++] ;
if (j > 128) {
for (j -= 128; j > 0; j--)
out_array[k++] = in_array[i] ;
i++ ;
}
else
for (l = 0; l < j; l++)
out_array[k++] = in_array[i++] ;
}
return(k) ;
}
-30-
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/