From owner-freebsd-arch Thu Apr 25 17:17:22 2002 Delivered-To: freebsd-arch@freebsd.org Received: from mail.rpi.edu (mail.rpi.edu [128.113.22.40]) by hub.freebsd.org (Postfix) with ESMTP id 9A94137B404; Thu, 25 Apr 2002 17:16:43 -0700 (PDT) Received: from [128.113.24.47] (gilead.netel.rpi.edu [128.113.24.47]) by mail.rpi.edu (8.12.1/8.12.1) with ESMTP id g3Q0Gfn5126116; Thu, 25 Apr 2002 20:16:42 -0400 Mime-Version: 1.0 X-Sender: drosih@mail.rpi.edu Message-Id: In-Reply-To: References: <200202091752.g19HqFP11551@green.bikeshed.org> <20020210040158.A26957@chiark.greenend.org.uk> Date: Thu, 25 Apr 2002 20:16:40 -0400 To: arch@FreeBSD.ORG From: Garance A Drosihn Subject: Re: diff & patch problem with 'No newline' Cc: freebsd-standards@FreeBSD.ORG Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Scanned-By: MIMEDefang 2.3 (www dot roaringpenguin dot com slash mimedefang) Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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-arch" in the body of the message