summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2001-12-03 12:26:15 +0000
committerSimon Tatham <anakin@pobox.com>2001-12-03 12:26:15 +0000
commit15f9f47056700ed8fea2659e15cb1b28415f7cb6 (patch)
tree13391b6c7a751b966fc68291b49f6c52180de0df
parent51e3a125697288583d6a999adef5a4e7a7f673fb (diff)
downloadhalibut-15f9f47056700ed8fea2659e15cb1b28415f7cb6.zip
halibut-15f9f47056700ed8fea2659e15cb1b28415f7cb6.tar.gz
halibut-15f9f47056700ed8fea2659e15cb1b28415f7cb6.tar.bz2
halibut-15f9f47056700ed8fea2659e15cb1b28415f7cb6.tar.xz
Implement browse sequence support
[originally from svn r1438]
-rw-r--r--winhelp.c48
-rw-r--r--winhelp.h6
2 files changed, 41 insertions, 13 deletions
diff --git a/winhelp.c b/winhelp.c
index 3ed8cfd..c0731c8 100644
--- a/winhelp.c
+++ b/winhelp.c
@@ -14,7 +14,6 @@
* to add indexing support.
* - nonbreaking spaces and hyphens will be needed.
* - tabs, and tab stop settings in the paragraphinfo.
- * - browse sequence support.
*
* Potential future features:
*
@@ -109,6 +108,8 @@ char *dupstr(char *s) { char *r = mknewa(char, 1+strlen(s)); strcpy(r,s); return
#define MAX_PAGE_SIZE 0x800 /* max page size in any B-tree */
#define TOPIC_BLKSIZE 4096 /* implied by version/flags combo */
+typedef struct WHLP_TOPIC_tag context;
+
struct file {
char *name; /* file name, will need freeing */
unsigned char *data; /* file data, will need freeing */
@@ -123,16 +124,16 @@ struct topiclink {
int recordtype;
int len1, len2;
unsigned char *data1, *data2;
- struct topiclink *browse_next, *browse_prev;
+ context *context;
struct topiclink *nonscroll, *scroll, *nexttopic;
int block_size; /* for the topic header - *boggle* */
};
-typedef struct WHLP_TOPIC_tag context;
struct WHLP_TOPIC_tag {
char *name; /* needs freeing */
unsigned long hash;
struct topiclink *link; /* this provides TOPICOFFSET */
+ context *browse_next, *browse_prev;
char *title; /* needs freeing */
};
@@ -394,8 +395,8 @@ void whlp_begin_topic(WHLP h, WHLP_TOPIC topic, char *title, ...)
h->prevtopic->nexttopic = link;
h->prevtopic = link;
- link->browse_next = link->browse_prev =
- link->nonscroll = link->scroll = NULL;
+ link->nonscroll = link->scroll = NULL;
+ link->context = topic;
link->block_size = 0;
link->recordtype = 2; /* topic header */
@@ -427,6 +428,21 @@ void whlp_begin_topic(WHLP h, WHLP_TOPIC topic, char *title, ...)
addpos234(h->text, link, count234(h->text));
}
+void whlp_browse_link(WHLP h, WHLP_TOPIC before, WHLP_TOPIC after)
+{
+ /*
+ * See if the `before' topic is already linked to another one,
+ * and break the link to that if so. Likewise the `after'
+ * topic.
+ */
+ if (before->browse_next)
+ before->browse_next->browse_prev = NULL;
+ if (after->browse_prev)
+ after->browse_prev->browse_next = NULL;
+ before->browse_next = after;
+ after->browse_prev = before;
+}
+
/* ----------------------------------------------------------------------
* Manage the actual generation of paragraph and text records.
*/
@@ -519,8 +535,8 @@ void whlp_begin_para(WHLP h, int para_type)
* that aren't type 2 they should never actually be needed.
*/
link->nexttopic = NULL;
- link->browse_next = link->browse_prev =
- link->nonscroll = link->scroll = NULL;
+ link->context = NULL;
+ link->nonscroll = link->scroll = NULL;
link->recordtype = 32; /* text record */
@@ -706,8 +722,8 @@ static void whlp_topic_layout(WHLP h)
link->len2 = 0;
link->nexttopic = NULL;
link->recordtype = 2;
- link->browse_next = link->browse_prev =
- link->nonscroll = link->scroll = NULL;
+ link->nonscroll = link->scroll = NULL;
+ link->context = NULL;
addpos234(h->text, link, count234(h->text));
/*
@@ -751,14 +767,14 @@ static void whlp_topic_layout(WHLP h)
continue;
PUT_32BIT_LSB_FIRST(link->data1 + 0, link->block_size);
- if (link->browse_prev)
+ if (link->context && link->context->browse_prev)
PUT_32BIT_LSB_FIRST(link->data1 + 4,
- link->browse_prev->topicoffset);
+ link->context->browse_prev->link->topicoffset);
else
PUT_32BIT_LSB_FIRST(link->data1 + 4, 0xFFFFFFFFL);
- if (link->browse_next)
+ if (link->context && link->context->browse_next)
PUT_32BIT_LSB_FIRST(link->data1 + 8,
- link->browse_next->topicoffset);
+ link->context->browse_next->link->topicoffset);
else
PUT_32BIT_LSB_FIRST(link->data1 + 8, 0xFFFFFFFFL);
PUT_32BIT_LSB_FIRST(link->data1 + 12, topicnum);
@@ -1700,6 +1716,12 @@ int main(void)
}
#endif
+ /*
+ * Browse sequence.
+ */
+ whlp_browse_link(h, t1, t2);
+ whlp_browse_link(h, t2, t3);
+
whlp_close(h, "test.hlp");
return 0;
}
diff --git a/winhelp.h b/winhelp.h
index e6014db..afadcfd 100644
--- a/winhelp.h
+++ b/winhelp.h
@@ -56,6 +56,12 @@ void whlp_start_macro(WHLP h, char *macro);
WHLP_TOPIC whlp_register_topic(WHLP h, char *context_name, char **clash);
/*
+ * Link two topics together in a browse sequence. Automatically
+ * takes care of the forward and reverse links.
+ */
+void whlp_browse_link(WHLP h, WHLP_TOPIC before, WHLP_TOPIC after);
+
+/*
* After calling whlp_register_topic for all topics, you should
* call this, which will sort out all loose ends and allocate
* context names for all anonymous topics. Then you can start