diff options
author | Mikael Hallendal <micke@codefactory.se> | 2002-04-14 12:04:47 +0000 |
---|---|---|
committer | Mikael Hallendal <hallski@src.gnome.org> | 2002-04-14 12:04:47 +0000 |
commit | 1e6548a0ab147517708873b3e462028351da810c (patch) | |
tree | 748af121fe54302e58716a039fcaab923174ffb0 | |
parent | 88af72c87538c5a34d194becf69bfea9d8e0a728 (diff) | |
download | yelp-1e6548a0ab147517708873b3e462028351da810c.tar.gz |
- use GError to signal errors while parsing document. Still needs to be
2002-04-14 Mikael Hallendal <micke@codefactory.se>
* src/yelp-db2html.c:
- use GError to signal errors while parsing document. Still needs
to be added to above layers.
- don't leek the stylesheet name.
* src/yelp-error.[ch]: added.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/yelp-db2html.c | 32 | ||||
-rw-r--r-- | src/yelp-error.c | 35 | ||||
-rw-r--r-- | src/yelp-error.h | 34 |
5 files changed, 102 insertions, 7 deletions
@@ -1,5 +1,12 @@ 2002-04-14 Mikael Hallendal <micke@codefactory.se> + * src/yelp-db2html.c: + - use GError to signal errors while parsing document. Still needs + to be added to above layers. + - don't leek the stylesheet name. + + * src/yelp-error.[ch]: added. + * src/yelp-view-content.c: added includes to fix warnings. * src/yelp-view-index.c: same. diff --git a/src/Makefile.am b/src/Makefile.am index 22272512..ab7b9674 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,6 +30,7 @@ yelp_SOURCES = \ yelp-marshal.c yelp-marshal.h \ yelp-base.c yelp-base.h \ yelp-db2html.c yelp-db2html.h \ + yelp-error.c yelp-error.h \ yelp-history.c yelp-history.h \ yelp-html.c yelp-html.h \ yelp-index-model.c yelp-index-model.h \ diff --git a/src/yelp-db2html.c b/src/yelp-db2html.c index 83239577..b5ad5915 100644 --- a/src/yelp-db2html.c +++ b/src/yelp-db2html.c @@ -39,6 +39,7 @@ #include <libxslt/transform.h> #include <libxslt/xsltutils.h> +#include "yelp-error.h" #include "yelp-db2html.h" #define d(x) @@ -54,7 +55,6 @@ yelp_db2html_convert (const gchar *document, const char *params[16 + 1]; char *gdb_pathname; /* path to the file to be parsed */ char *gdb_rootid; /* id of sect, chapt, etc to be parsed */ - static char *gdb_stylesheet; /* stylesheet to be used */ char **gdb_split_docname; /* placeholder for file type determination */ char *ptr; gboolean has_rootid; @@ -70,9 +70,6 @@ yelp_db2html_convert (const gchar *document, d(g_print ("Convert file: %s\n", gdb_docname)); - /* stylesheet location based on Linux Standard Base * - * http://www.linuxbase.org/spec/gLSB/gLSB/sgmlr002.html */ - gdb_stylesheet = g_strconcat (PREFIX "/share/sgml/docbook/gnome-customization-0.1/gnome-customization.xsl", NULL); /* check to see if gdb_docname has a ?sectid included */ for (ptr = gdb_docname; *ptr; ptr++){ @@ -90,10 +87,21 @@ yelp_db2html_convert (const gchar *document, /* parse the stylesheet */ if (!gdb_xslreturn) { - gdb_xslreturn = xsltParseStylesheetFile ((const xmlChar *)gdb_stylesheet); + gchar *gdb_stylesheet; + /* stylesheet location based on Linux Standard Base * + * http://www.linuxbase.org/spec/gLSB/gLSB/sgmlr002.html */ + gdb_stylesheet = g_strconcat (PREFIX "/share/sgml/docbook/gnome-customization-0.1/gnome-customization.xsl", NULL); + + gdb_xslreturn = xsltParseStylesheetFile ((const xmlChar *) gdb_stylesheet); + g_free (gdb_stylesheet); } if (!gdb_xslreturn) { + g_set_error (error, + YELP_ERROR, + YELP_ERROR_DOCBOOK_2_HTML, + "Error while parsing the stylesheet, make sure you have your docbook environment setup correctly"); + /* FIXME: Set GError */ return FALSE; } @@ -102,14 +110,21 @@ yelp_db2html_convert (const gchar *document, * FIXME - we need to be more sophisticated about this * then parse as either xml or sgml */ gdb_split_docname = g_strsplit(gdb_docname, ".", 2); + if (!strcmp(gdb_split_docname[1], "sgml")) { - gdb_doc = docbParseFile(gdb_docname, "UTF-8"); + gdb_doc = docbParseFile(gdb_docname, "UTF-8"); } else { (gdb_doc = xmlParseFile(gdb_docname)); } if (gdb_doc == NULL) { /* FIXME: Set something in the GError */ + g_set_error (error, + YELP_ERROR, + YELP_ERROR_DOCBOOK_2_HTML, + "Couldn't parse the document '%s'", + gdb_docname); + g_free (gdb_docname); return FALSE; @@ -144,7 +159,10 @@ yelp_db2html_convert (const gchar *document, gdb_results = xsltApplyStylesheet(gdb_xslreturn, gdb_doc, params); if (!gdb_results) { - /* FIXME: Set GError */ + g_set_error (error, + YELP_ERROR, + YELP_ERROR_DOCBOOK_2_HTML, + "Error while applying the stylesheet"); return FALSE; } diff --git a/src/yelp-error.c b/src/yelp-error.c new file mode 100644 index 00000000..6eb77b68 --- /dev/null +++ b/src/yelp-error.c @@ -0,0 +1,35 @@ +/* -*- 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. + */ + +#include <config.h> + +#include "yelp-error.h" + +GQuark +yelp_error_quark (void) +{ + static GQuark q = 0; + + if (q == 0) { + q = g_quark_from_static_string ("yelp-error-quark"); + } + + return q; +} diff --git a/src/yelp-error.h b/src/yelp-error.h new file mode 100644 index 00000000..a6b57c1c --- /dev/null +++ b/src/yelp-error.h @@ -0,0 +1,34 @@ +/* -*- 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. + */ + +#ifndef __YELP_ERROR_H__ +#define __YELP_ERROR_H__ + +#include <glib.h> + +#define YELP_ERROR yelp_error_quark () + +typedef enum { + YELP_ERROR_DOCBOOK_2_HTML +} YelpError; + +GQuark yelp_error_quark (void) G_GNUC_CONST; + +#endif /* __YELP_ERROR_H__ */ |