Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Aug 2008 16:13:54 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 146535 for review
Message-ID:  <200808031613.m73GDsq0047207@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=146535

Change 146535 by gabor@gabor_server on 2008/08/03 16:13:49

	- Add some work-in-progress code for --strip-trailing-cr

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/diff/diff.c#17 edit
.. //depot/projects/soc2008/gabor_textproc/diff/diff.h#6 edit
.. //depot/projects/soc2008/gabor_textproc/diff/diffreg.c#6 edit

Differences ...

==== //depot/projects/soc2008/gabor_textproc/diff/diff.c#17 (text+ko) ====

@@ -46,7 +46,7 @@
 #include "diff.h"
 
 int	 aflag, bflag, dflag, iflag, lflag, Nflag, Pflag, pflag, rflag;
-int	 sflag, tflag, Tflag, wflag, uniflag;
+int	 sflag, tflag, Tflag, wflag, uniflag, strip_cr;
 int	 format, status;
 int	 fcase_behave = FCASE_SENSITIVE;
 unsigned long long context;
@@ -63,6 +63,7 @@
 	FROMFILE_OPT,
 	TOFILE_OPT,
 	UNIDIR_OPT,
+	STRIPCR_OPT,
 	NOOP_OPT
 };
 
@@ -70,8 +71,7 @@
 static struct option longopts[] = {
 	{ "ignore-file-name-case",	no_argument,		NULL,	FCASE_IGNORE_OPT },
 	{ "no-ignore-file-name-case",	no_argument,		NULL,	FCASE_SENSITIVE_OPT },
-/* XXX: UNIMPLEMENTED
-	{ "strip-trailing-cr",		no_argument,		NULL,	OPT_STRIPCR }, */
+	{ "strip-trailing-cr",		no_argument,		NULL,	STRIPCR_OPT },
 	{ "normal",			no_argument,		NULL,	NORMAL_OPT },
 /* XXX: UNIMPLEMENTED
 	{ "tabsize",			optional_argument,	NULL,	OPT_TSIZE }, */
@@ -284,9 +284,9 @@
 		case FCASE_IGNORE_OPT:
 			fcase_behave = FCASE_IGNORE;
 			break;
-		case 'F':
-		case 'y':
-		case 'W':
+		case STRIPCR_OPT:
+			strip_cr = 1;
+			break;
 		case NOOP_OPT:
 			/* noop, compatibility */
 			break;

==== //depot/projects/soc2008/gabor_textproc/diff/diff.h#6 (text+ko) ====

@@ -83,7 +83,7 @@
 };
 
 extern int	 aflag, bflag, dflag, iflag, lflag, Nflag, Pflag, pflag, rflag,
-		 sflag, tflag, Tflag, wflag, uniflag;
+		 sflag, tflag, Tflag, wflag, uniflag, strip_cr;
 extern int	 format, status;
 extern int	 fcase_behave;
 extern unsigned long long context;

==== //depot/projects/soc2008/gabor_textproc/diff/diffreg.c#6 (text+ko) ====

@@ -779,8 +779,16 @@
 				    (c == '\n' && d == EOF))) {
 					break;
 				}
+				if ((strip_cr) &&
+				    ((c == EOF && d == '\r') ||
+				    (c == '\r' && d == EOF)))
+					break;
 				ctold++;
 				ctnew++;
+				while ((strip_cr) && (c == '\r'))
+					c = getc(f1);
+				while ((strip_cr) && (d == '\r'))
+					d = getc(f2);
 				if (bflag && isspace(c) && isspace(d)) {
 					do {
 						if (c == '\n')
@@ -1228,6 +1236,8 @@
 	if (!bflag && !wflag) {
 		if (iflag)
 			for (i = 0; (t = getc(f)) != '\n'; i++) {
+				if (t == '\r' && strip_cr)
+					continue;
 				if (t == EOF) {
 					if (i == 0)
 						return (0);
@@ -1237,6 +1247,8 @@
 			}
 		else
 			for (i = 0; (t = getc(f)) != '\n'; i++) {
+				if (t == '\r' && strip_cr)
+					continue;
 				if (t == EOF) {
 					if (i == 0)
 						return (0);
@@ -1276,6 +1288,7 @@
 	 * There is a remote possibility that we end up with a zero sum.
 	 * Zero is used as an EOF marker, so return 1 instead.
 	 */
+	printf("HASH: %d\n", (sum == 0 ? 1 : sum));
 	return (sum == 0 ? 1 : sum);
 }
 



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