]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/file.c
make bind(2) error handling consistent
[plan9front.git] / sys / src / cmd / file.c
index 6e2eb1b14d6540adc2b5536a0f98d072c64914bf..bd9d1afb5b492146277b6c53411a34177dbc2026 100644 (file)
@@ -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,6 +168,7 @@ int longoff(void);
 int    istar(void);
 int    isface(void);
 int    isexec(void);
+int    isudiff(void);
 int    p9bitnum(char*, int*);
 int    p9subfont(uchar*);
 void   print_utf(void);
@@ -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 */
@@ -872,6 +876,16 @@ struct     FILE_STRING
        "BEGIN:VCARD\n",        "vCard",                12,     "text/directory;profile=vcard",
        "AT&T",                 "DjVu document",        4,      "image/vnd.djvu",
        "Extended module: ",    "XM audio",             17,     "audio/xm",
+       "MThd",                 "midi audio",           4,      "audio/midi",
+       "MUS\x1a",              "mus audio",            4,      "audio/mus",
+       "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
+       "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
+       "\x00\x00\x00\xbb\x11\x22\x00\x44\xff\xff\xff\xff\xff\xff\xff\xff"
+       "\xaa\x99\x55\x66", "Xilinx bitstream (not byteswappped)", 52, OCTET,
+       "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
+       "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
+       "\xbb\x00\x00\x00\x44\x00\x22\x11\xff\xff\xff\xff\xff\xff\xff\xff"
+       "\x66\x55\x99\xaa", "Xilinx bitstream (byteswappped)", 52, OCTET,
        0,0,0,0
 };
 
@@ -972,6 +986,25 @@ char*      html_string[] = {
        0,
 };
 
+int
+isudiff(void)
+{
+       char *p;
+
+       p = (char*)buf;
+       if((p = strstr(p, "diff")) != nil)
+       if((p = strchr(p, '\n')) != nil)
+       if(strncmp(++p, "--- ", 4) == 0)
+       if((p = strchr(p, '\n')) != nil)
+       if(strncmp(++p, "+++ ", 4) == 0)
+       if((p = strchr(p, '\n')) != nil)
+       if(strncmp(++p, "@@ ", 3) == 0){
+               print("%s\n", mime ? "text/plain" : "unified diff output");
+               return 1;
+       }
+       return 0;
+}
+
 int
 ishtml(void)
 {
@@ -1211,6 +1244,24 @@ ismp3(void)
        return 0;
 }
 
+int
+ismp4(void)
+{
+       if(nbuf <= 12)
+               return 0;
+       if(memcmp(&buf[4], "ftyp", 4) != 0)
+               return 0;
+       if(memcmp(&buf[8], "isom", 4) == 0){
+               print("%s\n", mime ? "video/mp4" : "mp4 video");
+               return 1;
+       }
+       if(memcmp(&buf[8], "M4A ", 4) == 0){
+               print("%s\n", mime ? "audio/m4a" : "m4a audio");
+               return 1;
+       }
+       return 0;
+}
+
 /*
  * low entropy means encrypted
  */
@@ -1653,4 +1704,3 @@ isface(void)
                print("face image depth %d\n", ldepth);
        return 1;
 }
-