Introduce global (cross-backend) \cfg{contents} and \cfg{index}
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Fri, 2 Jun 2006 19:19:12 +0000 (19:19 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Fri, 2 Jun 2006 19:19:12 +0000 (19:19 +0000)
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
bk_info.c
bk_paper.c
bk_whlp.c
doc/input.but
doc/output.but
error.c
inputs/test.but

index 4311d26..a1b46f6 100644 (file)
--- 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);
                }
                    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);
            }
        }
     }
            }
        }
     }
index 85461c4..5b82177 100644 (file)
--- 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 *lquote, *rquote;
     wchar_t *sectsuffix, *underline;
     wchar_t *rule;
+    wchar_t *index_text;
 } infoconfig;
 
 typedef struct {
 } 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 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;
 
 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.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
 
     /*
      * 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);
                }
                    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;
 
            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);
 
            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;
        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;
 
        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);
 
 
        info_menu_item(&topnode->text, newnode, NULL, &conf);
 
@@ -1035,32 +1050,49 @@ static node *info_node_new(char *name, int charset)
     return n;
 }
 
     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;
 
     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) {
     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++;
     }
        } 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,
 }
 
 static void info_menu_item(info_data *text, node *n, paragraph *p,
index 64e44ed..dff6dc4 100644 (file)
@@ -120,6 +120,7 @@ struct paper_conf_Tag {
     int pagenum_fontsize;
     int footer_distance;
     wchar_t *lquote, *rquote, *bullet;
     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;
     /* 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.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
 
     /*
      * 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);
                }
                    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")) {
            } 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;
      */
     {
        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);
 
        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,
        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;
            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.
         */
        /*
         * 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);
 
        firstidx = make_para_data(para_UnnumberedChapter, 0, 0, 0,
                                  NULL, NULL, index_title, conf);
index 14e6b01..d15d029 100644 (file)
--- 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;
 typedef struct {
     int charset;
     wchar_t *bullet, *lquote, *rquote, *titlepage, *sectsuffix, *listsuffix;
+    wchar_t *contents_text;
     char *filename;
 } whlpconf;
 
     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.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".";
 
     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);
                }
                    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.
      */
     /* ------------------------------------------------------------------
      * 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
 
     /*
      * The manual title goes in the non-scroll region, and also
index 2d6d489..38a7a65 100644 (file)
@@ -1327,6 +1327,16 @@ subsections of a chapter.
 \dd Exactly like \c{chapter}, but changes the name given to
 appendices.
 
 \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
 \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{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
 \c \cfg{input-charset}{ASCII}
 
 The default for \cw{\\cfg\{input-charset\}} can be changed with the
index dafa276..4df4502 100644 (file)
@@ -624,6 +624,16 @@ different language.
 the first chapter heading), contents, and index respectively, in the
 navigation bar, contents, and index.
 
 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
 \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
diff --git a/error.c b/error.c
index f7461ef..dfe65e3 100644 (file)
--- 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;
     int i, j;
     char *sp, *sp2;
     wchar_t *wsp, *wsp2;
-    filepos fpos, fpos2;
+    filepos fpos, fpos2, *fposp;
     int flags;
 
     switch(code) {
     int flags;
 
     switch(code) {
@@ -248,11 +248,14 @@ static void do_error(int code, va_list ap) {
        flags = FILEPOS;
        break;
       case err_infonodechar:
        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);
        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 *);
        break;
       case err_text_codeline:
        fpos = *va_arg(ap, filepos *);
index 2e37c19..af1f2fc 100644 (file)
@@ -9,6 +9,9 @@ Lines, Not Just Two. How's That For Ludicrous?
 document}{sub-sub}
 \cfg{man-headnumbers}{true}
 
 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.
 
 This paragraph is not labelled \q{preamble}, but should still appear
 as it.