Commit df6dc99d authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

moved some defines to the header file.

2004-08-14  Sven Neumann  <sven@gimp.org>

	* plug-ins/help/help.[ch]: moved some defines to the header file.

	* plug-ins/help/domain.c: trivial change to remove the libgimpbase
	dependency.

	* plug-ins/help/Makefile.am
	* plug-ins/help/gimp-help-lookup.c: added a very simple
	command-line tool that allows to lookup a help-id.
parent 8044f8ca
2004-08-14 Sven Neumann <sven@gimp.org>
* plug-ins/help/help.[ch]: moved some defines to the header file.
* plug-ins/help/domain.c: trivial change to remove the libgimpbase
dependency.
* plug-ins/help/Makefile.am
* plug-ins/help/gimp-help-lookup.c: added a very simple
command-line tool that allows to lookup a help-id.
2004-08-13 DindinX <david@dindinx.org>
* plug-ins/common/edge.c: update the preview when the user choose a
......
......@@ -3,4 +3,5 @@ Makefile
.deps
_libs
.libs
gimp-help-lookup
help
......@@ -7,6 +7,8 @@ if OS_WIN32
mwindows = -mwindows
endif
AM_CPPFLAGS = -DDATADIR=\""$(gimpdatadir)"\"
AM_LDFLAGS = $(mwindows)
libexecdir = $(gimpplugindir)/plug-ins
......@@ -32,3 +34,14 @@ LDADD = \
$(GLIB_LIBS) \
$(RT_LIBS) \
$(INTLLIBS)
noinst_PROGRAMS = gimp-help-lookup
gimp_help_lookup_SOURCES = \
domain.c \
domain.h \
locales.c \
locales.h \
help.h \
gimp-help-lookup.c
......@@ -21,18 +21,24 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* This code is written so that it can also be compiled standalone.
* It shouldn't depend on libgimp.
*/
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include <glib.h>
#include "domain.h"
#include "help.h"
#ifdef DISABLE_NLS
#define _(String) (String)
#else
#include "libgimp/stdplugins-intl.h"
#endif
struct _HelpDomain
......@@ -53,21 +59,26 @@ struct _HelpLocale
/* local function prototypes */
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
static void domain_free (HelpDomain *domain);
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
static void domain_free (HelpDomain *domain);
static HelpLocale * domain_locale_new (const gchar *locale_id);
static void domain_locale_free (HelpLocale *locale);
static HelpLocale * domain_locale_new (const gchar *locale_id);
static void domain_locale_free (HelpLocale *locale);
static HelpLocale * domain_locale_lookup (HelpDomain *domain,
const gchar *locale_id);
static const gchar * domain_locale_map (HelpLocale *locale,
const gchar *help_id);
static HelpLocale * domain_locale_lookup (HelpDomain *domain,
const gchar *locale_id);
static const gchar * domain_locale_map (HelpLocale *locale,
const gchar *help_id);
static gboolean domain_locale_parse (HelpDomain *domain,
HelpLocale *locale,
GError **error);
static void domain_error_set_message (GError **error,
const gchar *format,
const gchar *filename);
static gboolean domain_locale_parse (HelpDomain *domain,
HelpLocale *locale,
GError **error);
/* private variables */
......@@ -343,7 +354,7 @@ domain_locale_parse (HelpDomain *domain,
{
GMarkupParseContext *context;
DomainParser *parser;
gchar *base_dir;
gchar *basedir;
gchar *filename;
gboolean success;
GIOChannel *io;
......@@ -363,12 +374,20 @@ domain_locale_parse (HelpDomain *domain,
locale->help_missing = NULL;
}
base_dir = g_filename_from_uri (domain->help_uri, NULL, NULL);
filename = g_build_filename (base_dir,
basedir = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! basedir)
{
g_set_error (error, 0, 0,
"Cannot determine location of gimp-help.xml from '%s'",
domain->help_uri);
return FALSE;
}
filename = g_build_filename (basedir,
locale->locale_id,
"gimp-help.xml",
NULL);
g_free (base_dir);
g_free (basedir);
#ifdef GIMP_HELP_DEBUG
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
......@@ -380,17 +399,9 @@ domain_locale_parse (HelpDomain *domain,
io = g_io_channel_new_file (filename, "r", error);
if (! io)
{
if (error)
{
gchar *msg;
msg = g_strdup_printf (_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
g_free ((*error)->message);
(*error)->message = msg;
}
domain_error_set_message (error,
_("Could not open '%s' for reading: %s"),
filename);
g_free (filename);
return FALSE;
}
......@@ -415,16 +426,7 @@ domain_locale_parse (HelpDomain *domain,
g_free (parser);
if (! success)
{
if (error)
{
gchar *msg = g_strdup_printf (_("Parse error in '%s':\n%s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
g_free ((*error)->message);
(*error)->message = msg;
}
}
domain_error_set_message (error, _("Parse error in '%s':\n%s"), filename);
g_free (filename);
......@@ -653,3 +655,20 @@ domain_parser_parse_missing (DomainParser *parser,
#endif
}
}
static void
domain_error_set_message (GError **error,
const gchar *format,
const gchar *filename)
{
if (error && *error)
{
gchar *name = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
gchar *msg = g_strdup_printf (format, name, (*error)->message);
g_free (name);
g_free ((*error)->message);
(*error)->message = msg;
}
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimp-help-lookup - a standalone gimp-help ID to filename mapper
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include "domain.h"
#include "help.h"
#include "locales.h"
static gchar * lookup (const gchar *help_domain,
const gchar *help_locales,
const gchar *help_id);
gint
main (gint argc,
gchar *argv[])
{
const gchar *help_root = g_getenv (GIMP_HELP_ENV_URI);
const gchar *help_locales = NULL;
const gchar *help_id = argc > 1 ? argv[1] : GIMP_HELP_DEFAULT_ID;
gchar *uri;
if (help_root)
uri = g_strdup (help_root);
else
uri = g_filename_to_uri (DATADIR G_DIR_SEPARATOR_S GIMP_HELP_PREFIX,
NULL, NULL);
domain_register (GIMP_HELP_DEFAULT_DOMAIN, uri);
g_free (uri);
uri = lookup (GIMP_HELP_DEFAULT_DOMAIN, help_locales, help_id);
if (uri)
{
g_print ("%s\n", uri);
g_free (uri);
}
return uri ? EXIT_SUCCESS : EXIT_FAILURE;
}
static gchar *
lookup (const gchar *help_domain,
const gchar *help_locales,
const gchar *help_id)
{
HelpDomain *domain = domain_lookup (help_domain);
if (domain)
{
GList *locales = locales_parse (help_locales ?
help_locales : GIMP_HELP_DEFAULT_LOCALE);
gchar *full_uri = domain_map (domain, locales, help_id);
g_list_foreach (locales, (GFunc) g_free, NULL);
g_list_free (locales);
return full_uri;
}
return NULL;
}
......@@ -21,18 +21,24 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* This code is written so that it can also be compiled standalone.
* It shouldn't depend on libgimp.
*/
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include <glib.h>
#include "domain.h"
#include "help.h"
#ifdef DISABLE_NLS
#define _(String) (String)
#else
#include "libgimp/stdplugins-intl.h"
#endif
struct _HelpDomain
......@@ -53,21 +59,26 @@ struct _HelpLocale
/* local function prototypes */
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
static void domain_free (HelpDomain *domain);
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
static void domain_free (HelpDomain *domain);
static HelpLocale * domain_locale_new (const gchar *locale_id);
static void domain_locale_free (HelpLocale *locale);
static HelpLocale * domain_locale_new (const gchar *locale_id);
static void domain_locale_free (HelpLocale *locale);
static HelpLocale * domain_locale_lookup (HelpDomain *domain,
const gchar *locale_id);
static const gchar * domain_locale_map (HelpLocale *locale,
const gchar *help_id);
static HelpLocale * domain_locale_lookup (HelpDomain *domain,
const gchar *locale_id);
static const gchar * domain_locale_map (HelpLocale *locale,
const gchar *help_id);
static gboolean domain_locale_parse (HelpDomain *domain,
HelpLocale *locale,
GError **error);
static void domain_error_set_message (GError **error,
const gchar *format,
const gchar *filename);
static gboolean domain_locale_parse (HelpDomain *domain,
HelpLocale *locale,
GError **error);
/* private variables */
......@@ -343,7 +354,7 @@ domain_locale_parse (HelpDomain *domain,
{
GMarkupParseContext *context;
DomainParser *parser;
gchar *base_dir;
gchar *basedir;
gchar *filename;
gboolean success;
GIOChannel *io;
......@@ -363,12 +374,20 @@ domain_locale_parse (HelpDomain *domain,
locale->help_missing = NULL;
}
base_dir = g_filename_from_uri (domain->help_uri, NULL, NULL);
filename = g_build_filename (base_dir,
basedir = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! basedir)
{
g_set_error (error, 0, 0,
"Cannot determine location of gimp-help.xml from '%s'",
domain->help_uri);
return FALSE;
}
filename = g_build_filename (basedir,
locale->locale_id,
"gimp-help.xml",
NULL);
g_free (base_dir);
g_free (basedir);
#ifdef GIMP_HELP_DEBUG
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
......@@ -380,17 +399,9 @@ domain_locale_parse (HelpDomain *domain,
io = g_io_channel_new_file (filename, "r", error);
if (! io)
{
if (error)
{
gchar *msg;
msg = g_strdup_printf (_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
g_free ((*error)->message);
(*error)->message = msg;
}
domain_error_set_message (error,
_("Could not open '%s' for reading: %s"),
filename);
g_free (filename);
return FALSE;
}
......@@ -415,16 +426,7 @@ domain_locale_parse (HelpDomain *domain,
g_free (parser);
if (! success)
{
if (error)
{
gchar *msg = g_strdup_printf (_("Parse error in '%s':\n%s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
g_free ((*error)->message);
(*error)->message = msg;
}
}
domain_error_set_message (error, _("Parse error in '%s':\n%s"), filename);
g_free (filename);
......@@ -653,3 +655,20 @@ domain_parser_parse_missing (DomainParser *parser,
#endif
}
}
static void
domain_error_set_message (GError **error,
const gchar *format,
const gchar *filename)
{
if (error && *error)
{
gchar *name = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
gchar *msg = g_strdup_printf (format, name, (*error)->message);
g_free (name);
g_free ((*error)->message);
(*error)->message = msg;
}
}
......@@ -21,18 +21,24 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* This code is written so that it can also be compiled standalone.
* It shouldn't depend on libgimp.
*/
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include <glib.h>
#include "domain.h"
#include "help.h"
#ifdef DISABLE_NLS
#define _(String) (String)
#else
#include "libgimp/stdplugins-intl.h"
#endif
struct _HelpDomain
......@@ -53,21 +59,26 @@ struct _HelpLocale
/* local function prototypes */
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
static void domain_free (HelpDomain *domain);
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
static void domain_free (HelpDomain *domain);
static HelpLocale * domain_locale_new (const gchar *locale_id);
static void domain_locale_free (HelpLocale *locale);
static HelpLocale * domain_locale_new (const gchar *locale_id);
static void domain_locale_free (HelpLocale *locale);
static HelpLocale * domain_locale_lookup (HelpDomain *domain,
const gchar *locale_id);
static const gchar * domain_locale_map (HelpLocale *locale,
const gchar *help_id);
static HelpLocale * domain_locale_lookup (HelpDomain *domain,
const gchar *locale_id);
static const gchar * domain_locale_map (HelpLocale *locale,
const gchar *help_id);
static gboolean domain_locale_parse (HelpDomain *domain,
HelpLocale *locale,
GError **error);
static void domain_error_set_message (GError **error,
const gchar *format,
const gchar *filename);
static gboolean domain_locale_parse (HelpDomain *domain,
HelpLocale *locale,
GError **error);
/* private variables */
......@@ -343,7 +354,7 @@ domain_locale_parse (HelpDomain *domain,
{
GMarkupParseContext *context;
DomainParser *parser;
gchar *base_dir;
gchar *basedir;
gchar *filename;
gboolean success;
GIOChannel *io;
......@@ -363,12 +374,20 @@ domain_locale_parse (HelpDomain *domain,
locale->help_missing = NULL;
}
base_dir = g_filename_from_uri (domain->help_uri, NULL, NULL);
filename = g_build_filename (base_dir,
basedir = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! basedir)
{
g_set_error (error, 0, 0,
"Cannot determine location of gimp-help.xml from '%s'",
domain->help_uri);
return FALSE;
}
filename = g_build_filename (basedir,
locale->locale_id,
"gimp-help.xml",
NULL);
g_free (base_dir);
g_free (basedir);
#ifdef GIMP_HELP_DEBUG
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
......@@ -380,17 +399,9 @@ domain_locale_parse (HelpDomain *domain,
io = g_io_channel_new_file (filename, "r", error);
if (! io)
{
if (error)
{
gchar *msg;
msg = g_strdup_printf (_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
g_free ((*error)->message);
(*error)->message = msg;
}
domain_error_set_message (error,
_("Could not open '%s' for reading: %s"),
filename);
g_free (filename);
return FALSE;
}
......@@ -415,16 +426,7 @@ domain_locale_parse (HelpDomain *domain,
g_free (parser);
if (! success)
{
if (error)
{
gchar *msg = g_strdup_printf (_("Parse error in '%s':\n%s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
g_free ((*error)->message);
(*error)->message = msg;
}
}
domain_error_set_message (error, _("Parse error in '%s':\n%s"), filename);
g_free (filename);
......@@ -653,3 +655,20 @@ domain_parser_parse_missing (DomainParser *parser,
#endif
}
}
static void
domain_error_set_message (GError **error,
const gchar *format,
const gchar *filename)
{
if (error && *error)
{
gchar *name = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
gchar *msg = g_strdup_printf (format, name, (*error)->message);
g_free (name);
g_free ((*error)->message);
(*error)->message = msg;
}
}
......@@ -21,18 +21,24 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* This code is written so that it can also be compiled standalone.
* It shouldn't depend on libgimp.
*/
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include <glib.h>
#include "domain.h"
#include "help.h"
#ifdef DISABLE_NLS
#define _(String) (String)
#else
#include "libgimp/stdplugins-intl.h"
#endif
struct _HelpDomain
......@@ -53,21 +59,26 @@ struct _HelpLocale
/* local function prototypes */
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
static void domain_free (HelpDomain *domain);
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
static void domain_free (HelpDomain *domain);
static HelpLocale * domain_locale_new (const gchar *locale_id);
static void domain_locale_free (HelpLocale *locale);
static HelpLocale * domain_locale_new (const gchar *locale_id);
static void domain_locale_free (HelpLocale *locale);
static HelpLocale * domain_locale_lookup (HelpDomain *domain,
const gchar *locale_id);
static const gchar * domain_locale_map (HelpLocale *locale,
const gchar *help_id);
static HelpLocale * domain_locale_lookup (HelpDomain *domain,
const gchar *locale_id);
static const gchar * domain_locale_map (HelpLocale *locale,
const gchar *help_id);
static gboolean domain_locale_parse (HelpDomain *domain,
HelpLocale *locale,
GError **error);
static void domain_error_set_message (GError **error,
const gchar *format,
const gchar *filename);
static gboolean domain_locale_parse (HelpDomain *domain,
HelpLocale *locale,
GError **error);
/* private variables */
......@@ -343,7 +354,7 @@ domain_locale_parse (HelpDomain *domain,
{
GMarkupParseContext *context;
DomainParser *parser;
gchar *base_dir;
gchar *basedir;
gchar *filename;
gboolean success;
GIOChannel *io;
......@@ -363,12 +374,20 @@ domain_locale_parse (HelpDomain *domain,
locale->help_missing = NULL;
}
base_dir = g_filename_from_uri (domain->help_uri, NULL, NULL);
filename = g_build_filename (base_dir,
basedir = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! basedir)
{
g_set_error (error, 0, 0,
"Cannot determine location of gimp-help.xml from '%s'",
domain->help_uri);
return FALSE;
}
filename = g_build_filename (basedir,
locale->locale_id,
"gimp-help.xml",
NULL);
g_free (base_dir);
g_free (basedir);
#ifdef GIMP_HELP_DEBUG
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
......@@ -380,17 +399,9 @@ domain_locale_parse (HelpDomain *domain,
io = g_io_channel_new_file (filename, "r", error);
if (! io)
{
if (error)
{
gchar *msg;
msg = g_strdup_printf (_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
g_free ((*error)->message);
(*error)->message = msg;
}
domain_error_set_message (error,
_("Could not open '%s' for reading: %s"),
filename);
g_free (filename);
return FALSE;
}
......@@ -415,16 +426,7 @@ domain_locale_parse (HelpDomain *domain,
g_free (parser);
if (! success)
{
if (error)
{
gchar *msg = g_strdup_printf (_("Parse error in '%s':\n%s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
g_free ((*error)->message);
(*error)->message = msg;
}
}
domain_error_set_message (error, _("Parse error in '%s':\n%s"), filename);
g_free (filename);
......@@ -653,3 +655,20 @@ domain_parser_parse_missing (DomainParser *parser,
#endif
}
}
static void
domain_error_set_message (GError **error,
const<