All pastes #521448 Raw Edit

Untitled

public text v1 · immutable
#521448 ·published 2007-05-30 05:55 UTC
rendered paste body
#include <stdio.h>

int usage() {
	printf("Usage: dmc2raw in.dmc out.raw");
	return 1;
}

int main(int argc, char *argv[]) {
	FILE *in,*out;
	int counter=32;
	int c;
	if(argc < 3) return usage();
	in=fopen(argv[1],"rb");
	out=fopen(argv[2],"wb");
        if(!in || !out) return 1;
	while( (c=getc(in)) != EOF ) {
		int bit=8;
		c &= 0xFF;
		while(bit--) {
			if(!(c&1) && counter > 0) counter--;
			if((c&1) && counter < 63) counter++;
			fputc( (counter*4) & 0xFF, out);
			c >>= 1;
		}
	}
	fclose(in);
	fclose(out);	
        return 0;
}