Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/editors/patch.c


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/editors/patch.c

    r2725 r3232  
    1616 * -o outfile output here instead of in place
    1717 * -r rejectfile write rejected hunks to this file
     18 * --dry-run (regression!)
    1819 *
    1920 * -f force (no questions asked)
     
    2223 */
    2324
    24 //applet:IF_PATCH(APPLET(patch, _BB_DIR_USR_BIN, _BB_SUID_DROP))
    25 
    26 //kbuild:lib-$(CONFIG_PATCH) += patch.o
    27 
    2825//config:config PATCH
    2926//config:   bool "patch"
     
    3128//config:   help
    3229//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
    3334
    3435//usage:#define patch_trivial_usage
     
    4041//usage:     "\n    -R,--reverse        Reverse patch"
    4142//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 */
    4344//usage:     "\n    -E,--remove-empty-files Remove output files if they become empty"
    4445//usage:    )
     
    5051//usage:     "\n    -E  Remove output files if they become empty"
    5152//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 */
    5255//usage:
    5356//usage:#define patch_example_usage
     
    6871// Free all the elements of a linked list
    6972// Call freeit() on each element before freeing it.
    70 static
    71 void dlist_free(struct double_list *list, void (*freeit)(void *data))
     73static void dlist_free(struct double_list *list, void (*freeit)(void *data))
    7274{
    7375    while (list) {
     
    8183
    8284// 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)
     85static struct double_list *dlist_add(struct double_list **list, char *data)
    8586{
    8687    struct double_list *llist;
     
    131132#define FLAG_IGNORE  (1 << 4)
    132133#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)
    135136
    136137// Dispose of a line of input, either by writing it out or discarding it.
     
    230231        if (PATCH_DEBUG) fdprintf(2, "HUNK:%s\n", plist->data);
    231232    }
    232     matcheof = matcheof < TT.context;
     233    matcheof = !matcheof || matcheof < TT.context;
    233234
    234235    if (PATCH_DEBUG) fdprintf(2,"MATCHEOF=%c\n", matcheof ? 'Y' : 'N');
     
    239240    plist = TT.current_hunk;
    240241    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);
    243244
    244245        TT.linenum++;
     
    353354    char *oldname = NULL, *newname = NULL;
    354355    char *opt_p, *opt_i;
     356    long oldlen = oldlen; /* for compiler */
     357    long newlen = newlen; /* for compiler */
    355358
    356359    INIT_TT();
     
    392395                dlist_add(&TT.current_hunk, patchline);
    393396
    394                 if (*patchline != '+') TT.oldlen--;
    395                 if (*patchline != '-') TT.newlen--;
     397                if (*patchline != '+') oldlen--;
     398                if (*patchline != '-') newlen--;
    396399
    397400                // Context line?
     
    401404                // If we've consumed all expected hunk lines, apply the hunk.
    402405
    403                 if (!TT.oldlen && !TT.newlen) state = apply_one_hunk();
     406                if (!oldlen && !newlen) state = apply_one_hunk();
    404407                continue;
    405408            }
     
    448451            // Read oldline[,oldlen] +newline[,newlen]
    449452
    450             TT.oldlen = TT.newlen = 1;
     453            TT.oldlen = oldlen = TT.newlen = newlen = 1;
    451454            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);
    453456            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);
    455461
    456462            TT.context = 0;
     
    462468                char *name;
    463469
    464                 oldsum = TT.oldline + TT.oldlen;
    465                 newsum = TT.newline + TT.newlen;
     470                oldsum = TT.oldline + oldlen;
     471                newsum = TT.newline + newlen;
    466472
    467473                name = reverse ? oldname : newname;
     
    469475                // We're deleting oldname if new file is /dev/null (before -p)
    470476                // 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)) {
    473478                    name = reverse ? newname : oldname;
    474479                    empty++;
     
    476481
    477482                // 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;
    484492                }
    485493
Note: See TracChangeset for help on using the changeset viewer.