summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2009-04-08 06:22:43 +0200
committerAndreas Gruenbacher <agruen@suse.de>2009-04-08 06:23:11 +0200
commit2e583114c723b678977579dd7156049867832c29 (patch)
treef1a1dd206925f1cbdaa7d079640793fa97be9600
parent7e2373f0623423b5e9098b0c65903bbbd5db74ed (diff)
downloadpatch-2e583114c723b678977579dd7156049867832c29.tar.gz
Add support for sending output to standard output
-rw-r--r--ChangeLog5
-rw-r--r--patch.man6
-rw-r--r--src/patch.c13
3 files changed, 18 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 441a5cc..68675ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
2009-04-08 Andreas Gruenbacher <agruen@suse.de>
- * src/patch.c (main): Remove redundant check.
+ * src/patch.c (create_output_file): Add support for sending output
+ to standard output.
+ (main): Allow -o -. Remove redundant check.
+ * patch.man: Document the new use of -o.
2009-04-07 Andreas Gruenbacher <agruen@suse.de>
diff --git a/patch.man b/patch.man
index b671833..2720090 100644
--- a/patch.man
+++ b/patch.man
@@ -425,9 +425,9 @@ this:
.RS
.nf
.B <<<<<<<
-lines from the original file
+.I lines from the original file
.B =======
-lines from the patch
+.I lines from the patch
.B >>>>>>>
.RE
.fi
@@ -451,6 +451,8 @@ instead of patching files in place.
Do not use this option if
.I outfile
is one of the files to be patched.
+When \fIoutfile\fP is \fB\-\fP, send output to standard output, and send any
+messages that would usually go to standard output to standard error.
.TP
\fB\-p\fP\fInum\fP or \fB\*=strip\fP\fB=\fP\fInum\fP
Strip the smallest prefix containing
diff --git a/src/patch.c b/src/patch.c
index b2ad822..ffc5e39 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -737,8 +737,6 @@ get_some_switches (void)
noreverse = true;
break;
case 'o':
- if (strcmp (optarg, "-") == 0)
- fatal ("can't output patches to standard output");
outfile = savestr (optarg);
break;
case 'p':
@@ -1343,7 +1341,16 @@ create_output_file (char const *name, int open_flags)
static void
init_output (char const *name, int open_flags, struct outstate *outstate)
{
- outstate->ofp = name ? create_output_file (name, open_flags) : (FILE *) 0;
+ if (! name)
+ outstate->ofp = (FILE *) 0;
+ else if (strcmp (name, "-") != 0)
+ outstate->ofp = create_output_file (name, open_flags);
+ else
+ {
+ outstate->ofp = stdout;
+ stdout = stderr;
+ }
+
outstate->after_newline = true;
outstate->zero_output = true;
}