diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-07-16 18:09:21 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-07-16 18:09:21 +0000 |
commit | 87104837f8d2f765f35a3562fdce090a5df732ca (patch) | |
tree | fffe65d53c4824aa4dbf8c4d91e2b37750783436 /usr.bin/patch/pch.c | |
parent | 22d3b2bd5a59dc3997adfcb0a55fc38aee9db33b (diff) |
Teach patch how to deal with \ No newline at end of file.
From NetBSD.
ok deraadt@
Diffstat (limited to 'usr.bin/patch/pch.c')
-rw-r--r-- | usr.bin/patch/pch.c | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index c0c01b8242a..a2228d080ed 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: pch.c,v 1.13 2003/04/08 00:18:31 deraadt Exp $ */ +/* $OpenBSD: pch.c,v 1.14 2003/07/16 18:09:20 otto Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: pch.c,v 1.13 2003/04/08 00:18:31 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: pch.c,v 1.14 2003/07/16 18:09:20 otto Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -404,6 +404,30 @@ malformed () /* 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, -1L, SEEK_CUR); + + return FALSE; +} + /* True if there is more of the current diff listing to process. */ bool @@ -612,6 +636,14 @@ another_hunk() 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 && @@ -739,6 +771,12 @@ another_hunk() 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); @@ -839,6 +877,12 @@ another_hunk() 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 = ' '; @@ -874,6 +918,12 @@ another_hunk() p_char[filldst] = ch; p_line[filldst] = s; p_len[filldst++] = strlen(s); + if (fillsrc > p_ptrn_lines) { + if (remove_special_line()) { + p_len[fillsrc - 1] -= 1; + s[p_len[fillsrc - 1]] = 0; + } + } break; default: p_end = filldst; @@ -950,6 +1000,12 @@ another_hunk() 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++; @@ -982,6 +1038,11 @@ another_hunk() 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? */ if (!pch_swap()) |