summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2001-12-06 08:37:54 +0000
committerSimon Tatham <anakin@pobox.com>2001-12-06 08:37:54 +0000
commitd098f79c9b7dd52c534fed83bb1eb6a3080a03af (patch)
tree5c1ba8ac94e9ef4dddcdb3e0ea61d450305f50ed
parent1327ff7779e53416bbaf4785f21e5eb79095d3d0 (diff)
downloadhalibut-d098f79c9b7dd52c534fed83bb1eb6a3080a03af.zip
halibut-d098f79c9b7dd52c534fed83bb1eb6a3080a03af.tar.gz
halibut-d098f79c9b7dd52c534fed83bb1eb6a3080a03af.tar.bz2
halibut-d098f79c9b7dd52c534fed83bb1eb6a3080a03af.tar.xz
Create a .CNT contents file alongside the .HLP. (The .CNT file is
deliberately incorrect, to compensate for a bug in WinHelp. With any luck MS will never fix the bug and this .CNT will continue to work forever. Since WinHelp is theoretically obsolete, this sounds reasonably likely.) [originally from svn r1456]
-rw-r--r--bk_whlp.c63
1 files changed, 60 insertions, 3 deletions
diff --git a/bk_whlp.c b/bk_whlp.c
index 5341919..cf4757d 100644
--- a/bk_whlp.c
+++ b/bk_whlp.c
@@ -17,6 +17,8 @@ struct bk_whlp_state {
indexdata *idx;
keywordlist *keywords;
WHLP_TOPIC curr_topic;
+ FILE *cntfp;
+ int cnt_last_level, cnt_workaround;
};
/*
@@ -37,11 +39,13 @@ static int whlp_convert(wchar_t *s, char **result, int hard_spaces);
static void whlp_mkparagraph(struct bk_whlp_state *state,
int font, word *text, int subsidiary);
static void whlp_navmenu(struct bk_whlp_state *state, paragraph *p);
+static void whlp_contents_write(struct bk_whlp_state *state,
+ int level, char *text, WHLP_TOPIC topic);
void whlp_backend(paragraph *sourceform, keywordlist *keywords,
indexdata *idx) {
WHLP h;
- char *filename;
+ char *filename, *cntname;
paragraph *p, *lastsect;
struct bk_whlp_state state;
WHLP_TOPIC contents_topic;
@@ -49,7 +53,11 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
indexentry *ie;
filename = "output.hlp"; /* FIXME: configurability */
-
+ cntname = "output.cnt"; /* corresponding contents file */
+
+ state.cntfp = fopen(cntname, "wb");
+ state.cnt_last_level = -1; state.cnt_workaround = 0;
+
h = state.h = whlp_new();
state.keywords = keywords;
state.idx = idx;
@@ -125,8 +133,11 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
}
if (rs.text) {
whlp_title(h, rs.text);
+ fprintf(state.cntfp, ":Title %s\r\n", rs.text);
sfree(rs.text);
}
+ whlp_contents_write(&state, 1, "Title page", contents_topic);
+ /* FIXME: configurability in that string */
}
/*
@@ -239,6 +250,27 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
rs.text ? rs.text : "",
macro, NULL);
sfree(macro);
+
+ {
+ /*
+ * Output the .cnt entry.
+ */
+ int i;
+ paragraph *q;
+ i = 1;
+ for (q = p; q->parent; q = q->parent) i++;
+ if (p->child) {
+ /*
+ * Need two entries: one directory, and then
+ * one actual link. The link is on the next
+ * level down.
+ */
+ whlp_contents_write(&state, i, rs.text, NULL);
+ i++;
+ }
+ whlp_contents_write(&state, i, rs.text, new_topic);
+ }
+
sfree(rs.text);
whlp_begin_para(h, WHLP_PARA_NONSCROLL);
@@ -326,9 +358,9 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
break;
}
+ fclose(state.cntfp);
whlp_close(h, filename);
-
/*
* Loop over the index entries, cleaning up our final text
* forms.
@@ -338,6 +370,31 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
}
}
+static void whlp_contents_write(struct bk_whlp_state *state,
+ int level, char *text, WHLP_TOPIC topic) {
+ /*
+ * Horrifying bug in WinHelp. When dropping a section level or
+ * more without using a folder-type entry, WinHelp accidentally
+ * adds one to the section level. So we correct for that here.
+ */
+ if (state->cnt_last_level > level && topic)
+ state->cnt_workaround = -1;
+ else if (!topic)
+ state->cnt_workaround = 0;
+ state->cnt_last_level = level;
+
+ fprintf(state->cntfp, "%d ", level + state->cnt_workaround);
+ while (*text) {
+ if (*text == '=')
+ fputc('\\', state->cntfp);
+ fputc(*text, state->cntfp);
+ text++;
+ }
+ if (topic)
+ fprintf(state->cntfp, "=%s", whlp_topic_id(topic));
+ fputc('\n', state->cntfp);
+}
+
static void whlp_navmenu(struct bk_whlp_state *state, paragraph *p) {
whlp_begin_para(state->h, WHLP_PARA_NONSCROLL);
whlp_start_hyperlink(state->h, (WHLP_TOPIC)p->private_data);