generated html version of bdfcheck.cHOME

#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
#include "u8.h"
/* checks the bdf of neoletters for consistency */

int xdgval(int c){
	if(c >= '0' && c <= '9')return c - '0';
	if(c >= 'A' && c <= 'F')return c - 'A' + 10;
	if(c >= 'a' && c <= 'f')return c - 'a' + 10;
}
char line[300];
char fontname[100];
int fontasc, fontdesc, pixelsize;
int pxw,pxh,stx,sty;

int main () {
	/* PARSE A BDF FROM STDIN */
	fgets(line,300,stdin);
	float vernum;
	sscanf(line,"STARTFONT %f",&vernum);
	fgets(line,300,stdin);
	sscanf(line,"FONT %99s",fontname);
	fgets(line,300,stdin);
	int ptsz, xdpi, ydpi;
	sscanf(line,"SIZE %d %d %d",&ptsz,&xdpi,&ydpi);
	fgets(line,300,stdin);
	sscanf(line,"FONTBOUNDINGBOX %d %d %d %d",&pxw,&pxh,&stx,&sty);
	do fgets(line,300,stdin);
	while(strncmp(line,"STARTPROPERTIES",15));
	int i,nprops;
	sscanf(line,"STARTPROPERTIES %d",&nprops);
	for(i=0;i<nprops;i++){
		fgets(line,300,stdin);
		if(!strncmp(line,"PIXEL_SIZE",10)){
			sscanf(line,"PIXEL_SIZE %d",&pixelsize);
		}else if(!strncmp(line,"FONT_ASCENT",11)){
			sscanf(line,"FONT_ASCENT %d",&fontasc);
		}else if(!strncmp(line,"FONT_DESCENT",12)){
			sscanf(line,"FONT_DESCENT %d",&fontdesc);
		}
	}
	do fgets(line,300,stdin);
	while(strncmp(line,"CHARS",5));
	int nchars;
	sscanf(line,"CHARS %d",&nchars);
//	printf("loading 00%, 0\r",nchars);
	for(i=0;i<nchars;i++){
		fgets(line,300,stdin);
		char cname[100];
		sscanf(line,"STARTCHAR %99s",cname);
		fgets(line,300,stdin);
		int ccode;
		sscanf(line,"ENCODING %d",&ccode);
		do fgets(line,300,stdin);
		while(strncmp(line,"DWIDTH",6));
		int dwidth;
		sscanf(line,"DWIDTH %d",&dwidth);
		fgets(line,300,stdin);
		int bbx[4];
		sscanf(line,"BBX %d %d %d %d",bbx, bbx+1,bbx+2,bbx+3);
		if(dwidth != u8chrwid(ccode)*9)printf("U%04x has wrong dwidth\n",ccode);
		if(bbx[2]<0)printf("U%04x has stray pixels left\n",ccode);
		if(bbx[3]<-4)printf("U%04x has stray pixels below\n",ccode);
		if(bbx[1]+bbx[3]+4 >16)printf("U%04x has stray pixels above\n",ccode);
		if(bbx[0]+bbx[2]> u8chrwid(ccode)*9)printf("U%04x has stray pixels right\n",ccode);
		int bytewidth = bbx[0]/8 + (bbx[0] % 8 ? 1 : 0);
		int bmplen = bytewidth * bbx[1];
		fgets(line,300,stdin);
//		printf("loading %02d% U%04x,%s\r",i*100/nchars,ccode,cname);
		do fgets(line,300,stdin);
		while(strncmp(line,"ENDCHAR",7));
	}
}