X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=sys%2Fsrc%2Fcmd%2Ffile.c;h=bd9d1afb5b492146277b6c53411a34177dbc2026;hb=ac88ce4f7f19be1aae1fdf390fa870b4be8dc3f5;hp=fdf3a7c0194709c07d0144fab31c124e2f8f2198;hpb=72cde47068ac541c5e054319c1b7c48efdc937db;p=plan9front.git diff --git a/sys/src/cmd/file.c b/sys/src/cmd/file.c index fdf3a7c01..bd9d1afb5 100644 --- a/sys/src/cmd/file.c +++ b/sys/src/cmd/file.c @@ -152,6 +152,7 @@ int ismbox(void); int islimbo(void); int istga(void); int ismp3(void); +int ismp4(void); int ismung(void); int isp9bit(void); int isp9font(void); @@ -167,7 +168,8 @@ int longoff(void); int istar(void); int isface(void); int isexec(void); -int p9bitnum(uchar*); +int isudiff(void); +int p9bitnum(char*, int*); int p9subfont(uchar*); void print_utf(void); void type(char*, int); @@ -183,6 +185,7 @@ int (*call[])(void) = iff, /* interchange file format (strings) */ longoff, /* recognizable by 4 bytes at some offset */ isoffstr, /* recognizable by string at some offset */ + isudiff, /* unified diff output */ isrfc822, /* email file */ ismbox, /* mail box */ istar, /* recognizable by tar checksum */ @@ -198,6 +201,7 @@ int (*call[])(void) = isicocur, /* windows icon or cursor file */ isface, /* ascii face file */ istga, + ismp4, ismp3, /* last resorts */ @@ -266,7 +270,7 @@ type(char *file, int nlen) } fname = file; if ((fd = open(file, OREAD)) < 0) { - print("cannot open: %r\n"); + fprint(2, "cannot open: %r\n"); return; } filetype(fd); @@ -345,7 +349,7 @@ filetype(int fd) free(mbuf); mbuf = dirfstat(fd); if(mbuf == nil){ - print("cannot stat: %r\n"); + fprint(2, "cannot stat: %r\n"); return; } if(mbuf->mode & DMDIR) { @@ -362,7 +366,7 @@ filetype(int fd) /* may be reading a pipe on standard input */ nbuf = readn(fd, buf, sizeof(buf)-1); if(nbuf < 0) { - print("cannot read: %r\n"); + fprint(2, "cannot read: %r\n"); return; } if(nbuf == 0) { @@ -610,6 +614,7 @@ Filemagic long0tab[] = { 070707, 0xFFFF, "cpio archive", "application/x-cpio", 0x2F7, 0xFFFF, "tex dvi", "application/dvi", 0xfaff, 0xfeff, "mp3 audio", "audio/mpeg", + 0xf0ff, 0xf6ff, "aac audio", "audio/mpeg", /* 0xfeedface: this could alternately be a Next Plan 9 boot image */ 0xcefaedfe, 0xFFFFFFFF, "32-bit power Mach-O executable", OCTET, /* 0xfeedfacf */ @@ -626,6 +631,12 @@ Filemagic long0tab[] = { */ 0xad4e5cd1, 0xFFFFFFFF, "venti arena", OCTET, 0x2bb19a52, 0xFFFFFFFF, "paq archive", OCTET, + 0x1a53454e, 0xFFFFFFFF, "NES ROM", OCTET, + /* tcpdump pcap file */ + 0xa1b2c3d4, 0xFFFFFFFF, "pcap file", "application/vnd.tcpdump.pcap", + 0xd4c3b2a1, 0xFFFFFFFF, "pcap file", "application/vnd.tcpdump.pcap", + 0xa1b23c4d, 0xFFFFFFFF, "pcap file", "application/vnd.tcpdump.pcap", + 0x4d3cb2a1, 0xFFFFFFFF, "pcap file", "application/vnd.tcpdump.pcap", }; int @@ -666,6 +677,8 @@ Fileoffmag longofftab[] = { 256*1024, 0xc75e5cd1, 0xFFFFFFFF, "venti index section", OCTET, 128*1024, 0x89ae7637, 0xFFFFFFFF, "fossil write buffer", OCTET, 4, 0x31647542, 0xFFFFFFFF, "OS X finder properties", OCTET, + 0x100, 0x41474553, 0xFFFFFFFF, "SEGA ROM", OCTET, + 0x1fc, 0xAA550000, 0xFFFF0000, "bootable disk image", OCTET, }; int @@ -789,11 +802,11 @@ struct FILE_STRING "\x1f\x9d", "compressed", 2, "application/x-compress", "\x1f\x8b", "gzip compressed", 2, "application/x-gzip", "BZh", "bzip2 compressed", 3, "application/x-bzip2", - "!\n__.SYMDEF", "archive random library", 16, "application/octet-stream", - "!\n", "archive", 8, "application/octet-stream", - "070707", "cpio archive - ascii header", 6, "application/octet-stream", - "#!/bin/rc", "rc executable file", 9, "text/plain", - "#!/bin/sh", "sh executable file", 9, "text/plain", + "!\n__.SYMDEF", "archive random library", 16, OCTET, + "!\n", "archive", 8, OCTET, + "070707", "cpio archive - ascii header", 6, OCTET, + "#!/bin/rc", "rc executable file", 9, PLAIN, + "#!/bin/sh", "sh executable file", 9, PLAIN, "%!", "postscript", 2, "application/postscript", "\004%!", "postscript", 3, "application/postscript", "x T post", "troff output for post", 8, "application/troff", @@ -820,20 +833,20 @@ struct FILE_STRING "BM", "bmp", 2, "image/bmp", "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1", "microsoft office document", 8, "application/doc", " 1) { - c = *bp++; - if(!isdigit(c)) - return -1; - n = n*10 + c-'0'; - len--; - } - if(*bp != ' ') + if(s[P9BITLEN-1] != ' ') + return -1; + s[P9BITLEN-1] = '\0'; + *v = strtol(s, &es, 10); + s[P9BITLEN-1] = ' '; + if(es != &s[P9BITLEN-1]) return -1; - return n; + return 0; } int @@ -1335,13 +1388,18 @@ depthof(char *s, int *newp) if(s == es) return -1; if('0'<=*s && *s<='9') - return 1<= 0) - len = (hix+px-1)/px - lox/px; - else{ /* make positive before divide */ - t = (-lox)+px-1; - t = (t/px)*px; - len = (t+hix+px-1)/px; - } + len = (hix+px-1)/px; }else - len = (hix-lox)*dep/8; - len *= hiy - loy; /* col length */ + len = hix*dep/8; + len *= hiy; /* col length */ len += 5 * P9BITLEN; /* size of initial ascii */ /* @@ -1400,8 +1456,8 @@ isp9bit(void) * for subfont, the subfont header should follow immediately. */ if (cmpr) { - print(mime ? "image/p9bit\n" : "Compressed %splan 9 image or subfont, depth %d\n", - newlabel, dep); + print(mime ? "image/p9bit\n" : "Compressed %splan 9 image or subfont, depth %d, size %dx%d\n", + newlabel, dep, hix, hiy); return 1; } /* @@ -1410,11 +1466,13 @@ isp9bit(void) */ if (len != 0 && (mbuf->length == 0 || mbuf->length == len || mbuf->length > len && mbuf->length < len+P9BITLEN)) { - print(mime ? "image/p9bit\n" : "%splan 9 image, depth %d\n", newlabel, dep); + print(mime ? "image/p9bit\n" : "%splan 9 image, depth %d, size %dx%d\n", + newlabel, dep, hix, hiy); return 1; } if (p9subfont(buf+len)) { - print(mime ? "image/p9bit\n" : "%ssubfont file, depth %d\n", newlabel, dep); + print(mime ? "image/p9bit\n" : "%ssubfont file, depth %d, size %dx%d\n", + newlabel, dep, hix, hiy); return 1; } return 0; @@ -1429,16 +1487,15 @@ p9subfont(uchar *p) if (p+3*P9BITLEN > buf+sizeof(buf)) return 1; - n = p9bitnum(p + 0*P9BITLEN); /* char count */ - if (n < 0) + if (p9bitnum((char*)p + 0*P9BITLEN, &n) < 0) /* char count */ return 0; - h = p9bitnum(p + 1*P9BITLEN); /* height */ - if (h < 0) + if (p9bitnum((char*)p + 1*P9BITLEN, &h) < 0) /* height */ return 0; - a = p9bitnum(p + 2*P9BITLEN); /* ascent */ - if (a < 0) + if (p9bitnum((char*)p + 2*P9BITLEN, &a) < 0) /* ascent */ return 0; - return 1; + if(n > 0 && h > 0 && a >= 0) + return 1; + return 0; } #define WHITESPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') @@ -1485,7 +1542,7 @@ isp9font(void) } } if (i) { - print(mime ? "text/plain\n" : "font file\n"); + print("%s\n", mime ? PLAIN : "font file"); return 1; } return 0; @@ -1647,4 +1704,3 @@ isface(void) print("face image depth %d\n", ldepth); return 1; } -