diff options
| author | Simon Tatham <anakin@pobox.com> | 2006-06-02 19:19:12 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2006-06-02 19:19:12 +0000 |
| commit | 9e8ca006788e2148154711e1e67b88f495d94e26 (patch) | |
| tree | b3886338af0052ddf9dfbd6eb7212e317eb2bea5 | |
| parent | 9c7ee9bd5c91b41792c40e12669b43aceea2a544 (diff) | |
| download | halibut-9e8ca006788e2148154711e1e67b88f495d94e26.zip halibut-9e8ca006788e2148154711e1e67b88f495d94e26.tar.gz halibut-9e8ca006788e2148154711e1e67b88f495d94e26.tar.bz2 halibut-9e8ca006788e2148154711e1e67b88f495d94e26.tar.xz | |
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.
[originally from svn r6724]
| -rw-r--r-- | bk_html.c | 4 | ||||
| -rw-r--r-- | bk_info.c | 68 | ||||
| -rw-r--r-- | bk_paper.c | 14 | ||||
| -rw-r--r-- | bk_whlp.c | 14 | ||||
| -rw-r--r-- | doc/input.but | 12 | ||||
| -rw-r--r-- | doc/output.but | 10 | ||||
| -rw-r--r-- | error.c | 9 | ||||
| -rw-r--r-- | inputs/test.but | 3 |
8 files changed, 107 insertions, 27 deletions
@@ -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); } } } @@ -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, @@ -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); @@ -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{<TITLE>} tag, this @@ -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. |