@@ 4,7 4,7 @@
/* entry has 1 byte in widtab + 8 bytes per tile */
-#define ufxlen(n) (1 + ((n)*(n)*8))
+#define ufxlen(n) ((n)*(n)*8)
enum{
@@ 36,13 36,21 @@ struct MapFile{
};
-uint fwidth, nglyphs;
+struct GlyphInfo{
+ uchar top, bottom, left, width;
+};
+
+
+uint fwidth, nglyphs, glyphlen;
uchar setconv, donaive, doholes;
struct MapFile *mapfiles, *lastmf;
uchar wasmferr, wasreaderr;
+uchar *gbitmaps;
+struct GlyphInfo *ginfo;
+
void
bioerr(char *s)
@@ 278,6 286,71 @@ printmapfile(struct MapFile *mf)
void
+sniffdims(char *file)
+{
+ uint len;
+ Dir *d;
+ char c;
+
+ len = strlen(file);
+
+ if(fwidth < 1){
+ c = file[len-1];
+ file[len-1] = '\0';
+ if('1' <= c && c <= '8' && strcmp(file+len-4, ".uf") != 0){
+ fwidth = c - '0';
+ }
+ }
+ if(fwidth < 1)
+ sysfatal("can't determine glyph width");
+
+ glyphlen = ufxlen(fwidth);
+
+ d = dirstat(file);
+ if(d == nil)
+ sysfatal("%r");
+
+ if(nglyphs > 0){
+ if(d->length % (1+glyphlen) != 0)
+ sysfatal("can't determine file dimensions");
+ nglyphs = d->length / (1+glyphlen);
+ }else if(nglyphs * (1+glyphlen) > d->length)
+ sysfatal("file too short");
+}
+void
+loadufx(char *infile)
+{
+ Biobuf *b;
+ uint i, len;
+ int n;
+
+ len = nglyphs * glyphlen;
+ gbitmaps = malloc(len);
+ ginfo = malloc(nglyphs * sizeof(struct GlyphInfo));
+ b = Bopen(infile, OREAD);
+
+ for(i = 0; i < nglyphs; i++){
+ n = Bgetc(b);
+ if(n < 0)
+ sysfatal("%r");
+ ginfo[i].width = n;
+ }
+
+ if(Bread(b, gbitmaps, len) == len)
+ sysfatal("%r");
+
+ Bterm(b);
+}
+void
+parseglyphs(void)
+{
+ uint i;
+
+ sysfatal("TODO");
+}
+
+
+void
usage(void)
{
fprint(2, "usage: %s [-nh] [-m mapfile] [-l length] [-x width] in.ufx out/\n", argv0);
@@ 296,6 369,8 @@ main(int argc, char **argv)
break;
case 'x':
fwidth = atoi(EARGF(usage()));
+ if(1 > fwidth || fwidth > 8)
+ sysfatal("-x: width must be in range 1-8");
break;
case 'n':
setconv = 1;
@@ 324,9 399,11 @@ main(int argc, char **argv)
if(argc != 2)
usage();
+ infile = argv[0];
+ outdir = argv[1];
- // TODO: calculate length etc etc
+ sniffdims(infile);
for(mf = mapfiles; mf != nil; mf = mf->next)
parsemapfile(mf);
@@ 334,4 411,6 @@ main(int argc, char **argv)
exits("mapfile");
for(mf = mapfiles; mf != nil; mf = mf->next)
printmapfile(mf);
+
+ loadufx(infile);
}