summaryrefslogtreecommitdiffstats
path: root/meta/packages/patch/patch-2.5.9/unified-reject-files.diff
diff options
context:
space:
mode:
Diffstat (limited to 'meta/packages/patch/patch-2.5.9/unified-reject-files.diff')
-rw-r--r--meta/packages/patch/patch-2.5.9/unified-reject-files.diff305
1 files changed, 305 insertions, 0 deletions
diff --git a/meta/packages/patch/patch-2.5.9/unified-reject-files.diff b/meta/packages/patch/patch-2.5.9/unified-reject-files.diff
new file mode 100644
index 0000000000..6bfa00dd75
--- /dev/null
+++ b/meta/packages/patch/patch-2.5.9/unified-reject-files.diff
@@ -0,0 +1,305 @@
1Generate unified diff style reject files. Also include the C function names
2in reject files whenever possible.
3
4 $ cat > f.orig
5 < a() {
6 < 2
7 < 3
8 <
9 < 5
10 < 6
11 < }
12
13 $ sed -e 's/5/5a/' f.orig > f
14 $ diff -U2 -p f.orig f > f.diff
15 $ sed -e 's/5/5a/' -e 's/6/6x/' f.orig > f
16 $ ./patch -F0 -s --no-backup-if-mismatch f --reject-unified < f.diff
17 > 1 out of 1 hunk FAILED -- saving rejects to file f.rej
18
19 $ cat f.rej
20 > @@ -3,5 +3,5 @@ a() {
21 > 3
22 >
23 > -5
24 > +5a
25 > 6
26 > }
27
28 $ ./patch -F0 -s --no-backup-if-mismatch f < f.diff
29 > 1 out of 1 hunk FAILED -- saving rejects to file f.rej
30
31 $ cat f.rej
32 > *************** a() {
33 > *** 3,7 ****
34 > 3
35 >
36 > - 5
37 > 6
38 > }
39 > --- 3,7 ----
40 > 3
41 >
42 > + 5a
43 > 6
44 > }
45
46 $ diff -Nu -p /dev/null f.orig > f2.diff
47 $ ./patch -F0 -s --no-backup-if-mismatch f --reject-unified < f2.diff
48 > Patch attempted to create file f, which already exists.
49 > 1 out of 1 hunk FAILED -- saving rejects to file f.rej
50
51 $ cat f.rej
52 > @@ -0,0 +1,7 @@
53 > +a() {
54 > +2
55 > +3
56 > +
57 > +5
58 > +6
59 > +}
60
61 $ rm -f f f.orig f.rej f.diff f2.diff
62
63Index: patch-2.5.9/pch.c
64===================================================================
65--- patch-2.5.9.orig/pch.c
66+++ patch-2.5.9/pch.c
67@@ -68,6 +68,7 @@ static LINENUM p_sline; /* and the lin
68 static LINENUM p_hunk_beg; /* line number of current hunk */
69 static LINENUM p_efake = -1; /* end of faked up lines--don't free */
70 static LINENUM p_bfake = -1; /* beg of faked up lines */
71+static char *p_c_function; /* the C function a hunk is in */
72
73 enum nametype { OLD, NEW, INDEX, NONE };
74
75@@ -888,6 +889,19 @@ another_hunk (enum diff difftype, bool r
76 next_intuit_at(line_beginning,p_input_line);
77 return chars_read == (size_t) -1 ? -1 : 0;
78 }
79+ s = buf;
80+ while (*s == '*')
81+ s++;
82+ if (*s == ' ')
83+ {
84+ p_c_function = s;
85+ while (*s != '\n')
86+ s++;
87+ *s = '\0';
88+ p_c_function = savestr (p_c_function);
89+ }
90+ else
91+ p_c_function = NULL;
92 p_hunk_beg = p_input_line + 1;
93 while (p_end < p_max) {
94 chars_read = get_line ();
95@@ -1277,8 +1291,18 @@ another_hunk (enum diff difftype, bool r
96 else
97 p_repl_lines = 1;
98 if (*s == ' ') s++;
99- if (*s != '@')
100+ if (*s++ != '@')
101 malformed ();
102+ if (*s++ == '@' && *s == ' ' && *s != '\0')
103+ {
104+ p_c_function = s;
105+ while (*s != '\n')
106+ s++;
107+ *s = '\0';
108+ p_c_function = savestr (p_c_function);
109+ }
110+ else
111+ p_c_function = NULL;
112 if (!p_ptrn_lines)
113 p_first++; /* do append rather than insert */
114 if (!p_repl_lines)
115@@ -1884,6 +1908,12 @@ pch_hunk_beg (void)
116 return p_hunk_beg;
117 }
118
119+char const *
120+pch_c_function (void)
121+{
122+ return p_c_function;
123+}
124+
125 /* Is the newline-terminated line a valid `ed' command for patch
126 input? If so, return the command character; if not, return 0.
127 This accepts accepts just a subset of the valid commands, but it's
128Index: patch-2.5.9/pch.h
129===================================================================
130--- patch-2.5.9.orig/pch.h
131+++ patch-2.5.9/pch.h
132@@ -25,6 +25,7 @@
133 LINENUM pch_end (void);
134 LINENUM pch_first (void);
135 LINENUM pch_hunk_beg (void);
136+char const *pch_c_function (void);
137 LINENUM pch_newfirst (void);
138 LINENUM pch_prefix_context (void);
139 LINENUM pch_ptrn_lines (void);
140Index: patch-2.5.9/patch.man
141===================================================================
142--- patch-2.5.9.orig/patch.man
143+++ patch-2.5.9/patch.man
144@@ -517,6 +517,9 @@ instead of the default
145 .B \&.rej
146 file.
147 .TP
148+\fB\*=reject\-unified\fP
149+Produce unified reject files. The default is to produce context type reject files.
150+.TP
151 \fB\-R\fP or \fB\*=reverse\fP
152 Assume that this patch was created with the old and new files swapped.
153 (Yes, I'm afraid that does happen occasionally, human nature being what it
154Index: patch-2.5.9/common.h
155===================================================================
156--- patch-2.5.9.orig/common.h
157+++ patch-2.5.9/common.h
158@@ -146,6 +146,7 @@ XTERN int invc;
159 XTERN struct stat instat;
160 XTERN bool dry_run;
161 XTERN bool posixly_correct;
162+XTERN bool unified_reject_files;
163
164 XTERN char const *origprae;
165 XTERN char const *origbase;
166Index: patch-2.5.9/patch.c
167===================================================================
168--- patch-2.5.9.orig/patch.c
169+++ patch-2.5.9/patch.c
170@@ -522,6 +522,7 @@ static struct option const longopts[] =
171 {"no-backup-if-mismatch", no_argument, NULL, CHAR_MAX + 6},
172 {"posix", no_argument, NULL, CHAR_MAX + 7},
173 {"quoting-style", required_argument, NULL, CHAR_MAX + 8},
174+ {"unified-reject-files", no_argument, NULL, CHAR_MAX + 9},
175 {NULL, no_argument, NULL, 0}
176 };
177
178@@ -580,6 +581,7 @@ static char const *const option_help[] =
179 " --verbose Output extra information about the work being done.",
180 " --dry-run Do not actually change any files; just print what would happen.",
181 " --posix Conform to the POSIX standard.",
182+" --unified-reject-files Create unified reject files.",
183 "",
184 " -d DIR --directory=DIR Change the working directory to DIR first.",
185 #if HAVE_SETMODE_DOS
186@@ -779,6 +781,9 @@ get_some_switches (void)
187 (enum quoting_style) i);
188 }
189 break;
190+ case CHAR_MAX + 9:
191+ unified_reject_files = true;
192+ break;
193 default:
194 usage (stderr, 2);
195 }
196@@ -927,6 +932,24 @@ locate_hunk (LINENUM fuzz)
197 return 0;
198 }
199
200+static char *
201+format_linerange (char rangebuf[LINENUM_LENGTH_BOUND*2 + 2],
202+ LINENUM first, LINENUM lines)
203+{
204+ if (lines == 1)
205+ rangebuf = format_linenum (rangebuf, first);
206+ else
207+ {
208+ char *rb;
209+ rangebuf = format_linenum (rangebuf + LINENUM_LENGTH_BOUND + 1, lines);
210+ rb = rangebuf-1;
211+ rangebuf = format_linenum (rangebuf - LINENUM_LENGTH_BOUND - 1,
212+ (lines > 0) ? first : 0);
213+ *rb = ',';
214+ }
215+ return rangebuf;
216+}
217+
218 /* We did not find the pattern, dump out the hunk so they can handle it. */
219
220 static void
221@@ -943,8 +966,83 @@ abort_hunk (void)
222 (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ****" : "";
223 char const *minuses =
224 (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ----" : " -----";
225+ char const *function = pch_c_function();
226+ if (function == NULL)
227+ function = "";
228+
229+ if (unified_reject_files)
230+ {
231+ /* produce unified reject files */
232+ char rangebuf0[LINENUM_LENGTH_BOUND*2 + 2];
233+ char rangebuf1[LINENUM_LENGTH_BOUND*2 + 2];
234+ LINENUM j;
235+
236+ /* Find the beginning of the remove and insert section. */
237+ for (j = 0; j <= pat_end; j++)
238+ if (pch_char (j) == '=')
239+ break;
240+ for (i = j+1; i <= pat_end; i++)
241+ if (pch_char (i) == '^')
242+ break;
243+ if (pch_char (0) != '*' || j > pat_end || i > pat_end+1)
244+ fatal ("internal error in abort_hunk");
245+ i = 1; j++;
246+
247+ /* @@ -from,lines +to,lines @@ */
248+ fprintf (rejfp, "@@ -%s +%s @@%s\n",
249+ format_linerange (rangebuf0, oldfirst, pch_ptrn_lines()),
250+ format_linerange (rangebuf1, newfirst, pch_repl_lines()),
251+ function);
252+
253+ while ( (i <= pat_end && pch_char (i) != '=')
254+ || (j <= pat_end && pch_char (j) != '^'))
255+ {
256+ if (i <= pat_end
257+ && (pch_char (i) == '-' || pch_char (i) == '!'))
258+ {
259+ fputc('-', rejfp);
260+ pch_write_line (i++, rejfp);
261+ }
262+ else if (j <= pat_end
263+ && (pch_char (j) == '+' || pch_char (j) == '!'))
264+ {
265+ fputc('+', rejfp);
266+ pch_write_line (j++, rejfp);
267+ }
268+ else if ((i <= pat_end
269+ && (pch_char (i) == ' ' || pch_char (i) == '\n')) &&
270+ (j > pat_end
271+ || (pch_char (j) == ' ' || pch_char (j) == '\n')))
272+ {
273+ /* Unless j is already past the end, lines i and j
274+ must be equal here. */
275+
276+ if (pch_char (i) == ' ')
277+ fputc(' ', rejfp);
278+ pch_write_line (i++, rejfp);
279+ if (j <= pat_end)
280+ j++;
281+ }
282+ else if ((j <= pat_end &&
283+ (pch_char (j) == ' ' || pch_char (j) == '\n')) &&
284+ (pch_char (i) == '='))
285+ {
286+ if (pch_char (j) == ' ')
287+ fputc(' ', rejfp);
288+ pch_write_line (j++, rejfp);
289+ }
290+ else
291+ fatal ("internal error in abort_hunk");
292+ }
293+
294+ if (ferror (rejfp))
295+ write_fatal ();
296+ return;
297+ }
298
299- fprintf(rejfp, "***************\n");
300+ /* produce context type reject files */
301+
302+ fprintf(rejfp, "***************%s\n", function);
303 for (i=0; i<=pat_end; i++) {
304 char numbuf0[LINENUM_LENGTH_BOUND + 1];
305 char numbuf1[LINENUM_LENGTH_BOUND + 1];