Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Apr 2002 20:16:40 -0400
From:      Garance A Drosihn <drosih@rpi.edu>
To:        arch@FreeBSD.ORG
Cc:        freebsd-standards@FreeBSD.ORG
Subject:   Re: diff & patch problem with 'No newline'
Message-ID:  <p05111716b8ee4c8dea6b@[128.113.24.47]>
In-Reply-To: <p05111715b8ee4710a108@[128.113.24.47]>
References:  <200202091752.g19HqFP11551@green.bikeshed.org> <p05101421b88b76a6aa12@[128.113.24.47]> <20020210040158.A26957@chiark.greenend.org.uk> <p05101422b88ba26bec5e@[128.113.24.47]> <p05111715b8ee4710a108@[128.113.24.47]>

next in thread | previous in thread | raw e-mail | index | archive | help
At 8:11 PM -0400 4/25/02, Garance A Drosihn wrote:
>The patch is pretty straightforward, and I would like to
>get it into our patch in for 4.6-release (along with the
>minor change to 'diff').  Any objections?

I guess it would help if I showed what the patch is...
NetBSD has apparently been running with this for a
few weeks.

Index: pch.c
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/patch/pch.c,v
retrieving revision 1.17
diff -u -r1.17 pch.c
--- pch.c	2 Aug 2000 06:54:21 -0000	1.17
+++ pch.c	26 Apr 2002 00:14:33 -0000
@@ -434,6 +434,30 @@
  		/* about as informative as "Syntax error" in C */
  }

+/*
+ * True if the line has been discarded (i.e. it is a line saying
+ *  "\ No newline at end of file".)
+ */
+static bool
+remove_special_line(void)
+{
+	int c;
+
+	c = fgetc(pfp);
+	if (c == '\\') {
+		do {
+			c = fgetc(pfp);
+		} while (c != EOF && c != '\n');
+
+		return TRUE;
+	}
+
+	if (c != EOF)
+		fseek(pfp, -1, SEEK_CUR);
+
+	return FALSE;
+}
+
  /* True if there is more of the current diff listing to process. */

  bool
@@ -641,6 +665,15 @@
  		    p_end--;
  		    return FALSE;
  		}
+		if (p_end == p_ptrn_lines)
+		{
+			if (remove_special_line()) {
+				int len;
+
+				len = strlen(p_line[p_end]) - 1;
+				(p_line[p_end])[len] = 0;
+			}
+		}
  		break;
  	    case '\t': case '\n':	/* assume the 2 spaces got eaten */
  		if (repl_beginning && repl_could_be_missing &&
@@ -768,6 +801,14 @@
  	    assert(fillsrc==p_end+1 || fillsrc==repl_beginning);
  	    assert(filldst==p_end+1 || filldst==repl_beginning);
  	}
+
+	if (p_line[p_end] != NULL)
+	{
+		if (remove_special_line()) {
+			p_len[p_end] -= 1;
+			(p_line[p_end])[p_len[p_end]] = 0;
+		}
+	}
      }
      else if (diff_type == UNI_DIFF) {
  	long line_beginning = ftell(pfp);
@@ -865,6 +906,12 @@
  		p_Char[fillsrc] = ch;
  		p_line[fillsrc] = s;
  		p_len[fillsrc++] = strlen(s);
+		if (fillsrc > p_ptrn_lines) {
+			if (remove_special_line()) {
+				p_len[fillsrc - 1] -= 1;
+				s[p_len[fillsrc - 1]] = 0;
+			}
+		}
  		break;
  	    case '=':
  		ch = ' ';
@@ -900,6 +947,12 @@
  		p_Char[filldst] = ch;
  		p_line[filldst] = s;
  		p_len[filldst++] = strlen(s);
+		if (fillsrc > p_ptrn_lines) {
+			if (remove_special_line()) {
+				p_len[filldst - 1] -= 1;
+				s[p_len[filldst - 1]] = 0;
+			}
+		}
  		break;
  	    default:
  		p_end = filldst;
@@ -975,6 +1028,12 @@
  	    p_len[i] = strlen(p_line[i]);
  	    p_Char[i] = '-';
  	}
+
+	if (remove_special_line()) {
+		p_len[i-1] -= 1;
+		(p_line[i-1])[p_len[i-1]] = 0;
+	}
+
  	if (hunk_type == 'c') {
  	    ret = pgets(buf, sizeof buf, pfp);
  	    p_input_line++;
@@ -1006,6 +1065,11 @@
  	    }
  	    p_len[i] = strlen(p_line[i]);
  	    p_Char[i] = '+';
+	}
+
+	if (remove_special_line()) {
+		p_len[i-1] -= 1;
+		(p_line[i-1])[p_len[i-1]] = 0;
  	}
      }
      if (reverse)			/* backwards patch? */

-- 
Garance Alistair Drosehn            =   gad@gilead.netel.rpi.edu
Senior Systems Programmer           or  gad@freebsd.org
Rensselaer Polytechnic Institute    or  drosih@rpi.edu

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




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