aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-08-22 05:39:15 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-08-22 05:39:15 +0200
commite7b0a9e5bc60617fb00c321430253d7771d40fd3 (patch)
tree5152c7e606fb72423de8d56c5c97a977c6852033 /editors
parentfd27fa83094a85b3e8cb0485467ffa65b572b923 (diff)
downloadbusybox-e7b0a9e5bc60617fb00c321430253d7771d40fd3.tar.gz
patch: support "patch [FILE [PATCH]]" format
function old new delta xopen_stdin - 15 +15 patch_main 2075 2041 -34 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/patch.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/editors/patch.c b/editors/patch.c
index 3ed4eba45..c40f54155 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -447,10 +447,21 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
INIT_TT();
opts = getopt32(argv, FLAG_STR, &opt_p, &opt_i);
+ argv += optind;
reverse = opts & FLAG_REVERSE;
TT.prefix = (opts & FLAG_PATHLEN) ? xatoi(opt_p) : 0; // can be negative!
- if (opts & FLAG_INPUT) TT.filepatch = xopen(opt_i, O_RDONLY);
TT.filein = TT.fileout = -1;
+ if (opts & FLAG_INPUT) {
+ TT.filepatch = xopen_stdin(opt_i);
+ } else {
+ if (argv[0] && argv[1]) {
+ TT.filepatch = xopen_stdin(argv[1]);
+ }
+ }
+ if (argv[0]) {
+ oldname = xstrdup(argv[0]);
+ newname = xstrdup(argv[0]);
+ }
// Loop through the lines in the patch
for(;;) {
@@ -498,18 +509,20 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
state = 1;
}
- free(*name);
finish_oldfile();
- // Trim date from end of filename (if any). We don't care.
- for (s = patchline+4; *s && *s!='\t'; s++)
- if (*s=='\\' && s[1]) s++;
- i = atoi(s);
- if (i>1900 && i<=1970)
- *name = xstrdup("/dev/null");
- else {
- *s = 0;
- *name = xstrdup(patchline+4);
+ if (!argv[0]) {
+ free(*name);
+ // Trim date from end of filename (if any). We don't care.
+ for (s = patchline+4; *s && *s!='\t'; s++)
+ if (*s=='\\' && s[1]) s++;
+ i = atoi(s);
+ if (i>1900 && i<=1970)
+ *name = xstrdup("/dev/null");
+ else {
+ *s = 0;
+ *name = xstrdup(patchline+4);
+ }
}
// We defer actually opening the file because svn produces broken