svn commit: r310879 - user/bapt/diff
Baptiste Daroussin
bapt at FreeBSD.org
Sat Dec 31 00:49:31 UTC 2016
Author: bapt
Date: Sat Dec 31 00:49:30 2016
New Revision: 310879
URL: https://svnweb.freebsd.org/changeset/base/310879
Log:
Implement diff --strip-trailing-cr
Modified:
user/bapt/diff/diff.c
user/bapt/diff/diff.h
user/bapt/diff/diffreg.c
Modified: user/bapt/diff/diff.c
==============================================================================
--- user/bapt/diff/diff.c Sat Dec 31 00:01:21 2016 (r310878)
+++ user/bapt/diff/diff.c Sat Dec 31 00:49:30 2016 (r310879)
@@ -50,6 +50,7 @@ regex_t ignore_re;
#define OPTIONS "0123456789aBbC:cdD:efhI:iL:lnNPpqrS:sTtU:uwX:x:"
enum {
OPT_TSIZE = CHAR_MAX + 1,
+ OPT_STRIPCR,
};
static struct option longopts[] = {
@@ -78,6 +79,7 @@ static struct option longopts[] = {
{ "ignore-all-space", no_argument, 0, 'w' },
{ "exclude", required_argument, 0, 'x' },
{ "exclude-from", required_argument, 0, 'X' },
+ { "strip-trailing-cr", no_argument, NULL, OPT_STRIPCR },
{ "tabsize", optional_argument, NULL, OPT_TSIZE },
{ NULL, 0, 0, '\0'}
};
@@ -224,6 +226,9 @@ main(int argc, char **argv)
usage();
}
break;
+ case OPT_STRIPCR:
+ dflags |= D_STRIPCR;
+ break;
default:
usage();
break;
Modified: user/bapt/diff/diff.h
==============================================================================
--- user/bapt/diff/diff.h Sat Dec 31 00:01:21 2016 (r310878)
+++ user/bapt/diff/diff.h Sat Dec 31 00:49:30 2016 (r310879)
@@ -65,6 +65,7 @@
#define D_PROTOTYPE 0x080 /* Display C function prototype */
#define D_EXPANDTABS 0x100 /* Expand tabs to spaces */
#define D_IGNOREBLANKS 0x200 /* Ignore white space changes */
+#define D_STRIPCR 0x500 /* Strip trailing cr */
/*
* Status values for print_status() and diffreg() return values
Modified: user/bapt/diff/diffreg.c
==============================================================================
--- user/bapt/diff/diffreg.c Sat Dec 31 00:01:21 2016 (r310878)
+++ user/bapt/diff/diffreg.c Sat Dec 31 00:49:30 2016 (r310879)
@@ -776,7 +776,7 @@ check(FILE *f1, FILE *f2, int flags)
ixnew[j] = ctnew += skipline(f2);
j++;
}
- if (flags & (D_FOLDBLANKS|D_IGNOREBLANKS|D_IGNORECASE)) {
+ if (flags & (D_FOLDBLANKS|D_IGNOREBLANKS|D_IGNORECASE|D_STRIPCR)) {
for (;;) {
c = getc(f1);
d = getc(f2);
@@ -795,6 +795,20 @@ check(FILE *f1, FILE *f2, int flags)
}
ctold++;
ctnew++;
+ if (flags & D_STRIPCR) {
+ if (c == '\r') {
+ if ((c = getc(f1)) == '\n') {
+ ctnew++;
+ break;
+ }
+ }
+ if (d == '\r') {
+ if ((d = getc(f2)) == '\n') {
+ ctold++;
+ break;
+ }
+ }
+ }
if ((flags & D_FOLDBLANKS) && isspace(c) &&
isspace(d)) {
do {
@@ -850,8 +864,9 @@ check(FILE *f1, FILE *f2, int flags)
ixnew[j] = ctnew;
j++;
}
- for (; j <= len[1]; j++)
+ for (; j <= len[1]; j++) {
ixnew[j] = ctnew += skipline(f2);
+ }
/*
* if (jackpot)
* fprintf(stderr, "jackpot\n");
@@ -1246,6 +1261,12 @@ readhash(FILE *f, int flags)
if ((flags & (D_FOLDBLANKS|D_IGNOREBLANKS)) == 0) {
if (flags & D_IGNORECASE)
for (i = 0; (t = getc(f)) != '\n'; i++) {
+ if (flags & D_STRIPCR && t == '\r') {
+ t = getc(f);
+ if (t == '\n')
+ break;
+ ungetc(t, f);
+ }
if (t == EOF) {
if (i == 0)
return (0);
@@ -1255,6 +1276,12 @@ readhash(FILE *f, int flags)
}
else
for (i = 0; (t = getc(f)) != '\n'; i++) {
+ if (flags & D_STRIPCR && t == '\r') {
+ t = getc(f);
+ if (t == '\n')
+ break;
+ ungetc(t, f);
+ }
if (t == EOF) {
if (i == 0)
return (0);
@@ -1265,8 +1292,8 @@ readhash(FILE *f, int flags)
} else {
for (i = 0;;) {
switch (t = getc(f)) {
- case '\t':
case '\r':
+ case '\t':
case '\v':
case '\f':
case ' ':
More information about the svn-src-user
mailing list