Index: patch.c --- patch-2.5.9/patch.c 2003-05-20 06:55:03.000000000 -0700 +++ ./patch.c 2004-01-29 11:24:34.000000000 -0800 @@ -932,57 +932,51 @@ locate_hunk (LINENUM fuzz) static void abort_hunk (void) { - register LINENUM i; + char numbuf0[LINENUM_LENGTH_BOUND + 1]; + char numbuf1[LINENUM_LENGTH_BOUND + 1]; + register LINENUM old = 1; + register LINENUM lastline = pch_ptrn_lines (); + register LINENUM new = lastline+1; register LINENUM pat_end = pch_end (); + /* add in last_offset to guess the same as the previous successful hunk */ - LINENUM oldfirst = pch_first() + last_offset; - LINENUM newfirst = pch_newfirst() + last_offset; - LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1; - LINENUM newlast = newfirst + pch_repl_lines() - 1; - char const *stars = - (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ****" : ""; - char const *minuses = - (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ----" : " -----"; + fprintf (rejfp, "@@ -%s,%s ", + format_linenum (numbuf0, pch_first() + last_offset), + format_linenum (numbuf1, lastline)); + fprintf (rejfp, "+%s,%s @@\n", + format_linenum (numbuf0, pch_newfirst() + last_offset), + format_linenum (numbuf1, pch_repl_lines())); - fprintf(rejfp, "***************\n"); - for (i=0; i<=pat_end; i++) { - char numbuf0[LINENUM_LENGTH_BOUND + 1]; - char numbuf1[LINENUM_LENGTH_BOUND + 1]; - switch (pch_char(i)) { - case '*': - if (oldlast < oldfirst) - fprintf(rejfp, "*** 0%s\n", stars); - else if (oldlast == oldfirst) - fprintf (rejfp, "*** %s%s\n", - format_linenum (numbuf0, oldfirst), stars); - else - fprintf (rejfp, "*** %s,%s%s\n", - format_linenum (numbuf0, oldfirst), - format_linenum (numbuf1, oldlast), stars); - break; - case '=': - if (newlast < newfirst) - fprintf(rejfp, "--- 0%s\n", minuses); - else if (newlast == newfirst) - fprintf (rejfp, "--- %s%s\n", - format_linenum (numbuf0, newfirst), minuses); - else - fprintf (rejfp, "--- %s,%s%s\n", - format_linenum (numbuf0, newfirst), - format_linenum (numbuf1, newlast), minuses); - break; - case ' ': case '-': case '+': case '!': - fprintf (rejfp, "%c ", pch_char (i)); - /* fall into */ - case '\n': - pch_write_line (i, rejfp); + while (pch_char(new) == '=' || pch_char(new) == '\n') + new++; + + while (old <= lastline) { + if (pch_char(old) == '-' || pch_char(old) == '!') { + fputc ('-', rejfp); + pch_write_line (old++, rejfp); + } + else if (new > pat_end) { break; - default: + } + else if (pch_char(new) == '+' || pch_char(new) == '!') { + fputc ('+', rejfp); + pch_write_line (new++, rejfp); + } + else if (pch_char(old) != ' ' || pch_char(new) != ' ') { fatal ("fatal internal error in abort_hunk"); } + else { + fputc (' ', rejfp); + pch_write_line (old++, rejfp); + new++; + } if (ferror (rejfp)) write_fatal (); } + while (new <= pat_end && pch_char(new) == '+') { + fputc ('+', rejfp); + pch_write_line (new++, rejfp); + } } /* We found where to apply it (we hope), so do it. */