Deleted Added
full compact
patch.c (276706) patch.c (276807)
1/*-
2 * Copyright 1986, Larry Wall
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following condition is met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this condition and the following disclaimer.
8 *

--- 9 unchanged lines hidden (view full) ---

18 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
19 * SUCH DAMAGE.
20 *
21 * patch - a program to apply diffs to original files
22 *
23 * -C option added in 1998, original code by Marc Espie, based on FreeBSD
24 * behaviour
25 *
1/*-
2 * Copyright 1986, Larry Wall
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following condition is met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this condition and the following disclaimer.
8 *

--- 9 unchanged lines hidden (view full) ---

18 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
19 * SUCH DAMAGE.
20 *
21 * patch - a program to apply diffs to original files
22 *
23 * -C option added in 1998, original code by Marc Espie, based on FreeBSD
24 * behaviour
25 *
26 * $OpenBSD: patch.c,v 1.52 2014/11/26 18:34:51 millert Exp $
27 * $FreeBSD: stable/10/usr.bin/patch/patch.c 276706 2015-01-05 16:09:51Z pfg $
26 * $OpenBSD: patch.c,v 1.54 2014/12/13 10:31:07 tobias Exp $
27 * $FreeBSD: stable/10/usr.bin/patch/patch.c 276807 2015-01-08 03:44:54Z pfg $
28 *
29 */
30
31#include <sys/types.h>
32#include <sys/stat.h>
33
34#include <ctype.h>
35#include <getopt.h>

--- 174 unchanged lines hidden (view full) ---

210
211 /* make sure we clean up /tmp in case of disaster */
212 set_signals(0);
213
214 patch_seen = false;
215 for (open_patch_file(filearg[1]); there_is_another_patch();
216 reinitialize_almost_everything()) {
217 /* for each patch in patch file */
28 *
29 */
30
31#include <sys/types.h>
32#include <sys/stat.h>
33
34#include <ctype.h>
35#include <getopt.h>

--- 174 unchanged lines hidden (view full) ---

210
211 /* make sure we clean up /tmp in case of disaster */
212 set_signals(0);
213
214 patch_seen = false;
215 for (open_patch_file(filearg[1]); there_is_another_patch();
216 reinitialize_almost_everything()) {
217 /* for each patch in patch file */
218
218
219 patch_seen = true;
220
221 warn_on_invalid_line = true;
222
223 if (outname == NULL)
219 patch_seen = true;
220
221 warn_on_invalid_line = true;
222
223 if (outname == NULL)
224 outname = savestr(filearg[0]);
224 outname = xstrdup(filearg[0]);
225
226 /* for ed script just up and do it and exit */
227 if (diff_type == ED_DIFF) {
228 do_ed_script();
229 continue;
230 }
231 /* initialize the patched file */
232 if (!skip_rest_of_patch)

--- 178 unchanged lines hidden (view full) ---

411 else
412 say("%d out of %d hunks %s while patching %s\n",
413 failed, hunk, skip_rest_of_patch ? "ignored" : "failed", filearg[0]);
414 if (!check_only && move_file(TMPREJNAME, rejname) < 0)
415 trejkeep = true;
416 }
417 set_signals(1);
418 }
225
226 /* for ed script just up and do it and exit */
227 if (diff_type == ED_DIFF) {
228 do_ed_script();
229 continue;
230 }
231 /* initialize the patched file */
232 if (!skip_rest_of_patch)

--- 178 unchanged lines hidden (view full) ---

411 else
412 say("%d out of %d hunks %s while patching %s\n",
413 failed, hunk, skip_rest_of_patch ? "ignored" : "failed", filearg[0]);
414 if (!check_only && move_file(TMPREJNAME, rejname) < 0)
415 trejkeep = true;
416 }
417 set_signals(1);
418 }
419
419
420 if (!patch_seen)
421 error = 2;
422
423 my_exit(error);
424 /* NOTREACHED */
425}
426
427/* Prepare to find the next patch to do in the patch file. */

--- 81 unchanged lines hidden (view full) ---

