socsvn commit: r237117 - in soc2012/jhagewood/diff3: . diff3

jhagewood at FreeBSD.org jhagewood at FreeBSD.org
Tue Jun 5 07:53:25 UTC 2012


Author: jhagewood
Date: Tue Jun  5 07:53:22 2012
New Revision: 237117
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=237117

Log:

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	Tue Jun  5 06:43:45 2012	(r237116)
+++ soc2012/jhagewood/diff3/diff3/diff3prog.c	Tue Jun  5 07:53:22 2012	(r237117)
@@ -152,6 +152,7 @@
 void repos(int);
 void separate(const char *);
 __dead void edscript(int);
+void remove_cr(FILE *);
 __dead void trouble(void);
 void increase(void);
 __dead void try_help(void);
@@ -173,13 +174,13 @@
 	{ "text",		no_argument,		NULL,	'a' },
 	{ "version",		no_argument,		NULL,	'v' },
 	{ "help",		no_argument,		NULL,	HELP_OPT },	
-	
+	{ "strip-trailing-cr",	no_argument,		NULL,	STRIPCR_OPT },
+		
 	/* features to implement */
 	{ "show-all",		no_argument,		NULL,	'A' },
 	{ "easy-only", 		no_argument,		NULL,	'3' },
 	{ "merge",		no_argument,		NULL,	'm' },
 	{ "label",		required_argument,	NULL,	'L' },
-	{ "strip-trailing-cr",	no_argument,		NULL,	STRIPCR_OPT },
 	{ "diff-program",	required_argument,	NULL,	DIFFPROG_OPT },
 
 
@@ -270,6 +271,8 @@
 	for (i = 0; i <= 2; i++) {
 		if ((fp[i] = fopen(argv[i + 2], "r")) == NULL)
 			err(EXIT_FAILURE, "can't open %s", argv[i + 2]);
+		if (strip_cr)
+			remove_cr(fp[i]);
 	}
 	merge(m, n);
 	exit(EXIT_SUCCESS);
@@ -622,6 +625,26 @@
 		(void)fseek(fp[i], (long)-nchar, SEEK_CUR);
 }
 
+/* Removes carriage return from open file. 
+ * TODO: Remove trailing cr only.
+ */
+void
+remove_cr(FILE *f) {
+	
+	char ch; 
+	fpos_t position;
+	
+	while ( ch != EOF) {
+		fgetpos(f, &position);
+		ch = fgetc(f);
+		if (ch == '\r') {
+			fsetpos(f, &position);
+			fputc((int)'\0', f);
+		}
+	}
+	rewind(f);
+}
+
 __dead void
 trouble(void)
 {

Modified: soc2012/jhagewood/diff3/hagewood-diff3.patch
==============================================================================
--- soc2012/jhagewood/diff3/hagewood-diff3.patch	Tue Jun  5 06:43:45 2012	(r237116)
+++ soc2012/jhagewood/diff3/hagewood-diff3.patch	Tue Jun  5 07:53:22 2012	(r237117)
@@ -11,7 +11,7 @@
  .include <bsd.prog.mk>
 diff -rupN jhagewood/diff3/diff3-orig/diff3prog.c jhagewood/diff3/diff3/diff3prog.c
 --- jhagewood/diff3/diff3-orig/diff3prog.c	2012-06-04 23:30:11.000000000 -0400
-+++ jhagewood/diff3/diff3/diff3prog.c	2012-06-05 01:17:18.000000000 -0400
++++ jhagewood/diff3/diff3/diff3prog.c	2012-06-05 07:53:14.000000000 -0400
 @@ -82,6 +82,9 @@
  
  /* diff3 - 3-way differential file comparison */
@@ -22,8 +22,11 @@
  /* diff3 [-ex3EX] d13 d23 f1 f2 f3 [m1 m3]
   *
   * d13 = diff report on f1 vs f3
-@@ -151,22 +154,26 @@ void separate(const char *);
+@@ -149,33 +152,38 @@ void prange(struct range *);
+ void repos(int);
+ void separate(const char *);
  __dead void edscript(int);
++void remove_cr(FILE *);
  __dead void trouble(void);
  void increase(void);
 -__dead void usage(void);
@@ -50,13 +53,14 @@
 -
 +	{ "version",		no_argument,		NULL,	'v' },
 +	{ "help",		no_argument,		NULL,	HELP_OPT },	
-+	
++	{ "strip-trailing-cr",	no_argument,		NULL,	STRIPCR_OPT },
++		
  	/* features to implement */
  	{ "show-all",		no_argument,		NULL,	'A' },
  	{ "easy-only", 		no_argument,		NULL,	'3' },
-@@ -174,8 +181,8 @@ static struct option longopts[] = {
+ 	{ "merge",		no_argument,		NULL,	'm' },
  	{ "label",		required_argument,	NULL,	'L' },
- 	{ "strip-trailing-cr",	no_argument,		NULL,	STRIPCR_OPT },
+-	{ "strip-trailing-cr",	no_argument,		NULL,	STRIPCR_OPT },
  	{ "diff-program",	required_argument,	NULL,	DIFFPROG_OPT },
 -	{ "version",		no_argument,		NULL,	'v' },
 -	{ "help",		no_argument,		NULL,	HELP_OPT }
@@ -65,7 +69,7 @@
  };
  
  
-@@ -216,12 +223,19 @@ main(int argc, char **argv)
+@@ -216,12 +224,19 @@ main(int argc, char **argv)
  		case 'X':
  			oflag = eflag = 1;
  			break;
@@ -85,7 +89,7 @@
  		case STRIPCR_OPT:
  			strip_cr = 1;
  			break;
-@@ -233,8 +247,10 @@ main(int argc, char **argv)
+@@ -233,8 +248,10 @@ main(int argc, char **argv)
  	argc -= optind;
  	argv += optind;
  	/* XXX - argc usage seems wrong here */
@@ -97,7 +101,43 @@
  
  	if (oflag) {
  		(void)snprintf(f1mark, sizeof(f1mark), "<<<<<<< %s",
-@@ -699,12 +715,38 @@ increase(void)
+@@ -254,6 +271,8 @@ main(int argc, char **argv)
+ 	for (i = 0; i <= 2; i++) {
+ 		if ((fp[i] = fopen(argv[i + 2], "r")) == NULL)
+ 			err(EXIT_FAILURE, "can't open %s", argv[i + 2]);
++		if (strip_cr)
++			remove_cr(fp[i]);
+ 	}
+ 	merge(m, n);
+ 	exit(EXIT_SUCCESS);
+@@ -606,6 +625,26 @@ repos(int nchar)
+ 		(void)fseek(fp[i], (long)-nchar, SEEK_CUR);
+ }
+ 
++/* Removes carriage return from open file. 
++ * TODO: Remove trailing cr only.
++ */
++void
++remove_cr(FILE *f) {
++	
++	char ch; 
++	fpos_t position;
++	
++	while ( ch != EOF) {
++		fgetpos(f, &position);
++		ch = fgetc(f);
++		if (ch == '\r') {
++			fsetpos(f, &position);
++			fputc((int)'\0', f);
++		}
++	}
++	rewind(f);
++}
++
+ __dead void
+ trouble(void)
+ {
+@@ -699,12 +738,38 @@ increase(void)
  }
  
  


More information about the svn-soc-all mailing list