diff output.c @ 24:daa801fe719e

fix some bugs
author David A. Holland
date Mon, 20 Dec 2010 04:30:02 -0500
parents cef2dc916269
children 01c3a2088ab4
line wrap: on
line diff
--- a/output.c	Mon Dec 20 04:21:51 2010 -0500
+++ b/output.c	Mon Dec 20 04:30:02 2010 -0500
@@ -14,10 +14,15 @@
 void
 output_open(void)
 {
-	outputfd = open(mode.output_file, O_WRONLY|O_CREAT|O_TRUNC, 0664);
-	if (outputfd < 0) {
-		warn("%s", mode.output_file);
-		die();
+	if (mode.output_file == NULL) {
+		outputfd = STDOUT_FILENO;
+	} else {
+		outputfd = open(mode.output_file, O_WRONLY|O_CREAT|O_TRUNC,
+				0664);
+		if (outputfd < 0) {
+			warn("%s", mode.output_file);
+			die();
+		}
 	}
 }
 
@@ -100,12 +105,19 @@
 			}
 		}
 	}
+	pos++;
+
+	if (pos > start) {
+		if (!incomment || mode.output_retain_comments) {
+			dowrite(buf + start, pos - start);
+		}
+	}
 }
 
 void
 output_eof(void)
 {
-	if (outputfd >= 0) {
+	if (mode.output_file != NULL && outputfd >= 0) {
 		close(outputfd);
 	}
 	outputfd = -1;