shithub: neatmkfn

Download patch

ref: c55c928fc9ce1cdbb8fa8a7aeeb6eea54e2b7657
parent: e477744371b17cb5cebe277a94a1b3c599173ffe
author: Jacob Moody <moody@posixcafe.org>
date: Mon Feb 13 20:09:33 EST 2023

initial port

--- a/afm.c
+++ b/afm.c
@@ -1,8 +1,8 @@
 /* AFM fonts */
+#include <u.h>
+#include <libc.h>
 #include <ctype.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include "mkfn.h"
 
 #define TOKLEN		256
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,14 @@
+</$objtype/mkfile
+
+BIN=/$objtype/bin/
+TARG=neatmkfn
+
+OFILES=\
+	mkfn.$O\
+	trfn.$O\
+	sbuf.$O\
+	tab.$O\
+	afm.$O\
+	otf.$O\
+
+</sys/src/cmd/mkone
--- a/mkfn.c
+++ b/mkfn.c
@@ -15,10 +15,10 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include <u.h>
+#include <libc.h>
 #include <ctype.h>
 #include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
 #include "mkfn.h"
 
 #define LEN(a)		((sizeof(a) / sizeof((a)[0])))
--- a/mkfn.h
+++ b/mkfn.h
@@ -26,6 +26,9 @@
 extern int mkfn_pos;		/* include glyph positions */
 extern int mkfn_dry;		/* generate no output */
 
+#pragma incomplete struct sbuf
+#pragma incomplete struct tab
+
 /* variable length string buffer */
 struct sbuf *sbuf_make(void);
 void sbuf_free(struct sbuf *sb);
--- a/otf.c
+++ b/otf.c
@@ -1,10 +1,7 @@
 /* OpenType and TrueType fonts */
-#include <arpa/inet.h>
-#include <errno.h>
+#include <u.h>
+#include <libc.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
 #include "mkfn.h"
 
 #define MAX(a, b)	((a) < (b) ? (b) : (a))
@@ -15,12 +12,15 @@
 #define GNLEN		(64)
 #define NGRPS		2048
 
-#define U32(buf, off)		(htonl(*(u32 *) ((buf) + (off))))
-#define U16(buf, off)		(htons(*(u16 *) ((buf) + (off))))
-#define U8(buf, off)		(*(u8 *) ((buf) + (off)))
-#define S16(buf, off)		((s16) htons(*(u16 *) ((buf) + (off))))
-#define S32(buf, off)		((s32) htonl(*(u32 *) ((buf) + (off))))
+#define htonl(x)		(x)
+#define htons(x)		(x)
 
+#define U32(buf, off)		(htonl(*(u32 *) (((uchar*)buf) + (off))))
+#define U16(buf, off)		(htons(*(u16 *) (((uchar*)buf) + (off))))
+#define U8(buf, off)		(*(u8 *) (((uchar*)buf) + (off)))
+#define S16(buf, off)		((s16) htons(*(u16 *) (((uchar*)buf) + (off))))
+#define S32(buf, off)		((s32) htonl(*(u32 *) (((uchar*)buf) + (off))))
+
 #define GCTXLEN		16	/* number of context backtrack coverage arrays */
 
 typedef unsigned int u32;
@@ -81,11 +81,11 @@
 	int nrecs = U16(otf->off, 4);
 	int i;
 	for (i = 0; i < nrecs; i++) {
-		void *rec = otf->off + 12 + i * 16;	/* an otf table record */
+		char *rec = (char*)otf->off + 12 + i * 16;	/* an otf table record */
 		if (!strncmp(rec, name, 4))
-			return otf->otf + U32(rec, 8);
+			return (uchar*)otf->otf + U32(rec, 8);
 	}
-	return NULL;
+	return nil;
 }
 
 /* obtain postscript font name from name table */
