X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=sys%2Fsrc%2Fcmd%2Ffile.c;h=7da5abdaaf6540421d8d2c185eac40e181fb79b0;hb=8035bb7dd1a83e3b98b3bb54defe0dbf35c861cf;hp=d42f99d47f0570da3baa436ac84d8b71d6bbed15;hpb=3efbb4fa00f8d8d055227f54e71e2eb24ff39729;p=plan9front.git diff --git a/sys/src/cmd/file.c b/sys/src/cmd/file.c index d42f99d47..7da5abdaa 100644 --- a/sys/src/cmd/file.c +++ b/sys/src/cmd/file.c @@ -150,11 +150,13 @@ int ishtml(void); int isrfc822(void); int ismbox(void); int islimbo(void); +int ismp3(void); int ismung(void); int isp9bit(void); int isp9font(void); int isrtf(void); int ismsdos(void); +int isicocur(void); int iself(void); int istring(void); int isoffstr(void); @@ -192,7 +194,9 @@ int (*call[])(void) = isp9bit, /* plan 9 image (as from /dev/window) */ isrtf, /* rich text format */ ismsdos, /* msdos exe (virus file attachement) */ + isicocur, /* windows icon or cursor file */ isface, /* ascii face file */ + ismp3, /* last resorts */ ismung, /* entropy compressed/encrypted */ @@ -586,7 +590,7 @@ Filemagic long0tab[] = { /* "pXc2 */ 0x32630070, 0xFFFF00FF, "pac4 audio file\n", OCTET, 0xBA010000, 0xFFFFFFFF, "mpeg system stream\n", OCTET, - 0x43614c66, 0xFFFFFFFF, "FLAC audio file\n", OCTET, + 0x43614c66, 0xFFFFFFFF, "FLAC audio file\n", "audio/flac", 0x30800CC0, 0xFFFFFFFF, "inferno .dis executable\n", OCTET, 0x04034B50, 0xFFFFFFFF, "zip archive\n", "application/zip", 070707, 0xFFFF, "cpio archive\n", "application/x-cpio", @@ -800,12 +804,14 @@ struct FILE_STRING "\377\330\377\340", "jpeg", 4, "image/jpeg", "\377\330\377\341", "jpeg", 4, "image/jpeg", "\377\330\377\333", "jpeg", 4, "image/jpeg", + "\xff\xd8", "jpeg", 2, "image/jpeg", "BM", "bmp", 2, "image/bmp", "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1", "microsoft office document", 8, "application/doc", "' to html table */ count = 0; p = buf; for(;;) { - while (p < buf+nbuf && *p != '<') + while(p < buf+nbuf && *p != '<') p++; p++; if (p >= buf+nbuf) break; if(*p == '/') p++; - q = p; - while(p < buf+nbuf && isalpha(*p)) - p++; - if (p >= buf+nbuf) + if(p >= buf+nbuf) break; - for(i = 0; html_string[i]; i++) { - if(cistrncmp(html_string[i], (char*)q, p-q) == 0) { - if(++count > 2) { - print(mime ? "text/html\n" : "HTML file\n"); - return 1; + for(i = 0; html_string[i]; i++){ + n = strlen(html_string[i]); + if(p + n > buf+nbuf) + continue; + if(cistrncmp(html_string[i], (char*)p, n) == 0) { + p += n; + if(p < buf+nbuf && strchr("\t\r\n />", *p)){ + if(++count > 2) { + print(mime ? "text/html\n" : "HTML file\n"); + return 1; + } } break; } } - p++; } return 0; } @@ -1150,6 +1137,23 @@ isas(void) return 1; } +int +ismp3(void) +{ + uchar *p, *e; + + p = buf; + e = p + nbuf-1; + while((p < e) && (p = memchr(p, 0xFF, e - p))){ + if((p[1] & 0xFE) == 0xFA){ + print(mime ? "audio/mpeg\n" : "mp3 audio\n"); + return 1; + } + p++; + } + return 0; +} + /* * low entropy means encrypted */ @@ -1178,6 +1182,9 @@ ismung(void) else if(buf[0]=='B' && buf[1]=='Z' && buf[2]=='h') print(mime ? "application/x-bzip2" : "bzip2 compressed\n"); + else + if(buf[0]==0x78 && buf[1]==0x9c) + print(mime ? "application/x-deflate" : "zlib compressed\n"); else print(mime ? OCTET : "encrypted\n"); return 1; @@ -1348,7 +1355,7 @@ isp9bit(void) * for subfont, the subfont header should follow immediately. */ if (cmpr) { - print(mime ? OCTET : "Compressed %splan 9 image or subfont, depth %d\n", + print(mime ? "image/p9bit\n" : "Compressed %splan 9 image or subfont, depth %d\n", newlabel, dep); return 1; } @@ -1358,11 +1365,11 @@ isp9bit(void) */ if (len != 0 && (mbuf->length == 0 || mbuf->length == len || mbuf->length > len && mbuf->length < len+P9BITLEN)) { - print(mime ? OCTET : "%splan 9 image, depth %d\n", newlabel, dep); + print(mime ? "image/p9bit\n" : "%splan 9 image, depth %d\n", newlabel, dep); return 1; } if (p9subfont(buf+len)) { - print(mime ? OCTET : "%ssubfont file, depth %d\n", newlabel, dep); + print(mime ? "image/p9bit\n" : "%ssubfont file, depth %d\n", newlabel, dep); return 1; } return 0; @@ -1474,6 +1481,24 @@ ismsdos(void) return 0; } +int +isicocur(void) +{ + if(buf[0] || buf[1] || buf[3] || buf[9]) + return 0; + if(buf[4] == 0x00 && buf[5] == 0x00) + return 0; + switch(buf[2]){ + case 1: + print(mime ? "image/x-icon\n" : "Microsoft icon file\n"); + return 1; + case 2: + print(mime ? "image/x-icon\n" : "Microsoft cursor file\n"); + return 1; + } + return 0; +} + int iself(void) {