Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Jul 2012 16:23:49 +0000
From:      jhagewood@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r239554 - in soc2012/jhagewood/diff3: . diff3
Message-ID:  <20120718162349.74FC3106564A@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhagewood
Date: Wed Jul 18 16:23:49 2012
New Revision: 239554
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239554

Log:
  Fixed textfile detection in diff3

Modified:
  soc2012/jhagewood/diff3/diff3/diff3prog.c
  soc2012/jhagewood/diff3/hagewood-diff3.patch

Modified: soc2012/jhagewood/diff3/diff3/diff3prog.c
==============================================================================
--- soc2012/jhagewood/diff3/diff3/diff3prog.c	Wed Jul 18 16:22:22 2012	(r239553)
+++ soc2012/jhagewood/diff3/diff3/diff3prog.c	Wed Jul 18 16:23:49 2012	(r239554)
@@ -148,7 +148,7 @@
 static void change(int, struct range *, int);
 static void keep(int, struct range *);
 static void merge(int, int);
-static int asciifile(FILE *);
+static int istextfile(FILE *);
 static void prange(struct range *);
 static void repos(int);
 static void separate(const char *);
@@ -381,7 +381,7 @@
 	d2 = d23;
 	j = 0;
 
-	if ((asciifile(fp[0]) && asciifile(fp[1]) && asciifile(fp[2])) == 0) {
+	if ((istextfile(fp[0]) && istextfile(fp[1]) && istextfile(fp[2])) == 0) {
 		printf("Binary file detected; comparison failed\n");
 		exit(EXIT_FAILURE);
 	}
@@ -477,24 +477,22 @@
 }
 
 static int
