Mercurial > hg > toybox
comparison toys/posix/patch.c @ 1422:88aaf45c7fbb draft
Fix a couple patch bugs concerning error output.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 05 Aug 2014 19:27:02 -0500 |
parents | 0a87952492ae |
children |
comparison
equal
deleted
inserted
replaced
1421:30014454681f | 1422:88aaf45c7fbb |
---|---|
91 } | 91 } |
92 | 92 |
93 static void fail_hunk(void) | 93 static void fail_hunk(void) |
94 { | 94 { |
95 if (!TT.current_hunk) return; | 95 if (!TT.current_hunk) return; |
96 dlist_terminate(TT.current_hunk); | |
97 | 96 |
98 fprintf(stderr, "Hunk %d FAILED %ld/%ld.\n", | 97 fprintf(stderr, "Hunk %d FAILED %ld/%ld.\n", |
99 TT.hunknum, TT.oldline, TT.newline); | 98 TT.hunknum, TT.oldline, TT.newline); |
100 toys.exitval = 1; | 99 toys.exitval = 1; |
101 | 100 |
135 struct double_list *plist, *buf = NULL, *check; | 134 struct double_list *plist, *buf = NULL, *check; |
136 int matcheof = 0, reverse = toys.optflags & FLAG_R, backwarn = 0; | 135 int matcheof = 0, reverse = toys.optflags & FLAG_R, backwarn = 0; |
137 int (*lcmp)(char *aa, char *bb); | 136 int (*lcmp)(char *aa, char *bb); |
138 | 137 |
139 lcmp = (toys.optflags & FLAG_l) ? (void *)loosecmp : (void *)strcmp; | 138 lcmp = (toys.optflags & FLAG_l) ? (void *)loosecmp : (void *)strcmp; |
140 | |
141 dlist_terminate(TT.current_hunk); | 139 dlist_terminate(TT.current_hunk); |
142 | 140 |
143 // Match EOF if there aren't as many ending context lines as beginning | 141 // Match EOF if there aren't as many ending context lines as beginning |
144 for (plist = TT.current_hunk; plist; plist = plist->next) { | 142 for (plist = TT.current_hunk; plist; plist = plist->next) { |
145 if (plist->data[0]==' ') matcheof++; | 143 if (plist->data[0]==' ') matcheof++; |
201 // recheck remaining buffered data for a new match. | 199 // recheck remaining buffered data for a new match. |
202 | 200 |
203 if (PATCH_DEBUG) { | 201 if (PATCH_DEBUG) { |
204 int bug = 0; | 202 int bug = 0; |
205 | 203 |
206 while (plist->data[bug] == check->data[bug]) bug++; | 204 if (!plist) fprintf(stderr, "NULL plist\n"); |
207 fprintf(stderr, "NOT(%d:%d!=%d): %s\n", bug, plist->data[bug], | 205 else { |
208 check->data[bug], plist->data); | 206 while (plist->data[bug] == check->data[bug]) bug++; |
207 fprintf(stderr, "NOT(%d:%d!=%d): %s\n", bug, plist->data[bug], | |
208 check->data[bug], plist->data); | |
209 } | |
209 } | 210 } |
210 | 211 |
211 TT.state = 3; | 212 TT.state = 3; |
212 do_line(check = dlist_pop(&buf)); | 213 do_line(check = dlist_pop(&buf)); |
213 plist = TT.current_hunk; | 214 plist = TT.current_hunk; |
295 // If we've consumed all expected hunk lines, apply the hunk. | 296 // If we've consumed all expected hunk lines, apply the hunk. |
296 | 297 |
297 if (!TT.oldlen && !TT.newlen) state = apply_one_hunk(); | 298 if (!TT.oldlen && !TT.newlen) state = apply_one_hunk(); |
298 continue; | 299 continue; |
299 } | 300 } |
301 dlist_terminate(TT.current_hunk); | |
300 fail_hunk(); | 302 fail_hunk(); |
301 state = 0; | 303 state = 0; |
302 continue; | 304 continue; |
303 } | 305 } |
304 | 306 |