=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/patch/pch.c,v retrieving revision 1.13 retrieving revision 1.14 diff -c -r1.13 -r1.14 *** src/usr.bin/patch/pch.c 2003/04/08 00:18:31 1.13 --- src/usr.bin/patch/pch.c 2003/07/16 18:09:20 1.14 *************** *** 1,7 **** ! /* $OpenBSD: pch.c,v 1.13 2003/04/08 00:18:31 deraadt Exp $ */ #ifndef lint ! static char rcsid[] = "$OpenBSD: pch.c,v 1.13 2003/04/08 00:18:31 deraadt Exp $"; #endif /* not lint */ #include "EXTERN.h" --- 1,7 ---- ! /* $OpenBSD: pch.c,v 1.14 2003/07/16 18:09:20 otto Exp $ */ #ifndef lint ! static char rcsid[] = "$OpenBSD: pch.c,v 1.14 2003/07/16 18:09:20 otto Exp $"; #endif /* not lint */ #include "EXTERN.h" *************** *** 404,409 **** --- 404,433 ---- /* 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,617 **** --- 636,649 ---- 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,744 **** --- 771,782 ---- 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,844 **** --- 877,888 ---- 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,879 **** --- 918,929 ---- 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,955 **** --- 1000,1011 ---- 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++; *************** *** 981,986 **** --- 1037,1047 ---- } 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? */