Deleted Added
full compact
patch.c (246074) patch.c (246091)
1/* $FreeBSD: head/usr.bin/patch/patch.c 246074 2013-01-29 17:03:18Z gabor $ */
2/*-
1/*-
3 *
4 * Copyright 1986, Larry Wall
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following condition is met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this condition and the following disclaimer.
10 *
11 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY

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

20 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
21 * SUCH DAMAGE.
22 *
23 * patch - a program to apply diffs to original files
24 *
25 * -C option added in 1998, original code by Marc Espie, based on FreeBSD
26 * behaviour
27 *
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 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY

--- 8 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 *
28 * $OpenBSD: patch.c,v 1.45 2007/04/18 21:52:24 sobrado Exp $
29 * $DragonFly: src/usr.bin/patch/patch.c,v 1.10 2008/08/10 23:39:56 joerg Exp $
26 * $OpenBSD: patch.c,v 1.50 2012/05/15 19:32:02 millert Exp $
27 * $FreeBSD: head/usr.bin/patch/patch.c 246091 2013-01-29 20:05:16Z delphij $
30 *
31 */
32
33#include <sys/types.h>
34#include <sys/stat.h>
35
36#include <ctype.h>
37#include <getopt.h>

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

109static bool remove_empty_files = false;
110
111/* true if -R was specified on command line. */
112static bool reverse_flag_specified = false;
113
114/* buffer holding the name of the rejected patch file. */
115static char rejname[NAME_MAX + 1];
116
28 *
29 */
30
31#include <sys/types.h>
32#include <sys/stat.h>
33
34#include <ctype.h>
35#include <getopt.h>

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

107static bool remove_empty_files = false;
108
109/* true if -R was specified on command line. */
110static bool reverse_flag_specified = false;
111
112/* buffer holding the name of the rejected patch file. */
113static char rejname[NAME_MAX + 1];
114
117/* buffer for stderr */
118static char serrbuf[BUFSIZ];
119
120/* how many input lines have been irretractibly output */
121static LINENUM last_frozen_line = 0;
122
123static int Argc; /* guess */
124static char **Argv;
125static int Argc_last; /* for restarting plan_b */
126static char **Argv_last;
127

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

145
146
147/* Apply a set of diffs as appropriate. */
148
149int
150main(int argc, char *argv[])
151{
152 int error = 0, hunk, failed, i, fd;
115/* how many input lines have been irretractibly output */
116static LINENUM last_frozen_line = 0;
117
118static int Argc; /* guess */
119static char **Argv;
120static int Argc_last; /* for restarting plan_b */
121static char **Argv_last;
122

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

140
141
142/* Apply a set of diffs as appropriate. */
143
144int
145main(int argc, char *argv[])
146{
147 int error = 0, hunk, failed, i, fd;
148 bool patch_seen;
153 LINENUM where = 0, newwhere, fuzz, mymaxfuzz;
154 const char *tmpdir;
155 char *v;
156
149 LINENUM where = 0, newwhere, fuzz, mymaxfuzz;
150 const char *tmpdir;
151 char *v;
152
157 setbuf(stderr, serrbuf);
153 setlinebuf(stdout);
154 setlinebuf(stderr);
158 for (i = 0; i < MAXFILEC; i++)
159 filearg[i] = NULL;
160
161 buf_size = INITLINELEN;
162 buf = malloc((unsigned)(buf_size));
163 if (buf == NULL)
164 fatal("out of memory\n");
165

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

209 v = getenv("VERSION_CONTROL");
210 if (v != NULL || !posix)
211 backup_type = get_version(v); /* OK to pass NULL. */
212 }
213
214 /* make sure we clean up /tmp in case of disaster */
215 set_signals(0);
216
155 for (i = 0; i < MAXFILEC; i++)
156 filearg[i] = NULL;
157
158 buf_size = INITLINELEN;
159 buf = malloc((unsigned)(buf_size));
160 if (buf == NULL)
161 fatal("out of memory\n");
162

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

206 v = getenv("VERSION_CONTROL");
207 if (v != NULL || !posix)
208 backup_type = get_version(v); /* OK to pass NULL. */
209 }
210
211 /* make sure we clean up /tmp in case of disaster */
212 set_signals(0);
213
214 patch_seen = false;
217 for (open_patch_file(filearg[1]); there_is_another_patch();
218 reinitialize_almost_everything()) {
219 /* for each patch in patch file */
215 for (open_patch_file(filearg[1]); there_is_another_patch();
216 reinitialize_almost_everything()) {
217 /* for each patch in patch file */
218
219 patch_seen = true;
220
221 warn_on_invalid_line = true;
222
223 if (outname == NULL)
224 outname = savestr(filearg[0]);
225
226 /* for ed script just up and do it and exit */
227 if (diff_type == ED_DIFF) {

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

395 if (*rejname == '\0') {
396 if (strlcpy(rejname, outname,
397 sizeof(rejname)) >= sizeof(rejname))
398 fatal("filename %s is too long\n", outname);
399 if (strlcat(rejname, REJEXT,
400 sizeof(rejname)) >= sizeof(rejname))
401 fatal("filename %s is too long\n", outname);
402 }
220
221 warn_on_invalid_line = true;
222
223 if (outname == NULL)
224 outname = savestr(filearg[0]);
225
226 /* for ed script just up and do it and exit */
227 if (diff_type == ED_DIFF) {

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

395 if (*rejname == '\0') {
396 if (strlcpy(rejname, outname,
397 sizeof(rejname)) >= sizeof(rejname))
398 fatal("filename %s is too long\n", outname);
399 if (strlcat(rejname, REJEXT,
400 sizeof(rejname)) >= sizeof(rejname))
401 fatal("filename %s is too long\n", outname);
402 }
403 if (skip_rest_of_patch) {
404 say("%d out of %d hunks ignored--saving rejects to %s\n",
405 failed, hunk, rejname);
406 } else {
407 say("%d out of %d hunks failed--saving rejects to %s\n",
408 failed, hunk, rejname);
409 }
403 if (!check_only)
404 say("%d out of %d hunks %s--saving rejects to %s\n",
405 failed, hunk, skip_rest_of_patch ? "ignored" : "failed", rejname);
406 else
407 say("%d out of %d hunks %s\n",
408 failed, hunk, skip_rest_of_patch ? "ignored" : "failed");
410 if (!check_only && move_file(TMPREJNAME, rejname) < 0)
411 trejkeep = true;
412 }
413 set_signals(1);
414 }
409 if (!check_only && move_file(TMPREJNAME, rejname) < 0)
410 trejkeep = true;
411 }
412 set_signals(1);
413 }
414
415 if (!patch_seen)
416 error = 2;
417
415 my_exit(error);
416 /* NOTREACHED */
417}
418
419/* Prepare to find the next patch to do in the patch file. */
420
421static void
422reinitialize_almost_everything(void)

--- 644 unchanged lines hidden ---
418 my_exit(error);
419 /* NOTREACHED */
420}
421
422/* Prepare to find the next patch to do in the patch file. */
423
424static void
425reinitialize_almost_everything(void)

--- 644 unchanged lines hidden ---