diff options
author | Narayana Pattipati <narayana.pattipati@wipro.com> | 2002-08-07 18:20:24 +0000 |
---|---|---|
committer | Mikael Hallendal <hallski@src.gnome.org> | 2002-08-07 18:20:24 +0000 |
commit | e7b9947758c4b6b1bf29354cc6ef8dca1abcd974 (patch) | |
tree | f83db23eda9f82da607c18aee0de6a0114ed5788 | |
parent | cddeb759a6db4e26ee23981e8f949f45e146dfe8 (diff) | |
download | yelp-e7b9947758c4b6b1bf29354cc6ef8dca1abcd974.tar.gz |
Made changes to make yelp read the cached HTML files. Fixes #85258 new
2002-08-07 Narayana Pattipati <narayana.pattipati@wipro.com>
* src/yelp-reader.c (yelp_reader_start): Made changes to make yelp
read the cached HTML files. Fixes #85258
* src/yelp-pregenerate.c: new file. Creates yelp-pregenerate utility
which pre-generates HTML files from XML files.
* src/yelp-pregenerate.h: new file
* src/yelp-reader.h: Added prototype for look_for_html_help_file
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | src/.cvsignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 11 | ||||
-rw-r--r-- | src/yelp-db2html.c | 1 | ||||
-rw-r--r-- | src/yelp-pregenerate.c | 510 | ||||
-rw-r--r-- | src/yelp-pregenerate.h | 42 | ||||
-rw-r--r-- | src/yelp-reader.c | 215 | ||||
-rw-r--r-- | src/yelp-reader.h | 1 |
8 files changed, 748 insertions, 42 deletions
@@ -1,3 +1,12 @@ +2002-08-07 Narayana Pattipati <narayana.pattipati@wipro.com> + + * src/yelp-reader.c (yelp_reader_start): Made changes to make yelp + read the cached HTML files. Fixes #85258 + * src/yelp-pregenerate.c: new file. Creates yelp-pregenerate utility + which pre-generates HTML files from XML files. + * src/yelp-pregenerate.h: new file + * src/yelp-reader.h: Added prototype for look_for_html_help_file + 2002-08-05 Sander Vesik <sander.vesik@sun.com> * stylesheets/yelp-customization.xsl: - apply bold formating to guibuttons diff --git a/src/.cvsignore b/src/.cvsignore index 7ed37c19..508f2c41 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -16,4 +16,5 @@ yelp-marshal.c yelp-marshal.h yelp yelp-db2html +yelp-pregenerate core* diff --git a/src/Makefile.am b/src/Makefile.am index 3ad5e772..d9ca4014 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,7 +10,8 @@ INCLUDES = \ -DGNOMELOCALEDIR=\""$(yelplocaledir)"\" \ -DLIBGNOME_MAN2HTML=\"$(LIBGNOME_MAN2HTML)\" \ -DLIBGNOME_INFO2HTML=\"$(LIBGNOME_INFO2HTML)\" \ - -DSERVERDIR=\"$(libexecdir)\" + -DSERVERDIR=\"$(libexecdir)\" \ + -DBINDIR=\""$(bindir)"\" if HTML_WIDGET_GTKHTML1 @@ -20,7 +21,7 @@ html_widget_impl=yelp-html-gtkhtml2.c endif libexec_PROGRAMS = yelp-db2html -bin_PROGRAMS = yelp +bin_PROGRAMS = yelp yelp-pregenerate noinst_PROGRAMS = test-uri test-reader @@ -66,9 +67,15 @@ yelp-marshal-main.c: yelp-marshal.c yelp_db2html_SOURCES = \ yelp-db2html.c +yelp_pregenerate_SOURCES = \ + yelp-pregenerate.c yelp-pregenerate.h + yelp_db2html_LDADD = \ @YELP_LIBS@ +yelp_pregenerate_LDADD = \ + @YELP_LIBS@ + yelp_SOURCES = \ $(gnome_yelp_idl_sources) \ yelp-base.c yelp-base.h \ diff --git a/src/yelp-db2html.c b/src/yelp-db2html.c index b90fc77c..3d97713f 100644 --- a/src/yelp-db2html.c +++ b/src/yelp-db2html.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * gnome-db2html3 - by John Fleck - based on Daniel Veillard's * xsltproc: user program for the XSL Transformation engine diff --git a/src/yelp-pregenerate.c b/src/yelp-pregenerate.c new file mode 100644 index 00000000..70608940 --- /dev/null +++ b/src/yelp-pregenerate.c @@ -0,0 +1,510 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2002 Sun Microsyatems Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA. + * + */ + +#include <config.h> +#include <glib.h> +#include <string.h> +#include <sys/time.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include <libgnome/gnome-i18n.h> +#include <libxml/xmlversion.h> +#include <libxml/xmlmemory.h> +#include <libxml/debugXML.h> +#include <libxml/HTMLtree.h> +#include <libxml/DOCBparser.h> +#include <libxml/catalog.h> +#include "yelp-pregenerate.h" + +static gboolean parse_books (GNode *tree, + xmlDoc *doc); +static gboolean parse_section (GNode *parent, + xmlNode *xml_node); +static void parse_doc_source (GNode *parent, + xmlNode *xml_node, + gchar *docid); +static gchar * strip_scheme (gchar *original_uri, + gchar **scheme); + +static gboolean tree_empty (xmlNode *cl_node); +static gboolean trim_empty_branches (xmlNode *cl_node); +Section * section_new (SectionType type, + const gchar *name); + +static gboolean yelp_pregenerate_write_to_html (gchar *xml_file, + gchar *html_data); + +static GHashTable *seriesid_hash = NULL; +static GHashTable *docid_hash = NULL; +static GList *xml_list = NULL; + +#define YELP_DB2HTML BINDIR"/yelp-db2html" +#define BUFFER_SIZE 16384 + + +gint +main (gint argc, gchar **argv) +{ + /* This utility pre-generates HTML files from a given list of XML + * files. + */ + + gchar *xml_url; + gchar *xml_file; + gchar *command_line = NULL; + gchar *html_data = NULL; + GError *error = NULL; + gint exit_status; + GList *index; + GNode *tree; + FILE *fp = NULL; + gchar buffer[256]; + int c = 0; + + if (argc < 2) { + g_print ("Pre-generates HTML files from XML files. This uses yelp-db2html executable\nfor XML to HTML conversion.\n\nUsage: yelp-pregenerate [OPTIONS] \n\n" + "-a : Pregenerate HTMLs for all XML files installed in \n the system\n" + "-f <XML-LIST-FILE> : Pregenerate HTMLs for all the XML files specified in\n file XML-LIST-FILE. Enter full path of XML-LIST-FILE\n" + "<XML_FILE(S)>.... : Enter one or more XML files to be converted to \n HTML files on the command line\n\n"); + + exit (1); + } + + c = getopt (argc, argv, "af:"); + + switch (c) { + case 'a': + g_print ("Pre-generating HTMLs for all XML files installed in the system.\n"); + tree = g_new0 (GNode, 1); + + yelp_pregenerate_xml_list_init (tree); + + g_node_destroy (tree); + break; + case 'f': + g_print ("Pre-generating HTMLs for the list of XML files specified in %s\n", argv[optind - 1]); + + fp = fopen (argv[optind - 1], "r"); + + if (fp == NULL) { + g_print ("Error in opening the file %s\n", + argv[optind - 1]); + exit (1); + } + + while (fgets (buffer, 256, fp) != NULL) { + xml_file = g_strchomp (buffer); + xml_list = g_list_append (xml_list, g_strdup(xml_file)); + } + + fclose (fp); + break; + + case -1: + + if (argc >= 2) { + int i = 1; + g_print ("Pre-generating HTMLs for the XML files entered on the command line\n"); + while (i <= argc -1 && argv[i]) { + if (g_strrstr (argv[i], ".xml")) { + xml_list = g_list_append (xml_list, argv[i]); + } else { + g_print("The file %s entered on the command line is not an XML file\n", argv[i]); + } + i++; + } + } + break; + + case '?': + g_print ("Usage: yelp-pregenerate [OPTIONS] \n\n" + "-a : Pregenerate HTMLs for all XML files installed in \n the system\n" + "-f <XML-LIST-FILE> : Pregenerate HTMLs for all the XML files specified in\n file XML-LIST-FILE. Enter full path of XML-LIST-FILE\n" + "<XML_FILE(S)>.... : Enter one or more XML files to beconverted to \n HTML files on the command line\n\n"); + exit (1); + + default : + exit (1); + + } + + for (index = xml_list; index; index = index->next) { + html_data = NULL; + error = NULL; + + xml_url = (gchar *)index->data; + + if (!g_file_test (xml_url, G_FILE_TEST_EXISTS)) { + g_print ("File %s to be parsed does not exist\n", xml_url); + continue; + } + + command_line = g_strdup_printf ("%s/yelp-db2html %s", + SERVERDIR, + xml_url); + + g_print ("Parsing %s\n", xml_url); + + g_spawn_command_line_sync (command_line, + &html_data, + NULL, + &exit_status, + &error); + + if (html_data) { + yelp_pregenerate_write_to_html (xml_url, html_data); + } + } + + g_list_free (xml_list); + g_free (command_line); + g_free (html_data); + + exit (0); +} + + +/* This function gets the list of XML help files installed in the system + * by querying the Scrollkeeper database. + */ + +gboolean +yelp_pregenerate_xml_list_init (GNode *tree) +{ + gchar *docpath; + gchar *full_command; + xmlDoc *doc; + const GList *node; + gboolean success = FALSE; + gchar *std_err; + gchar *command, *argument; + + g_return_val_if_fail (tree != NULL, FALSE); + + seriesid_hash = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, NULL); + + docid_hash = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + + doc = NULL; + + for (node = gnome_i18n_get_language_list ("LC_MESSAGES"); node; node = node->next) { + command = "scrollkeeper-get-content-list"; + argument = node->data; + full_command = g_strconcat (command, + " ", argument, NULL); + + success = g_spawn_command_line_sync (full_command, + &docpath, + &std_err, NULL, NULL); + g_free (full_command); + g_free (std_err); + + if (!success) { + g_warning ("Didn't successfully run command: '%s %s'", + command, argument); + return FALSE; + } + + if (docpath) { + docpath = g_strchomp (docpath); + doc = xmlParseFile (docpath); + g_free (docpath); + } + + if (doc) { + if (doc->xmlRootNode && + !tree_empty(doc->xmlRootNode->xmlChildrenNode)) { + break; + } else { + xmlFreeDoc (doc); + doc = NULL; + } + } + } + + if (doc) { + + trim_empty_branches (doc->xmlRootNode); + + parse_books (tree, doc); + + xmlFreeDoc (doc); + } + + return TRUE; +} + + +gboolean +parse_books (GNode *tree, xmlDoc *doc) +{ + xmlNode *node; + gboolean success; + GNode *book_node; + + g_return_val_if_fail (tree != NULL, FALSE); + + node = doc->xmlRootNode; + + if (!node || !node->name || + g_ascii_strcasecmp (node->name, "ScrollKeeperContentsList")) { + g_warning ("Invalid ScrollKeeper XML Contents List!"); + return FALSE; + } + + book_node = g_node_append_data (tree, + section_new (YELP_SECTION_CATEGORY, + "scrollkeeper")); + + for (node = node->xmlChildrenNode; node; node = node->next) { + if (!g_ascii_strcasecmp (node->name, "sect")) { + success = parse_section (book_node, node); + } + } + + return TRUE; +} + +static gboolean +parse_section (GNode *parent, xmlNode *xml_node) +{ + xmlNode *cur; + xmlChar *xml_str; + gchar *name; + GNode *node; + gchar *docid; + + /* Find the title */ + for (cur = xml_node->xmlChildrenNode; cur; cur = cur->next) { + if (!g_ascii_strcasecmp (cur->name, "title")) { + xml_str = xmlNodeGetContent (cur); + + if (xml_str) { + name = g_strdup (xml_str); + xmlFree (xml_str); + } + } + } + + if (!name) { + g_warning ("Couldn't find name of the section"); + return FALSE; + } + + node = g_node_append_data (parent, + section_new (YELP_SECTION_CATEGORY, name)); + + for (cur = xml_node->xmlChildrenNode; cur; cur = cur->next) { + if (!g_ascii_strcasecmp (cur->name, "sect")) { + parse_section (node, cur); + } + else if (!g_ascii_strcasecmp (cur->name, "doc")) { + + xml_str = xmlGetProp (cur, "docid"); + if (xml_str) { + docid = g_strdup (xml_str); + xmlFree (xml_str); + } + + parse_doc_source (node, cur, docid); + } + } + + return TRUE; +} + + +static void +parse_doc_source (GNode *parent, xmlNode *xml_node, gchar *docid) +{ + xmlNode *cur; + xmlChar *xml_str; + gchar *docsource; + + for (cur = xml_node->xmlChildrenNode; cur; cur = cur->next) { + + if (!g_ascii_strcasecmp (cur->name, "docsource")) { + xml_str = xmlNodeGetContent (cur); + docsource = strip_scheme (xml_str, NULL); + + xml_list = g_list_append (xml_list, docsource); + xmlFree (xml_str); + break; + } + } +} + + +static gchar * +strip_scheme(gchar *original_uri, gchar **scheme) +{ + gchar *new_uri; + gchar *point; + + point = strstr (original_uri, ":"); + + if (!point) { + if (scheme) { + *scheme = NULL; + } + + return g_strdup (original_uri); + } + + if (scheme) { + *scheme = g_strndup(original_uri, point - original_uri); + } + + new_uri = g_strdup (point + 1); + + return new_uri; +} + + +Section * +section_new (SectionType type, + const gchar *name) +{ + Section *section; + + section = g_new0 (Section, 1); + + section->type = type; + + if (name) { + section->name = g_strdup (name); + } else { + section->name = g_strdup (""); + } + + return section; +} + +static gboolean +trim_empty_branches (xmlNode *node) +{ + xmlNode *child; + xmlNode *next; + gboolean empty; + + if (!node) { + return TRUE; + } + + for (child = node->xmlChildrenNode; child; child = next) { + next = child->next; + + if (!g_ascii_strcasecmp (child->name, "sect")) { + empty = trim_empty_branches (child); + if (empty) { + xmlUnlinkNode (child); + xmlFreeNode (child); + } + } + } + + for (child = node->xmlChildrenNode; child; child = child->next) { + if (!g_ascii_strcasecmp (child->name, "sect") || + !g_ascii_strcasecmp (child->name, "doc")) { + return FALSE; + } + } + + return TRUE; +} + +static gboolean +tree_empty (xmlNode *cl_node) +{ + xmlNode *node, *next; + gboolean ret_val; + + if (cl_node == NULL) + return TRUE; + + for (node = cl_node; node != NULL; node = next) { + next = node->next; + + if (!g_ascii_strcasecmp (node->name, "sect") && + node->xmlChildrenNode->next != NULL) { + ret_val = tree_empty (node->xmlChildrenNode->next); + + if (!ret_val) { + return ret_val; + } + } + + if (!g_ascii_strcasecmp (node->name, "doc")) { + return FALSE; + } + } + + return TRUE; +} + +/* Stores the result of XML to HTML conversion in the same directory where + * the XML file resides. + */ + +static gboolean +yelp_pregenerate_write_to_html (gchar *xml_url, + gchar *html_data) +{ + gchar *pos; + GString *path; + gchar *html_url; + gint len = 0; + FILE *fp; + + pos = g_strrstr (xml_url, ".xml"); + + len = pos - xml_url; + + path = g_string_new (xml_url); + + path = g_string_truncate (path, len); + + path = g_string_append (path, ".html"); + + html_url = g_string_free (path, FALSE); + + fp = fopen (html_url, "w+"); + + if (fp == NULL) { + g_print ("Error in opening file %s\n", html_url); + + return FALSE; + } + + g_print ("Writing output to %s\n", html_url); + + fwrite (html_data, strlen (html_data), 1, fp); + + fclose (fp); + + return TRUE; +} diff --git a/src/yelp-pregenerate.h b/src/yelp-pregenerate.h new file mode 100644 index 00000000..d468948f --- /dev/null +++ b/src/yelp-pregenerate.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2002 Sun Microsystems Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#ifndef __YELP_PREGENERATE_H__ +#define __YELP_PREGENERATE_H__ + +typedef struct _Section Section; + +#define SECTION(x) ((Section *) x) + +typedef enum { + YELP_SECTION_DOCUMENT_SECTION, + YELP_SECTION_DOCUMENT, + YELP_SECTION_CATEGORY, + YELP_SECTION_INDEX +} SectionType; + +struct _Section { + gchar *name; + SectionType type; +}; + +gboolean yelp_pregenerate_xml_list_init (GNode *tree); + +#endif /* __YELP_PREGENERATE_H__*/ diff --git a/src/yelp-reader.c b/src/yelp-reader.c index 6ca00367..6e19e8d6 100644 --- a/src/yelp-reader.c +++ b/src/yelp-reader.c @@ -725,9 +725,14 @@ yelp_reader_new () gboolean yelp_reader_start (YelpReader *reader, YelpURI *uri) { - YelpReaderPriv *priv; + YelpReaderPriv *priv; ReaderThreadData *th_data; gint stamp; + const gchar *document = NULL; + gchar *chunk = NULL; + gchar *str_uri = NULL; + gchar buffer[BUFFER_SIZE]; + YelpURI *new_uri; g_return_val_if_fail (YELP_IS_READER (reader), FALSE); g_return_val_if_fail (uri != NULL, FALSE); @@ -751,49 +756,100 @@ yelp_reader_start (YelpReader *reader, YelpURI *uri) th_data->uri = yelp_uri_ref (uri); th_data->stamp = stamp; - if (yelp_uri_get_type (uri) == YELP_URI_TYPE_DOCBOOK_XML || - yelp_uri_get_type (uri) == YELP_URI_TYPE_DOCBOOK_SGML) { - const gchar *document; - gchar *chunk; + str_uri = yelp_uri_to_string (uri); - document = yelp_cache_lookup (yelp_uri_get_path (uri)); - - if (document) { - if (yelp_uri_get_section (uri) && - strcmp (yelp_uri_get_section (uri), "")) { - chunk = reader_get_chunk (document, - yelp_uri_get_section (uri)); - } else { - chunk = reader_get_chunk (document, "toc"); - } - - if (chunk) { - ReaderQueueData *q_data; - - q_data = reader_q_data_new (reader, stamp, - READER_QUEUE_TYPE_START); - g_async_queue_push (priv->thread_queue, - q_data); - - q_data = reader_q_data_new (reader, stamp, - READER_QUEUE_TYPE_DATA); - - q_data->data = chunk; - g_async_queue_push (priv->thread_queue, - q_data); - - q_data = reader_q_data_new (reader, stamp, - READER_QUEUE_TYPE_FINISHED); - - g_async_queue_push (priv->thread_queue, - q_data); - - g_idle_add ((GSourceFunc) reader_idle_check_queue, th_data); - return TRUE; + if (str_uri && *str_uri) { + str_uri = look_for_html_help_file (str_uri); + new_uri = yelp_uri_new (str_uri); + } + else + new_uri = yelp_uri_copy (uri); + + g_free (str_uri); + + if (yelp_uri_get_type (new_uri) == YELP_URI_TYPE_DOCBOOK_XML || + yelp_uri_get_type (new_uri) == YELP_URI_TYPE_DOCBOOK_SGML) { + + document = yelp_cache_lookup (yelp_uri_get_path (new_uri)); + } + + /* check if there is HTML cache. If found, use the HTML cache. */ + else if (yelp_uri_get_type (new_uri) == YELP_URI_TYPE_HTML) { + GnomeVFSHandle *handle; + GnomeVFSResult result; + GString *html_buffer; + GnomeVFSFileSize n; + + result = gnome_vfs_open (&handle, + yelp_uri_get_path (new_uri), + GNOME_VFS_OPEN_READ); + + if (result != GNOME_VFS_OK) { + /* FIXME: Signal error */ + yelp_uri_unref (new_uri); + return FALSE; + } + + html_buffer = NULL; + + while (TRUE) { + result = gnome_vfs_read (handle, buffer, + BUFFER_SIZE, &n); + + /* FIXME: Do some error checking */ + if (result != GNOME_VFS_OK) { + break; } + + if (html_buffer == NULL) + html_buffer = g_string_new (g_strndup (buffer, + n)); + else + html_buffer = g_string_append (html_buffer, + g_strndup (buffer, + n)); } + document = html_buffer->str; + g_string_free (html_buffer, FALSE); } - + + if (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"); + } + + if (chunk) { + ReaderQueueData *q_data; + + q_data = reader_q_data_new (reader, stamp, + READER_QUEUE_TYPE_START); + g_async_queue_push (priv->thread_queue, + q_data); + + q_data = reader_q_data_new (reader, stamp, + READER_QUEUE_TYPE_DATA); + + q_data->data = chunk; + g_async_queue_push (priv->thread_queue, + q_data); + + q_data = reader_q_data_new (reader, stamp, + READER_QUEUE_TYPE_FINISHED); + g_async_queue_push (priv->thread_queue, + q_data); + + g_idle_add ((GSourceFunc) reader_idle_check_queue, + th_data); + + yelp_uri_unref (new_uri); + return TRUE; + } + } + g_timeout_add (100, (GSourceFunc) reader_idle_check_queue, th_data); g_thread_create_full ((GThreadFunc) reader_start, th_data, @@ -801,6 +857,9 @@ yelp_reader_start (YelpReader *reader, YelpURI *uri) TRUE, FALSE, G_THREAD_PRIORITY_NORMAL, NULL /* FIXME: check for errors */); + + yelp_uri_unref (new_uri); + return FALSE; } @@ -819,3 +878,79 @@ yelp_reader_cancel (YelpReader *reader) STAMP_MUTEX_UNLOCK; } + + +/* Given an XML file, look if there is a cached HTML file. If the HTML is + * newer than XML, return it. Else return XML only. + */ + +gchar * +look_for_html_help_file (gchar *url) +{ + gchar *sect, *pos; + int len=0; + GString *path; + char *html_url, *xml_url; + char *scheme; + struct stat html_stat, xml_stat; + + if (g_strrstr (url, ".xml") == NULL) + return url; + + path = g_string_new (url); + sect = g_strrstr (url, "?"); + + len = sect - url; + path = g_string_truncate (path, len); + + scheme = g_strrstr (path->str, ":"); + + xml_url = g_strdup (scheme + 1); + + pos = g_strrstr (path->str, ".xml"); + + if (pos == NULL) { + g_string_free (path, TRUE); + g_free (xml_url); + + return url; + } + + len = pos - path->str; + + path = g_string_truncate (path, len); + + path = g_string_append (path, ".html"); + + scheme = g_strrstr (path->str, ":"); + + html_url = g_strdup (scheme + 1); + + if (g_file_test (html_url, G_FILE_TEST_EXISTS)) { + + stat (html_url, &html_stat); + stat (xml_url, &xml_stat); + + g_free (xml_url); + g_free (html_url); + + if (html_stat.st_mtime >= xml_stat.st_mtime) { + + if (sect) + path = g_string_append (path, sect); + + return g_string_free (path, FALSE); + } + else { + g_string_free (path, TRUE); + return url; + } + } + else { + g_free (xml_url); + g_free (html_url); + g_string_free (path, TRUE); + + return url; + } +} diff --git a/src/yelp-reader.h b/src/yelp-reader.h index d545c87a..01b3250f 100644 --- a/src/yelp-reader.h +++ b/src/yelp-reader.h @@ -65,5 +65,6 @@ YelpReader * yelp_reader_new (void); gboolean yelp_reader_start (YelpReader *reader, YelpURI *uri); void yelp_reader_cancel (YelpReader *reader); +gchar * look_for_html_help_file (gchar *xml_uri); #endif /* __YELP_READER_H__ */ |