X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/halibut/blobdiff_plain/6e6747065dd221528a52a383f0f99712c8cd82e4..05e9c3c2e7be6c54e31121132f43db83597381e8:/bk_html.c diff --git a/bk_html.c b/bk_html.c index 96f3083..3a49bdc 100644 --- a/bk_html.c +++ b/bk_html.c @@ -253,7 +253,7 @@ static htmlconfig html_configure(paragraph *source) { ret.nasect = 1; ret.asect = snewn(ret.nasect, sectlevel); ret.asect[0].just_numbers = TRUE; - ret.achapter.number_at_all = TRUE; + ret.asect[0].number_at_all = TRUE; ret.asect[0].number_suffix = L" "; ret.ncdepths = 0; ret.contents_depths = 0; @@ -348,7 +348,7 @@ static htmlconfig html_configure(paragraph *source) { break; if (i == lenof(versions)) - error(err_htmlver, &p->fpos, vername); + err_htmlver(&p->fpos, vername); else ret.htmlver = versions[i].ver; } else if (!ustricmp(k, L"html-single-filename")) { @@ -381,7 +381,7 @@ static htmlconfig html_configure(paragraph *source) { frag = adv(frag); } } else - error(err_cfginsufarg, &p->fpos, p->origkeyword, 1); + err_cfginsufarg(&p->fpos, p->origkeyword, 1); } else if (!ustricmp(k, L"html-chapter-numeric")) { ret.achapter.just_numbers = utob(uadv(k)); } else if (!ustricmp(k, L"html-chapter-shownumber")) { @@ -548,7 +548,7 @@ static htmlconfig html_configure(paragraph *source) { * turn both off. */ if (!ret.chm_filename ^ !ret.hhp_filename) { - error(err_chmnames); + err_chmnames(); sfree(ret.chm_filename); ret.chm_filename = NULL; sfree(ret.hhp_filename); ret.hhp_filename = NULL; } @@ -884,9 +884,12 @@ 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); + err_cantopenw(f->filename); ho.charset = conf.output_charset; ho.restrict_charset = conf.restrict_charset; @@ -1682,7 +1685,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords, ho.fp = fopen(conf.hhp_filename, "w"); if (!ho.fp) - error(err_cantopenw, conf.hhp_filename); + err_cantopenw(conf.hhp_filename); fprintf(ho.fp, "[OPTIONS]\n" @@ -1757,7 +1760,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords, ho.fp = fopen(conf.hhc_filename, "w"); if (!ho.fp) - error(err_cantopenw, conf.hhc_filename); + err_cantopenw(conf.hhc_filename); ho.charset = CS_CP1252; /* as far as I know, HHC files are */ ho.restrict_charset = CS_CP1252; /* hardwired to this charset */ @@ -1871,7 +1874,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords, ho.fp = fopen(hhk_filename, "w"); if (!ho.fp) - error(err_cantopenw, hhk_filename); + err_cantopenw(hhk_filename); ho.charset = CS_CP1252; /* as far as I know, HHK files are */ ho.restrict_charset = CS_CP1252; /* hardwired to this charset */ @@ -2173,7 +2176,7 @@ static void html_words(htmloutput *ho, word *words, int flags, htmlfile *file, keywordlist *keywords, htmlconfig *cfg) { word *w; - char *c; + char *c, *c2, *p, *q; int style, type; for (w = words; w; w = w->next) switch (w->type) { @@ -2181,7 +2184,20 @@ static void html_words(htmloutput *ho, word *words, int flags, if (flags & LINKS) { element_open(ho, "a"); c = utoa_dup(w->text, CS_ASCII); - element_attr(ho, "href", c); + c2 = snewn(1 + 10*strlen(c), char); + for (p = c, q = c2; *p; p++) { + if (*p == '&') + q += sprintf(q, "&"); + else if (*p == '<') + q += sprintf(q, "<"); + else if (*p == '>') + q += sprintf(q, ">"); + else + *q++ = *p; + } + *q = '\0'; + element_attr(ho, "href", c2); + sfree(c2); sfree(c); } break; @@ -2507,7 +2523,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); }