summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Hallendal <micke@codefactory.se>2002-05-04 23:56:59 +0000
committerMikael Hallendal <hallski@src.gnome.org>2002-05-04 23:56:59 +0000
commit23e0f23e343a05f0db33c3b1f980bd008f3a502b (patch)
treea258b44c6da4e8ec322acca2424f4ae16672ca28
parent8c160a02a80f989fefad498953851a6533854c7f (diff)
downloadyelp-23e0f23e343a05f0db33c3b1f980bd008f3a502b.tar.gz
added YELP_ERROR_URI_NOT_EXIST
2002-05-05 Mikael Hallendal <micke@codefactory.se> * src/yelp-error.h: added YELP_ERROR_URI_NOT_EXIST * src/yelp-uri.[ch]: - Added, this is functions for manipulating and working with the different uri-schemes possible. * src/Makefile.am: - added test-uri. - added yelp-uri.[ch]
-rw-r--r--ChangeLog12
-rw-r--r--src/Makefile.am15
-rw-r--r--src/test-uri.c56
-rw-r--r--src/yelp-error.h1
-rw-r--r--src/yelp-html.c1
-rw-r--r--src/yelp-uri.c273
-rw-r--r--src/yelp-uri.h80
-rw-r--r--src/yelp-util.c2
8 files changed, 437 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index af0505c8..6f10958f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2002-05-05 Mikael Hallendal <micke@codefactory.se>
+
+ * src/yelp-error.h: added YELP_ERROR_URI_NOT_EXIST
+
+ * src/yelp-uri.[ch]:
+ - Added, this is functions for manipulating and working with the
+ different uri-schemes possible.
+
+ * src/Makefile.am:
+ - added test-uri.
+ - added yelp-uri.[ch]
+
2002-05-04 Sander Vesik <sander.vesik@sun.com>
* stylesheets/yelp-customization.xsl: remove non-linking Next >>>
diff --git a/src/Makefile.am b/src/Makefile.am
index f38c2d43..7afddefa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,17 @@ INCLUDES = \
bin_PROGRAMS = yelp
+noinst_PROGRAMS = test-uri
+
+test_uri_SOURCES = \
+ test-uri.c \
+ yelp-uri.c yelp-uri.h \
+ yelp-error.c yelp-error.h \
+ yelp-util.c yelp-util.h
+
+test_uri_LDADD = \
+ $(YELP_LIBS)
+
install-exec-local:
rm -f $(bindir)/gnome-help
ln -s yelp $(bindir)/gnome-help
@@ -42,8 +53,8 @@ yelp_SOURCES = \
yelp-view-content.c yelp-view-content.h \
yelp-view-index.c yelp-view-index.h \
yelp-view-toc.c yelp-view-toc.h \
- yelp-window.c yelp-window.h
-
+ yelp-window.c yelp-window.h \
+ yelp-uri.c yelp-uri.h
yelp_LDADD = \
$(YELP_LIBS)
diff --git a/src/test-uri.c b/src/test-uri.c
new file mode 100644
index 00000000..d08cece5
--- /dev/null
+++ b/src/test-uri.c
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2002 Mikael Hallendal <micke@codefactory.se>
+ *
+ * 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@codefactory.se>
+ */
+
+#include <libgnomevfs/gnome-vfs.h>
+#include "yelp-uri.h"
+
+int
+main (int argc, char **argv)
+{
+ YelpURI *uri;
+ GError *error = NULL;
+
+ if (argc < 2) {
+ g_print ("Usage: test-uri uri\n");
+ return 1;
+ }
+
+ gnome_vfs_init ();
+
+ uri = yelp_uri_new (argv[1], &error);
+
+ if (error) {
+ g_print ("Error: %s\n", error->message);
+
+ return 1;
+ }
+
+ g_print ("URI_TYPE : %d\n", yelp_uri_get_type (uri));
+ g_print ("URI_PATH : %s\n", yelp_uri_get_path (uri));
+ g_print ("URI_SECTION: %s\n", yelp_uri_get_section (uri));
+
+ yelp_uri_unref (uri);
+
+ gnome_vfs_shutdown ();
+
+ return 0;
+}
diff --git a/src/yelp-error.h b/src/yelp-error.h
index 29c01578..02021c70 100644
--- a/src/yelp-error.h
+++ b/src/yelp-error.h
@@ -26,6 +26,7 @@
#define YELP_ERROR yelp_error_quark ()
typedef enum {
+ YELP_ERROR_URI_NOT_EXIST,
YELP_ERROR_DOCBOOK_2_HTML,
YELP_ERROR_FAILED_OPEN
diff --git a/src/yelp-html.c b/src/yelp-html.c
index 7d33a025..809fb96b 100644
--- a/src/yelp-html.c
+++ b/src/yelp-html.c
@@ -36,6 +36,7 @@
#include "yelp-marshal.h"
#include "yelp-db2html.h"
#include "yelp-error.h"
+#include "yelp-uri.h"
#include "yelp-html.h"
#define d(x)
diff --git a/src/yelp-uri.c b/src/yelp-uri.c
new file mode 100644
index 00000000..130944e4
--- /dev/null
+++ b/src/yelp-uri.c
@@ -0,0 +1,273 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2002 Mikael Hallendal <micke@codefactory.se>
+ *
+ * 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@codefactory.se>
+ */
+
+#include <string.h>
+#include <libgnomevfs/gnome-vfs.h>
+#include <libgnomevfs/gnome-vfs-mime-utils.h>
+#include <libgnome/gnome-i18n.h>
+
+#include "yelp-error.h"
+#include "yelp-util.h"
+#include "yelp-uri.h"
+
+#define d(x) x
+
+struct _YelpURI {
+ YelpURIType type;
+ gchar *path;
+ gchar *section;
+ gint ref_count;
+};
+
+static YelpURIType uri_get_doc_type (const gchar *str_uri);
+static gchar * uri_get_doc_path (const gchar *str_uri,
+ GError **error);
+static gchar * uri_get_doc_section (const gchar *str_uri);
+static gchar * uri_get_absolute_path (const gchar *path);
+
+static YelpURIType
+uri_get_doc_type (const gchar *str_uri)
+{
+ YelpURIType ret_val = YELP_URI_TYPE_UNKNOWN;
+
+ if (!strncmp (str_uri, "man:", 4)) {
+ ret_val = YELP_URI_TYPE_MAN;
+ }
+ else if (!strncmp (str_uri, "info:", 5)) {
+ ret_val = YELP_URI_TYPE_INFO;
+ }
+ else if (!strncmp (str_uri, "ghelp:", 6)) {
+ gchar *mime_type = NULL;
+ gchar *docpath;
+
+ docpath = uri_get_doc_path (str_uri, NULL);
+
+ if (!docpath) {
+ return YELP_URI_TYPE_NON_EXISTENT;
+ }
+
+ mime_type = gnome_vfs_get_mime_type (docpath);
+
+ if (mime_type) {
+ if (!g_strcasecmp (mime_type, "text/xml")) {
+ ret_val = YELP_URI_TYPE_DOCBOOK_XML;
+ }
+ else if (!g_strcasecmp (mime_type, "text/sgml")) {
+ ret_val = YELP_URI_TYPE_DOCBOOK_SGML;
+ }
+ else if (!g_strcasecmp (mime_type, "text/html")) {
+ ret_val = YELP_URI_TYPE_HTML;
+ }
+
+ g_free (mime_type);
+ }
+
+ g_free (docpath);
+ }
+
+ return ret_val;
+}
+
+static gchar *
+uri_get_doc_path (const gchar *str_uri, GError **error)
+{
+ gchar *no_anchor_uri;
+ gchar *ret_val = NULL;
+ const gchar *ch = NULL;
+
+ /* remove the anchor from the doc path */
+ if ((ch = strchr (str_uri, '?')) || (ch = strchr (str_uri, '#'))) {
+ no_anchor_uri = g_strndup (str_uri, ch - str_uri);
+ } else {
+ no_anchor_uri = g_strdup (str_uri);
+ }
+
+ if (!g_ascii_strncasecmp (no_anchor_uri, "man:", 4)) {
+ ret_val = g_strdup (no_anchor_uri + 4);
+ }
+ else if (!g_ascii_strncasecmp (no_anchor_uri, "info:", 5)) {
+ ret_val = g_strdup (no_anchor_uri + 5);
+ }
+ else if (!g_ascii_strncasecmp (no_anchor_uri, "ghelp:", 6)) {
+ ret_val = uri_get_absolute_path (no_anchor_uri + 6);
+
+ if (!g_file_test (ret_val, G_FILE_TEST_EXISTS)) {
+ g_set_error (error,
+ YELP_ERROR,
+ YELP_ERROR_URI_NOT_EXIST,
+ _("%s does not exist."), str_uri);
+ g_free (ret_val);
+ ret_val = NULL;
+ }
+ }
+
+ g_free (no_anchor_uri);
+
+ return ret_val;
+}
+
+static gchar *
+uri_get_doc_section (const gchar *str_uri)
+{
+ const gchar *ch = NULL;
+
+ if ((ch = strchr (str_uri, '?')) || (ch = strchr (str_uri, '#'))) {
+ return g_strdup (ch + 1);
+ }
+
+ return NULL;
+}
+
+static gchar *
+uri_get_absolute_path (const gchar *path)
+{
+ gchar *ret_val = NULL;
+ gchar *work_path;
+
+ work_path = g_strdup (path);
+
+ g_strstrip (work_path);
+
+ if (path[0] == '/') {
+ gint i = 1;
+ gint len = strlen (work_path);
+
+ while (i < len && work_path[i] == '/') {
+ ++i;
+ }
+
+ /* check_xml_promotion ? */
+
+ ret_val = g_strdup (work_path + (i - 1));
+ } else {
+/*
+ * 1: ghelp:nautilus
+ * 2: ghelp:AisleRiot2/Klondike
+ */
+ }
+
+ g_free (work_path);
+
+ return ret_val;
+ /* ... implement jrb's uri scheme */
+}
+
+YelpURIReader *
+yelp_uri_reader_new (YelpURIReaderOpenCallback open_cb,
+ YelpURIReaderReadCallback read_cb,
+ YelpURIReaderCloseCallback close_cb,
+ gpointer user_data)
+{
+ YelpURIReader *reader;
+
+ reader = g_new0 (YelpURIReader, 1);
+
+ reader->open_callback = open_cb;
+ reader->read_callback = read_cb;
+ reader->close_callback = close_cb;
+ reader->user_data = user_data;
+
+ return reader;
+}
+
+YelpURI *
+yelp_uri_new (const gchar *str_uri, GError **error)
+{
+ YelpURI *uri;
+ GError *tmp_error = NULL;
+
+ uri = g_new0 (YelpURI, 1);
+
+ uri->type = uri_get_doc_type (str_uri);
+ uri->path = uri_get_doc_path (str_uri, &tmp_error);
+ uri->section = uri_get_doc_section (str_uri);
+ uri->ref_count = 1;
+
+ if (tmp_error) {
+ g_propagate_error (error, tmp_error);
+ g_error_free (tmp_error);
+ }
+
+ return uri;
+}
+
+YelpURIType
+yelp_uri_get_type (YelpURI *uri)
+{
+ g_return_val_if_fail (uri != NULL, YELP_URI_TYPE_UNKNOWN);
+
+ return uri->type;
+}
+
+const gchar *
+yelp_uri_get_path (YelpURI *uri)
+{
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ return uri->path;
+}
+
+const gchar *
+yelp_uri_get_section (YelpURI *uri)
+{
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ return uri->section;
+}
+
+gboolean
+yelp_uri_read (YelpURI *uri, YelpURIReader *reader, GError **error)
+{
+ /* Read directly */
+ return TRUE;
+}
+
+gboolean
+yelp_uri_read_async (YelpURI *uri, YelpURIReader *reader, GError **error)
+{
+ /* For now read in a g_idle */
+ return TRUE;
+}
+
+void
+yelp_uri_ref (YelpURI *uri)
+{
+ g_return_if_fail (uri != NULL);
+
+ uri->ref_count++;
+}
+
+void
+yelp_uri_unref (YelpURI *uri)
+{
+ g_return_if_fail (uri != NULL);
+
+ uri->ref_count--;
+
+ if (uri->ref_count == 0) {
+ d(g_print ("Freeing up URI\n"));
+
+ g_free (uri->path);
+ g_free (uri->section);
+ g_free (uri);
+ }
+}
diff --git a/src/yelp-uri.h b/src/yelp-uri.h
new file mode 100644
index 00000000..492f84bd
--- /dev/null
+++ b/src/yelp-uri.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2002 Mikael Hallendal <micke@codefactory.se>
+ *
+ * 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@codefactory.se>
+ */
+
+#ifndef __YELP_URI_H__
+#define __YELP_URI_H__
+
+#include <glib.h>
+
+#define YELP_URI(x) ((YelpURI *) x)
+
+typedef enum {
+ YELP_URI_TYPE_NON_EXISTENT,
+ YELP_URI_TYPE_UNKNOWN,
+ YELP_URI_TYPE_DOCBOOK_XML,
+ YELP_URI_TYPE_DOCBOOK_SGML,
+ YELP_URI_TYPE_HTML,
+ YELP_URI_TYPE_MAN,
+ YELP_URI_TYPE_INFO
+} YelpURIType;
+
+typedef struct _YelpURI YelpURI;
+
+typedef int (*YelpURIReaderOpenCallback) (gpointer user_data,
+ GError *error);
+typedef int (*YelpURIReaderReadCallback) (gpointer user_data,
+ const gchar *buffer,
+ gint len,
+ GError *error);
+typedef int (*YelpURIReaderCloseCallback) (gpointer user_data,
+ GError *error);
+typedef struct {
+ YelpURIReaderOpenCallback open_callback;
+ YelpURIReaderReadCallback read_callback;
+ YelpURIReaderCloseCallback close_callback;
+ gpointer user_data;
+} YelpURIReader;
+
+YelpURIReader * yelp_uri_reader_new (YelpURIReaderOpenCallback open_cb,
+ YelpURIReaderReadCallback read_cb,
+ YelpURIReaderCloseCallback close_cb,
+ gpointer user_data);
+
+YelpURI * yelp_uri_new (const gchar *str_uri,
+ GError **error);
+
+YelpURIType yelp_uri_get_type (YelpURI *uri);
+const gchar * yelp_uri_get_path (YelpURI *uri);
+const gchar * yelp_uri_get_section (YelpURI *uri);
+
+gboolean yelp_uri_read (YelpURI *uri,
+ YelpURIReader *reader,
+ GError **error);
+
+gboolean yelp_uri_read_async (YelpURI *uri,
+ YelpURIReader *reader,
+ GError **error);
+
+void yelp_uri_ref (YelpURI *uri);
+void yelp_uri_unref (YelpURI *uri);
+
+#endif /* __YELP_URI_H__ */
diff --git a/src/yelp-util.c b/src/yelp-util.c
index 9d340feb..16c8b3e8 100644
--- a/src/yelp-util.c
+++ b/src/yelp-util.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2001 Mikael Hallendal <micke@codefactory.se>
+ * Copyright (C) 2001-2002 Mikael Hallendal <micke@codefactory.se>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as