Make the Deflate decoder correctly handle the special case of a
[sgt/halibut] / bk_text.c
index c8ded79..e323802 100644 (file)
--- a/bk_text.c
+++ b/bk_text.c
@@ -323,7 +323,10 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
     /*
      * Open the output file.
      */
-    tf.fp = fopen(conf.filename, "w");
+    if (!strcmp(conf.filename, "-"))
+       tf.fp = stdout;
+    else
+       tf.fp = fopen(conf.filename, "w");
     if (!tf.fp) {
        error(err_cantopenw, conf.filename);
        return;
@@ -460,7 +463,8 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
      * Tidy up
      */
     text_output(&tf, NULL);           /* end charset conversion */
-    fclose(tf.fp);
+    if (tf.fp != stdout)
+       fclose(tf.fp);
     sfree(conf.asect);
     sfree(conf.filename);
 }
@@ -493,7 +497,7 @@ static void text_output_many(textfile *tf, int n, wchar_t c)
     wchar_t s[2];
     s[0] = c;
     s[1] = L'\0';
-    while (n--)
+    while (n-- > 0)
        text_output(tf, s);
 }