summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2001-12-04 21:33:03 +0000
committerSimon Tatham <anakin@pobox.com>2001-12-04 21:33:03 +0000
commit38181905971fab7106f1f4b90db8da26497158b9 (patch)
tree26e8e64f06ab2f07fb2999acbd5726767a8de64e
parent5e3a21913b6a47e78d3e4edd4238d028b90827b7 (diff)
downloadhalibut-38181905971fab7106f1f4b90db8da26497158b9.zip
halibut-38181905971fab7106f1f4b90db8da26497158b9.tar.gz
halibut-38181905971fab7106f1f4b90db8da26497158b9.tar.bz2
halibut-38181905971fab7106f1f4b90db8da26497158b9.tar.xz
Indexing in the Help backend now seems to work! Woo!
[originally from svn r1450]
-rw-r--r--bk_whlp.c44
-rw-r--r--buttress.h1
-rw-r--r--index.c13
3 files changed, 53 insertions, 5 deletions
diff --git a/bk_whlp.c b/bk_whlp.c
index a9975c9..0da37a1 100644
--- a/bk_whlp.c
+++ b/bk_whlp.c
@@ -17,8 +17,9 @@
struct bk_whlp_state {
WHLP h;
+ indexdata *idx;
keywordlist *keywords;
- paragraph *biblio;
+ WHLP_TOPIC curr_topic;
};
static void whlp_rdaddwc(rdstringc *rs, word *text);
@@ -33,12 +34,15 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
char *filename;
paragraph *p, *lastsect;
struct bk_whlp_state state;
- WHLP_TOPIC contents_topic, curr_topic;
+ WHLP_TOPIC contents_topic;
+ int i;
+ indexentry *ie;
filename = "output.hlp"; /* FIXME: configurability */
h = state.h = whlp_new();
state.keywords = keywords;
+ state.idx = idx;
whlp_start_macro(h, "CB(\"btn_about\",\"&About\",\"About()\")");
whlp_start_macro(h, "CB(\"btn_up\",\"&Up\",\"Contents()\")");
@@ -61,6 +65,16 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
}
}
+ /*
+ * Loop over the index entries, preparing final text forms for
+ * each one.
+ */
+ for (i = 0; (ie = index234(idx->entries, i)) != NULL; i++) {
+ rdstringc rs = {0, 0, NULL};
+ whlp_rdaddwc(&rs, ie->text);
+ ie->backend_data = rs.text;
+ }
+
whlp_prepare(h);
/* ------------------------------------------------------------------
@@ -134,7 +148,7 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
whlp_navmenu(&state, p);
}
- curr_topic = contents_topic;
+ state.curr_topic = contents_topic;
lastsect = NULL;
/* ------------------------------------------------------------------
@@ -179,8 +193,8 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
char *macro, *topicid;
new_topic = p->private_data;
- whlp_browse_link(h, curr_topic, new_topic);
- curr_topic = new_topic;
+ whlp_browse_link(h, state.curr_topic, new_topic);
+ state.curr_topic = new_topic;
if (p->kwtext) {
whlp_rdaddwc(&rs, p->kwtext);
@@ -274,6 +288,15 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
}
whlp_close(h, filename);
+
+
+ /*
+ * Loop over the index entries, cleaning up our final text
+ * forms.
+ */
+ for (i = 0; (ie = index234(idx->entries, i)) != NULL; i++) {
+ sfree(ie->backend_data);
+ }
}
static void whlp_navmenu(struct bk_whlp_state *state, paragraph *p) {
@@ -303,7 +326,18 @@ static void whlp_mkparagraph(struct bk_whlp_state *state,
for (; text; text = text->next) switch (text->type) {
case word_HyperLink:
case word_HyperEnd:
+ break;
+
case word_IndexRef:
+ {
+ indextag *tag = index_findtag(state->idx, text->text);
+ int i;
+ if (!tag)
+ break;
+ for (i = 0; i < tag->nrefs; i++)
+ whlp_index_term(state->h, tag->refs[i]->backend_data,
+ state->curr_topic);
+ }
break;
case word_UpperXref:
diff --git a/buttress.h b/buttress.h
index 5b274d5..0fd69a9 100644
--- a/buttress.h
+++ b/buttress.h
@@ -375,6 +375,7 @@ void cleanup_index(indexdata *);
void index_merge(indexdata *, int is_explicit, wchar_t *, word *);
void build_index(indexdata *);
void index_debug(indexdata *);
+indextag *index_findtag(indexdata *idx, wchar_t *name);
/*
* contents.c
diff --git a/index.c b/index.c
index 3fb45a1..b5005ac 100644
--- a/index.c
+++ b/index.c
@@ -31,12 +31,25 @@ static int compare_tags(void *av, void *bv) {
return ustricmp(a->name, b->name);
}
+static int compare_to_find_tag(void *av, void *bv) {
+ wchar_t *a = (wchar_t *)av;
+ indextag *b = (indextag *)bv;
+ return ustricmp(a, b->name);
+}
+
static int compare_entries(void *av, void *bv) {
indexentry *a = (indexentry *)av, *b = (indexentry *)bv;
return compare_wordlists(a->text, b->text);
}
/*
+ * Back-end utility: find the indextag with a given name.
+ */
+indextag *index_findtag(indexdata *idx, wchar_t *name) {
+ return find234(idx->tags, name, compare_to_find_tag);
+}
+
+/*
* Add a \IM. `tags' points to a zero-terminated chain of
* zero-terminated strings ("first\0second\0thirdandlast\0\0").
* `text' points to a word list.