=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/patch/patch.c,v retrieving revision 1.18 retrieving revision 1.19 diff -c -r1.18 -r1.19 *** src/usr.bin/patch/patch.c 2003/07/16 16:06:53 1.18 --- src/usr.bin/patch/patch.c 2003/07/18 02:00:09 1.19 *************** *** 1,4 **** ! /* $OpenBSD: patch.c,v 1.18 2003/07/16 16:06:53 otto Exp $ */ /* patch - a program to apply diffs to original files * --- 1,4 ---- ! /* $OpenBSD: patch.c,v 1.19 2003/07/18 02:00:09 deraadt Exp $ */ /* patch - a program to apply diffs to original files * *************** *** 9,15 **** * is met: * 1. Redistributions of source code must retain the above copyright * notice, this condition and the following disclaimer. ! * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE --- 9,15 ---- * is met: * 1. Redistributions of source code must retain the above copyright * notice, this condition and the following disclaimer. ! * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *************** *** 27,39 **** */ #ifndef lint ! static char rcsid[] = "$OpenBSD: patch.c,v 1.18 2003/07/16 16:06:53 otto Exp $"; #endif /* not lint */ #include "INTERN.h" #include "common.h" #include "EXTERN.h" - #include "version.h" #include "util.h" #include "pch.h" #include "inp.h" --- 27,38 ---- */ #ifndef lint ! static char rcsid[] = "$OpenBSD: patch.c,v 1.19 2003/07/18 02:00:09 deraadt Exp $"; #endif /* not lint */ #include "INTERN.h" #include "common.h" #include "EXTERN.h" #include "util.h" #include "pch.h" #include "inp.h" *************** *** 41,64 **** /* procedures */ ! void reinitialize_almost_everything(); ! void get_some_switches(); ! LINENUM locate_hunk(); ! void abort_hunk(); ! void apply_hunk(); ! void init_output(); ! void init_reject(); ! void copy_till(); ! void spew_output(); ! void dump_line(); ! bool patch_match(); ! bool similar(); ! void re_input(); ! #ifdef __GNUC__ ! void my_exit() __attribute__((noreturn)); ! #else ! void my_exit(); ! #endif /* TRUE if -E was specified on command line. */ static int remove_empty_files = FALSE; --- 40,61 ---- /* procedures */ ! void reinitialize_almost_everything(void); ! void get_some_switches(void); ! LINENUM locate_hunk(LINENUM); ! void abort_hunk(void); ! void apply_hunk(LINENUM); ! void init_output(char *); ! void init_reject(char *); ! void copy_till(LINENUM); ! void spew_output(void); ! void dump_line(LINENUM); ! bool patch_match(LINENUM, LINENUM, LINENUM); ! bool similar(char *, char *, int); ! void re_input(void); ! void my_exit(int) __attribute__((noreturn)); ! int optcmp(const void *, const void *); ! char decode_long_option(char *); /* TRUE if -E was specified on command line. */ static int remove_empty_files = FALSE; *************** *** 72,80 **** /* Apply a set of diffs as appropriate. */ int ! main(argc,argv) ! int argc; ! char **argv; { LINENUM where; LINENUM newwhere; --- 69,75 ---- /* Apply a set of diffs as appropriate. */ int ! main(int argc, char *argv[]) { LINENUM where; LINENUM newwhere; *************** *** 103,130 **** } if (asprintf(&TMPOUTNAME, "%s/patchoXXXXXXXXXX", tmpdir) == -1) ! fatal1("cannot allocate memory"); if ((i = mkstemp(TMPOUTNAME)) < 0) ! pfatal2("can't create %s", TMPOUTNAME); ! Close(i); if (asprintf(&TMPINNAME, "%s/patchiXXXXXXXXXX", tmpdir) == -1) ! fatal1("cannot allocate memory"); if ((i = mkstemp(TMPINNAME)) < 0) ! pfatal2("can't create %s", TMPINNAME); ! Close(i); if (asprintf(&TMPREJNAME, "%s/patchrXXXXXXXXXX", tmpdir) == -1) ! fatal1("cannot allocate memory"); if ((i = mkstemp(TMPREJNAME)) < 0) ! pfatal2("can't create %s", TMPREJNAME); ! Close(i); if (asprintf(&TMPPATNAME, "%s/patchpXXXXXXXXXX", tmpdir) == -1) ! fatal1("cannot allocate memory"); if ((i = mkstemp(TMPPATNAME)) < 0) ! pfatal2("can't create %s", TMPPATNAME); ! Close(i); } { --- 98,125 ---- } if (asprintf(&TMPOUTNAME, "%s/patchoXXXXXXXXXX", tmpdir) == -1) ! fatal("cannot allocate memory"); if ((i = mkstemp(TMPOUTNAME)) < 0) ! pfatal("can't create %s", TMPOUTNAME); ! close(i); if (asprintf(&TMPINNAME, "%s/patchiXXXXXXXXXX", tmpdir) == -1) ! fatal("cannot allocate memory"); if ((i = mkstemp(TMPINNAME)) < 0) ! pfatal("can't create %s", TMPINNAME); ! close(i); if (asprintf(&TMPREJNAME, "%s/patchrXXXXXXXXXX", tmpdir) == -1) ! fatal("cannot allocate memory"); if ((i = mkstemp(TMPREJNAME)) < 0) ! pfatal("can't create %s", TMPREJNAME); ! close(i); if (asprintf(&TMPPATNAME, "%s/patchpXXXXXXXXXX", tmpdir) == -1) ! fatal("cannot allocate memory"); if ((i = mkstemp(TMPPATNAME)) < 0) ! pfatal("can't create %s", TMPPATNAME); ! close(i); } { *************** *** 145,151 **** Argc = argc; Argv = argv; get_some_switches(); ! /* make sure we clean up /tmp in case of disaster */ set_signals(0); --- 140,146 ---- Argc = argc; Argv = argv; get_some_switches(); ! /* make sure we clean up /tmp in case of disaster */ set_signals(0); *************** *** 158,184 **** if (outname == Nullch) outname = savestr(filearg[0]); ! /* for ed script just up and do it and exit */ if (diff_type == ED_DIFF) { do_ed_script(); continue; } ! /* initialize the patched file */ if (!skip_rest_of_patch) init_output(TMPOUTNAME); ! /* initialize reject file */ init_reject(TMPREJNAME); ! /* find out where all the lines are */ if (!skip_rest_of_patch) scan_input(filearg[0]); ! /* from here on, open no standard i/o files, because malloc */ /* might misfire and we can't catch it easily */ ! /* apply each hunk of patch */ hunk = 0; failed = 0; --- 153,179 ---- if (outname == Nullch) outname = savestr(filearg[0]); ! /* for ed script just up and do it and exit */ if (diff_type == ED_DIFF) { do_ed_script(); continue; } ! /* initialize the patched file */ if (!skip_rest_of_patch) init_output(TMPOUTNAME); ! /* initialize reject file */ init_reject(TMPREJNAME); ! /* find out where all the lines are */ if (!skip_rest_of_patch) scan_input(filearg[0]); ! /* from here on, open no standard i/o files, because malloc */ /* might misfire and we can't catch it easily */ ! /* apply each hunk of patch */ hunk = 0; failed = 0; *************** *** 196,202 **** /* dwim for reversed patch? */ if (!pch_swap()) { if (fuzz == Nulline) ! say1( "Not enough memory to try swapped hunk! Assuming unswapped.\n"); continue; } --- 191,197 ---- /* dwim for reversed patch? */ if (!pch_swap()) { if (fuzz == Nulline) ! say( "Not enough memory to try swapped hunk! Assuming unswapped.\n"); continue; } *************** *** 204,240 **** where = locate_hunk(fuzz); /* try again */ if (where == Nulline) { /* didn't find it swapped */ if (!pch_swap()) /* put it back to normal */ ! fatal1("lost hunk on alloc error!\n"); reverse = !reverse; } else if (noreverse) { if (!pch_swap()) /* put it back to normal */ ! fatal1("lost hunk on alloc error!\n"); reverse = !reverse; ! say1( "Ignoring previously applied (or reversed) patch.\n"); skip_rest_of_patch = TRUE; } else if (batch) { if (verbose) ! say3( "%seversed (or previously applied) patch detected! %s -R.", reverse ? "R" : "Unr", reverse ? "Assuming" : "Ignoring"); } else { ! ask3( "%seversed (or previously applied) patch detected! %s -R? [y] ", reverse ? "R" : "Unr", reverse ? "Assume" : "Ignore"); if (*buf == 'n') { ! ask1("Apply anyway? [n] "); if (*buf != 'y') skip_rest_of_patch = TRUE; where = Nulline; reverse = !reverse; if (!pch_swap()) /* put it back to normal */ ! fatal1("lost hunk on alloc error!\n"); } } } --- 199,235 ---- where = locate_hunk(fuzz); /* try again */ if (where == Nulline) { /* didn't find it swapped */ if (!pch_swap()) /* put it back to normal */ ! fatal("lost hunk on alloc error!\n"); reverse = !reverse; } else if (noreverse) { if (!pch_swap()) /* put it back to normal */ ! fatal("lost hunk on alloc error!\n"); reverse = !reverse; ! say( "Ignoring previously applied (or reversed) patch.\n"); skip_rest_of_patch = TRUE; } else if (batch) { if (verbose) ! say( "%seversed (or previously applied) patch detected! %s -R.", reverse ? "R" : "Unr", reverse ? "Assuming" : "Ignoring"); } else { ! ask( "%seversed (or previously applied) patch detected! %s -R? [y] ", reverse ? "R" : "Unr", reverse ? "Assume" : "Ignore"); if (*buf == 'n') { ! ask("Apply anyway? [n] "); if (*buf != 'y') skip_rest_of_patch = TRUE; where = Nulline; reverse = !reverse; if (!pch_swap()) /* put it back to normal */ ! fatal("lost hunk on alloc error!\n"); } } } *************** *** 242,248 **** ++fuzz <= mymaxfuzz); if (skip_rest_of_patch) { /* just got decided */ ! Fclose(ofp); ofp = Nullfp; } } --- 237,243 ---- ++fuzz <= mymaxfuzz); if (skip_rest_of_patch) { /* just got decided */ ! fclose(ofp); ofp = Nullfp; } } *************** *** 252,275 **** abort_hunk(); failed++; if (verbose) ! say3("Hunk #%d ignored at %ld.\n", hunk, newwhere); } else if (where == Nulline) { abort_hunk(); failed++; if (verbose) ! say3("Hunk #%d failed at %ld.\n", hunk, newwhere); } else { apply_hunk(where); if (verbose) { ! say3("Hunk #%d succeeded at %ld", hunk, newwhere); if (fuzz) ! say2(" with fuzz %ld", fuzz); if (last_offset) ! say3(" (offset %ld line%s)", last_offset, last_offset==1L?"":"s"); ! say1(".\n"); } } } --- 247,270 ---- abort_hunk(); failed++; if (verbose) ! say("Hunk #%d ignored at %ld.\n", hunk, newwhere); } else if (where == Nulline) { abort_hunk(); failed++; if (verbose) ! say("Hunk #%d failed at %ld.\n", hunk, newwhere); } else { apply_hunk(where); if (verbose) { ! say("Hunk #%d succeeded at %ld", hunk, newwhere); if (fuzz) ! say(" with fuzz %ld", fuzz); if (last_offset) ! say(" (offset %ld line%s)", last_offset, last_offset==1L?"":"s"); ! say(".\n"); } } } *************** *** 277,305 **** if (out_of_mem && using_plan_a) { Argc = Argc_last; Argv = Argv_last; ! say1("\n\nRan out of memory using Plan A--trying again...\n\n"); if (ofp) ! Fclose(ofp); ofp = Nullfp; if (rejfp) ! Fclose(rejfp); rejfp = Nullfp; continue; } ! assert(hunk); ! /* finish spewing out the new file */ if (!skip_rest_of_patch) spew_output(); ! /* and put the output where desired */ ignore_signals(); if (!skip_rest_of_patch) { struct stat statbuf; char *realout = outname; ! if (!check_only) { if (move_file(TMPOUTNAME, outname) < 0) { toutkeep = TRUE; realout = TMPOUTNAME; --- 272,300 ---- if (out_of_mem && using_plan_a) { Argc = Argc_last; Argv = Argv_last; ! say("\n\nRan out of memory using Plan A--trying again...\n\n"); if (ofp) ! fclose(ofp); ofp = Nullfp; if (rejfp) ! fclose(rejfp); rejfp = Nullfp; continue; } ! assert(hunk); ! /* finish spewing out the new file */ if (!skip_rest_of_patch) spew_output(); ! /* and put the output where desired */ ignore_signals(); if (!skip_rest_of_patch) { struct stat statbuf; char *realout = outname; ! if (!check_only) { if (move_file(TMPOUTNAME, outname) < 0) { toutkeep = TRUE; realout = TMPOUTNAME; *************** *** 311,350 **** if (remove_empty_files && stat(realout, &statbuf) == 0 && statbuf.st_size == 0) { if (verbose) ! say2("Removing %s (empty after patching).\n", realout); while (unlink(realout) >= 0) ; /* while is for Eunice. */ } } } ! Fclose(rejfp); rejfp = Nullfp; if (failed) { failtotal += failed; if (!*rejname) { if (strlcpy(rejname, outname, sizeof(rejname)) >= sizeof(rejname)) ! fatal2("filename %s is too long\n", outname); ! ! #ifndef FLEXFILENAMES ! { ! char *s = strrchr(rejname,'/'); ! ! if (!s) ! s = rejname; ! if (strlen(s) > 13) ! if (s[12] == '.') /* try to preserve difference */ ! s[12] = s[13]; /* between .h, .c, .y, etc. */ ! s[13] = '\0'; ! } ! #endif if (strlcat(rejname, REJEXT, sizeof(rejname)) >= sizeof(rejname)) ! fatal2("filename %s is too long\n", outname); } if (skip_rest_of_patch) { ! say4("%d out of %d hunks ignored--saving rejects to %s\n", failed, hunk, rejname); } else { ! say4("%d out of %d hunks failed--saving rejects to %s\n", failed, hunk, rejname); } if (!check_only && move_file(TMPREJNAME, rejname) < 0) --- 306,332 ---- if (remove_empty_files && stat(realout, &statbuf) == 0 && statbuf.st_size == 0) { if (verbose) ! say("Removing %s (empty after patching).\n", realout); while (unlink(realout) >= 0) ; /* while is for Eunice. */ } } } ! fclose(rejfp); rejfp = Nullfp; if (failed) { failtotal += failed; if (!*rejname) { if (strlcpy(rejname, outname, sizeof(rejname)) >= sizeof(rejname)) ! fatal("filename %s is too long\n", outname); if (strlcat(rejname, REJEXT, sizeof(rejname)) >= sizeof(rejname)) ! fatal("filename %s is too long\n", outname); } if (skip_rest_of_patch) { ! say("%d out of %d hunks ignored--saving rejects to %s\n", failed, hunk, rejname); } else { ! say("%d out of %d hunks failed--saving rejects to %s\n", failed, hunk, rejname); } if (!check_only && move_file(TMPREJNAME, rejname) < 0) *************** *** 353,359 **** set_signals(1); } if (!patch_seen) ! failtotal++; my_exit(failtotal); /* NOTREACHED */ } --- 335,341 ---- set_signals(1); } if (!patch_seen) ! failtotal++; my_exit(failtotal); /* NOTREACHED */ } *************** *** 395,408 **** get_some_switches(); if (filec >= 2) ! fatal1("you may not change to a different patch file\n"); } static char * ! nextarg() { if (!--Argc) ! fatal2("missing argument after `%s'\n", *Argv); return *++Argv; } --- 377,390 ---- get_some_switches(); if (filec >= 2) ! fatal("you may not change to a different patch file\n"); } static char * ! nextarg(void) { if (!--Argc) ! fatal("missing argument after `%s'\n", *Argv); return *++Argv; } *************** *** 414,430 **** }; int ! optcmp(a, b) ! struct option *a, *b; { return strcmp (a->long_opt, b->long_opt); } /* Decode Long options beginning with "--" to their short equivalents. */ char ! decode_long_option(opt) ! char *opt; { /* This table must be sorted on the first field. We also decode unimplemented options as those will be handled later anyway. */ --- 396,412 ---- }; int ! optcmp(const void *v1, const void *v2) { + const struct option *a = v1, *b = v2; + return strcmp (a->long_opt, b->long_opt); } /* Decode Long options beginning with "--" to their short equivalents. */ char ! decode_long_option(char *opt) { /* This table must be sorted on the first field. We also decode unimplemented options as those will be handled later anyway. */ *************** *** 469,475 **** void get_some_switches() { ! Reg1 char *s; rejname[0] = '\0'; Argc_last = Argc; --- 451,457 ---- void get_some_switches() { ! char *s; rejname[0] = '\0'; Argc_last = Argc; *************** *** 483,489 **** } if (*s != '-' || !s[1]) { if (filec == MAXFILEC) ! fatal1("too many file arguments\n"); filearg[filec++] = savestr(s); } else { --- 465,471 ---- } if (*s != '-' || !s[1]) { if (filec == MAXFILEC) ! fatal("too many file arguments\n"); filearg[filec++] = savestr(s); } else { *************** *** 506,528 **** diff_type = CONTEXT_DIFF; break; case 'C': ! check_only = TRUE; break; case 'd': if (!*++s) s = nextarg(); if (chdir(s) < 0) ! pfatal2("can't cd to %s", s); break; case 'D': ! do_defines = TRUE; if (!*++s) s = nextarg(); if (!isalpha(*s) && '_' != *s) ! fatal1("argument to -D is not an identifier\n"); ! Snprintf(if_defined, sizeof if_defined, "#ifdef %s\n", s); ! Snprintf(not_defined, sizeof not_defined, "#ifndef %s\n", s); ! Snprintf(end_defined, sizeof end_defined, "#endif /* %s */\n", s); break; case 'e': diff_type = ED_DIFF; --- 488,510 ---- diff_type = CONTEXT_DIFF; break; case 'C': ! check_only = TRUE; break; case 'd': if (!*++s) s = nextarg(); if (chdir(s) < 0) ! pfatal("can't cd to %s", s); break; case 'D': ! do_defines = TRUE; if (!*++s) s = nextarg(); if (!isalpha(*s) && '_' != *s) ! fatal("argument to -D is not an identifier\n"); ! snprintf(if_defined, sizeof if_defined, "#ifdef %s\n", s); ! snprintf(not_defined, sizeof not_defined, "#ifndef %s\n", s); ! snprintf(end_defined, sizeof end_defined, "#endif /* %s */\n", s); break; case 'e': diff_type = ED_DIFF; *************** *** 561,567 **** break; case 'r': if (strlcpy(rejname, nextarg(), sizeof(rejname)) >= sizeof(rejname)) ! fatal1("argument for -r is too long\n"); break; case 'R': reverse = TRUE; --- 543,549 ---- break; case 'r': if (strlcpy(rejname, nextarg(), sizeof(rejname)) >= sizeof(rejname)) ! fatal("argument for -r is too long\n"); break; case 'R': reverse = TRUE; *************** *** 614,625 **** locate_hunk(fuzz) LINENUM fuzz; { ! Reg1 LINENUM first_guess = pch_first() + last_offset; ! Reg2 LINENUM offset; LINENUM pat_lines = pch_ptrn_lines(); ! Reg3 LINENUM max_pos_offset = input_lines - first_guess ! - pat_lines + 1; ! Reg4 LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + pch_context(); if (!pat_lines) /* null range matches always */ --- 596,607 ---- locate_hunk(fuzz) LINENUM fuzz; { ! LINENUM first_guess = pch_first() + last_offset; ! LINENUM offset; LINENUM pat_lines = pch_ptrn_lines(); ! LINENUM max_pos_offset = input_lines - first_guess ! - pat_lines + 1; ! LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + pch_context(); if (!pat_lines) /* null range matches always */ *************** *** 629,641 **** if (first_guess <= input_lines && patch_match(first_guess, Nulline, fuzz)) return first_guess; for (offset = 1; ; offset++) { ! Reg5 bool check_after = (offset <= max_pos_offset); ! Reg6 bool check_before = (offset <= max_neg_offset); if (check_after && patch_match(first_guess, offset, fuzz)) { #ifdef DEBUGGING if (debug & 1) ! say3("Offset changing from %ld to %ld\n", last_offset, offset); #endif last_offset = offset; return first_guess+offset; --- 611,623 ---- if (first_guess <= input_lines && patch_match(first_guess, Nulline, fuzz)) return first_guess; for (offset = 1; ; offset++) { ! bool check_after = (offset <= max_pos_offset); ! bool check_before = (offset <= max_neg_offset); if (check_after && patch_match(first_guess, offset, fuzz)) { #ifdef DEBUGGING if (debug & 1) ! say("Offset changing from %ld to %ld\n", last_offset, offset); #endif last_offset = offset; return first_guess+offset; *************** *** 643,649 **** else if (check_before && patch_match(first_guess, -offset, fuzz)) { #ifdef DEBUGGING if (debug & 1) ! say3("Offset changing from %ld to %ld\n", last_offset, -offset); #endif last_offset = -offset; return first_guess-offset; --- 625,631 ---- else if (check_before && patch_match(first_guess, -offset, fuzz)) { #ifdef DEBUGGING if (debug & 1) ! say("Offset changing from %ld to %ld\n", last_offset, -offset); #endif last_offset = -offset; return first_guess-offset; *************** *** 658,665 **** void abort_hunk() { ! Reg1 LINENUM i; ! Reg2 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; --- 640,647 ---- void abort_hunk() { ! LINENUM i; ! 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; *************** *** 694,700 **** fprintf(rejfp, "%c %s", pch_char(i), pfetch(i)); break; default: ! fatal1("fatal internal error in abort_hunk\n"); } } } --- 676,682 ---- fprintf(rejfp, "%c %s", pch_char(i), pfetch(i)); break; default: ! fatal("fatal internal error in abort_hunk\n"); } } } *************** *** 705,725 **** apply_hunk(where) LINENUM where; { ! Reg1 LINENUM old = 1; ! Reg2 LINENUM lastline = pch_ptrn_lines(); ! Reg3 LINENUM new = lastline+1; #define OUTSIDE 0 #define IN_IFNDEF 1 #define IN_IFDEF 2 #define IN_ELSE 3 ! Reg4 int def_state = OUTSIDE; ! Reg5 bool R_do_defines = do_defines; ! Reg6 LINENUM pat_end = pch_end(); where--; while (pch_char(new) == '=' || pch_char(new) == '\n') new++; ! while (old <= lastline) { if (pch_char(old) == '-') { copy_till(where + old - 1); --- 687,707 ---- apply_hunk(where) LINENUM where; { ! LINENUM old = 1; ! LINENUM lastline = pch_ptrn_lines(); ! LINENUM new = lastline+1; #define OUTSIDE 0 #define IN_IFNDEF 1 #define IN_IFDEF 2 #define IN_ELSE 3 ! int def_state = OUTSIDE; ! bool R_do_defines = do_defines; ! LINENUM pat_end = pch_end(); where--; while (pch_char(new) == '=' || pch_char(new) == '\n') new++; ! while (old <= lastline) { if (pch_char(old) == '-') { copy_till(where + old - 1); *************** *** 756,766 **** new++; } else if (pch_char(new) != pch_char(old)) { ! say3("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n", pch_hunk_beg() + old, pch_hunk_beg() + new); #ifdef DEBUGGING ! say3("oldchar = '%c', newchar = '%c'\n", pch_char(old), pch_char(new)); #endif my_exit(1); --- 738,748 ---- new++; } else if (pch_char(new) != pch_char(old)) { ! say("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n", pch_hunk_beg() + old, pch_hunk_beg() + new); #ifdef DEBUGGING ! say("oldchar = '%c', newchar = '%c'\n", pch_char(old), pch_char(new)); #endif my_exit(1); *************** *** 801,807 **** copy_till(where + old - 1); if (R_do_defines) { if (def_state == OUTSIDE) { ! fputs(if_defined, ofp); def_state = IN_IFDEF; } else if (def_state == IN_IFNDEF) { --- 783,789 ---- copy_till(where + old - 1); if (R_do_defines) { if (def_state == OUTSIDE) { ! fputs(if_defined, ofp); def_state = IN_IFDEF; } else if (def_state == IN_IFNDEF) { *************** *** 827,833 **** { ofp = fopen(name, "w"); if (ofp == Nullfp) ! pfatal2("can't create %s", name); } /* Open a file to put hunks we can't locate. */ --- 809,815 ---- { ofp = fopen(name, "w"); if (ofp == Nullfp) ! pfatal("can't create %s", name); } /* Open a file to put hunks we can't locate. */ *************** *** 838,856 **** { rejfp = fopen(name, "w"); if (rejfp == Nullfp) ! pfatal2("can't create %s", name); } /* Copy input file to output, up to wherever hunk is to be applied. */ void copy_till(lastline) ! Reg1 LINENUM lastline; { ! Reg2 LINENUM R_last_frozen_line = last_frozen_line; if (R_last_frozen_line > lastline) ! fatal1("misordered hunks! output would be garbled\n"); while (R_last_frozen_line < lastline) { dump_line(++R_last_frozen_line); } --- 820,838 ---- { rejfp = fopen(name, "w"); if (rejfp == Nullfp) ! pfatal("can't create %s", name); } /* Copy input file to output, up to wherever hunk is to be applied. */ void copy_till(lastline) ! LINENUM lastline; { ! LINENUM R_last_frozen_line = last_frozen_line; if (R_last_frozen_line > lastline) ! fatal("misordered hunks! output would be garbled\n"); while (R_last_frozen_line < lastline) { dump_line(++R_last_frozen_line); } *************** *** 864,874 **** { #ifdef DEBUGGING if (debug & 256) ! say3("il=%ld lfl=%ld\n",input_lines,last_frozen_line); #endif if (input_lines) copy_till(input_lines); /* dump remainder of file */ ! Fclose(ofp); ofp = Nullfp; } --- 846,856 ---- { #ifdef DEBUGGING if (debug & 256) ! say("il=%ld lfl=%ld\n",input_lines,last_frozen_line); #endif if (input_lines) copy_till(input_lines); /* dump remainder of file */ ! fclose(ofp); ofp = Nullfp; } *************** *** 878,885 **** dump_line(line) LINENUM line; { ! Reg1 char *s; ! Reg2 char R_newline = '\n'; s = ifetch(line, 0); if (s == NULL) --- 860,867 ---- dump_line(line) LINENUM line; { ! char *s; ! char R_newline = '\n'; s = ifetch(line, 0); if (s == NULL) *************** *** 896,904 **** LINENUM offset; LINENUM fuzz; { ! Reg1 LINENUM pline = 1 + fuzz; ! Reg2 LINENUM iline; ! Reg3 LINENUM pat_lines = pch_ptrn_lines() - fuzz; for (iline=base+offset+fuzz; pline <= pat_lines; pline++,iline++) { if (canonicalize) { --- 878,886 ---- LINENUM offset; LINENUM fuzz; { ! LINENUM pline = 1 + fuzz; ! LINENUM iline; ! LINENUM pat_lines = pch_ptrn_lines() - fuzz; for (iline=base+offset+fuzz; pline <= pat_lines; pline++,iline++) { if (canonicalize) { *************** *** 919,927 **** bool similar(a,b,len) ! Reg1 char *a; ! Reg2 char *b; ! Reg3 int len; { if (a == NULL || b == NULL) return FALSE; --- 901,909 ---- bool similar(a,b,len) ! char *a; ! char *b; ! int len; { if (a == NULL || b == NULL) return FALSE; *************** *** 951,963 **** my_exit(status) int status; { ! Unlink(TMPINNAME); if (!toutkeep) { ! Unlink(TMPOUTNAME); } if (!trejkeep) { ! Unlink(TMPREJNAME); } ! Unlink(TMPPATNAME); exit(status); } --- 933,945 ---- my_exit(status) int status; { ! unlink(TMPINNAME); if (!toutkeep) { ! unlink(TMPOUTNAME); } if (!trejkeep) { ! unlink(TMPREJNAME); } ! unlink(TMPPATNAME); exit(status); }