2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-08-14 23:47:22 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimp-help-lookup - a standalone gimp-help ID to filename mapper
|
2008-05-17 00:56:33 +08:00
|
|
|
* Copyright (C) 2004-2008 Sven Neumann <sven@gimp.org>
|
2004-08-14 23:47:22 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-08-14 23:47:22 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-08-14 23:47:22 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2004-08-14 23:47:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-10-16 04:25:56 +08:00
|
|
|
#include "libgimp/gimp.h"
|
2004-08-15 00:59:16 +08:00
|
|
|
|
2006-11-21 05:46:21 +08:00
|
|
|
#include "gimphelp.h"
|
2004-08-14 23:47:22 +08:00
|
|
|
|
|
|
|
|
2008-05-17 00:56:33 +08:00
|
|
|
static void show_version (void) G_GNUC_NORETURN;
|
2004-08-14 23:47:22 +08:00
|
|
|
|
2008-05-17 00:56:33 +08:00
|
|
|
static gchar * lookup (const gchar *help_domain,
|
|
|
|
const gchar *help_locales,
|
|
|
|
const gchar *help_id);
|
|
|
|
|
|
|
|
static GimpHelpProgress * progress_new (void);
|
2005-02-17 07:29:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
static const gchar *help_base = NULL;
|
2005-09-26 03:30:55 +08:00
|
|
|
static gchar *help_root = NULL;
|
2005-02-17 07:29:26 +08:00
|
|
|
static const gchar *help_locales = NULL;
|
|
|
|
static const gchar **help_ids = NULL;
|
|
|
|
|
2008-05-17 00:56:33 +08:00
|
|
|
static gboolean be_verbose = FALSE;
|
|
|
|
|
2005-02-17 07:29:26 +08:00
|
|
|
|
|
|
|
static const GOptionEntry entries[] =
|
2004-08-15 00:59:16 +08:00
|
|
|
{
|
2005-02-17 07:29:26 +08:00
|
|
|
{ "version", 'v', 0,
|
|
|
|
G_OPTION_ARG_CALLBACK, (GOptionArgFunc) show_version,
|
|
|
|
"Show version information and exit", NULL
|
|
|
|
},
|
|
|
|
{ "base", 'b', 0,
|
|
|
|
G_OPTION_ARG_STRING, &help_base,
|
2008-04-03 00:17:26 +08:00
|
|
|
"Specifies base URI", "URI"
|
2005-02-17 07:29:26 +08:00
|
|
|
},
|
|
|
|
{ "root", 'r', 0,
|
|
|
|
G_OPTION_ARG_FILENAME, &help_root,
|
2008-04-03 00:17:26 +08:00
|
|
|
"Specifies root directory for index files", "DIR"
|
2005-02-17 07:29:26 +08:00
|
|
|
},
|
|
|
|
{ "lang", 'l', 0,
|
|
|
|
G_OPTION_ARG_STRING, &help_locales,
|
|
|
|
"Specifies help language", "LANG"
|
|
|
|
},
|
2008-05-17 00:56:33 +08:00
|
|
|
{
|
|
|
|
"verbose", 0, 0,
|
|
|
|
G_OPTION_ARG_NONE, &be_verbose,
|
|
|
|
"Be more verbose", NULL
|
|
|
|
},
|
2005-02-17 07:29:26 +08:00
|
|
|
{
|
|
|
|
G_OPTION_REMAINING, 0, 0,
|
|
|
|
G_OPTION_ARG_STRING_ARRAY, &help_ids,
|
|
|
|
NULL, NULL
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
2004-08-15 00:59:16 +08:00
|
|
|
|
2004-08-14 23:47:22 +08:00
|
|
|
|
|
|
|
gint
|
|
|
|
main (gint argc,
|
|
|
|
gchar *argv[])
|
|
|
|
{
|
2005-02-17 07:29:26 +08:00
|
|
|
GOptionContext *context;
|
|
|
|
gchar *uri;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
help_base = g_getenv (GIMP_HELP_ENV_URI);
|
2008-04-02 18:30:58 +08:00
|
|
|
help_root = g_build_filename (gimp_data_directory (), GIMP_HELP_PREFIX, NULL);
|
2005-02-17 07:29:26 +08:00
|
|
|
|
|
|
|
context = g_option_context_new ("HELP-ID");
|
|
|
|
g_option_context_add_main_entries (context, entries, NULL);
|
2008-05-17 00:56:33 +08:00
|
|
|
|
2005-02-17 07:29:26 +08:00
|
|
|
if (! g_option_context_parse (context, &argc, &argv, &error))
|
2004-08-15 00:59:16 +08:00
|
|
|
{
|
2005-02-17 07:29:26 +08:00
|
|
|
g_print ("%s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return EXIT_FAILURE;
|
2004-08-15 00:59:16 +08:00
|
|
|
}
|
2004-08-14 23:47:22 +08:00
|
|
|
|
2004-08-15 01:53:40 +08:00
|
|
|
if (help_base)
|
|
|
|
uri = g_strdup (help_base);
|
2004-08-14 23:47:22 +08:00
|
|
|
else
|
2004-08-15 01:59:37 +08:00
|
|
|
uri = g_filename_to_uri (help_root, NULL, NULL);
|
2004-08-14 23:47:22 +08:00
|
|
|
|
2008-04-02 18:30:58 +08:00
|
|
|
gimp_help_register_domain (GIMP_HELP_DEFAULT_DOMAIN, uri);
|
2004-08-14 23:47:22 +08:00
|
|
|
g_free (uri);
|
|
|
|
|
2005-02-17 07:29:26 +08:00
|
|
|
uri = lookup (GIMP_HELP_DEFAULT_DOMAIN,
|
|
|
|
help_locales ? help_locales : GIMP_HELP_DEFAULT_LOCALE,
|
|
|
|
help_ids ? help_ids[0] : GIMP_HELP_DEFAULT_ID);
|
2004-08-14 23:47:22 +08:00
|
|
|
|
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
g_print ("%s\n", uri);
|
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
|
2005-02-17 07:29:26 +08:00
|
|
|
g_option_context_free (context);
|
2005-09-26 03:30:55 +08:00
|
|
|
g_free (help_root);
|
2005-02-17 07:29:26 +08:00
|
|
|
|
2004-08-14 23:47:22 +08:00
|
|
|
return uri ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
lookup (const gchar *help_domain,
|
|
|
|
const gchar *help_locales,
|
|
|
|
const gchar *help_id)
|
|
|
|
{
|
2006-11-21 05:46:21 +08:00
|
|
|
GimpHelpDomain *domain = gimp_help_lookup_domain (help_domain);
|
2004-08-14 23:47:22 +08:00
|
|
|
|
|
|
|
if (domain)
|
|
|
|
{
|
2008-05-17 00:56:33 +08:00
|
|
|
GimpHelpProgress *progress = progress_new ();
|
|
|
|
GList *locales;
|
|
|
|
gchar *full_uri;
|
|
|
|
|
|
|
|
locales = gimp_help_parse_locales (help_locales);
|
|
|
|
full_uri = gimp_help_domain_map (domain, locales, help_id, progress,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
gimp_help_progress_free (progress);
|
2004-08-14 23:47:22 +08:00
|
|
|
|
2011-03-08 00:10:18 +08:00
|
|
|
g_list_free_full (locales, (GDestroyNotify) g_free);
|
2004-08-14 23:47:22 +08:00
|
|
|
|
|
|
|
return full_uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-02-17 07:29:26 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
show_version (void)
|
|
|
|
{
|
|
|
|
g_print ("gimp-help-lookup version %s\n", GIMP_VERSION);
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
2008-05-17 00:56:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
progress_start (const gchar *message,
|
|
|
|
gboolean cancelable,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
if (be_verbose)
|
|
|
|
g_printerr ("\n%s\n", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
progress_end (gpointer user_data)
|
|
|
|
{
|
|
|
|
if (be_verbose)
|
|
|
|
g_printerr ("done\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
progress_set_value (gdouble percentage,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
if (be_verbose)
|
|
|
|
g_printerr (".");
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpHelpProgress *
|
|
|
|
progress_new (void)
|
|
|
|
{
|
|
|
|
const GimpHelpProgressVTable vtable =
|
|
|
|
{
|
|
|
|
progress_start,
|
|
|
|
progress_end,
|
|
|
|
progress_set_value
|
|
|
|
};
|
|
|
|
|
|
|
|
return gimp_help_progress_new (&vtable, NULL);
|
|
|
|
}
|