generated html version of ttfgasp.cHOME

#include "stdio.h"
#include "stdint.h"

typedef uint32_t u32;
typedef uint16_t u16;
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

uint32_t read32(FILE *f){
	uint32_t c;
	fread(&c,4,1,f);
	c = c >> 16 | c << 16;
	c = c >> 8 & 0xFF00FF | c << 8 & 0xFF00FF00;
	return c;
}

void write32(FILE *f,uint32_t c){
	c = c >> 16 | c << 16;
	c = c >> 8 & 0xFF00FF | c << 8 & 0xFF00FF00;
	fwrite(&c,4,1,f);
}

uint16_t read16(FILE *f){
	uint16_t c;
	fread(&c,2,1,f);
	c = c >> 8 | c << 8;
	return c;
}

void write16(FILE *f, uint16_t c){
	c = c >> 8 | c << 8;
	fwrite(&c,2,1,f);
}

void goloc(FILE *f, long loc){
	fseek(f,loc,SEEK_SET);
}

void gorel(FILE *f, long x){
	fseek(f,x,SEEK_CUR);
}

u32 pad4(u32 x){
	return x/4 + (x%4?1:0);
}

int main(int argc, char **argv){
	FILE *f = fopen(argv[1],"r+");
	// fix the OS/2 table
	while(read32(f)!=*(u32*)"psag");
	unsigned i,cksum_loc = ftell(f);
	uint32_t cksum = read32(f);
	uint32_t gasp_loc = read32(f);
	uint32_t gasp_len = read32(f);
	unsigned gasp_flags;
	printf("gasp is at %x\n",gasp_loc);
	goloc(f,gasp_loc);
	write16(f,1);
	goloc(f,gasp_loc+6);
	sscanf(argv[2],"%x",&gasp_flags);
	write16(f,gasp_flags);
	u32 sum = 0;
	goloc(f,gasp_loc);
	for(i=0;i<pad4(gasp_len);i++)sum += read32(f);
	goloc(f,cksum_loc);
	write32(f,sum);
	return 0;
}