changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: file(1): recognise unified diff output

changeset 7263: b703b47e2940
parent 7262: f0621f169310
child 7264: 2a3c4f34c585
author: Alex Musolino <alex@musolino.id.au>
date: Sat, 08 Jun 2019 15:56:03 +0930
files: sys/src/cmd/file.c
description: file(1): recognise unified diff output
     1.1--- a/sys/src/cmd/file.c
     1.2+++ b/sys/src/cmd/file.c
     1.3@@ -167,6 +167,7 @@ int	longoff(void);
     1.4 int	istar(void);
     1.5 int	isface(void);
     1.6 int	isexec(void);
     1.7+int	isudiff(void);
     1.8 int	p9bitnum(char*, int*);
     1.9 int	p9subfont(uchar*);
    1.10 void	print_utf(void);
    1.11@@ -183,6 +184,7 @@ int	(*call[])(void) =
    1.12 	iff,		/* interchange file format (strings) */
    1.13 	longoff,	/* recognizable by 4 bytes at some offset */
    1.14 	isoffstr,	/* recognizable by string at some offset */
    1.15+	isudiff,	/* unified diff output */
    1.16 	isrfc822,	/* email file */
    1.17 	ismbox,		/* mail box */
    1.18 	istar,		/* recognizable by tar checksum */
    1.19@@ -983,6 +985,25 @@ char*	html_string[] = {
    1.20 };
    1.21 
    1.22 int
    1.23+isudiff(void)
    1.24+{
    1.25+	char *p;
    1.26+
    1.27+	p = (char*)buf;
    1.28+	if((p = strstr(p, "diff")) != nil)
    1.29+	if((p = strchr(p, '\n')) != nil)
    1.30+	if(strncmp(++p, "--- ", 4) == 0)
    1.31+	if((p = strchr(p, '\n')) != nil)
    1.32+	if(strncmp(++p, "+++ ", 4) == 0)
    1.33+	if((p = strchr(p, '\n')) != nil)
    1.34+	if(strncmp(++p, "@@ ", 3) == 0){
    1.35+		print("%s\n", mime ? "text/plain" : "unified diff output");
    1.36+		return 1;
    1.37+	}
    1.38+	return 0;
    1.39+}
    1.40+
    1.41+int
    1.42 ishtml(void)
    1.43 {
    1.44 	int i, n, count;