@@ -92,11 +92,11 @@
 static void otf_name(struct otf *otf, void *tab)
 {
 	char name[256];
-	void *str = tab + U16(tab, 4);		/* storage area */
+	uchar *str = (uchar*)tab + U16(tab, 4);	/* storage area */
 	int n = U16(tab, 2);			/* number of name records */
 	int i;
 	for (i = 0; i < n; i++) {
-		void *rec = tab + 6 + 12 * i;
+		uchar *rec = (uchar*)tab + 6 + 12 * i;
 		int pid = U16(rec, 0);		/* platform id */
 		int eid = U16(rec, 2);		/* encoding id */
 		int lid = U16(rec, 4);		/* language id */
@@ -115,11 +115,11 @@
 static void otf_cmap4(struct otf *otf, void *cmap4)
 {
 	int nsegs;
-	void *ends, *begs, *deltas, *offsets;
+	uchar *ends, *begs, *deltas, *offsets;
 	int beg, end, delta, offset;
 	int i, j;
 	nsegs = U16(cmap4, 6) / 2;
-	ends = cmap4 + 14;
+	ends = (uchar*)cmap4 + 14;
 	begs = ends + 2 * nsegs + 2;
 	deltas = begs + 2 * nsegs;
 	offsets = deltas + 2 * nsegs;
@@ -145,10 +145,10 @@
 	int nrecs = U16(cmap, 2);
 	int i;
 	for (i = 0; i < nrecs; i++) {
-		void *rec = cmap + 4 + i * 8;	/* a cmap record */
+		uchar *rec = (uchar*)cmap + 4 + i * 8;	/* a cmap record */
 		int plat = U16(rec, 0);
 		int enc = U16(rec, 2);
-		void *tab = cmap + U32(rec, 4);	/* a cmap subtable */
+		uchar *tab = (uchar*)cmap + U32(rec, 4);	/* a cmap subtable */
 		int fmt = U16(tab, 0);
 		if (plat == 3 && enc == 1 && fmt == 4)
 			otf_cmap4(otf, tab);
@@ -157,14 +157,14 @@
 
 static void otf_post(struct otf *otf, void *post)
 {
-	void *post2;			/* version 2.0 header */
-	void *index;			/* glyph name indices */
-	void *names;			/* glyph names */
+	uchar *post2;			/* version 2.0 header */
+	uchar *index;			/* glyph name indices */
+	uchar *names;			/* glyph names */
 	int cname = 0;
 	int i;
 	if (U32(post, 0) != 0x20000)
 		return;
-	post2 = post + 32;
+	post2 = (uchar*)post + 32;
 	glyph_n = U16(post2, 0);
 	index = post2 + 2;
 	names = index + 2 * glyph_n;
@@ -183,11 +183,11 @@
 
 static void otf_glyf(struct otf *otf, void *glyf)
 {
-	void *maxp = otf_table(otf, "maxp");
-	void *head = otf_table(otf, "head");
-	void *loca = otf_table(otf, "loca");
-	void *gdat;
-	void *gdat_next;
+	uchar *maxp = otf_table(otf, "maxp");
+	uchar *head = otf_table(otf, "head");
+	uchar *loca = otf_table(otf, "loca");
+	uchar *gdat;
+	uchar *gdat_next;
 	int n = U16(maxp, 4);
 	int fmt = U16(head, 50);
 	int i, j;
@@ -195,11 +195,11 @@
 		glyph_n = n;
 	for (i = 0; i < n; i++) {
 		if (fmt) {
-			gdat = glyf + U32(loca, 4 * i);
-			gdat_next = glyf + U32(loca, 4 * (i + 1));
+			gdat = (uchar*)glyf + U32(loca, 4 * i);
+			gdat_next = (uchar*)glyf + U32(loca, 4 * (i + 1));
 		} else {
-			gdat = glyf + U16(loca, 2 * i) * 2;
-			gdat_next = glyf + U16(loca, 2 * (i + 1)) * 2;
+			gdat = (uchar*)glyf + U16(loca, 2 * i) * 2;
+			gdat_next = (uchar*)glyf + U16(loca, 2 * (i + 1)) * 2;
 		}
 		if (gdat < gdat_next)
 			for (j = 0; j < 4; j++)
@@ -225,7 +225,7 @@
 	int i, j;
 	int n = U16(kern, 2);		/* number of kern subtables */
 	for (i = 0; i < n; i++) {
-		void *tab = kern + off;	/* a kern subtable */
+		uchar *tab = (uchar*)kern + off;	/* a kern subtable */
 		int cov = U16(tab, 4);
 		off += U16(tab, 2);
 		if ((cov >> 8) == 0 && (cov & 1)) {	/* format 0 */
@@ -370,13 +370,13 @@
 	int ncov, nvals;
 	int vlen = valuerecord_len(vfmt);
 	int i;
-	cov = coverage(sub + U16(sub, 2), &ncov);
+	cov = coverage((uchar*)sub + U16(sub, 2), &ncov);
 	if (fmt == 1) {
 		for (i = 0; i < ncov; i++) {
-			if (valuerecord_small(vfmt, sub + 6))
+			if (valuerecord_small(vfmt, (uchar*)sub + 6))
 				continue;
 			printf("gpos %s 1 %s", feat, glyph_name[cov[i]]);
-			valuerecord_print(vfmt, sub + 6);
+			valuerecord_print(vfmt, (uchar*)sub + 6);
 			printf("\n");
 		}
 	}
@@ -383,10 +383,10 @@
 	if (fmt == 2) {
 		nvals = U16(sub, 6);
 		for (i = 0; i < nvals; i++) {
-			if (valuerecord_small(vfmt, sub + 6))
+			if (valuerecord_small(vfmt, (uchar*)sub + 6))
 				continue;
 			printf("gpos %s 1 %s", feat, glyph_name[cov[i]]);
-			valuerecord_print(vfmt, sub + 8 + i * vlen);
+			valuerecord_print(vfmt, (uchar*)sub + 8 + i * vlen);
 			printf("\n");
 		}
 	}
@@ -405,9 +405,9 @@
 	vrlen = valuerecord_len(vfmt1) + valuerecord_len(vfmt2);
 	if (fmt == 1) {
 		int nc1 = U16(sub, 8);
-		int *cov = coverage(sub + U16(sub, 2), NULL);
+		int *cov = coverage((uchar*)sub + U16(sub, 2), nil);
 		for (i = 0; i < nc1; i++) {
-			void *c2 = sub + U16(sub, 10 + 2 * i);
+			uchar *c2 = (uchar*)sub + U16((uchar*)sub, 10 + 2 * i);
 			int nc2 = U16(c2, 0);
 			for (j = 0; j < nc2; j++) {
 				int second = U16(c2 + 2 + (2 + vrlen) * j, 0);
@@ -430,8 +430,8 @@
 		static int gl1[NGLYPHS], gl2[NGLYPHS];
 		static int cls1[NGLYPHS], cls2[NGLYPHS];
 		static int grp1[NGLYPHS], grp2[NGLYPHS];
-		int ngl1 = classdef(sub + U16(sub, 8), gl1, cls1);
-		int ngl2 = classdef(sub + U16(sub, 10), gl2, cls2);
+		int ngl1 = classdef((uchar*)sub + U16(sub, 8), gl1, cls1);
+		int ngl2 = classdef((uchar*)sub + U16(sub, 10), gl2, cls2);
 		int ncls1 = U16(sub, 12);
 		int ncls2 = U16(sub, 14);
 		for (i = 0; i < ncls1; i++)
@@ -442,14 +442,14 @@
 			for (j = 0; j < ncls2; j++) {
 				fmtoff1 = 16 + (i * ncls2 + j) * vrlen;
 				fmtoff2 = fmtoff1 + valuerecord_len(vfmt1);
-				if (valuerecord_small(vfmt1, sub + fmtoff1) &&
-					valuerecord_small(vfmt2, sub + fmtoff2))
+				if (valuerecord_small(vfmt1, (uchar*)sub + fmtoff1) &&
+					valuerecord_small(vfmt2, (uchar*)sub + fmtoff2))
 					continue;
 				printf("gpos %s %d", feat, 2);
 				printf(" @%d", grp1[i]);
-				valuerecord_print(vfmt1, sub + fmtoff1);
+				valuerecord_print(vfmt1, (uchar*)sub + fmtoff1);
 				printf(" @%d", grp2[j]);
-				valuerecord_print(vfmt2, sub + fmtoff2);
+				valuerecord_print(vfmt2, (uchar*)sub + fmtoff2);
 				printf("\n");
 			}
 		}
@@ -467,7 +467,7 @@
 	int igrp, ogrp;
 	if (fmt != 1)
 		return;
-	cov = coverage(sub + U16(sub, 2), NULL);
+	cov = coverage((uchar*)sub + U16(sub, 2), nil);
 	n = U16(sub, 4);
 	icov = malloc(n * sizeof(icov[0]));
 	ocov = malloc(n * sizeof(ocov[0]));
@@ -518,16 +518,16 @@
 	int mcnt;		/* mark coverage size */
 	int bcnt;		/* base coverage size */
 	int ccnt;		/* class count */
-	void *marks;		/* mark array table */
-	void *bases;		/* base array table */
+	uchar *marks;		/* mark array table */
+	uchar *bases;		/* base array table */
 	int i, j;
 	if (fmt != 1)
 		return;
-	mcov = coverage(sub + U16(sub, 2), &mcnt);
-	bcov = coverage(sub + U16(sub, 4), &bcnt);
+	mcov = coverage((uchar*)sub + U16(sub, 2), &mcnt);
+	bcov = coverage((uchar*)sub + U16(sub, 4), &bcnt);
 	ccnt = U16(sub, 6);
-	marks = sub + U16(sub, 8);
-	bases = sub + U16(sub, 10);
+	marks = (uchar*)sub + U16(sub, 8);
+	bases = (uchar*)sub + U16(sub, 10);
 	/* define a group for base glyphs */
 	bgrp = ggrp_coverage(bcov, bcnt);
 	/* define a group for each mark class */
@@ -583,17 +583,17 @@
 	int mcnt;		/* mark coverage size */
 	int lcnt;		/* ligature coverage size */
 	int ccnt;		/* class count */
-	void *marks;		/* mark array table */
-	void *ligas;		/* ligature array table */
+	uchar *marks;		/* mark array table */
+	uchar *ligas;		/* ligature array table */
 	int i, j, k;
 	/* only marks at the end of ligatures are supported */
 	if (fmt != 1)
 		return;
-	mcov = coverage(sub + U16(sub, 2), &mcnt);
-	lcov = coverage(sub + U16(sub, 4), &lcnt);
+	mcov = coverage((uchar*)sub + U16(sub, 2), &mcnt);
+	lcov = coverage((uchar*)sub  + U16(sub, 4), &lcnt);
 	ccnt = U16(sub, 6);
-	marks = sub + U16(sub, 8);
-	ligas = sub + U16(sub, 10);
+	marks = (uchar*)sub  + U16(sub, 8);
+	ligas = (uchar*)sub  + U16(sub, 10);
 	/* define a group for ligatures */
 	lgrp = ggrp_coverage(lcov, lcnt);
 	/* define a group for each mark class */
@@ -622,7 +622,7 @@
 	printf("gsec %d\n", sec + 1);
 	/* GPOS rules for each ligature before a mark */
 	for (i = 0; i < lcnt; i++) {
-		void *ligattach = ligas + U16(ligas, 2 + 2 * i);
+		uchar *ligattach = ligas + U16(ligas, 2 + 2 * i);
 		int comcnt = U16(ligattach, 0);		/* component count */
 		/* considering only the last component */
 		k = comcnt - 1;
@@ -631,7 +631,7 @@
 		if (!U16(ligattach, 2 + 2 * ccnt * k))
 			continue;
 		for (j = 0; j < ccnt; j++) {
-			char *base = ligattach + U16(ligattach, 2 + 2 * ccnt * k + 2 * j);
+			uchar *base = ligattach + U16(ligattach, 2 + 2 * ccnt * k + 2 * j);
 			int dx = uwid(S16(base, 2)) - uwid(glyph_wid[lcov[i]]);
 			int dy = uwid(S16(base, 4));
 			if (otf_r2l(feat)) {
@@ -689,7 +689,7 @@
 	int fmt = U16(sub, 0);
 	int ncov;
 	int i;
-	cov = coverage(sub + U16(sub, 2), &ncov);
+	cov = coverage((uchar*)sub + U16(sub, 2), &ncov);
 	if (fmt == 1) {
 		for (i = 0; i < ncov; i++) {
 			int dst = cov[i] + S16(sub, 4);
@@ -724,10 +724,10 @@
 	int n, i, j;
 	if (fmt != 1)
 		return;
-	cov = coverage(sub + U16(sub, 2), NULL);
+	cov = coverage((uchar*)sub + U16(sub, 2), nil);
 	n = U16(sub, 4);
 	for (i = 0; i < n; i++) {
-		void *alt = sub + U16(sub, 6 + 2 * i);
+		uchar *alt = (uchar*)sub + U16(sub, 6 + 2 * i);
 		int nalt = U16(alt, 0);
 		for (j = 0; j < nalt; j++) {
 			printf("gsub %s %d", feat, 2 + gctx_len(ctx, 1));
@@ -749,10 +749,10 @@
 	int n, i, j, k;
 	if (fmt != 1)
 		return;
-	cov = coverage(sub + U16(sub, 2), NULL);
+	cov = coverage((uchar*)sub + U16(sub, 2), nil);
 	n = U16(sub, 4);
 	for (i = 0; i < n; i++) {
-		void *set = sub + U16(sub, 6 + 2 * i);
+		uchar *set = (uchar*)sub + U16(sub, 6 + 2 * i);
 		int nset = U16(set, 0);
 		for (j = 0; j < nset; j++) {
 			void *lig = set + U16(set, 2 + 2 * j);
@@ -774,7 +774,7 @@
 static void otf_gsubtype6(struct otf *otf, void *sub, char *feat, void *gsub)
 {
 	struct gctx ctx = {{0}};
-	void *lookups = gsub + U16(gsub, 8);
+	uchar *lookups = (uchar*)gsub + U16(gsub, 8);
 	int fmt = U16(sub, 0);
 	int *cov;
 	int i, j, nsub, ncov;
@@ -785,7 +785,7 @@
 	}
 	ctx.bn = U16(sub, off);
 	for (i = 0; i < ctx.bn; i++) {
-		cov = coverage(sub + U16(sub, off + 2 + 2 * i), &ncov);
+		cov = coverage((uchar*)sub + U16(sub, off + 2 + 2 * i), &ncov);
 		ctx.bgrp[i] = ggrp_coverage(cov, ncov);
 		free(cov);
 	}
@@ -792,7 +792,7 @@
 	off += 2 + 2 * ctx.bn;
 	ctx.in = U16(sub, off);
 	for (i = 0; i < ctx.in; i++) {
-		cov = coverage(sub + U16(sub, off + 2 + 2 * i), &ncov);
+		cov = coverage((uchar*)sub + U16(sub, off + 2 + 2 * i), &ncov);
 		ctx.igrp[i] = ggrp_coverage(cov, ncov);
 		free(cov);
 	}
@@ -799,7 +799,7 @@
 	off += 2 + 2 * ctx.in;
 	ctx.ln = U16(sub, off);
 	for (i = 0; i < ctx.ln; i ++) {
-		cov = coverage(sub + U16(sub, off + 2 + 2 * i), &ncov);
+		cov = coverage((uchar*)sub + U16(sub, off + 2 + 2 * i), &ncov);
 		ctx.lgrp[i] = ggrp_coverage(cov, ncov);
 		free(cov);
 	}
@@ -807,12 +807,12 @@
 	nsub = U16(sub, off);	/* nsub > 1 is not supported */
 	for (i = 0; i < nsub && i < 1; i++) {
 		int lidx = U16(sub, off + 2 + 4 * i + 2);
-		void *lookup = lookups + U16(lookups, 2 + 2 * lidx);
+		uchar *lookup = lookups + U16(lookups, 2 + 2 * lidx);
 		int ltype = U16(lookup, 0);
 		int ntabs = U16(lookup, 4);
 		ctx.seqidx = U16(sub, off + 2 + 4 * i);
 		for (j = 0; j < ntabs; j++) {
-			void *tab = lookup + U16(lookup, 6 + 2 * j);
+			uchar *tab = lookup + U16(lookup, 6 + 2 * j);
 			int type = ltype;
 			if (type == 7) {	/* extension substitution */
 				type = U16(tab, 2);
@@ -841,8 +841,8 @@
 			char *stag, char *ltag,
 			struct otflookup *lookups, int lookups_n)
 {
-	void *feats = gtab + U16(gtab, 6);
-	void *feat = feats + U16(featrec, 4);
+	uchar *feats = (uchar*)gtab + U16(gtab, 6);
+	uchar *feat = (uchar*)feats + U16(featrec, 4);
 	char ftag[8] = "";
 	int n = U16(feat, 2);
 	int i, j;
@@ -870,7 +870,7 @@
 static int otf_lang(struct otf *otf, void *gtab, void *lang, char *stag, char *ltag,
 		struct otflookup *lookups, int lookups_n)
 {
-	void *feats = gtab + U16(gtab, 6);
+	uchar *feats = (uchar*)gtab + U16(gtab, 6);
 	int featidx = U16(lang, 2);
 	int nfeat = U16(lang, 4);
 	int i;
@@ -907,7 +907,7 @@
 /* extract lookup tables for all features of the given gsub/gpos table */
 static int otf_gtab(struct otf *otf, void *gpos, struct otflookup *lookups)
 {
-	void *scripts = gpos + U16(gpos, 4);
+	uchar *scripts = (uchar*)gpos + U16(gpos, 4);
 	int nscripts, nlangs;
 	void *script;
 	char stag[8], ltag[8];		/* script and language tags */
@@ -915,7 +915,7 @@
 	int n = 0;
 	nscripts = U16(scripts, 0);
 	for (i = 0; i < nscripts; i++) {
-		void *grec = scripts + 2 + 6 * i;
+		uchar *grec = scripts + 2 + 6 * i;
 		memcpy(stag, grec, 4);
 		stag[4] = '\0';
 		if (!mkfn_script(stag, nscripts))
@@ -922,15 +922,15 @@
 			continue;
 		script = scripts + U16(grec, 4);
 		nlangs = U16(script, 2);
-		if (U16(script, 0) && mkfn_lang(NULL, nlangs + (U16(script, 0) != 0)))
-			n = otf_lang(otf, gpos, script + U16(script, 0),
+		if (U16(script, 0) && mkfn_lang(nil, nlangs + (U16(script, 0) != 0)))
+			n = otf_lang(otf, gpos, (uchar*)script + U16(script, 0),
 						stag, "", lookups, n);
 		for (j = 0; j < nlangs; j++) {
-			void *lrec = script + 4 + 6 * j;
+			uchar *lrec = (uchar*)script + 4 + 6 * j;
 			memcpy(ltag, lrec, 4);
 			ltag[4] = '\0';
 			if (mkfn_lang(ltag, nlangs + (U16(script, 0) != 0)))
-				n = otf_lang(otf, gpos, script + U16(lrec, 4),
+				n = otf_lang(otf, gpos, (uchar*)script + U16(lrec, 4),
 						stag, ltag, lookups, n);
 		}
 	}
@@ -941,13 +941,13 @@
 static void otf_gpos(struct otf *otf, void *gpos)
 {
 	struct otflookup lookups[NLOOKUPS];
-	void *lookuplist = gpos + U16(gpos, 8);
+	uchar *lookuplist = (uchar*)gpos + U16(gpos, 8);
 	int nlookups = otf_gtab(otf, gpos, lookups);
 	int i, j;
 	if (mkfn_dry)
 		return;
 	for (i = 0; i < nlookups; i++) {
-		void *lookup = lookuplist + U16(lookuplist, 2 + 2 * lookups[i].lookup);
+		uchar *lookup = lookuplist + U16(lookuplist, 2 + 2 * lookups[i].lookup);
 		int ltype = U16(lookup, 0);
 		int ntabs = U16(lookup, 4);
 		char *tag = lookuptag(&lookups[i]);
@@ -954,7 +954,7 @@
 		sec = (i + 1) * 10;
 		printf("gsec %d %s\n", sec, tag);
 		for (j = 0; j < ntabs; j++) {
-			void *tab = lookup + U16(lookup, 6 + 2 * j);
+			uchar *tab = lookup + U16(lookup, 6 + 2 * j);
 			int type = ltype;
 			if (type == 9) {	/* extension positioning */
 				type = U16(tab, 2);
@@ -986,13 +986,13 @@
 static void otf_gsub(struct otf *otf, void *gsub)
 {
 	struct otflookup lookups[NLOOKUPS];
-	void *lookuplist = gsub + U16(gsub, 8);
+	uchar *lookuplist = (uchar*)gsub + U16(gsub, 8);
 	int nlookups = otf_gtab(otf, gsub, lookups);
 	int i, j;
 	if (mkfn_dry)
 		return;
 	for (i = 0; i < nlookups; i++) {
-		void *lookup = lookuplist + U16(lookuplist, 2 + 2 * lookups[i].lookup);
+		uchar *lookup = lookuplist + U16(lookuplist, 2 + 2 * lookups[i].lookup);
 		int ltype = U16(lookup, 0);
 		int ntabs = U16(lookup, 4);
 		char *tag = lookuptag(&lookups[i]);
@@ -999,7 +999,7 @@
 		sec = (i + 1) * 10;
 		printf("gsec %d %s\n", sec, tag);
 		for (j = 0; j < ntabs; j++) {
-			void *tab = lookup + U16(lookup, 6 + 2 * j);
+			uchar *tab = lookup + U16(lookup, 6 + 2 * j);
 			int type = ltype;
 			if (type == 7) {	/* extension substitution */
 				type = U16(tab, 2);
@@ -1007,13 +1007,13 @@
 			}
 			switch (type) {
 			case 1:
-				otf_gsubtype1(otf, tab, tag, NULL);
+				otf_gsubtype1(otf, tab, tag, nil);
 				break;
 			case 3:
-				otf_gsubtype3(otf, tab, tag, NULL);
+				otf_gsubtype3(otf, tab, tag, nil);
 				break;
 			case 4:
-				otf_gsubtype4(otf, tab, tag, NULL);
+				otf_gsubtype4(otf, tab, tag, nil);
 				break;
 			case 6:
 				otf_gsubtype6(otf, tab, tag, gsub);
@@ -1083,12 +1083,12 @@
 {
 	int cnt = U16(idx, 0);
 	int sz = U8(idx, 2);
-	return idx + 3 + (cnt + 1) * sz - 1 + cff_int(idx, 3 + i * sz, sz);
+	return (uchar*)idx + 3 + (cnt + 1) * sz - 1 + cff_int(idx, 3 + i * sz, sz);
 }
 
 static int cffidx_len(void *idx, int i)
 {
-	return cffidx_get(idx, i + 1) - cffidx_get(idx, i);
+	return (uchar*)cffidx_get(idx, i + 1) - (uchar*)cffidx_get(idx, i);
 }
 
 static void *cffidx_end(void *idx)
@@ -1139,24 +1139,24 @@
 
 static void otf_cff(struct otf *otf, void *cff)
 {
-	void *nameidx;		/* name index */
-	void *topidx;		/* top dict index */
-	void *stridx;		/* string idx */
-	void *chridx;		/* charstrings index */
-	void *charset;		/* charset offset */
+	uchar *nameidx;		/* name index */
+	uchar *topidx;		/* top dict index */
+	uchar *stridx;		/* string idx */
+	uchar *chridx;		/* charstrings index */
+	uchar *charset;		/* charset offset */
 	int badcff;		/* invalid CFF SIDs */
 	int i, j;
 	if (U8(cff, 0) != 1)
 		return;
-	nameidx = cff + U8(cff, 2);
+	nameidx = (uchar*)cff + U8(cff, 2);
 	topidx = cffidx_end(nameidx);
 	if (cffidx_cnt(nameidx) < 1)
 		return;
 	stridx = cffidx_end(topidx);
-	chridx = cff + cffdict_get(cffidx_get(topidx, 0),
-			cffidx_len(topidx, 0), 17, NULL);
-	charset = cff + cffdict_get(cffidx_get(topidx, 0),
-			cffidx_len(topidx, 0), 15, NULL);
+	chridx = (uchar*)cff + cffdict_get(cffidx_get(topidx, 0),
+			cffidx_len(topidx, 0), 17, nil);
+	charset = (uchar*)cff + cffdict_get(cffidx_get(topidx, 0),
+			cffidx_len(topidx, 0), 15, nil);
 	glyph_n = cffidx_cnt(chridx);
 	badcff = cffidx_cnt(chridx) - 391 > cffidx_cnt(stridx);
 	strcpy(glyph_name[0], ".notdef");
--- a/sbuf.c
+++ b/sbuf.c
@@ -1,8 +1,7 @@
 /* Variable Length String Buffer */
-#include <stdarg.h>
+#include <u.h>
+#include <libc.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include "mkfn.h"
 
 #define MAX(a, b)	((a) < (b) ? (b) : (a))
--- a/tab.c
+++ b/tab.c
@@ -1,6 +1,6 @@
 /* A Dictionary */
-#include <stdlib.h>
-#include <string.h>
+#include <u.h>
+#include <libc.h>
 #include "mkfn.h"
 
 struct tab {
@@ -49,5 +49,5 @@
 			return tab->vals[i];
 		i = tab->next[i];
 	}
-	return NULL;
+	return nil;
 }
--- a/trfn.c
+++ b/trfn.c
@@ -1,7 +1,7 @@
+#include <u.h>
+#include <libc.h>
 #include <ctype.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include "mkfn.h"
 #include "trfn_agl.h"
 #include "trfn_ch.h"