~mmach/netext73/busybox

« back to all changes in this revision

Viewing changes to editors/patch_toybox.c

  • Committer: mmach
  • Date: 2023-07-06 04:40:25 UTC
  • Revision ID: netbit73@gmail.com-20230706044025-2ia9985i8wzdn2a7
1.36.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
                else free(pop);
80
80
 
81
81
                // End doubly linked list too.
82
 
                if (list==pop) break;
 
82
                if (list == pop) break;
83
83
        }
84
84
}
85
85
 
137
137
        long len = 0;
138
138
 
139
139
        for (;;) {
140
 
                if (1>read(fd, &c, 1)) break;
 
140
                if (1 > read(fd, &c, 1)) break;
141
141
                if (!(len & 63)) buf=xrealloc(buf, len+65);
142
 
                if ((buf[len++]=c) == end) break;
 
142
                if ((buf[len++] = c) == end) break;
143
143
        }
144
 
        if (buf) buf[len]=0;
 
144
        if (buf) buf[len] = 0;
145
145
        if (plen) *plen = len;
146
146
 
147
147
        return buf;
153
153
        long len;
154
154
        char *buf = get_rawline(fd, &len, '\n');
155
155
 
156
 
        if (buf && buf[--len]=='\n') buf[len]=0;
 
156
        if (buf && buf[--len] == '\n') buf[len] = 0;
157
157
 
158
158
        return buf;
159
159
}
165
165
        long len;
166
166
        char buf[4096];
167
167
 
168
 
        if (in<0) return;
 
168
        if (in < 0) return;
169
169
        for (;;) {
170
170
                len = safe_read(in, buf, 4096);
171
 
                if (len<1) break;
 
171
                if (len < 1) break;
172
172
                xwrite(out, buf, len);
173
173
        }
174
174
}
179
179
{
180
180
        char *temp = xstrdup(*tempname);
181
181
 
182
 
        temp[strlen(temp)-6]=0;
 
182
        temp[strlen(temp)-6] = 0;
183
183
        if (fdin != -1) {
184
184
                xsendfile(fdin, fdout);
185
185
                xclose(fdin);
263
263
{
264
264
        struct double_list *dlist = (struct double_list *)data;
265
265
 
266
 
        if (TT.state>1 && *dlist->data != TT.state)
 
266
        if (TT.state > 1 && *dlist->data != TT.state)
267
267
                fdprintf(TT.state == 2 ? 2 : TT.fileout,
268
 
                        "%s\n", dlist->data+(TT.state>3 ? 1 : 0));
 
268
                        "%s\n", dlist->data + (TT.state > 3 ? 1 : 0));
269
269
 
270
270
        if (PATCH_DEBUG) fdprintf(2, "DO %d: %s\n", TT.state, dlist->data);
271
271
 
314
314
 
315
315
        // Match EOF if there aren't as many ending context lines as beginning
316
316
        for (plist = TT.current_hunk; plist; plist = plist->next) {
317
 
                if (plist->data[0]==' ') matcheof++;
 
317
                if (plist->data[0] == ' ') matcheof++;
318
318
                else matcheof = 0;
319
319
                if (PATCH_DEBUG) fdprintf(2, "HUNK:%s\n", plist->data);
320
320
        }
385
385
 
386
386
                                // If we've reached the end of the buffer without confirming a
387
387
                                // match, read more lines.
388
 
                                if (check==buf) {
 
388
                                if (check == buf) {
389
389
                                        buf = 0;
390
390
                                        break;
391
391
                                }
441
441
        TT.filein = TT.fileout = -1;
442
442
 
443
443
        // Loop through the lines in the patch
444
 
        for(;;) {
 
444
        for (;;) {
445
445
                char *patchline;
446
446
 
447
447
                patchline = get_line(TT.filepatch);
456
456
 
457
457
                // Are we assembling a hunk?
458
458
                if (state >= 2) {
459
 
                        if (*patchline==' ' || *patchline=='+' || *patchline=='-') {
 
459
                        if (*patchline == ' ' || *patchline == '+' || *patchline == '-') {
460
460
                                dlist_add(&TT.current_hunk, patchline);
461
461
 
462
462
                                if (*patchline != '+') TT.oldlen--;
463
463
                                if (*patchline != '-') TT.newlen--;
464
464
 
465
465
                                // Context line?
466
 
                                if (*patchline==' ' && state==2) TT.context++;
467
 
                                else state=3;
 
466
                                if (*patchline == ' ' && state == 2) TT.context++;
 
467
                                else state = 3;
468
468
 
469
469
                                // If we've consumed all expected hunk lines, apply the hunk.
470
470
 
491
491
 
492
492
                        // Trim date from end of filename (if any).  We don't care.
493
493
                        for (s = patchline+4; *s && *s!='\t'; s++)
494
 
                                if (*s=='\\' && s[1]) s++;
 
494
                                if (*s == '\\' && s[1]) s++;
495
495
                        i = atoi(s);
496
 
                        if (i>1900 && i<=1970)
 
496
                        if (i > 1900 && i <= 1970)
497
497
                                *name = xstrdup("/dev/null");
498
498
                        else {
499
499
                                *s = 0;
537
537
                                // handle -p path truncation.
538
538
                                for (i=0, s = name; *s;) {
539
539
                                        if ((option_mask32 & FLAG_PATHLEN) && TT.prefix == i) break;
540
 
                                        if (*(s++)=='/') {
 
540
                                        if (*(s++) == '/') {
541
541
                                                name = s;
542
542
                                                i++;
543
543
                                        }