-asciifile(FILE *f)
+istextfile(FILE *f)
 {
-	wint_t ch = L'\0';
-	size_t i;
+	int	i, check_size;
+	char ch;
 
 	if (aflag || f == NULL)
 		return (1);
 	rewind(f);
-	errno = 0;
-	for (i = 0; i <= BUFSIZ; i++) {
-		if ((ch = fgetwc(f)) == WEOF) {
-			if (errno == EILSEQ)
-				return (0);
-			break;
-		}
-		if (!iswspace(ch) && iswcntrl(ch))
+	for (i = 0; i <= MAX_CHECK || ch != EOF; i++) {
+		ch = fgetc(f);
+		if (ch == '\0') {
+			rewind(f);
 			return (0);
+		}
 	}
+	rewind(f);
 	return (1);
 }
 

Modified: soc2012/jhagewood/diff3/hagewood-diff3.patch
==============================================================================
--- soc2012/jhagewood/diff3/hagewood-diff3.patch	Wed Jul 18 16:22:22 2012	(r239553)
+++ soc2012/jhagewood/diff3/hagewood-diff3.patch	Wed Jul 18 16:23:49 2012	(r239554)
@@ -1,6 +1,6 @@
 diff -rupN jhagewood/diff3/diff3-orig/Makefile jhagewood/diff3/diff3/Makefile
---- jhagewood/diff3/diff3-orig/Makefile	2012-07-07 19:37:18.000000000 -0400
-+++ jhagewood/diff3/diff3/Makefile	2012-07-07 19:37:18.000000000 -0400
+--- jhagewood/diff3/diff3-orig/Makefile	2012-07-18 16:22:12.000000000 -0400
++++ jhagewood/diff3/diff3/Makefile	2012-07-18 16:22:12.000000000 -0400
 @@ -6,6 +6,6 @@ BINDIR=	/usr/libexec
  
  beforeinstall:
@@ -10,8 +10,8 @@
  
  .include <bsd.prog.mk>
 diff -rupN jhagewood/diff3/diff3-orig/diff3prog.c jhagewood/diff3/diff3/diff3prog.c
---- jhagewood/diff3/diff3-orig/diff3prog.c	2012-07-07 19:37:18.000000000 -0400
-+++ jhagewood/diff3/diff3/diff3prog.c	2012-07-07 19:37:18.000000000 -0400
+--- jhagewood/diff3/diff3-orig/diff3prog.c	2012-07-18 16:22:12.000000000 -0400
++++ jhagewood/diff3/diff3/diff3prog.c	2012-07-18 16:23:30.267560000 -0400
 @@ -64,19 +64,23 @@
   *	@(#)diff3.c	8.1 (Berkeley) 6/6/93
   */
@@ -66,6 +66,14 @@
 -void change(int, struct range *, int);
 -void keep(int, struct range *);
 -void merge(int, int);
+-static int asciifile(FILE *);
+-void prange(struct range *);
+-void repos(int);
+-void separate(const char *);
+-__dead void edscript(int);
+-__dead void trouble(void);
+-void increase(void);
+-__dead void usage(void);
 +static int duplicate(struct range *, struct range *);
 +static int edit(struct diff *, int, int);
 +static char *getchange(FILE *);
@@ -76,14 +84,7 @@
 +static void change(int, struct range *, int);
 +static void keep(int, struct range *);
 +static void merge(int, int);
- static int asciifile(FILE *);
--void prange(struct range *);
--void repos(int);
--void separate(const char *);
--__dead void edscript(int);
--__dead void trouble(void);
--void increase(void);
--__dead void usage(void);
++static int istextfile(FILE *);
 +static void prange(struct range *);
 +static void repos(int);
 +static void separate(const char *);
@@ -225,22 +226,25 @@
  
 -	if( (asciifile(fp[0]) && asciifile(fp[1]) && asciifile(fp[2]) ) == 0)
 -	{
-+	if ((asciifile(fp[0]) && asciifile(fp[1]) && asciifile(fp[2])) == 0) {
++	if ((istextfile(fp[0]) && istextfile(fp[1]) && istextfile(fp[2])) == 0) {
  		printf("Binary file detected; comparison failed\n");
  		exit(EXIT_FAILURE);
  	}
-@@ -466,29 +479,29 @@ merge(int m1, int m2)
+@@ -464,31 +477,29 @@ merge(int m1, int m2)
+ }
+ 
  static int
- asciifile(FILE *f)
+-asciifile(FILE *f)
++istextfile(FILE *f)
  {
 -        wint_t   ch = L'\0';
 -        size_t   i;
--
++	int	i, check_size;
++	char ch;
+ 
 -        if (aflag || f == NULL)
 -                return (1);
-+	wint_t ch = L'\0';
-+	size_t i;
- 
+-
 -        rewind(f);
 -        errno = 0;
 -        for (i = 0; i <= BUFSIZ; i++) {
@@ -256,16 +260,14 @@
 +	if (aflag || f == NULL)
 +		return (1);
 +	rewind(f);
-+	errno = 0;
-+	for (i = 0; i <= BUFSIZ; i++) {
-+		if ((ch = fgetwc(f)) == WEOF) {
-+			if (errno == EILSEQ)
-+				return (0);
-+			break;
-+		}
-+		if (!iswspace(ch) && iswcntrl(ch))
++	for (i = 0; i <= MAX_CHECK || ch != EOF; i++) {
++		ch = fgetc(f);
++		if (ch == '\0') {
++			rewind(f);
 +			return (0);
++		}
 +	}
++	rewind(f);
 +	return (1);
  }
  
@@ -277,7 +279,7 @@
  	printf("====%s\n", s);
  }
  
-@@ -497,9 +510,10 @@ separate(const char *s)
+@@ -497,9 +508,10 @@ separate(const char *s)
   * It is to be printed only if it does not duplicate something to be
   * printed later.
   */
@@ -289,7 +291,7 @@
  	printf("%d:", i);
  	last[i] = rold->to;
  	prange(rold);
-@@ -510,12 +524,14 @@ change(int i, struct range *rold, int du
+@@ -510,12 +522,14 @@ change(int i, struct range *rold, int du
  	(void)skip(i, rold->to, "  ");
  }
  
@@ -307,7 +309,7 @@
  	if (rold->to <= rold->from)
  		printf("%da\n", rold->from - 1);
  	else {
-@@ -531,7 +547,7 @@ prange(struct range *rold)
+@@ -531,7 +545,7 @@ prange(struct range *rold)
   * and an artificial dummy difference (trange) must be ginned up to
   * correspond to the change reported in the other file.
   */
@@ -316,7 +318,7 @@
  keep(int i, struct range *rnew)
  {
  	int delta;
-@@ -547,7 +563,7 @@ keep(int i, struct range *rnew)
+@@ -547,7 +561,7 @@ keep(int i, struct range *rnew)
   * skip to just before line number from in file "i".  If "pr" is non-NULL,
   * print all skipped stuff with string pr as a prefix.
   */
@@ -325,7 +327,7 @@
  skip(int i, int from, char *pr)
  {
  	size_t j, n;
-@@ -558,7 +574,6 @@ skip(int i, int from, char *pr)
+@@ -558,7 +572,6 @@ skip(int i, int from, char *pr)
  			trouble();
  		if (pr != NULL)
  			printf("%s%s", Tflag == 1? "\t" : pr, line);
@@ -333,7 +335,7 @@
  		cline[i]++;
  	}
  	return ((int) n);
-@@ -568,10 +583,10 @@ skip(int i, int from, char *pr)
+@@ -568,10 +581,10 @@ skip(int i, int from, char *pr)
   * Return 1 or 0 according as the old range (in file 1) contains exactly
   * the same data as the new range (in file 2).
   */
@@ -346,7 +348,7 @@
  	int nchar;
  	int nline;
  
-@@ -597,7 +612,7 @@ duplicate(struct range *r1, struct range
+@@ -597,7 +610,7 @@ duplicate(struct range *r1, struct range
  	return (1);
  }
  
@@ -355,7 +357,7 @@
  repos(int nchar)
  {
  	int i;
-@@ -606,18 +621,43 @@ repos(int nchar)
+@@ -606,18 +619,43 @@ repos(int nchar)
  		(void)fseek(fp[i], (long)-nchar, SEEK_CUR);
  }
  
@@ -401,7 +403,7 @@
  	if (((dup + 1) & eflag) == 0)
  		return (j);
  	j++;
-@@ -632,10 +672,10 @@ edit(struct diff *diff, int dup, int j)
+@@ -632,10 +670,10 @@ edit(struct diff *diff, int dup, int j)
  }
  
  /* regurgitate */
@@ -414,7 +416,7 @@
  	char block[BUFSIZ];
  
  	for (n = n; n > 0; n--) {
-@@ -657,14 +697,13 @@ edscript(int n)
+@@ -657,14 +695,13 @@ edscript(int n)
  			printf("%da\n%s\n.\n", de[n].old.from - 1, f1mark);
  		}
  	}
@@ -431,7 +433,7 @@
  increase(void)
  {
  	struct diff *p;
-@@ -698,13 +737,29 @@ increase(void)
+@@ -698,13 +735,29 @@ increase(void)
  	szchanges = newsz;
  }
  



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120718162349.74FC3106564A>