From 6c481aff452a0eed147fc73144b461fe7c263d9e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 24 Oct 2009 09:33:21 +0000 Subject: Allow a hastily selected subset of the output formats to also accept "-" as a special file name meaning standard output. I've restricted it to just those output formats which can predictably output only one file, just for the sake of not having to faff too much with the others. Probably what I should have done for all of this would have been to write a set of wrappers around fopen, fclose and everything in between, and use them everywhere. Those wrappers would uniformly detect "-" and convert it into stdin or stdout as appropriate, would avoid fclosing those files for real when told to close them, and would also be able to handle reading a little bit of data from the start of a file and then pushing it all back even if the file were not seekable (which would allow input.c to lose the ugly special case whereby it can't currently read font files from standard input). [originally from svn r8729] --- bk_html.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'bk_html.c') diff --git a/bk_html.c b/bk_html.c index fad891c..90800f1 100644 --- a/bk_html.c +++ b/bk_html.c @@ -884,7 +884,10 @@ void html_backend(paragraph *sourceform, keywordlist *keywords, #define listname(lt) ( (lt)==UL ? "ul" : (lt)==OL ? "ol" : "dl" ) #define itemname(lt) ( (lt)==LI ? "li" : (lt)==DT ? "dt" : "dd" ) - ho.fp = fopen(f->filename, "w"); + if (!strcmp(f->filename, "-")) + ho.fp = stdout; + else + ho.fp = fopen(f->filename, "w"); if (!ho.fp) error(err_cantopenw, f->filename); @@ -2507,7 +2510,7 @@ static void html_text_limit_internal(htmloutput *ho, wchar_t const *text, static void cleanup(htmloutput *ho) { return_to_neutral(ho); - if (ho->fp) + if (ho->fp && ho->fp != stdout) fclose(ho->fp); } -- cgit v1.1