Revamp of the Halibut error handling mechanism.
[sgt/halibut] / bk_ps.c
diff --git a/bk_ps.c b/bk_ps.c
index a3d80a7..9b4cda6 100644 (file)
--- a/bk_ps.c
+++ b/bk_ps.c
@@ -13,7 +13,6 @@
 #define PS_MAXWIDTH 255
 
 static void ps_comment(FILE *fp, char const *leader, word *words);
-static void ps_token(FILE *fp, int *cc, char const *fmt, ...);
 static void ps_string_len(FILE *fp, int *cc, char const *str, int len);
 static void ps_string(FILE *fp, int *cc, char const *str);
 
@@ -49,9 +48,12 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords,
        }
     }
 
-    fp = fopen(filename, "w");
+    if (!strcmp(filename, "-"))
+       fp = stdout;
+    else
+       fp = fopen(filename, "w");
     if (!fp) {
-       error(err_cantopenw, filename);
+       err_cantopenw(filename);
        return;
     }
 
@@ -305,7 +307,8 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords,
 
     fprintf(fp, "%%%%EOF\n");
 
-    fclose(fp);
+    if (fp != stdout)
+       fclose(fp);
 
     sfree(filename);
 }
@@ -352,7 +355,7 @@ static void ps_comment(FILE *fp, char const *leader, word *words) {
     fprintf(fp, "\n");
 }
 
-static void ps_token(FILE *fp, int *cc, char const *fmt, ...) {
+void ps_token(FILE *fp, int *cc, char const *fmt, ...) {
     va_list ap;
 
     va_start(ap, fmt);