shithub: riscv

Download patch

ref: 26dc73c763de25196a60caba7f7815b13cf2f91f
parent: 78c7cd0c010c1c90dbc3358c2710bddaed379ce9
author: Alex Musolino <alex@musolino.id.au>
date: Sat Jun 8 11:56:03 EDT 2019

file(1): recognise unified diff output

--- a/sys/src/cmd/file.c
+++ b/sys/src/cmd/file.c
@@ -167,6 +167,7 @@
 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 @@
 	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 */
@@ -981,6 +983,25 @@
 	"a", "b", "i", "p", "q", "u",
 	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)