Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/editors/patch.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/editors/patch.c
r2725 r3232 16 16 * -o outfile output here instead of in place 17 17 * -r rejectfile write rejected hunks to this file 18 * --dry-run (regression!) 18 19 * 19 20 * -f force (no questions asked) … … 22 23 */ 23 24 24 //applet:IF_PATCH(APPLET(patch, _BB_DIR_USR_BIN, _BB_SUID_DROP))25 26 //kbuild:lib-$(CONFIG_PATCH) += patch.o27 28 25 //config:config PATCH 29 26 //config: bool "patch" … … 31 28 //config: help 32 29 //config: Apply a unified diff formatted patch. 30 31 //applet:IF_PATCH(APPLET(patch, BB_DIR_USR_BIN, BB_SUID_DROP)) 32 33 //kbuild:lib-$(CONFIG_PATCH) += patch.o 33 34 34 35 //usage:#define patch_trivial_usage … … 40 41 //usage: "\n -R,--reverse Reverse patch" 41 42 //usage: "\n -N,--forward Ignore already applied patches" 42 / /usage: "\n --dry-run Don't actually change files"43 /*usage: "\n --dry-run Don't actually change files" - TODO */ 43 44 //usage: "\n -E,--remove-empty-files Remove output files if they become empty" 44 45 //usage: ) … … 50 51 //usage: "\n -E Remove output files if they become empty" 51 52 //usage: ) 53 /* -u "interpret as unified diff" is supported but not documented: this info is not useful for --help */ 54 /* -x "debug" is supported but does nothing */ 52 55 //usage: 53 56 //usage:#define patch_example_usage … … 68 71 // Free all the elements of a linked list 69 72 // Call freeit() on each element before freeing it. 70 static 71 void dlist_free(struct double_list *list, void (*freeit)(void *data)) 73 static void dlist_free(struct double_list *list, void (*freeit)(void *data)) 72 74 { 73 75 while (list) { … … 81 83 82 84 // Add an entry before "list" element in (circular) doubly linked list 83 static 84 struct double_list *dlist_add(struct double_list **list, char *data) 85 static struct double_list *dlist_add(struct double_list **list, char *data) 85 86 { 86 87 struct double_list *llist; … … 131 132 #define FLAG_IGNORE (1 << 4) 132 133 #define FLAG_RMEMPTY (1 << 5) 133 / /non-standard:134 #define FLAG_DEBUG ( 1<< 6)134 /* Enable this bit and use -x for debug output: */ 135 #define FLAG_DEBUG (0 << 6) 135 136 136 137 // Dispose of a line of input, either by writing it out or discarding it. … … 230 231 if (PATCH_DEBUG) fdprintf(2, "HUNK:%s\n", plist->data); 231 232 } 232 matcheof = matcheof < TT.context;233 matcheof = !matcheof || matcheof < TT.context; 233 234 234 235 if (PATCH_DEBUG) fdprintf(2,"MATCHEOF=%c\n", matcheof ? 'Y' : 'N'); … … 239 240 plist = TT.current_hunk; 240 241 buf = NULL; 241 if ( TT.context) for (;;) {242 char *data = xmalloc_reads(TT.filein, NULL , NULL);242 if (reverse ? TT.oldlen : TT.newlen) for (;;) { 243 char *data = xmalloc_reads(TT.filein, NULL); 243 244 244 245 TT.linenum++; … … 353 354 char *oldname = NULL, *newname = NULL; 354 355 char *opt_p, *opt_i; 356 long oldlen = oldlen; /* for compiler */ 357 long newlen = newlen; /* for compiler */ 355 358 356 359 INIT_TT(); … … 392 395 dlist_add(&TT.current_hunk, patchline); 393 396 394 if (*patchline != '+') TT.oldlen--;395 if (*patchline != '-') TT.newlen--;397 if (*patchline != '+') oldlen--; 398 if (*patchline != '-') newlen--; 396 399 397 400 // Context line? … … 401 404 // If we've consumed all expected hunk lines, apply the hunk. 402 405 403 if (! TT.oldlen && !TT.newlen) state = apply_one_hunk();406 if (!oldlen && !newlen) state = apply_one_hunk(); 404 407 continue; 405 408 } … … 448 451 // Read oldline[,oldlen] +newline[,newlen] 449 452 450 TT.oldlen = TT.newlen = 1;453 TT.oldlen = oldlen = TT.newlen = newlen = 1; 451 454 TT.oldline = strtol(s, &s, 10); 452 if (*s == ',') TT.oldlen =strtol(s+1, &s, 10);455 if (*s == ',') TT.oldlen = oldlen = strtol(s+1, &s, 10); 453 456 TT.newline = strtol(s+2, &s, 10); 454 if (*s == ',') TT.newlen = strtol(s+1, &s, 10); 457 if (*s == ',') TT.newlen = newlen = strtol(s+1, &s, 10); 458 459 if (oldlen < 1 && newlen < 1) 460 bb_error_msg_and_die("Really? %s", patchline); 455 461 456 462 TT.context = 0; … … 462 468 char *name; 463 469 464 oldsum = TT.oldline + TT.oldlen;465 newsum = TT.newline + TT.newlen;470 oldsum = TT.oldline + oldlen; 471 newsum = TT.newline + newlen; 466 472 467 473 name = reverse ? oldname : newname; … … 469 475 // We're deleting oldname if new file is /dev/null (before -p) 470 476 // or if new hunk is empty (zero context) after patching 471 if (!strcmp(name, "/dev/null") || !(reverse ? oldsum : newsum)) 472 { 477 if (!strcmp(name, "/dev/null") || !(reverse ? oldsum : newsum)) { 473 478 name = reverse ? newname : oldname; 474 479 empty++; … … 476 481 477 482 // handle -p path truncation. 478 for (i=0, s = name; *s;) { 479 if ((option_mask32 & FLAG_PATHLEN) && TT.prefix == i) break; 480 if (*(s++)=='/') { 481 name = s; 482 i++; 483 } 483 for (i = 0, s = name; *s;) { 484 if ((option_mask32 & FLAG_PATHLEN) && TT.prefix == i) 485 break; 486 if (*s++ != '/') 487 continue; 488 while (*s == '/') 489 s++; 490 i++; 491 name = s; 484 492 } 485 493
Note:
See TracChangeset
for help on using the changeset viewer.