view window/runlengh.cc @ 36:6d1a5b7f0838

* Updated copyright/license information
author thib
date Sun, 15 Mar 2009 18:47:02 +0000
parents 223b71206888
children
line wrap: on
line source

/*
 * Copyright (c) 2004-2006  Kazunori "jagarl" Ueno
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include<stdio.h>

int main(int argc, char** argv) {
	if (argc != 2) return 0;
	FILE* f = fopen(argv[1],"rb");
	if (f==0) return 0;
	int i,j;
	fseek(f,0,2);
	int sz=ftell(f);
	fseek(f,0,0);
	char* buf=new char[sz];
	char* out = new char[sz];
	fread(buf,sz,1,f);
	fclose(f);
	int oc=0;
	for (i=0; i<sz; i++) {
		int d = buf[i];
		int c = d & 0xff;
		switch(c) {
		case 0x61: c=1; break;
		case 0xa2: c=2; break;
		case 0xc1: c=3; break;
		case 0xdf: c=4; break;
		case 0xde: c=5; break;
		case 0xff: c=6; break;
		}
		for (j=i; j<sz; j++)
			if (buf[j] != d) break;
		int cnt = j-i;
		if (cnt < 16) {
			out[oc++] = c | 0x08 | (cnt<<4);
		} else if (cnt < 256){
			out[oc++] = c;
			out[oc++] = cnt;
		} else fprintf(stderr,"cnt %d\n",cnt);
		if (j == sz) break;
		i = j-1;
	}
	printf("int button1_cnt = %d;\nchar button1[%d] = {\n\t",oc,oc+1);
	for (i=0; i<oc; i++) {
		printf("0x%02x,",int(out[i])&0xff);
		if ( (i&15) == 15) printf("\n\t");
	}
	printf("\n\t0xff};\n");
	return 0;
}
/* 2834bytes*/