--- gnome-libs-1.4.1.2.90/libgnome/gnome-url.c.ghelp Thu Aug 29 16:40:31 2002 +++ gnome-libs-1.4.1.2.90/libgnome/gnome-url.c Thu Aug 29 17:45:53 2002 @@ -26,8 +26,11 @@ #include <libgnome/gnome-exec.h> #include <libgnome/gnome-util.h> #include "gnome-popt.h" /* poptParseArgvString */ +#include "gnome-help.h" #include "gnome-url.h" +static gchar *uri_get_file_uri_from_ghelp_uri (const gchar *path); + #define DEFAULT_HANDLER "gnome-moz-remote --newwin \"%s\"" static gchar * @@ -107,6 +110,7 @@ { gint i; gchar *pos, *template; + gchar *tmp_url = NULL; gboolean free_template = FALSE; int argc; char **argv; @@ -123,15 +127,30 @@ strncpy (protocol, url, pos - url); protocol [pos - url] = '\0'; g_strdown (protocol); - - path = g_strconcat ("/Gnome/URL Handlers/", protocol, "-show", NULL); - template = gnome_config_get_string_with_default (path, &def); - g_free (path); - if (def) - template = gnome_url_default_handler (protocol); - else - free_template = TRUE; - g_free (protocol); + + if (strcmp (protocol, "ghelp") == 0) { + /* We no longer have any app (other than Galeon) + * that can handle both ghelp: URI's and GNOME 1 + * help files, so do a hardcoded translation + * and then run htmlview. + */ + if (strstr (url, "galeon") != NULL) { + /* But always use Galeon for Galeon */ + template = "galeon \"%s\""; + } else { + url = tmp_url = uri_get_file_uri_from_ghelp_uri (pos + 1); + template = "htmlview \"%s\""; + } + } else { + path = g_strconcat ("/Gnome/URL Handlers/", protocol, "-show", NULL); + template = gnome_config_get_string_with_default (path, &def); + g_free (path); + if (def) + template = gnome_url_default_handler (protocol); + else + free_template = TRUE; + g_free (protocol); + } } else /* no : ? -- this shouldn't happen. Use default handler */ template = gnome_url_default_handler (NULL); @@ -156,6 +175,9 @@ * security hole */ gnome_execute_async (NULL, argc, argv); + if (tmp_url) + g_free (tmp_url); + if (free_template) g_free (template); @@ -164,3 +186,103 @@ * it must be free and not g_free */ free(argv); } + +/* Next two functions borrowed from yelp, and modified to use + * gnome_help_file_path(). + * + * Copyright (C) 2002 Mikael Hallendal <micke@codefactory.se> + * + * From: Mikael Hallendal <micke@codefactory.se> + * To: Owen Taylor <otaylor@redhat.com> + * Date: 29 Aug 2002 22:29:37 +0200 + * Message-Id: <1030652977.32141.2.camel@fluffy.hallendal.net> + * + * Hi! + * + * I give permission to use the code in yelp-uri.c under the LPGL. + * + * Regards, + * Mikael Hallendal + */ +static gchar * +uri_get_path_from_relative (const gchar *path) +{ + gchar *doc_id; + gchar *file_name; + gchar *ret_val = NULL; + const gchar *ch, *hash; + int len; + + if ((ch = strchr (path, '/'))) { + /* 2: ghelp:AisleRiot2/Klondike */ + doc_id = g_strndup (path, ch - path); + + hash = strchr (ch + 1, '#'); + if (!hash) + hash = ch + 1 + strlen (ch + 1); + len = hash - (ch + 1); + + if (len >= 5 && strncmp (hash - 5, ".html", 5) == 0) + file_name = g_strdup (ch + 1); + else { + char *tmp = g_strndup (ch + 1, len); + file_name = g_strconcat (tmp, + ".html", + *hash ? "#" : NULL, + *hash ? hash + 1 : NULL, + NULL); + g_free (tmp); + } + } else { + /* 1: ghelp:nautilus */ + doc_id = (gchar *)path; + file_name = g_strdup ("index.html"); + } + + ret_val = gnome_help_file_path (doc_id, file_name); + + if (doc_id != path) + g_free (doc_id); + g_free (file_name); + + return ret_val; +} + +static gchar * +uri_get_path_from_ghelp_uri (const gchar *path) +{ + gchar *ret_val = NULL; + gchar *work_path; + + work_path = g_strdup (path); + + g_strstrip (work_path); + + if (path[0] == '/') { + /* Absolute URL */ + gint i = 1; + gint len = strlen (work_path); + + while (i < len && work_path[i] == '/') { + ++i; + } + + ret_val = g_strdup (work_path + (i - 1)); + } else { + ret_val = uri_get_path_from_relative (path); + } + + g_free (work_path); + + return ret_val; +} + +static gchar * +uri_get_file_uri_from_ghelp_uri (const gchar *path) +{ + char *tmp_path = uri_get_path_from_ghelp_uri (path); + char *result = g_strconcat ("file://", tmp_path, NULL); + + g_free (tmp_path); + return result; +}