#include #include #include "debug.h" #include "document.h" #include "mf_cob_expand.h" int mf_cob_expand( char *line ) { char newline[ LINE_LENGTH ]; unsigned char this, repeat; int c, l, offset; int i; bzero( newline, LINE_LENGTH ); l = strlen( line ); offset = 0; for( c = 0; c < l; c++ ) { this = line[ c ]; if( this > 127 ) { /* RLE char */ if( this < 225 ) { if( this > 190 ) { /* Repeat 0 */ for( i = ( int )this - 192; i >= 0; i-- ) { newline[ offset++ ] = '0'; } }else { /* Repeat space */ for( i = ( int )this - 128; i >= 0; i-- ) { newline[ offset++ ] = ' '; } } }else { /* This is next char RLE */ repeat = line[ ++c ]; for( i = ( int )this - 224; i >= 0; i-- ) { newline[ offset++ ] = repeat; } } }else { /* Literal */ newline[ offset++ ] = line[ c ]; } } /* Yeah, we could buffer overflow here if we hadn't written both halves. but the buffers are the same size. Oh well. */ strcpy( line, newline ); }