--- patch-2.5.9/patch.c 2003-05-20 06:55:03.000000000 -0700 +++ ./patch.c 2004-01-29 19:37:12.000000000 -0800 @@ -68,6 +68,8 @@ static bool spew_output (struct outstate static char const *make_temp (char); static int numeric_string (char const *, bool, char const *); static void abort_hunk (void); +static void abort_hunk_unified (void); +static void abort_hunk_posix (void); static void cleanup (void); static void get_some_switches (void); static void init_output (char const *, int, struct outstate *); @@ -932,6 +934,67 @@ locate_hunk (LINENUM fuzz) static void abort_hunk (void) { + if (diff_type == UNI_DIFF) + abort_hunk_unified (); + else + abort_hunk_posix (); +} + +static void +abort_hunk_unified (void) +{ + register LINENUM old = 1; + register LINENUM lastline = pch_ptrn_lines (); + register LINENUM new = lastline+1; + register LINENUM pat_end = pch_end (); + char numbuf0[LINENUM_LENGTH_BOUND + 1]; + char numbuf1[LINENUM_LENGTH_BOUND + 1]; + + while (pch_char(new) == '\n') + pch_write_line (new++, rejfp); + if (pch_char(new) == '=') + new++; + + /* add in last_offset to guess the same as the previous successful hunk */ + 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())); + + while (old <= lastline) { + if (pch_char(old) == '-' || pch_char(old) == '!') { + fputc ('-', rejfp); + pch_write_line (old++, rejfp); + } + else if (new > pat_end) { + break; + } + 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); + } +} + +static void +abort_hunk_posix (void) +{ register LINENUM i; register LINENUM pat_end = pch_end (); /* add in last_offset to guess the same as the previous successful hunk */