]> git.lizzy.rs Git - plan9front.git/commitdiff
file(1): recognise unified diff output
authorAlex Musolino <alex@musolino.id.au>
Sat, 8 Jun 2019 06:26:03 +0000 (15:56 +0930)
committerAlex Musolino <alex@musolino.id.au>
Sat, 8 Jun 2019 06:26:03 +0000 (15:56 +0930)
sys/src/cmd/file.c

index b64bb13a486933a53e6cfeea1d5093f58bc2ed3c..854e8e07c4d6bf5e3047f147f2e1ce793d0c485c 100644 (file)
@@ -167,6 +167,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 +184,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 */
@@ -982,6 +984,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)
 {