summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@src.gnome.org>2003-08-26 21:17:56 +0000
committerShaun McCance <shaunm@src.gnome.org>2003-08-26 21:17:56 +0000
commitb76cedfe8972dfc11467ac23c7276ff434b2dc9b (patch)
tree298998ec1b38a218cf37eb8ecb0b376c5f0636bb
parentaf1c29df9142c999465732bd30bcb761bae008f6 (diff)
downloadyelp-b76cedfe8972dfc11467ac23c7276ff434b2dc9b.tar.gz
src/yelp-cache.c src/yelp-cache.h src/yelp-db2html.c src/yelp-reader.c
* src/yelp-cache.c * src/yelp-cache.h * src/yelp-db2html.c * src/yelp-reader.c * src/yelp-scrollkeeper.c * src/yelp-view-content.c - Big speedup to transformation of large DocBook documents by generating navigation links in C from ScrollKeeper info.
-rw-r--r--ChangeLog11
-rw-r--r--src/yelp-cache.c32
-rw-r--r--src/yelp-cache.h21
-rw-r--r--src/yelp-db2html.c18
-rw-r--r--src/yelp-reader.c121
-rw-r--r--src/yelp-scrollkeeper.c12
-rw-r--r--src/yelp-view-content.c104
7 files changed, 274 insertions, 45 deletions
diff --git a/ChangeLog b/ChangeLog
index 67d92fe4..9a0944e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2003-08-26 Shaun McCance <shaunm@wolfram.com>
+ * src/yelp-cache.c
+ * src/yelp-cache.h
+ * src/yelp-db2html.c
+ * src/yelp-reader.c
+ * src/yelp-scrollkeeper.c
+ * src/yelp-view-content.c
+ - Big speedup to transformation of large DocBook documents
+ by generating navigation links in C from ScrollKeeper info.
+
+2003-08-26 Shaun McCance <shaunm@wolfram.com>
+
* README: Updated README so it's correct
2003-08-18 Shaun McCance <shaunm@wolfram.com>
diff --git a/src/yelp-cache.c b/src/yelp-cache.c
index bb7b0757..391c7a98 100644
--- a/src/yelp-cache.c
+++ b/src/yelp-cache.c
@@ -30,11 +30,17 @@
GHashTable *cache_table;
GMutex *cache_mutex;
+GHashTable *links_table;
+GMutex *links_mutex;
+
void
yelp_cache_init (void)
{
cache_mutex = g_mutex_new ();
cache_table = g_hash_table_new (g_str_hash, g_str_equal);
+
+ links_mutex = g_mutex_new ();
+ links_table = g_hash_table_new (g_str_hash, g_str_equal);
}
const gchar *
@@ -51,6 +57,20 @@ yelp_cache_lookup (const gchar *path)
return ret_val;
}
+YelpNavLinks *
+yelp_cache_lookup_links (const gchar *path)
+{
+ YelpNavLinks *ret_val;
+
+ g_mutex_lock (links_mutex);
+
+ ret_val = (YelpNavLinks *) g_hash_table_lookup (links_table, path);
+
+ g_mutex_unlock (links_mutex);
+
+ return ret_val;
+}
+
void
yelp_cache_add (const gchar *path, const gchar *html)
{
@@ -60,3 +80,15 @@ yelp_cache_add (const gchar *path, const gchar *html)
g_mutex_unlock (cache_mutex);
}
+
+void
+yelp_cache_add_links (const gchar *path, const YelpNavLinks *links)
+{
+ YelpNavLinks *new_links;
+
+ g_mutex_lock (links_mutex);
+
+ g_hash_table_insert (links_table, (gchar *) path, links);
+
+ g_mutex_unlock (links_mutex);
+}
diff --git a/src/yelp-cache.h b/src/yelp-cache.h
index bd6f74b0..0c1aad50 100644
--- a/src/yelp-cache.h
+++ b/src/yelp-cache.h
@@ -27,10 +27,31 @@
#include "yelp-uri.h"
+typedef struct _YelpNavLinks YelpNavLinks;
+
+#define YELP_NAV_LINKS(x) ((YelpNavLinks *) x)
+
+struct _YelpNavLinks {
+ gchar *prev_link_uri;
+ gchar *next_link_uri;
+ gchar *prev_link_title;
+ gchar *next_link_title;
+ gchar *prev_link_text;
+ gchar *next_link_text;
+ gchar *up_link_uri;
+ gchar *up_link_title;
+};
+
void yelp_cache_init (void);
const gchar * yelp_cache_lookup (const gchar *path);
void yelp_cache_add (const gchar *path,
const gchar *html);
+
+YelpNavLinks * yelp_cache_lookup_links (const gchar *path);
+
+void yelp_cache_add_links (const gchar *path,
+ const YelpNavLinks *links);
+
#endif /* __YELP_CACHE_H__ */
diff --git a/src/yelp-db2html.c b/src/yelp-db2html.c
index 1441f2c5..6c9d8c61 100644
--- a/src/yelp-db2html.c
+++ b/src/yelp-db2html.c
@@ -66,16 +66,28 @@ main (gint argc, gchar **argv)
const gchar *params[16 + 1];
gchar *pathname;
gchar *docpath;
+ gboolean gen_links;
db_doc = NULL;
putenv ("XML_CATALOG_FILES=" DATADIR "/yelp/catalog");
if (argc < 2) {
- g_print ("Usage 'yelp-db2html url'\n");
+ g_print ("Usage 'yelp-db2html [-n] url'\n");
exit (1);
}
- docpath = argv[1];
+ if (!strcmp (argv[1], "-n")) {
+ if (argc < 3) {
+ g_print ("Usage 'yelp-db2html [-n] url'\n");
+ exit (1);
+ }
+
+ docpath = argv[2];
+ gen_links = FALSE;
+ } else {
+ docpath = argv[1];
+ gen_links = TRUE;
+ }
if (!g_file_test (docpath, G_FILE_TEST_EXISTS)) {
g_warning ("'%s' doesn't exist.", docpath);
@@ -126,7 +138,7 @@ main (gint argc, gchar **argv)
params[6] = "yelp_max_chunk_depth";
params[7] = "2";
params[8] = "yelp_generate_navbar";
- params[9] = "1";
+ params[9] = (gen_links ? "1" : "0");
params[10] = "yelp_chunk_method";
params[11] = "'yelp'";
params[12] = NULL;
diff --git a/src/yelp-reader.c b/src/yelp-reader.c
index b018fd7b..6eac8e80 100644
--- a/src/yelp-reader.c
+++ b/src/yelp-reader.c
@@ -94,7 +94,7 @@ static void reader_q_data_free (ReaderQueueData *q_data);
static void reader_th_data_free (ReaderThreadData *th_data);
#endif
static gchar * reader_get_chunk (const gchar *document,
- const gchar *section);
+ YelpURI *uri);
static gchar *
reader_look_for_cached_help_file (const gchar *url);
@@ -261,9 +261,15 @@ reader_convert_start (ReaderThreadData *th_data)
break;
case YELP_URI_TYPE_DOCBOOK_XML:
case YELP_URI_TYPE_DOCBOOK_SGML:
- command_line = g_strdup_printf ("%s/yelp-db2html %s",
- SERVERDIR,
- yelp_uri_get_path (uri));
+ if (yelp_cache_lookup_links (yelp_uri_to_string (uri))) {
+ command_line = g_strdup_printf ("%s/yelp-db2html -n %s",
+ SERVERDIR,
+ yelp_uri_get_path (uri));
+ } else {
+ command_line = g_strdup_printf ("%s/yelp-db2html %s",
+ SERVERDIR,
+ yelp_uri_get_path (uri));
+ }
break;
default:
/* Set error */
@@ -312,14 +318,7 @@ reader_convert_start (ReaderThreadData *th_data)
yelp_uri_get_type (uri) == YELP_URI_TYPE_DOCBOOK_SGML) {
gchar *chunk;
- if (yelp_uri_get_section (uri) &&
- strcmp (yelp_uri_get_section (uri), "")) {
- chunk = reader_get_chunk (q_data->data,
- yelp_uri_get_section (uri));
- } else {
- chunk = reader_get_chunk (q_data->data,
- "toc");
- }
+ chunk = reader_get_chunk (q_data->data, uri);
g_free (q_data->data);
q_data->data = chunk;
@@ -634,25 +633,30 @@ reader_th_data_free (ReaderThreadData *th_data)
#endif
static gchar *
-reader_get_chunk (const gchar *document, const gchar *section)
+reader_get_chunk (const gchar *document, YelpURI *uri)
{
- gchar *header;
- gchar *chunk;
- const gchar *footer;
- gchar *ret_val;
- const gchar *start;
- const gchar *end;
- gchar *tag;
- GTimer *timer;
-
-/* g_print ("%s\n", document); */
-
- timer = g_timer_new ();
+ const gchar *section;
+ gchar *header;
+ gchar *chunk;
+ const gchar *footer;
+ gchar *ret_val;
+ const gchar *start;
+ const gchar *end;
+ gchar *tag;
+ GTimer *timer;
+ YelpNavLinks *links;
+ const gchar *nav_top;
+ const gchar *nav_bottom;
+
+ // timer = g_timer_new ();
+
+ section = yelp_uri_get_section (uri);
+ if (!section || !strcmp (section, ""))
+ section = "toc";
end = strstr (document, "<!-- End of header -->");
if (!end) {
-/* g_warning ("Wrong type of document\n"); */
return g_strdup (document);
}
@@ -663,7 +667,6 @@ reader_get_chunk (const gchar *document, const gchar *section)
g_free (tag);
if (!start) {
-/* g_warning ("Document doesn't include section: '%s'", section); */
g_free (header);
return g_strdup (document);
@@ -672,8 +675,6 @@ reader_get_chunk (const gchar *document, const gchar *section)
end = strstr (start, "<!-- End of chunk -->");
if (!end) {
-/* g_warning ("Document is doesn't contain end tag for section: %s", */
-/* section); */
g_free (header);
return g_strdup (document);
@@ -684,15 +685,59 @@ reader_get_chunk (const gchar *document, const gchar *section)
footer = strstr (document, "<!-- Start of footer -->");
if (!footer) {
-/* g_warning ("Couldn't find footer in document"); */
g_free (header);
g_free (chunk);
return g_strdup (document);
}
-
- ret_val = g_strconcat (header, chunk, footer, NULL);
-
+
+ links = yelp_cache_lookup_links (yelp_uri_to_string (uri));
+
+ if (!links) {
+ nav_top = "";
+ nav_bottom = "";
+ } else {
+ nav_top = g_strconcat ("<table width='100%'><tr>",
+ "<td width='40%' align='left'>",
+ "<a accesskey='p' href='",
+ links->prev_link_uri, "'>",
+ links->prev_link_title,
+ "</a></td>",
+ "<td width='40%' align='right'>",
+ "<a accesskey='n' href='",
+ links->next_link_uri, "'>",
+ links->next_link_title,
+ "</a></td>",
+ "</tr></table>",
+ "<hr>",
+ NULL);
+ nav_bottom = g_strconcat ("<hr class='bottom'>",
+ "<table width='100%'><tr>",
+ "<td width='40%' align='left'>",
+ "<a accesskey='p' href='",
+ links->prev_link_uri, "'>",
+ links->prev_link_title,
+ "</a><br>",
+ links->prev_link_text,
+ "</td>",
+ "<td width='20%' align='center'>",
+ "<a accesskey='u' href='",
+ links->up_link_uri, "'>",
+ links->up_link_title,
+ "</a></td>",
+ "<td width='40%' align='right'>",
+ "<a accesskey='n' href='",
+ links->next_link_uri, "'>",
+ links->next_link_title,
+ "</a><br>",
+ links->next_link_text,
+ "</td>",
+ "</tr></table>",
+ NULL);
+ }
+
+ ret_val = g_strconcat (header, nav_top, chunk, nav_bottom, footer, NULL);
+
g_free (header);
g_free (chunk);
@@ -902,14 +947,8 @@ yelp_reader_start (YelpReader *reader, YelpURI *uri)
} else {
document = read_document;
}
-
- if (yelp_uri_get_section (new_uri) &&
- strcmp (yelp_uri_get_section (new_uri), "")) {
- chunk = reader_get_chunk (document,
- yelp_uri_get_section (new_uri));
- } else {
- chunk = reader_get_chunk (document, "toc");
- }
+
+ chunk = reader_get_chunk (document, new_uri);
g_free (read_document);
yelp_uri_unref (new_uri);
diff --git a/src/yelp-scrollkeeper.c b/src/yelp-scrollkeeper.c
index edcd7eb5..216b1439 100644
--- a/src/yelp-scrollkeeper.c
+++ b/src/yelp-scrollkeeper.c
@@ -593,6 +593,7 @@ yelp_scrollkeeper_get_toc_tree (const gchar *docpath)
xmlNode *xml_node;
GNode *tree;
gchar *full_path;
+ gchar *title_path;
g_return_val_if_fail (docpath != NULL, NULL);
@@ -619,11 +620,22 @@ yelp_scrollkeeper_get_toc_tree (const gchar *docpath)
xml_node = doc->xmlRootNode->xmlChildrenNode;
full_path = g_strconcat ("ghelp:", docpath, NULL);
+ title_path = g_strconcat (full_path, "?title-page", NULL);
+
+ g_node_append_data (tree,
+ yelp_section_new (YELP_SECTION_DOCUMENT_SECTION,
+ _("About This Document"),
+ yelp_uri_new (title_path) ));
+ g_node_append_data (tree,
+ yelp_section_new (YELP_SECTION_DOCUMENT_SECTION,
+ _("Contents"),
+ yelp_uri_new (full_path) ));
for (; xml_node != NULL; xml_node = xml_node->next) {
scrollkeeper_parse_toc_section (tree, xml_node, full_path);
}
+ g_free (title_path);
g_free (full_path);
return tree;
diff --git a/src/yelp-view-content.c b/src/yelp-view-content.c
index c90c66b5..972e69ce 100644
--- a/src/yelp-view-content.c
+++ b/src/yelp-view-content.c
@@ -39,6 +39,7 @@
#include "yelp-scrollkeeper.h"
#include "yelp-util.h"
#include "yelp-uri.h"
+#include "yelp-cache.h"
#include "yelp-view-content.h"
#define d(x)
@@ -73,6 +74,9 @@ static void content_insert_tree (YelpViewContent *content,
GNode *node);
static void content_set_tree (YelpViewContent *content,
GNode *node);
+gboolean content_generate_links (GNode *node,
+ gpointer data);
+GNode * node_last_ancestor (GNode *node);
static void
content_show_uri (YelpView *view,
YelpURI *uri,
@@ -420,6 +424,98 @@ content_set_tree (YelpViewContent *content, GNode *node)
}
}
+
+GNode *
+node_last_ancestor (GNode *node)
+{
+ if (node->children)
+ return node_last_ancestor (g_node_last_child (node));
+ else
+ return node;
+}
+
+
+gboolean
+content_generate_links (GNode *node, gpointer data)
+{
+ GNode *prev_node;
+ GNode *next_node;
+ GNode *up_node;
+ YelpURI *prev_uri;
+ YelpURI *next_uri;
+ YelpURI *up_uri;
+ YelpNavLinks *links = g_new0 (YelpNavLinks, 1);
+ YelpURI *uri;
+
+ if (!node->data)
+ return FALSE;
+
+ uri = YELP_SECTION (node->data)->uri;
+
+ if (yelp_cache_lookup_links (yelp_uri_to_string (uri)))
+ return FALSE;
+
+ if (node->prev)
+ prev_node = node_last_ancestor (node->prev);
+ else if (node->parent && node->parent->data)
+ prev_node = node->parent;
+ else
+ prev_node = NULL;
+
+ if (node->children)
+ next_node = node->children;
+ else if (node->next)
+ next_node = node->next;
+ else if (node->parent && node->parent->next)
+ next_node = node->parent->next;
+ else
+ next_node = NULL;
+
+ if (yelp_uri_get_section (uri) &&
+ strcmp (yelp_uri_get_section (uri), "") &&
+ strcmp (yelp_uri_get_section (uri), "toc") &&
+ strcmp (yelp_uri_get_section (uri), "title-page"))
+ up_node = g_node_nth_child (g_node_get_root (node), 1);
+ else
+ up_node = NULL;
+
+ if (!prev_node) {
+ links->prev_link_uri = "";
+ links->prev_link_title = "";
+ links->prev_link_text = "";
+ } else {
+ prev_uri = YELP_SECTION (prev_node->data)->uri;
+ links->prev_link_uri = yelp_uri_to_string (prev_uri);
+ links->prev_link_title = _("Previous");
+ links->prev_link_text = YELP_SECTION (prev_node->data)->name;
+ }
+
+ if (!next_node) {
+ links->next_link_uri = "";
+ links->next_link_title = "";
+ links->next_link_text = "";
+ } else {
+ next_uri = YELP_SECTION (next_node->data)->uri;
+ links->next_link_uri = yelp_uri_to_string (next_uri);
+ links->next_link_title = _("Next");
+ links->next_link_text = YELP_SECTION (next_node->data)->name;
+ }
+
+ if (!up_node) {
+ links->up_link_uri = "";
+ links->up_link_title = "";
+ } else {
+ up_uri = YELP_SECTION (up_node->data)->uri;
+ links->up_link_uri = yelp_uri_to_string (up_uri);
+ links->up_link_title = YELP_SECTION (up_node->data)->name;
+ }
+
+ yelp_cache_add_links (yelp_uri_to_string (uri), links);
+
+ return FALSE;
+}
+
+
static void
content_show_uri (YelpView *view, YelpURI *uri, GError **error)
{
@@ -445,7 +541,13 @@ content_show_uri (YelpView *view, YelpURI *uri, GError **error)
gtk_widget_show (priv->tree_sw);
content_set_tree (YELP_VIEW_CONTENT (view),
node);
-
+
+ g_node_traverse (node,
+ G_PRE_ORDER,
+ G_TRAVERSE_ALL,
+ -1,
+ (GNodeTraverseFunc) content_generate_links,
+ NULL);
} else {
if (gtk_widget_is_focus (priv->tree_sw)) {
reset_focus = TRUE;