summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/patch/pch.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/patch/pch.c')
-rw-r--r--gnu/usr.bin/patch/pch.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/gnu/usr.bin/patch/pch.c b/gnu/usr.bin/patch/pch.c
index 71bbd25..c9ab9ce 100644
--- a/gnu/usr.bin/patch/pch.c
+++ b/gnu/usr.bin/patch/pch.c
@@ -434,6 +434,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, -1, SEEK_CUR);
+
+ return FALSE;
+}
+
/* True if there is more of the current diff listing to process. */
bool
@@ -641,6 +665,15 @@ 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 &&
@@ -768,6 +801,14 @@ 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);
@@ -865,6 +906,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 = ' ';
@@ -900,6 +947,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[filldst - 1] -= 1;
+ s[p_len[filldst - 1]] = 0;
+ }
+ }
break;
default:
p_end = filldst;
@@ -975,6 +1028,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++;
@@ -1007,6 +1066,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())
OpenPOWER on IntegriCloud