diff options
author | Shaun McCance <shaunm@src.gnome.org> | 2003-12-17 01:35:06 +0000 |
---|---|---|
committer | Shaun McCance <shaunm@src.gnome.org> | 2003-12-17 01:35:06 +0000 |
commit | b9c985f183c0beab2d3e0d872f079bdcb9be91b9 (patch) | |
tree | 068e1676ab3a26339347364a5b89dbde949eeee8 | |
parent | 645f2f8ab37f597208ecbc0817fc1a449a08ffcb (diff) | |
download | yelp-b9c985f183c0beab2d3e0d872f079bdcb9be91b9.tar.gz |
- Removing yelp-scrollkeeper and yelp-sections.
* src/Makefile.am:
* src/yelp-base.c:
* src/yelp-history.h:
* src/yelp-html.h:
* src/yelp-util.c:
* src/yelp-window.c:
- Removing yelp-scrollkeeper and yelp-sections.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/yelp-base.c | 2 | ||||
-rw-r--r-- | src/yelp-history.h | 3 | ||||
-rw-r--r-- | src/yelp-html.h | 1 | ||||
-rw-r--r-- | src/yelp-scrollkeeper.c | 632 | ||||
-rw-r--r-- | src/yelp-scrollkeeper.h | 35 | ||||
-rw-r--r-- | src/yelp-section.c | 84 | ||||
-rw-r--r-- | src/yelp-section.h | 60 | ||||
-rw-r--r-- | src/yelp-util.c | 359 | ||||
-rw-r--r-- | src/yelp-window.c | 2 |
11 files changed, 12 insertions, 1180 deletions
@@ -1,5 +1,15 @@ 2003-12-16 Shaun McCance <shaunm@gnome.org> + * src/Makefile.am: + * src/yelp-base.c: + * src/yelp-history.h: + * src/yelp-html.h: + * src/yelp-util.c: + * src/yelp-window.c: + - Removing yelp-scrollkeeper and yelp-sections. + +2003-12-16 Shaun McCance <shaunm@gnome.org> + * src/yelp-window.c: - Made sidebar selection follow the page loeded. diff --git a/src/Makefile.am b/src/Makefile.am index 782eb329..c139af41 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -75,11 +75,7 @@ yelp_SOURCES = \ yelp-error.c yelp-error.h \ yelp-history.c yelp-history.h \ yelp-html-gtkhtml2.c yelp-html.h \ - yelp-info.c yelp-info.h \ - yelp-man.c yelp-man.h \ yelp-pager.c yelp-pager.h \ - yelp-section.c yelp-section.h \ - yelp-scrollkeeper.c yelp-scrollkeeper.h \ yelp-toc-pager.c yelp-toc-pager.h \ yelp-util.c yelp-util.h \ yelp-window.c yelp-window.h \ diff --git a/src/yelp-base.c b/src/yelp-base.c index bebee033..5bbaf728 100644 --- a/src/yelp-base.c +++ b/src/yelp-base.c @@ -28,8 +28,6 @@ #include "yelp-cache.h" #include "yelp-window.h" -#include "yelp-section.h" -#include "yelp-scrollkeeper.h" #include "yelp-man.h" #include "yelp-info.h" #include "yelp-toc-pager.h" diff --git a/src/yelp-history.h b/src/yelp-history.h index 6d877e74..d341a136 100644 --- a/src/yelp-history.h +++ b/src/yelp-history.h @@ -24,7 +24,8 @@ #define __YELP_HISTORY_H__ #include <glib-object.h> -#include "yelp-section.h" + +#include "yelp-uri.h" #define YELP_TYPE_HISTORY (yelp_history_get_type ()) #define YELP_HISTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), YELP_TYPE_HISTORY, YelpHistory)) diff --git a/src/yelp-html.h b/src/yelp-html.h index 23b93252..0addc310 100644 --- a/src/yelp-html.h +++ b/src/yelp-html.h @@ -26,7 +26,6 @@ #include <gtk/gtkobject.h> #include <gtk/gtktypeutils.h> #include <gtk/gtkmarshal.h> -#include "yelp-section.h" #define YELP_TYPE_HTML (yelp_html_get_type ()) #define YELP_HTML(o) (GTK_CHECK_CAST ((o), YELP_TYPE_HTML, YelpHtml)) diff --git a/src/yelp-scrollkeeper.c b/src/yelp-scrollkeeper.c deleted file mode 100644 index 71e030ec..00000000 --- a/src/yelp-scrollkeeper.c +++ /dev/null @@ -1,632 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2001-2002 Mikael Hallendal <micke@imendio.com> - * - * 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. - * - * Author: Mikael Hallendal <micke@imendio.com> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <libxml/parser.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomevfs/gnome-vfs.h> - -#include "yelp-section.h" -#include "yelp-util.h" -#include "yelp-scrollkeeper.h" - -#define d(x) - -static gboolean scrollkeeper_trim_empty_branches (xmlNode *cl_node); -static gboolean scrollkeeper_tree_empty (xmlNode *cl_node); - -static gboolean scrollkeeper_parse_books (GNode *tree, - xmlDoc *doc); -static gboolean scrollkeeper_parse_section (GNode *parent, - xmlNode *xml_node); -static void scrollkeeper_parse_doc (GNode *parent, - xmlNode *xml_node, - gchar *docid); -static void scrollkeeper_parse_toc_section (GNode *parent, - xmlNode *xml_node, - const gchar *base_uri); -static gchar * scrollkeeper_get_xml_docpath (const gchar *command, - const gchar *argument); -static gchar * scrollkeeper_strip_scheme (gchar *original_uri, - gchar **scheme); - -static gboolean scrollkeeper_parse_index (GList **index); -static void scrollkeeper_parse_index_file (GList **index, - const gchar *index_path, - YelpSection *section); -static void scrollkeeper_parse_index_item (GList **index, - YelpSection *section, - xmlNode *node); - - -static GHashTable *seriesid_hash = NULL; -static GHashTable *docid_hash = NULL; - -static gboolean -scrollkeeper_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 = scrollkeeper_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 -scrollkeeper_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 = scrollkeeper_tree_empty ( - node->xmlChildrenNode->next); - - if (!ret_val) { - return ret_val; - } - } - - if (!g_ascii_strcasecmp (node->name, "doc")) { - return FALSE; - } - } - - return TRUE; -} - -static gboolean -scrollkeeper_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, - yelp_section_new (YELP_SECTION_CATEGORY, - "scrollkeeper", - NULL)); - - for (node = node->xmlChildrenNode; node; node = node->next) { - if (!g_ascii_strcasecmp (node->name, "sect")) { - success = scrollkeeper_parse_section (book_node, node); - } - } - - return TRUE; -} - -static gboolean -scrollkeeper_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, - yelp_section_new (YELP_SECTION_CATEGORY, - name, NULL)); - - for (cur = xml_node->xmlChildrenNode; cur; cur = cur->next) { - if (!g_ascii_strcasecmp (cur->name, "sect")) { - scrollkeeper_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); - } - - scrollkeeper_parse_doc (node, cur, docid); - } - } - - return TRUE; -} - -static void -scrollkeeper_parse_doc (GNode *parent, xmlNode *xml_node, gchar *docid) -{ - xmlNode *cur; - xmlChar *xml_str; - gchar *title; - gchar *omf; - gchar *link; - gchar *format; - gchar *docsource; - gchar *docseriesid; - GNode *node; - YelpURI *uri; - - docseriesid = NULL; - for (cur = xml_node->xmlChildrenNode; cur; cur = cur->next) { - if (!g_ascii_strcasecmp (cur->name, "doctitle")) { - xml_str = xmlNodeGetContent (cur); - title = g_strdup (xml_str); - xmlFree (xml_str); - } - else if (!g_ascii_strcasecmp (cur->name, "docomf")) { - xml_str = xmlNodeGetContent (cur); - omf = g_strdup (xml_str); - xmlFree (xml_str); - } - else if (!g_ascii_strcasecmp (cur->name, "docsource")) { - xml_str = xmlNodeGetContent (cur); - docsource = scrollkeeper_strip_scheme (xml_str, NULL); - link = g_strconcat ("ghelp:", docsource, NULL); - xmlFree (xml_str); - } - else if (!g_ascii_strcasecmp (cur->name, "docformat")) { - xml_str = xmlNodeGetContent (cur); - format = g_strdup (xml_str); - xmlFree (xml_str); - } - else if (!g_ascii_strcasecmp (cur->name, "docseriesid")) { - xml_str = xmlNodeGetContent (cur); - docseriesid = g_strdup (xml_str); - xmlFree (xml_str); - } - } - - uri = yelp_uri_new (link); - - node = g_node_append_data (parent, - yelp_section_new (YELP_SECTION_DOCUMENT, - title, uri)); - g_object_unref (uri); - - if (docseriesid) { - g_hash_table_insert (seriesid_hash, docseriesid, node); - } - - g_hash_table_insert (docid_hash, docid, node); - - g_free (title); - g_free (omf); - g_free (link); - g_free (format); - g_free (docsource); -} - -static void -scrollkeeper_parse_toc_section (GNode *parent, - xmlNode *xml_node, - const gchar *base_uri) -{ - gchar *name; - gchar *link; - xmlNode *next_child; - xmlChar *xml_str; - GNode *node; - gchar *str_uri; - YelpURI *uri; - - next_child = xml_node->xmlChildrenNode; - - xml_str = xmlNodeGetContent (next_child); - - if (!xml_str) { - return; - } - - /* Restrict the sidebar to be two levels deep */ - if (g_ascii_strncasecmp (xml_node->name, "tocsect1", 8) && - g_ascii_strncasecmp (xml_node->name, "tocsect2", 8)) { - return; - } - - name = g_strdup (xml_str); - xmlFree (xml_str); - g_strstrip (name); - - xml_str = xmlGetProp (xml_node, "linkid"); - - if (xml_str) { - link = g_strconcat ("?", xml_str, NULL); - g_strchomp (link); - xmlFree (xml_str); - } - - str_uri = g_strconcat (base_uri, link, NULL); - uri = yelp_uri_new (str_uri); - g_free (str_uri); - - node = g_node_append_data (parent, - yelp_section_new (YELP_SECTION_DOCUMENT_SECTION, - name, uri)); - g_object_unref (uri); - g_free (name); - - for (; next_child != NULL; next_child = next_child->next) { - if (!g_ascii_strncasecmp (next_child->name, "tocsect", 7)) { - scrollkeeper_parse_toc_section (node, next_child, base_uri); - } - } -} - -static gchar * -scrollkeeper_get_xml_docpath (const gchar *command, const gchar *argument) -{ - gboolean success; - gchar *full_command; - gchar *xml_location = NULL; - gchar *std_err; - gint exit_status; - - full_command = g_strconcat (command, " ", argument, NULL); - - success = g_spawn_command_line_sync (full_command, &xml_location, - &std_err, &exit_status, NULL); - - g_free (full_command); - g_free (std_err); - - if (!success) { - g_warning ("Didn't successfully run command: '%s %s'", - command, argument); - - if (xml_location) { - g_free (xml_location); - } - - return NULL; - } - - - if (exit_status) { - if (xml_location) { - g_free (xml_location); - } - return NULL; - } - - g_strchomp (xml_location); - - return xml_location; -} - -static gchar * -scrollkeeper_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; -} - -static gboolean -scrollkeeper_parse_index (GList **index) -{ - gchar *sk_data_dir = NULL; - gchar *index_dir; - GnomeVFSDirectoryHandle *dir; - GnomeVFSResult result; - GnomeVFSFileInfo *file_info; - GNode *node; - YelpSection *section; - - sk_data_dir = scrollkeeper_get_xml_docpath ("scrollkeeper-config", - "--pkglocalstatedir"); - - if (!sk_data_dir) { - return FALSE; - } - - index_dir = g_strdup_printf ("%s/index", sk_data_dir); - - g_free (sk_data_dir); - - result = gnome_vfs_directory_open (&dir, index_dir, - GNOME_VFS_FILE_INFO_DEFAULT); - - if (result != GNOME_VFS_OK) { - return FALSE; - } - - file_info = gnome_vfs_file_info_new (); - - while (gnome_vfs_directory_read_next (dir, file_info) == GNOME_VFS_OK) { - node = g_hash_table_lookup (docid_hash, file_info->name); - - if (node) { - gchar *index_path = g_strdup_printf ("%s/%s", - index_dir, - file_info->name); - - section = YELP_SECTION (node->data); - - scrollkeeper_parse_index_file (index, index_path, section); - - g_free (index_path); - } - } - - g_free (index_dir); - gnome_vfs_file_info_unref (file_info); - gnome_vfs_directory_close (dir); - - return TRUE; -} - -static void -scrollkeeper_parse_index_file (GList **index, - const gchar *index_path, - YelpSection *section) -{ - xmlDoc *doc; - xmlNode *node; - - doc = xmlParseFile (index_path); - - if (doc) { - node = doc->xmlRootNode; - - if (!node || !node->name || - g_ascii_strcasecmp (node->name, "indexdoc")) { - g_warning ("Invalid Index file, root node is '%s', it should be 'indexdoc'!", node->name); - return; - } - - for (node = node->xmlChildrenNode; node; node = node->next) { - if (!g_ascii_strcasecmp (node->name, "indexitem")) { - - scrollkeeper_parse_index_item (index, section, node); - } - } - } -} - -static void -scrollkeeper_parse_index_item (GList **index, YelpSection *section, xmlNode *node) -{ - xmlNode *cur; - xmlChar *title = NULL; - xmlChar *link = NULL; - xmlChar *xml_str; - - for (cur = node->xmlChildrenNode; cur; cur = cur->next) { - if (!g_ascii_strcasecmp (cur->name, "title")) { - xml_str = xmlNodeGetContent (cur); - - if (!g_utf8_validate (xml_str, -1, NULL)) { - g_warning ("Index title is not valid utf8"); - xmlFree (xml_str); - return; - } - - title = g_utf8_strdown (xml_str, -1); - xmlFree (xml_str); - } - else if (!g_ascii_strcasecmp (cur->name, "link")) { - xml_str = xmlGetProp (cur, "linkid"); - link = g_strconcat ("?", xml_str, NULL); - xmlFree (xml_str); - } - else if (!g_ascii_strcasecmp (cur->name, "indexitem")) { - scrollkeeper_parse_index_item (index, section, cur); - } - } - - if (title && link) { - YelpURI *uri; - YelpSection *index_section; - - uri = yelp_uri_new_relative (section->uri, link); - - d(g_print ("%s\n", yelp_uri_to_string (uri))); - - index_section = yelp_section_new (YELP_SECTION_INDEX, - title, uri); - - g_object_unref (uri); - - *index = g_list_prepend (*index, index_section); - - g_free (title); - g_free (link); - - title = link = NULL; - } -} - -gboolean -yelp_scrollkeeper_init (GNode *tree, GList **index) -{ - gchar *docpath; - xmlDoc *doc; - const GList *node; - - 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) { - docpath = scrollkeeper_get_xml_docpath ("scrollkeeper-get-content-list", - node->data); - - if (docpath) { - doc = xmlParseFile (docpath); - g_free (docpath); - } - - if (doc) { - if (doc->xmlRootNode && !scrollkeeper_tree_empty(doc->xmlRootNode->xmlChildrenNode)) { - break; - } else { - xmlFreeDoc (doc); - doc = NULL; - } - } - } - - if (doc) { - scrollkeeper_trim_empty_branches (doc->xmlRootNode); - - scrollkeeper_parse_books (tree, doc); - - xmlFreeDoc (doc); - } - - scrollkeeper_parse_index (index); - - return TRUE; -} - -GNode * -yelp_scrollkeeper_lookup_seriesid (const gchar *seriesid) -{ - return g_hash_table_lookup (seriesid_hash, seriesid); -} - -GNode * -yelp_scrollkeeper_get_toc_tree (const gchar *docpath) -{ - gchar *toc_file; - xmlDoc *doc = NULL; - xmlNode *xml_node; - GNode *tree; - gchar *full_path; - - g_return_val_if_fail (docpath != NULL, NULL); - - tree = g_node_new (NULL); - - toc_file = scrollkeeper_get_xml_docpath ("scrollkeeper-get-toc-from-docpath", - docpath); - - if (toc_file) { - doc = xmlParseFile (toc_file); - g_free (toc_file); - } - - if (!doc) { - /* g_warning ("Tried to parse a non-valid TOC file"); */ - return NULL; - } - - if (g_ascii_strcasecmp (doc->xmlRootNode->name, "toc")) { - g_warning ("Document with wrong root node, got: '%s'", - doc->xmlRootNode->name); - } - - xml_node = doc->xmlRootNode->xmlChildrenNode; - - full_path = g_strconcat ("ghelp:", docpath, NULL); - - for (; xml_node != NULL; xml_node = xml_node->next) { - scrollkeeper_parse_toc_section (tree, xml_node, full_path); - } - - g_free (full_path); - - return tree; -} - - diff --git a/src/yelp-scrollkeeper.h b/src/yelp-scrollkeeper.h deleted file mode 100644 index b728a231..00000000 --- a/src/yelp-scrollkeeper.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2001-2002 Mikael Hallendal <micke@imendio.com> - * - * 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. - * - * Author: Mikael Hallendal <micke@imendio.com> - */ - -#ifndef __YELP_SCROLLKEEPER_H__ -#define __YELP_SCROLLKEEPER_H__ - -#include <glib.h> -#include <gtk/gtktreestore.h> - -gboolean yelp_scrollkeeper_init (GNode *tree, - GList **index); -GNode * yelp_scrollkeeper_lookup_seriesid (const gchar *seriesid); - -GNode * yelp_scrollkeeper_get_toc_tree (const gchar *docpath); - -#endif /* __YELP_SCROLLKEEPER_H__ */ diff --git a/src/yelp-section.c b/src/yelp-section.c deleted file mode 100644 index 16b9cdd0..00000000 --- a/src/yelp-section.c +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2001-2002 Mikael Hallendal <micke@imendio.com> - * - * 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. - * - * Author: Mikael Hallendal <micke@imendio.com> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "string.h" -#include "yelp-section.h" - -YelpSection * -yelp_section_new (YelpSectionType type, - const gchar *name, - YelpURI *uri) -{ - YelpSection *section; - - section = g_new0 (YelpSection, 1); - - section->type = type; - - if (name) { - section->name = g_strdup (name); - } else { - section->name = g_strdup (""); - } - - if (uri) { - g_object_ref (uri); - section->uri = uri; - } else { - section->uri = NULL; - } - - - return section; -} - -YelpSection * -yelp_section_copy (const YelpSection *section) -{ - return yelp_section_new (section->type, - section->name, - section->uri); -} - -void -yelp_section_free (YelpSection *section) -{ - if (section->name) { - g_free (section->name); - } - - if (section->uri) { - g_object_unref (section->uri); - } -} - -gint -yelp_section_compare (gconstpointer a, - gconstpointer b) -{ - return strcmp (((YelpSection *)a)->name, - ((YelpSection *)b)->name); -} diff --git a/src/yelp-section.h b/src/yelp-section.h deleted file mode 100644 index ed14ce73..00000000 --- a/src/yelp-section.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2001-2002 Mikael Hallendal <micke@imendio.com> - * - * 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. - * - * Author: Mikael Hallendal <micke@imendio.com> - */ - -#ifndef __YELP_SECTION_H__ -#define __YELP_SECTION_H__ - -#include <glib-object.h> - -#include "yelp-uri.h" - -typedef struct _YelpSection YelpSection; - -#define YELP_SECTION(x) ((YelpSection *) x) - -typedef enum { - YELP_SECTION_DOCUMENT_SECTION, - YELP_SECTION_DOCUMENT, - YELP_SECTION_CATEGORY, - YELP_SECTION_INDEX -} YelpSectionType; - -struct _YelpSection { - gchar *name; - YelpURI *uri; - YelpSectionType type; -}; - -YelpSection * yelp_section_new (YelpSectionType type, - const gchar *name, - YelpURI *uri); - -YelpSection * yelp_section_copy (const YelpSection *section); - -void yelp_section_free (YelpSection *section); - -gint yelp_section_compare (gconstpointer a, - gconstpointer b); - -#endif /* __YELP_SECTION_H__ */ - - diff --git a/src/yelp-util.c b/src/yelp-util.c index 1b3647d3..670b8d8c 100644 --- a/src/yelp-util.c +++ b/src/yelp-util.c @@ -23,7 +23,6 @@ #include <libgnomevfs/gnome-vfs.h> #include <string.h> -#include "yelp-section.h" #include "yelp-util.h" /* This code comes from gnome vfs: */ @@ -276,361 +275,3 @@ yelp_util_resolve_relative_url (const char *base_uri, return result; } -char * -yelp_util_node_to_string_path (GNode *node) -{ - char *str, *t; - char *escaped_node_name; - YelpSection *section; - - section = node->data; - escaped_node_name = gnome_vfs_escape_set (section->name, " \t\n;/%"); - - str = escaped_node_name; - while (node->parent != NULL) { - node = node->parent; - - section = node->data; - if (section) { - escaped_node_name = gnome_vfs_escape_set (section->name, " \t\n;/%"); - - t = g_strconcat (escaped_node_name, "/", str, NULL); - g_free (escaped_node_name); - g_free (str); - str = t; - } - } - return str; -} - -static GNode * -yelp_util_string_path_to_node_helper (char **path, - GNode *node) -{ - char *unescaped_pathname; - YelpSection *section; - - if (*path == NULL) { - return NULL; - } - - if (node == NULL) { - return NULL; - } - - unescaped_pathname = gnome_vfs_unescape_string (*path, NULL); - - do { - section = node->data; - - if (strcmp (section->name, unescaped_pathname) == 0) { - g_free (unescaped_pathname); - path += 1; - - if (*path == NULL) { - return node; - } - - if (node->children) { - return yelp_util_string_path_to_node_helper (path, node->children); - } else { - return NULL; - } - } - - } while ((node = node->next) != NULL); - - g_free (unescaped_pathname); - - return NULL; -} - - -GNode * -yelp_util_string_path_to_node (const char *string_path, - GNode *root) -{ - char **path; - GNode *node; - - path = g_strsplit (string_path, "/", 0); - - node = yelp_util_string_path_to_node_helper (path, root->children); - - g_strfreev (path); - - return node; -} - - -GNode * -yelp_util_decompose_path_url (GNode *root, - const char *path_url, - YelpURI **embedded_uri) -{ - const gchar *first_part; - const gchar *second_part; - gchar *path; - GNode *res; - - *embedded_uri = NULL; - - if (strncmp (path_url, "path:", 5) != 0) { - return NULL; - } - - first_part = path_url + 5; - second_part = strchr(first_part, ';'); - - if (second_part) { - path = g_strndup (first_part, second_part - first_part); - second_part += 1; - } else { - path = g_strdup (first_part); - } - - res = yelp_util_string_path_to_node (path, root); - g_free (path); - - if (second_part) { - *embedded_uri = yelp_uri_new (second_part); - } - - return res; -} - -char * -yelp_util_compose_path_url (GNode *node, - const char *embedded_url) -{ - char *path; - char *url; - - path = yelp_util_node_to_string_path (node); - - if (path == NULL) { - return NULL; - } - - url = g_strconcat ("path:", path, ";", embedded_url, NULL); - - g_free (path); - - return url; -} - - -GNode * -yelp_util_find_toplevel (GNode *doc_tree, const gchar *name) -{ - GNode *node; - YelpSection *section; - - node = g_node_first_child (doc_tree); - - while (node) { - section = YELP_SECTION (node->data); - - if (!strcmp (name, section->name)) { - return node; - } - node = g_node_next_sibling (node); - } - - return NULL; -} - -static GNode *found_node; - -static gboolean -tree_find_node_name (GNode *node, const gchar *name) -{ - YelpSection *section; - - section = YELP_SECTION (node->data); - - if (!section || !section->name) { - return FALSE; - } - - if (!g_ascii_strcasecmp (name, section->name)) { - found_node = node; - return TRUE; - } - - return FALSE; -} - -GNode * -yelp_util_find_node_from_name (GNode *doc_tree, const gchar *name) -{ - found_node = NULL; - - g_node_traverse (doc_tree, G_IN_ORDER, - G_TRAVERSE_ALL, - -1, - (GNodeTraverseFunc) tree_find_node_name, - (gchar *) name); - - return found_node; -} - -static gboolean -tree_find_node_uri (GNode *node, YelpURI *uri) -{ - YelpSection *section; - - section = YELP_SECTION (node->data); - - if (!section || !section->uri) { - return FALSE; - } - - if (yelp_uri_equal (uri, section->uri)) { - found_node = node; - return TRUE; - } - - return FALSE; -} - -GNode * -yelp_util_find_node_from_uri (GNode *doc_tree, YelpURI *uri) -{ - found_node = NULL; - - g_node_traverse (doc_tree, G_IN_ORDER, - G_TRAVERSE_ALL, - -1, - (GNodeTraverseFunc) tree_find_node_uri, - uri); - - return found_node; -} - -gchar * -yelp_util_extract_docpath_from_uri (const gchar *inc_uri) -{ - GnomeVFSURI *uri; - gchar *str_uri; - gchar *transformed_uri; - gchar *docpath = NULL; - const gchar *ch = NULL; - - if ((ch = strchr (inc_uri, '?')) || (ch = strchr (inc_uri, '#'))) { - str_uri = g_strndup (inc_uri, ch - inc_uri); - } else { - str_uri = g_strdup (inc_uri); - } - - if (!strncmp (str_uri, "man:", 4)) { - return str_uri; - } - else if (!strncmp (str_uri, "info:", 5)) { - return str_uri; - } - else if (strncmp (str_uri, "ghelp:", 6)) { - /* Strange uri, just return the same string */ - return str_uri; - } - - if (strstr (str_uri, ".xml") || strstr (str_uri, ".sgml")) { - gchar *str; - - str = str_uri + 6; - uri = gnome_vfs_uri_new (str); - str = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE); - - /* strlen ("file://") == 7 */ - if (!strncmp (str, "file://", 7)) { - docpath = g_strdup (str + 7); - } - - g_free (str); - } - - if (!docpath) { - /* OK, nothing else have worked, try to get the docpath by * - * using the gnome-vfs-module */ - uri = gnome_vfs_uri_new (str_uri); - - if (uri) { - transformed_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE); - - if (!strncmp (transformed_uri, "file://", 7)) { - docpath = g_strdup (transformed_uri + 7); - } - else if (!strncmp (transformed_uri, "pipe:", 5)) { - gchar *start, *end; - gchar *escaped_string; - - /* pipe:gnome2-db2html%20'%2Fusr%2Fshare%2Fgnome%2Fhelp%2Fgaleon-manual%2FC%2Fgaleon-manual.sgml'%3Bmime-type%3Dtext%2Fhtml */ - - start = strchr (transformed_uri, '\'') + 1; - end = strrchr (transformed_uri, '\''); - - escaped_string = g_strndup (start, - end - start); - - docpath = gnome_vfs_unescape_string (escaped_string, - NULL); - } - } else { - docpath = NULL; - } - } - - g_free (str_uri); - -/* g_print ("Returning docpath: %s\n", docpath) */ - - return docpath; -} - -gchar * -yelp_util_split_uri (const gchar *uri, gchar **anchor) -{ - gchar *str; - gchar *ret = NULL; - const gchar *anchor_ptr; - gint len; - - anchor_ptr = yelp_util_find_anchor_in_uri (uri); - - if (!strncmp (uri, "ghelp:", 6)) { - str = yelp_util_extract_docpath_from_uri (uri); - ret = g_strconcat ("ghelp:", str, NULL); - g_free (str); - } - else if (!strncmp (uri, "man:", 4) || !strncmp (uri, "info:", 5)) { - if (!anchor_ptr) { - len = strlen (uri); - } else { - len = anchor_ptr - 1 - uri; - } - - ret = g_strndup (uri, len); - } - - if (anchor) { - *anchor = g_strdup (anchor_ptr); - } - - return ret; -} - -const gchar * -yelp_util_find_anchor_in_uri (const gchar *str_uri) -{ - gchar *anchor; - - if ((anchor = strstr (str_uri, "?"))) { - return anchor + 1; - } - else if ((anchor = strstr (str_uri, "#"))) { - return anchor + 1; - } - - return NULL; -} - diff --git a/src/yelp-window.c b/src/yelp-window.c index f5984cd9..8664096e 100644 --- a/src/yelp-window.c +++ b/src/yelp-window.c @@ -43,9 +43,7 @@ #include "yelp-history.h" #include "yelp-html.h" #include "yelp-pager.h" -#include "yelp-section.h" #include "yelp-toc-pager.h" -#include "yelp-util.h" #include "yelp-window.h" #define d(x) |