From f6220253b2e31a88862b8beae822ff11cc5576ab Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 2 Jun 2006 19:19:12 +0000 Subject: [PATCH] Introduce global (cross-backend) \cfg{contents} and \cfg{index} commands, allowing the fixed words "Contents" and "Index" generated in various output formats to be reconfigured into other languages. git-svn-id: svn://svn.tartarus.org/sgt/halibut@6724 cda61777-01e9-0310-a592-d414129be87e --- bk_html.c | 4 ++++ bk_info.c | 68 ++++++++++++++++++++++++++++++++++++++++++--------------- bk_paper.c | 14 +++++++++--- bk_whlp.c | 14 +++++++++--- doc/input.but | 12 ++++++++++ doc/output.but | 10 +++++++++ error.c | 9 +++++--- inputs/test.but | 3 +++ 8 files changed, 107 insertions(+), 27 deletions(-) diff --git a/bk_html.c b/bk_html.c index 4311d26..a1b46f6 100644 --- a/bk_html.c +++ b/bk_html.c @@ -259,6 +259,10 @@ static htmlconfig html_configure(paragraph *source) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } + } else if (!ustricmp(p->keyword, L"index")) { + ret.index_text = uadv(p->keyword); + } else if (!ustricmp(p->keyword, L"contents")) { + ret.contents_text = uadv(p->keyword); } } } diff --git a/bk_info.c b/bk_info.c index 85461c4..5b82177 100644 --- a/bk_info.c +++ b/bk_info.c @@ -39,6 +39,7 @@ typedef struct { wchar_t *lquote, *rquote; wchar_t *sectsuffix, *underline; wchar_t *rule; + wchar_t *index_text; } infoconfig; typedef struct { @@ -84,7 +85,8 @@ static int info_check_index(word *, node *, indexdata *); static int info_rdaddwc(info_data *, word *, word *, int, infoconfig *); static node *info_node_new(char *name, int charset); -static char *info_node_name(paragraph *p, infoconfig *); +static char *info_node_name_for_para(paragraph *p, infoconfig *); +static char *info_node_name_for_text(wchar_t *text, infoconfig *); static infoconfig info_configure(paragraph *source) { infoconfig ret; @@ -110,6 +112,7 @@ static infoconfig info_configure(paragraph *source) { ret.rquote = uadv(ret.lquote); ret.sectsuffix = L": "; ret.underline = L"\x203E\0-\0\0"; + ret.index_text = L"Index"; /* * Two-pass configuration so that we can pick up global config @@ -124,6 +127,8 @@ static infoconfig info_configure(paragraph *source) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } + } else if (!ustricmp(p->keyword, L"index")) { + ret.index_text = uadv(p->keyword); } } } @@ -247,7 +252,7 @@ void info_backend(paragraph *sourceform, keywordlist *keywords, node *newnode, *upnode; char *nodename; - nodename = info_node_name(p, &conf); + nodename = info_node_name_for_para(p, &conf); newnode = info_node_new(nodename, conf.charset); sfree(nodename); @@ -495,15 +500,25 @@ void info_backend(paragraph *sourceform, keywordlist *keywords, node *newnode; int i, j, k; indexentry *entry; + char *nodename; + + nodename = info_node_name_for_text(conf.index_text, &conf); + newnode = info_node_new(nodename, conf.charset); + sfree(nodename); - newnode = info_node_new("Index", conf.charset); newnode->up = topnode; currnode->next = newnode; newnode->prev = currnode; currnode->listnext = newnode; - info_rdaddsc(&newnode->text, "Index\n-----\n\n"); + k = info_rdadds(&newnode->text, conf.index_text); + info_rdaddsc(&newnode->text, "\n"); + while (k > 0) { + info_rdadds(&newnode->text, conf.underline); + k -= ustrwid(conf.underline, conf.charset); + } + info_rdaddsc(&newnode->text, "\n\n"); info_menu_item(&topnode->text, newnode, NULL, &conf); @@ -1035,32 +1050,49 @@ static node *info_node_new(char *name, int charset) return n; } -static char *info_node_name(paragraph *par, infoconfig *cfg) +static char *info_node_name_core(info_data *id, filepos *fpos) { - info_data id = EMPTY_INFO_DATA; char *p, *q; - id.charset = cfg->charset; - info_rdaddwc(&id, par->kwtext ? par->kwtext : par->words, - NULL, FALSE, cfg); - info_rdaddsc(&id, NULL); - /* - * We cannot have commas or colons in a node name. Remove any - * that we find, with a warning. + * We cannot have commas, colons or parentheses in a node name. + * Remove any that we find, with a warning. */ - p = q = id.output.text; + p = q = id->output.text; while (*p) { - if (*p == ':' || *p == ',') { - error(err_infonodechar, &par->fpos, *p); + if (*p == ':' || *p == ',' || *p == '(' || *p == ')') { + error(err_infonodechar, fpos, *p); } else { *q++ = *p; } p++; } - *p = '\0'; + *q = '\0'; + + return id->output.text; +} + +static char *info_node_name_for_para(paragraph *par, infoconfig *cfg) +{ + info_data id = EMPTY_INFO_DATA; + + id.charset = cfg->charset; + info_rdaddwc(&id, par->kwtext ? par->kwtext : par->words, + NULL, FALSE, cfg); + info_rdaddsc(&id, NULL); + + return info_node_name_core(&id, &par->fpos); +} + +static char *info_node_name_for_text(wchar_t *text, infoconfig *cfg) +{ + info_data id = EMPTY_INFO_DATA; + + id.charset = cfg->charset; + info_rdadds(&id, text); + info_rdaddsc(&id, NULL); - return id.output.text; + return info_node_name_core(&id, NULL); } static void info_menu_item(info_data *text, node *n, paragraph *p, diff --git a/bk_paper.c b/bk_paper.c index 64e44ed..dff6dc4 100644 --- a/bk_paper.c +++ b/bk_paper.c @@ -120,6 +120,7 @@ struct paper_conf_Tag { int pagenum_fontsize; int footer_distance; wchar_t *lquote, *rquote, *bullet; + wchar_t *contents_text, *index_text; /* These are derived from the above */ int base_width; int page_height; @@ -283,6 +284,8 @@ static paper_conf paper_configure(paragraph *source, font_list *fontlist) { ret.lquote = L"\x2018\0\x2019\0'\0'\0\0"; ret.rquote = uadv(ret.lquote); ret.bullet = L"\x2022\0-\0\0"; + ret.contents_text = L"Contents"; + ret.index_text = L"Index"; /* * Two-pass configuration so that we can pick up global config @@ -309,6 +312,10 @@ static paper_conf paper_configure(paragraph *source, font_list *fontlist) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } + } else if (!ustricmp(p->keyword, L"contents")) { + ret.contents_text = uadv(p->keyword); + } else if (!ustricmp(p->keyword, L"index")) { + ret.index_text = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"paper-bullet")) { ret.bullet = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"paper-page-width")) { @@ -547,7 +554,7 @@ void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords, */ { word *contents_title; - contents_title = fake_word(L"Contents"); + contents_title = fake_word(conf->contents_text); firstcont = make_para_data(para_UnnumberedChapter, 0, 0, 0, NULL, NULL, contents_title, conf); @@ -615,7 +622,8 @@ void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords, if (has_index) { pdata = make_para_data(para_Normal, 0, 0, conf->contents_margin, - NULL, NULL, fake_word(L"Index"), conf); + NULL, NULL, + fake_word(conf->index_text), conf); pdata->next = NULL; pdata->contents_entry = &index_placeholder_para; lastcont->next = pdata; @@ -835,7 +843,7 @@ void *paper_pre_backend(paragraph *sourceform, keywordlist *keywords, /* * Create a set of paragraphs for the index. */ - index_title = fake_word(L"Index"); + index_title = fake_word(conf->index_text); firstidx = make_para_data(para_UnnumberedChapter, 0, 0, 0, NULL, NULL, index_title, conf); diff --git a/bk_whlp.c b/bk_whlp.c index 14e6b01..d15d029 100644 --- a/bk_whlp.c +++ b/bk_whlp.c @@ -24,6 +24,7 @@ struct bk_whlp_state { typedef struct { int charset; wchar_t *bullet, *lquote, *rquote, *titlepage, *sectsuffix, *listsuffix; + wchar_t *contents_text; char *filename; } whlpconf; @@ -73,6 +74,7 @@ static whlpconf whlp_configure(paragraph *source) { ret.rquote = uadv(ret.lquote); ret.filename = dupstr("output.hlp"); ret.titlepage = L"Title page"; + ret.contents_text = L"Contents"; ret.sectsuffix = L": "; ret.listsuffix = L"."; @@ -122,6 +124,8 @@ static whlpconf whlp_configure(paragraph *source) { ret.lquote = uadv(p->keyword); ret.rquote = uadv(ret.lquote); } + } else if (!ustricmp(p->keyword, L"contents")) { + ret.contents_text = uadv(p->keyword); } } } @@ -314,9 +318,13 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords, /* ------------------------------------------------------------------ * Begin the contents page. */ - - whlp_begin_topic(h, contents_topic, "Contents", "DB(\"btn_up\")", NULL); - state.curr_topic = contents_topic; + { + rdstringc rs = {0, 0, NULL}; + whlp_rdadds(&rs, conf.contents_text, &conf, NULL); + whlp_begin_topic(h, contents_topic, rs.text, "DB(\"btn_up\")", NULL); + state.curr_topic = contents_topic; + sfree(rs.text); + } /* * The manual title goes in the non-scroll region, and also diff --git a/doc/input.but b/doc/input.but index 2d6d489..38a7a65 100644 --- a/doc/input.but +++ b/doc/input.but @@ -1327,6 +1327,16 @@ subsections of a chapter. \dd Exactly like \c{chapter}, but changes the name given to appendices. +\dt \I\cw{\\cfg\{contents\}}\cw{\\cfg\{contents\}\{}\e{new contents name}\cw{\}} + +\dd This changes the name given to the contents section (by default +\q{Contents}) in back ends which generate one. + +\dt \I\cw{\\cfg\{index\}}\cw{\\cfg\{index\}\{}\e{new index name}\cw{\}} + +\dd This changes the name given to the index section (by default +\q{Index}) in back ends which generate one. + \dt \I\cw{\\cfg\{input-charset\}}\cw{\\cfg\{input-charset\}\{}\e{character set name}\cw{\}} \dd This tells Halibut what \i{character set} you are writing your @@ -1405,6 +1415,8 @@ The \i{default settings} for the above options are: \c \cfg{chapter}{Chapter} \c \cfg{section}{Section} \c \cfg{appendix}{Appendix} +\c \cfg{contents}{Contents} +\c \cfg{index}{Index} \c \cfg{input-charset}{ASCII} The default for \cw{\\cfg\{input-charset\}} can be changed with the diff --git a/doc/output.but b/doc/output.but index dafa276..4df4502 100644 --- a/doc/output.but +++ b/doc/output.but @@ -624,6 +624,16 @@ different language. the first chapter heading), contents, and index respectively, in the navigation bar, contents, and index. +\lcont{ + +(\c{html-contents-text} and \c{html-index-text} override the +cross-format configuration keywords \c{contents} and \c{index} (see +\k{input-config}, if both appear. They are legacy keywords preserved +for backwards compatibility; you should generally use \c{contents} +and \c{index}.) + +} + \dt \I{\cw{\\cfg\{html-title-separator\}}}\cw{\\cfg\{html-title-separator\}\{}\e{text}\cw{\}} \dd If multiple headings are used in a file's \cw{} tag, this diff --git a/error.c b/error.c index f7461ef..dfe65e3 100644 --- a/error.c +++ b/error.c @@ -19,7 +19,7 @@ static void do_error(int code, va_list ap) { int i, j; char *sp, *sp2; wchar_t *wsp, *wsp2; - filepos fpos, fpos2; + filepos fpos, fpos2, *fposp; int flags; switch(code) { @@ -248,11 +248,14 @@ static void do_error(int code, va_list ap) { flags = FILEPOS; break; case err_infonodechar: - fpos = *va_arg(ap, filepos *); + fposp = va_arg(ap, filepos *); c = (char)va_arg(ap, int); sprintf(error, "info output format does not support '%c' in" " node names; removing", c); - flags = FILEPOS; + if (fposp) { + flags = FILEPOS; + fpos = *fposp; + } break; case err_text_codeline: fpos = *va_arg(ap, filepos *); diff --git a/inputs/test.but b/inputs/test.but index 2e37c19..af1f2fc 100644 --- a/inputs/test.but +++ b/inputs/test.but @@ -9,6 +9,9 @@ Lines, Not Just Two. How's That For Ludicrous? document}{sub-sub} \cfg{man-headnumbers}{true} +\cfg{contents}{Contents(edited)} +\cfg{index}{Index(alsoedited)} + This paragraph is not labelled \q{preamble}, but should still appear as it. -- 2.11.0