=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/patch/pch.c,v retrieving revision 1.41 retrieving revision 1.41.6.2 diff -u -r1.41 -r1.41.6.2 --- src/usr.bin/patch/pch.c 2013/11/26 13:19:07 1.41 +++ src/usr.bin/patch/pch.c 2015/07/31 18:21:58 1.41.6.2 @@ -1,4 +1,4 @@ -/* $OpenBSD: pch.c,v 1.41 2013/11/26 13:19:07 deraadt Exp $ */ +/* $OpenBSD: pch.c,v 1.41.6.2 2015/07/31 18:21:58 krw Exp $ */ /* * patch - a program to apply diffs to original files @@ -1393,7 +1393,19 @@ (*t == 'a' || *t == 'c' || *t == 'd' || *t == 'i' || *t == 's')) { if (pipefp != NULL) fputs(buf, pipefp); - if (*t != 'd') { + if (*t == 's') { + for (;;) { + bool continued = false; + t = buf + strlen(buf) - 1; + while (--t >= buf && *t == '\\') + continued = !continued; + if (!continued || + pgets(buf, sizeof buf, pfp) == NULL) + break; + if (pipefp != NULL) + fputs(buf, pipefp); + } + } else if (*t != 'd') { while (pgets(buf, sizeof buf, pfp) != NULL) { p_input_line++; if (pipefp != NULL) @@ -1448,18 +1460,9 @@ } if (path == NULL && !assume_exists) { /* - * No files found, look for something we can checkout from - * RCS/SCCS dirs. Same order as above. + * No files found, check to see if the diff could be + * creating a new file. */ - for (i = 0; i < MAX_FILE; i++) { - if (names[i].path != NULL && - (path = checked_in(names[i].path)) != NULL) - break; - } - /* - * Still no match? Check to see if the diff could be creating - * a new file. - */ if (path == NULL && ok_to_create_file && names[NEW_FILE].path != NULL) path = names[NEW_FILE].path; @@ -1469,7 +1472,7 @@ } static char * -compare_names(const struct file_name *names, bool assume_exists, int phase) +compare_names(const struct file_name *names, bool assume_exists) { size_t min_components, min_baselen, min_len, tmp; char *best = NULL; @@ -1486,9 +1489,7 @@ min_components = min_baselen = min_len = SIZE_MAX; for (i = INDEX_FILE; i >= OLD_FILE; i--) { path = names[i].path; - if (path == NULL || - (phase == 1 && !names[i].exists && !assume_exists) || - (phase == 2 && checked_in(path) == NULL)) + if (path == NULL || (!names[i].exists && !assume_exists)) continue; if ((tmp = num_components(path)) > min_components) continue; @@ -1519,17 +1520,12 @@ { char *best; - best = compare_names(names, assume_exists, 1); - if (best == NULL) { - best = compare_names(names, assume_exists, 2); - /* - * Still no match? Check to see if the diff could be creating - * a new file. - */ - if (best == NULL && ok_to_create_file && - names[NEW_FILE].path != NULL) - best = names[NEW_FILE].path; - } + best = compare_names(names, assume_exists); + + /* No match? Check to see if the diff could be creating a new file. */ + if (best == NULL && ok_to_create_file) + best = names[NEW_FILE].path; + return best ? savestr(best) : NULL; }