+paragraph *whlp_config_filename(char *filename)
+{
+ return cmdline_cfg_simple("winhelp-filename", filename, NULL);
+}
+
+static whlpconf whlp_configure(paragraph *source) {
+ paragraph *p;
+ whlpconf ret;
+
+ /*
+ * Defaults.
+ */
+ ret.charset = CS_CP1252;
+ ret.bullet = L"\x2022\0-\0\0";
+ ret.lquote = L"\x2018\0\x2019\0\"\0\"\0\0";
+ 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".";
+
+ /*
+ * Two-pass configuration so that we can pick up global config
+ * (e.g. `quotes') before having it overridden by specific
+ * config (`win-quotes'), irrespective of the order in which
+ * they occur.
+ */
+ for (p = source; p; p = p->next) {
+ if (p->type == para_Config) {
+ if (!ustricmp(p->keyword, L"quotes")) {
+ if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) {
+ ret.lquote = uadv(p->keyword);
+ ret.rquote = uadv(ret.lquote);
+ }
+ }
+ }
+ }
+
+ for (p = source; p; p = p->next) {
+ p->private_data = NULL;
+ if (p->type == para_Config) {
+ /*
+ * In principle we should support a `winhelp-charset'
+ * here. We don't, because my WinHelp output code
+ * doesn't know how to change character set. Once I
+ * find out, I'll support it.
+ */
+ if (p->parent && !ustricmp(p->keyword, L"winhelp-topic")) {
+ /* Store the topic name in the private_data field of the
+ * containing section. */
+ p->parent->private_data = uadv(p->keyword);
+ } else if (!ustricmp(p->keyword, L"winhelp-filename")) {
+ sfree(ret.filename);
+ ret.filename = dupstr(adv(p->origkeyword));
+ } else if (!ustricmp(p->keyword, L"winhelp-bullet")) {
+ ret.bullet = uadv(p->keyword);
+ } else if (!ustricmp(p->keyword, L"winhelp-section-suffix")) {
+ ret.sectsuffix = uadv(p->keyword);
+ } else if (!ustricmp(p->keyword, L"winhelp-list-suffix")) {
+ ret.listsuffix = uadv(p->keyword);
+ } else if (!ustricmp(p->keyword, L"winhelp-contents-titlepage")) {
+ ret.titlepage = uadv(p->keyword);
+ } else if (!ustricmp(p->keyword, L"winhelp-quotes")) {
+ if (*uadv(p->keyword) && *uadv(uadv(p->keyword))) {
+ ret.lquote = uadv(p->keyword);
+ ret.rquote = uadv(ret.lquote);
+ }
+ } else if (!ustricmp(p->keyword, L"contents")) {
+ ret.contents_text = uadv(p->keyword);
+ }
+ }
+ }
+
+ /*
+ * Now process fallbacks on quote characters and bullets.
+ */
+ while (*uadv(ret.rquote) && *uadv(uadv(ret.rquote)) &&
+ (!cvt_ok(ret.charset, ret.lquote) ||
+ !cvt_ok(ret.charset, ret.rquote))) {
+ ret.lquote = uadv(ret.rquote);
+ ret.rquote = uadv(ret.lquote);
+ }
+
+ while (*ret.bullet && *uadv(ret.bullet) &&
+ !cvt_ok(ret.charset, ret.bullet))
+ ret.bullet = uadv(ret.bullet);
+
+ return ret;
+}
+