509 if (optarg == NULL)
510 break;
511 if (verbose)
512 say("Warning, the ``-b suffix'' option has been"
513 " obsoleted by the -z option.\n");
514 /* FALLTHROUGH */
515 case 'z':
516 /* must directly follow 'b' case for backwards compat */
420 if (!patch_seen)
421 error = 2;
422
423 my_exit(error);
424 /* NOTREACHED */
425}
426
427/* Prepare to find the next patch to do in the patch file. */

--- 81 unchanged lines hidden (view full) ---

509 if (optarg == NULL)
510 break;
511 if (verbose)
512 say("Warning, the ``-b suffix'' option has been"
513 " obsoleted by the -z option.\n");
514 /* FALLTHROUGH */
515 case 'z':
516 /* must directly follow 'b' case for backwards compat */
517 simple_backup_suffix = savestr(optarg);
517 simple_backup_suffix = xstrdup(optarg);
518 break;
519 case 'B':
518 break;
519 case 'B':
520 origprae = savestr(optarg);
520 origprae = xstrdup(optarg);
521 break;
522 case 'c':
523 diff_type = CONTEXT_DIFF;
524 break;
525 case 'C':
526 check_only = true;
527 break;
528 case 'd':

--- 21 unchanged lines hidden (view full) ---

550 force = true;
551 break;
552 case 'F':
553 maxfuzz = atoi(optarg);
554 break;
555 case 'i':
556 if (++filec == MAXFILEC)
557 fatal("too many file arguments\n");
521 break;
522 case 'c':
523 diff_type = CONTEXT_DIFF;
524 break;
525 case 'C':
526 check_only = true;
527 break;
528 case 'd':

--- 21 unchanged lines hidden (view full) ---

550 force = true;
551 break;
552 case 'F':
553 maxfuzz = atoi(optarg);
554 break;
555 case 'i':
556 if (++filec == MAXFILEC)
557 fatal("too many file arguments\n");
558 filearg[filec] = savestr(optarg);
558 filearg[filec] = xstrdup(optarg);
559 break;
560 case 'l':
561 canonicalize = true;
562 break;
563 case 'n':
564 diff_type = NORMAL_DIFF;
565 break;
566 case 'N':
567 noreverse = true;
568 break;
569 case 'o':
559 break;
560 case 'l':
561 canonicalize = true;
562 break;
563 case 'n':
564 diff_type = NORMAL_DIFF;
565 break;
566 case 'N':
567 noreverse = true;
568 break;
569 case 'o':
570 outname = savestr(optarg);
570 outname = xstrdup(optarg);
571 break;
572 case 'p':
573 strippath = atoi(optarg);
574 break;
575 case 'r':
576 if (strlcpy(rejname, optarg,
577 sizeof(rejname)) >= sizeof(rejname))
578 fatal("argument for -r is too long\n");

--- 27 unchanged lines hidden (view full) ---

606 usage();
607 break;
608 }
609 }
610 Argc -= optind;
611 Argv += optind;
612
613 if (Argc > 0) {
571 break;
572 case 'p':
573 strippath = atoi(optarg);
574 break;
575 case 'r':
576 if (strlcpy(rejname, optarg,
577 sizeof(rejname)) >= sizeof(rejname))
578 fatal("argument for -r is too long\n");

--- 27 unchanged lines hidden (view full) ---

606 usage();
607 break;
608 }
609 }
610 Argc -= optind;
611 Argv += optind;
612
613 if (Argc > 0) {
614 filearg[0] = savestr(*Argv++);
614 filearg[0] = xstrdup(*Argv++);
615 Argc--;
616 while (Argc > 0) {
617 if (++filec == MAXFILEC)
618 fatal("too many file arguments\n");
615 Argc--;
616 while (Argc > 0) {
617 if (++filec == MAXFILEC)
618 fatal("too many file arguments\n");
619 filearg[filec] = savestr(*Argv++);
619 filearg[filec] = xstrdup(*Argv++);
620 Argc--;
621 }
622 }
623
624 if (getenv("POSIXLY_CORRECT") != NULL)
625 posix = 1;
626}
627

--- 452 unchanged lines hidden ---
620 Argc--;
621 }
622 }
623
624 if (getenv("POSIXLY_CORRECT") != NULL)
625 posix = 1;
626}
627

--- 452 unchanged lines hidden ---