i didn't double check if Runemax has made it into libc.h. i think it makes sense, even for 16-bit runes since Bgetc returns an int. and cases like this where a rune value is calculated as an int to protect against overflow. this patch depends on Runemax. 1. fix output bug. for character 0, the output was truncated because %C formats a 0 character, terminating the string. also defend against illegal utf values. 2. add -b baseoff to correct the character values for subfonts that don't start at character 0. while this is a hack (we should parse font(6) files instead so that each subfont could be discontinuous with this previous), it does make viewing a single subfont possible with much less work. Reference: /n/sources/patch/maybe/tweaknil Date: Sun Feb 14 17:16:43 CET 2010 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/tweak.c Sun Feb 14 17:08:59 2010 +++ /sys/src/cmd/tweak.c Sun Feb 14 17:08:56 2010 @@ -160,6 +160,7 @@ Image *values[256]; Image *greyvalues[256]; uchar data[8192]; +int base; Thing* tget(char*); void mesg(char*, ...); @@ -172,12 +173,29 @@ void tclose1(Thing*); void +usage(void) +{ + fprint(2, "usage: tweak [-b base] [file] ...\n"); + exits("usage"); +} + +void main(int argc, char *argv[]) { int i; Event e; Thing *t; + ARGBEGIN{ + case 'b': + base = atoi(EARGF(usage())); + if((uint)base > Runemax) + usage(); + break; + default: + usage(); + }ARGEND + mag = Mag; if(initdraw(error, 0, "tweak") < 0){ fprint(2, "tweak: initdraw failed: %r\n"); @@ -191,9 +209,8 @@ } einit(Emouse|Ekeyboard); eresized(0); - i = 1; setjmp(err); - for(; iname); if(t->c >= 0){ fc = &t->parent->s->info[t->c]; - sprint(l1, "c(hex): %x c(char): %C x: %d " + r = base+t->c+t->parent->off; + if((uint)r > Runemax) + snprint(buf1, sizeof buf1, ""); + else if(r == 0) + snprint(buf1, sizeof buf1, ""); + else + snprint(buf1, sizeof buf1, "%C", (Rune)r); + sprint(l1, "c(hex): %x c(char): %s x: %d " "top: %d bottom: %d left: %d width: %d iwidth: %d", - (int)(t->c+t->parent->off), (int)(t->c+t->parent->off), + r, buf1, fc->x, fc->top, fc->bottom, fc->left, fc->width, Dx(t->b->r)); }else if(t->s) --- /sys/man/1/tweak Sun Feb 14 17:09:05 2010 +++ /sys/man/1/tweak Sun Feb 14 17:09:04 2010 @@ -5,6 +5,10 @@ .SH SYNOPSIS .B tweak [ +.B -b +.I baseoff +] +[ .I file ... ] .SH DESCRIPTION @@ -43,6 +47,10 @@ .B ascent as defined in .IR cachechars (2). +It is assumed that the first character in the first file +is character 0 unless +.I baseoff +is given. .PP By means described below, magnified views of portions of the images may be displayed. @@ -165,3 +173,8 @@ For a program written to adjust width tables in fonts, .I tweak has been pushed unreasonably far. +.PP +Fonts with discontinuities will display incorrect character +values. It would be necessary to parse +.IR font (6) +files instead of subfonts.