1) Fix some cases where -m wasn't being respected. file -m /lib/face/48x48x8/n/nemo.1 2) Report on depth of p9bit files (including compressed). file /lib/face/*/p/pjw.1 3) 2 involved removing the string match for compressed images. This made exposed the fact that file wasn't handling depth<8 images properly. I've replaced the switch(d) in depthof() with a check for divisibility by/into 8, as per image(6). 4) To preserve results, do ismung after isp9(bit,font). In addition to 1 and 2, 3+4 make file's results more frequently correct (no more things like "Ascii & Arabic text" on 4 bit uncompressed images: see 'file /lib/face/48x48x4/r/rminnich.1'). Notes: Wed Oct 3 12:51:11 EDT 2007 rsc sure seems weird to print the depth and not the channel descriptor. Thu Oct 4 00:39:18 EDT 2007 geoff noted; perhaps the channel descriptor can be added. Reference: /n/sources/patch/applied/file-mime_p9bit.depth Date: Wed Oct 3 01:20:15 CES 2007 Signed-off-by: a@9srv.net Reviewed-by: geoff --- /sys/src/cmd/file.c Wed Oct 3 01:11:06 2007 +++ /sys/src/cmd/file.c Wed Oct 3 01:11:04 2007 @@ -188,9 +188,9 @@ islimbo, /* limbo source */ isc, /* c & alef compiler key words */ isas, /* assembler key words */ - ismung, /* entropy compressed/encrypted */ isp9font, /* plan 9 font */ isp9bit, /* plan 9 image (as from /dev/window) */ + ismung, /* entropy compressed/encrypted */ isenglish, /* char frequency English */ isrtf, /* rich text format */ ismsdos, /* msdos exe (virus file attachement) */ @@ -775,7 +775,6 @@ "%PDF", "PDF", 4, "application/pdf", "\n", "HTML file", 7, "text/html", "\n", "HTML file", 7, "text/html", - "compressed\n", "Compressed image or subfont", 11, "application/octet-stream", "\111\111\052\000", "tiff", 4, "image/tiff", "\115\115\000\052", "tiff", 4, "image/tiff", "\377\330\377\340", "jpeg", 4, "image/jpeg", @@ -1231,33 +1230,37 @@ d += strtoul(s, &s, 10); } - switch(d){ - case 32: - case 24: - case 16: - case 8: + if(d % 8 == 0 || 8 % d == 0) return d; - } - return -1; + else + return -1; } int isp9bit(void) { - int dep, lox, loy, hix, hiy, px, new; + int dep, lox, loy, hix, hiy, px, new, cmpr; ulong t; long len; char *newlabel; + uchar *cp; + cp = buf; + cmpr = 0; newlabel = "old "; - dep = depthof((char*)buf + 0*P9BITLEN, &new); + if(!memcmp(cp, "compressed\n", 11)) { + cmpr = 1; + cp = buf + 11; + } + + dep = depthof((char*)cp + 0*P9BITLEN, &new); if(new) newlabel = ""; - lox = p9bitnum(buf + 1*P9BITLEN); - loy = p9bitnum(buf + 2*P9BITLEN); - hix = p9bitnum(buf + 3*P9BITLEN); - hiy = p9bitnum(buf + 4*P9BITLEN); + lox = p9bitnum(cp + 1*P9BITLEN); + loy = p9bitnum(cp + 2*P9BITLEN); + hix = p9bitnum(cp + 3*P9BITLEN); + hiy = p9bitnum(cp + 4*P9BITLEN); if(dep < 0 || lox < 0 || loy < 0 || hix < 0 || hiy < 0) return 0; @@ -1277,25 +1280,30 @@ len += 5*P9BITLEN; /* size of initial ascii */ /* + * for compressed images, don't look any further. otherwise: * for image file, length is non-zero and must match calculation above * for /dev/window and /dev/screen the length is always zero * for subfont, the subfont header should follow immediately. */ + if (cmpr) { + print(mime ? OCTET : "Compressed %splan 9 image or subfont, depth %d\n", newlabel, dep); + return 1; + } if (len != 0 && mbuf->length == 0) { - print("%splan 9 image\n", newlabel); + print(mime ? OCTET : "%splan 9 image, depth %d\n", newlabel, dep); return 1; } if (mbuf->length == len) { - print("%splan 9 image\n", newlabel); + print(mime ? OCTET : "%splan 9 image, depth %d\n", newlabel, dep); return 1; } /* Ghostscript sometimes produces a little extra on the end */ if (mbuf->length < len+P9BITLEN) { - print("%splan 9 image\n", newlabel); + print(mime ? OCTET : "%splan 9 image, depth %d\n", newlabel, dep); return 1; } if (p9subfont(buf+len)) { - print("%ssubfont file\n", newlabel); + print(mime ? OCTET : "%ssubfont file, depth %d\n", newlabel, dep); return 1; } return 0;