From d2e74722f962217dc23c9524bd634c47597ba728 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 11 Aug 2002 15:28:24 +0000 Subject: [PATCH] Upgrade to Halibut xhtml backend, to allow leaf_level to be zero (in which case the whole of the HTML output will be in a single file, currently called Manual.html in the absence of configurability). This includes the index, if present. git-svn-id: svn://svn.tartarus.org/sgt/halibut@1831 cda61777-01e9-0310-a592-d414129be87e --- bk_xhtml.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/bk_xhtml.c b/bk_xhtml.c index 2016e10..18a7409 100644 --- a/bk_xhtml.c +++ b/bk_xhtml.c @@ -153,9 +153,6 @@ static xhtmlconfig xhtml_configure(paragraph *source) ret.contents_depth[5] = utoi(uadv(source->keyword)); } else if (!ustricmp(source->keyword, L"xhtml-leaf-level")) { ret.leaf_level = utoi(uadv(source->keyword)); - if (ret.leaf_level==0) { - fatal(err_whatever, "xhtml-leaf-level cannot be zero"); - } } else if (!ustricmp(source->keyword, L"xhtml-leaf-smallest-contents")) { ret.leaf_smallest_contents = utoi(uadv(source->keyword)); } else if (!ustricmp(source->keyword, L"xhtml-versionid")) { @@ -390,6 +387,12 @@ static void xhtml_ponder_layout(paragraph *p) currentfile = topfile; currentsect = topsection; + if (conf.leaf_level == 0) { + topfile->is_leaf = 1; + topfile->sections = topsection; + topsection->file = topfile; + } + for (; p; p=p->next) { int level = xhtml_para_level(p); @@ -596,8 +599,10 @@ void xhtml_backend(paragraph *sourceform, keywordlist *in_keywords, /* new system ... (writes to *.html, but isn't fully trusted) */ xhtml_do_top_file(topfile, sourceform); assert(!topfile->next); /* shouldn't have a sibling at all */ - xhtml_do_files(topfile->child); - xhtml_do_index(); + if (topfile->child) { + xhtml_do_files(topfile->child); + xhtml_do_index(); + } /* release file, section, index data structures */ xsect = topsection; @@ -629,6 +634,7 @@ static int xhtml_para_level(paragraph *p) case para_UnnumberedChapter: case para_Chapter: case para_Appendix: + case para_Title: return 1; break; /* case para_BiblioCited: @@ -685,17 +691,13 @@ static void xhtml_donavlinks(FILE *fp, xhtmlfile *file) } /* Write out the index file */ -static void xhtml_do_index() +static void xhtml_do_index_body(FILE *fp) { - word temp_word = { NULL, NULL, word_Normal, 0, 0, L"Index", { NULL, 0, 0} }; indexentry *y; int ti; - FILE *fp = fopen(xhtml_index_filename, "w"); - if (fp==NULL) - fatal(err_cantopenw, xhtml_index_filename); - xhtml_doheader(fp, &temp_word); - xhtml_donavlinks(fp, NULL); + if (count234(idx->entries) == 0) + return; /* don't write anything at all */ fprintf(fp, "
\n"); /* iterate over idx->entries using the tree functions and display everything */ @@ -728,6 +730,18 @@ static void xhtml_do_index() } } fprintf(fp, "
\n"); +} +static void xhtml_do_index() +{ + word temp_word = { NULL, NULL, word_Normal, 0, 0, L"Index", { NULL, 0, 0} }; + FILE *fp = fopen(xhtml_index_filename, "w"); + + if (fp==NULL) + fatal(err_cantopenw, xhtml_index_filename); + xhtml_doheader(fp, &temp_word); + xhtml_donavlinks(fp, NULL); + + xhtml_do_index_body(fp); xhtml_donavlinks(fp, NULL); xhtml_dofooter(fp); @@ -751,7 +765,8 @@ static void xhtml_do_file(xhtmlfile *file) xhtml_donavlinks(fp, file); - if (file->is_leaf && conf.leaf_contains_contents && xhtml_do_contents(NULL, file)>=conf.leaf_smallest_contents) + if (file->is_leaf && conf.leaf_contains_contents && + xhtml_do_contents(NULL, file)>=conf.leaf_smallest_contents) xhtml_do_contents(fp, file); xhtml_do_sections(fp, file->sections); if (!file->is_leaf) @@ -786,6 +801,17 @@ static void xhtml_do_top_file(xhtmlfile *file, paragraph *sourceform) if (!done) xhtml_doheader(fp, NULL /* Eek! */); + /* + * Display the title. + */ + for (p = sourceform; p; p = p->next) + { + if (p->type == para_Title) { + xhtml_heading(fp, p); + break; + } + } + /* Do the preamble and copyright */ for (p = sourceform; p; p = p->next) { @@ -808,6 +834,12 @@ static void xhtml_do_top_file(xhtmlfile *file, paragraph *sourceform) xhtml_do_contents(fp, file); xhtml_do_sections(fp, file->sections); + + if (count234(idx->entries) > 0) { + fprintf(fp, "

Index

\n"); + xhtml_do_index_body(fp); + } + xhtml_dofooter(fp); fclose(fp); } @@ -939,7 +971,7 @@ static int xhtml_add_contents_entry(FILE *fp, xhtmlsection *section, int limit) { if (!section || section->level > limit) return FALSE; - if (fp==NULL) + if (fp==NULL || !section->parent) return TRUE; while (last_level > section->level) { last_level--; @@ -1401,8 +1433,12 @@ static void xhtml_heading(FILE *fp, paragraph *p) if (sect) { fragment = sect->fragment; } else { - fragment = ""; /* FIXME: what else can we do? */ - error(err_whatever, "Couldn't locate heading cross-reference!"); + if (p->type == para_Title) + fragment = "title"; + else { + fragment = ""; /* FIXME: what else can we do? */ + error(err_whatever, "Couldn't locate heading cross-reference!"); + } } if (level>2 && nprefix) { /* FIXME: configurability on the level thing */ -- 2.11.0