Add an error check for correct formatting in Deflate uncompressed
[sgt/halibut] / bk_whlp.c
index 6593013..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;
+    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);
            }
        }
     }
@@ -212,6 +216,10 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
     }
 
     state.cntfp = fopen(cntname, "wb");
+    if (!state.cntfp) {
+       error(err_cantopenw, cntname);
+       return;
+    }
     state.cnt_last_level = -1; state.cnt_workaround = 0;
 
     /*
@@ -310,8 +318,13 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
     /* ------------------------------------------------------------------
      * Begin the contents page.
      */
-
-    whlp_begin_topic(h, contents_topic, "Contents", "DB(\"btn_up\")", NULL);
+    {
+       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
@@ -412,8 +425,6 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
                    whlp_navmenu(&state, p, &conf);
            }
 
-           state.curr_topic = contents_topic;
-
            done_contents_topic = TRUE;
        }