Commit 1d669a5b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

allow to specify the location of the index files independently from the

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

	* plug-ins/help/domain.[ch]: allow to specify the location of the
	index files independently from the base URL.

	* plug-ins/help/help.c: changed accordingly.

	* plug-ins/help/gimp-help-lookup.c: added command-line options to
	specify base URI and root directory for index files.
parent dba01430
2004-08-14 Sven Neumann <sven@gimp.org>
* plug-ins/help/domain.[ch]: allow to specify the location of the
index files independently from the base URL.
* plug-ins/help/help.c: changed accordingly.
* plug-ins/help/gimp-help-lookup.c: added command-line options to
specify base URI and root directory for index files.
2004-08-14 Sven Neumann <sven@gimp.org>
* plug-ins/help/locales.c (locales_parse): don't mess up the order
......
......@@ -45,6 +45,7 @@ struct _HelpDomain
{
gchar *help_domain;
gchar *help_uri;
gchar *help_root;
GHashTable *help_locales;
};
......@@ -60,7 +61,8 @@ struct _HelpLocale
/* local function prototypes */
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
const gchar *domain_uri,
const gchar *domain_root);
static void domain_free (HelpDomain *domain);
static HelpLocale * domain_locale_new (const gchar *locale_id);
......@@ -89,7 +91,8 @@ static GHashTable *domain_hash = NULL;
void
domain_register (const gchar *domain_name,
const gchar *domain_uri)
const gchar *domain_uri,
const gchar *domain_root)
{
g_return_if_fail (domain_name != NULL);
g_return_if_fail (domain_uri != NULL);
......@@ -105,7 +108,7 @@ domain_register (const gchar *domain_name,
g_hash_table_insert (domain_hash,
g_strdup (domain_name),
domain_new (domain_name, domain_uri));
domain_new (domain_name, domain_uri, domain_root));
}
HelpDomain *
......@@ -204,12 +207,24 @@ domain_exit (void)
static HelpDomain *
domain_new (const gchar *domain_name,
const gchar *domain_uri)
const gchar *domain_uri,
const gchar *domain_root)
{
HelpDomain *domain = g_new0 (HelpDomain, 1);
domain->help_domain = g_strdup (domain_name);
domain->help_uri = g_strdup (domain_uri);
domain->help_root = g_strdup (domain_root);
if (domain_uri)
{
/* strip trailing slash */
gint len = strlen (domain_uri);
if (len &&
domain_uri[len - 1] == '/')
domain->help_uri[len - 1] = '\0';
}
return domain;
}
......@@ -224,6 +239,7 @@ domain_free (HelpDomain *domain)
g_free (domain->help_domain);
g_free (domain->help_uri);
g_free (domain->help_root);
g_free (domain);
}
......@@ -354,10 +370,9 @@ domain_locale_parse (HelpDomain *domain,
{
GMarkupParseContext *context;
DomainParser *parser;
gchar *basedir;
GIOChannel *io;
gchar *filename;
gboolean success;
GIOChannel *io;
g_return_val_if_fail (domain != NULL, FALSE);
g_return_val_if_fail (locale != NULL, FALSE);
......@@ -374,8 +389,10 @@ domain_locale_parse (HelpDomain *domain,
locale->help_missing = NULL;
}
basedir = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! basedir)
if (! domain->help_root)
domain->help_root = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! domain->help_root)
{
g_set_error (error, 0, 0,
"Cannot determine location of gimp-help.xml from '%s'",
......@@ -383,17 +400,16 @@ domain_locale_parse (HelpDomain *domain,
return FALSE;
}
filename = g_build_filename (basedir,
filename = g_build_filename (domain->help_root,
locale->locale_id,
"gimp-help.xml",
NULL);
g_free (basedir);
#ifdef GIMP_HELP_DEBUG
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
locale->locale_id,
filename,
domain->help_domain);
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
locale->locale_id,
filename,
domain->help_domain);
#endif
io = g_io_channel_new_file (filename, "r", error);
......
......@@ -29,7 +29,8 @@ typedef struct _HelpDomain HelpDomain;
void domain_register (const gchar *domain_name,
const gchar *domain_uri);
const gchar *domain_uri,
const gchar *domain_root);
HelpDomain * domain_lookup (const gchar *domain_name);
gchar * domain_map (HelpDomain *domain,
......
......@@ -40,12 +40,14 @@ static gchar * lookup (const gchar *help_domain,
static void
usage (const gchar *name)
{
g_print ("gimp-help-lookup version %s\n\n", GIMP_VERSION);
g_print ("Looks up a help-id in the GIMP user manual.\n"
g_print ("gimp-help-lookup version %s\n", GIMP_VERSION);
g_print ("Looks up a help-id in the GIMP user manual.\n\n"
"Usage: %s [options] [help-id]\n\n", name);
g_print ("Valid options are:\n"
" -h, --help Output this help.\n"
" -v, --version Output version info.\n"
" -b, --base <uri> Speficies base URI.\n"
" -r, --root <directory> Speficies root directory for index files.\n"
" -l, --lang <language-code> Specifies help language.\n"
"\n");
}
......@@ -55,9 +57,10 @@ gint
main (gint argc,
gchar *argv[])
{
const gchar *help_root = g_getenv (GIMP_HELP_ENV_URI);
const gchar *help_base = g_getenv (GIMP_HELP_ENV_URI);
const gchar *help_locales = GIMP_HELP_DEFAULT_LOCALE;
const gchar *help_id = GIMP_HELP_DEFAULT_ID;
const gchar *help_root = NULL;
gchar *uri;
gint i;
......@@ -73,25 +76,44 @@ main (gint argc,
if (*opt == '-')
opt++;
switch (*opt)
switch (g_ascii_tolower (*opt))
{
case 'v':
g_print ("gimp-help-lookup version %s\n", GIMP_VERSION);
exit (EXIT_SUCCESS);
case 'b':
if (i + 1 < argc)
{
help_base = argv[++i];
continue;
}
break;
case 'r':
if (i + 1 < argc)
{
help_root = argv[++i];
continue;
}
break;
case 'l':
if (i + i < argc)
if (i + 1 < argc)
{
help_locales = argv[++i];
break;
continue;
}
/* else fallthrough */
case 'v':
g_print ("gimp-help-lookup version %s\n", GIMP_VERSION);
exit (EXIT_SUCCESS);
break;
case 'h':
default:
case '?':
usage (argv[0]);
exit (EXIT_SUCCESS);
}
g_printerr ("Error parsing the command-line options, try --help\n");
exit (EXIT_FAILURE);
}
else
{
......@@ -99,13 +121,13 @@ main (gint argc,
}
}
if (help_root)
uri = g_strdup (help_root);
if (help_base)
uri = g_strdup (help_base);
else
uri = g_filename_to_uri (DATADIR G_DIR_SEPARATOR_S GIMP_HELP_PREFIX,
NULL, NULL);
domain_register (GIMP_HELP_DEFAULT_DOMAIN, uri);
domain_register (GIMP_HELP_DEFAULT_DOMAIN, uri, help_root);
g_free (uri);
uri = lookup (GIMP_HELP_DEFAULT_DOMAIN, help_locales, help_id);
......
......@@ -45,6 +45,7 @@ struct _HelpDomain
{
gchar *help_domain;
gchar *help_uri;
gchar *help_root;
GHashTable *help_locales;
};
......@@ -60,7 +61,8 @@ struct _HelpLocale
/* local function prototypes */
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
const gchar *domain_uri,
const gchar *domain_root);
static void domain_free (HelpDomain *domain);
static HelpLocale * domain_locale_new (const gchar *locale_id);
......@@ -89,7 +91,8 @@ static GHashTable *domain_hash = NULL;
void
domain_register (const gchar *domain_name,
const gchar *domain_uri)
const gchar *domain_uri,
const gchar *domain_root)
{
g_return_if_fail (domain_name != NULL);
g_return_if_fail (domain_uri != NULL);
......@@ -105,7 +108,7 @@ domain_register (const gchar *domain_name,
g_hash_table_insert (domain_hash,
g_strdup (domain_name),
domain_new (domain_name, domain_uri));
domain_new (domain_name, domain_uri, domain_root));
}
HelpDomain *
......@@ -204,12 +207,24 @@ domain_exit (void)
static HelpDomain *
domain_new (const gchar *domain_name,
const gchar *domain_uri)
const gchar *domain_uri,
const gchar *domain_root)
{
HelpDomain *domain = g_new0 (HelpDomain, 1);
domain->help_domain = g_strdup (domain_name);
domain->help_uri = g_strdup (domain_uri);
domain->help_root = g_strdup (domain_root);
if (domain_uri)
{
/* strip trailing slash */
gint len = strlen (domain_uri);
if (len &&
domain_uri[len - 1] == '/')
domain->help_uri[len - 1] = '\0';
}
return domain;
}
......@@ -224,6 +239,7 @@ domain_free (HelpDomain *domain)
g_free (domain->help_domain);
g_free (domain->help_uri);
g_free (domain->help_root);
g_free (domain);
}
......@@ -354,10 +370,9 @@ domain_locale_parse (HelpDomain *domain,
{
GMarkupParseContext *context;
DomainParser *parser;
gchar *basedir;
GIOChannel *io;
gchar *filename;
gboolean success;
GIOChannel *io;
g_return_val_if_fail (domain != NULL, FALSE);
g_return_val_if_fail (locale != NULL, FALSE);
......@@ -374,8 +389,10 @@ domain_locale_parse (HelpDomain *domain,
locale->help_missing = NULL;
}
basedir = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! basedir)
if (! domain->help_root)
domain->help_root = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! domain->help_root)
{
g_set_error (error, 0, 0,
"Cannot determine location of gimp-help.xml from '%s'",
......@@ -383,17 +400,16 @@ domain_locale_parse (HelpDomain *domain,
return FALSE;
}
filename = g_build_filename (basedir,
filename = g_build_filename (domain->help_root,
locale->locale_id,
"gimp-help.xml",
NULL);
g_free (basedir);
#ifdef GIMP_HELP_DEBUG
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
locale->locale_id,
filename,
domain->help_domain);
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
locale->locale_id,
filename,
domain->help_domain);
#endif
io = g_io_channel_new_file (filename, "r", error);
......
......@@ -45,6 +45,7 @@ struct _HelpDomain
{
gchar *help_domain;
gchar *help_uri;
gchar *help_root;
GHashTable *help_locales;
};
......@@ -60,7 +61,8 @@ struct _HelpLocale
/* local function prototypes */
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
const gchar *domain_uri,
const gchar *domain_root);
static void domain_free (HelpDomain *domain);
static HelpLocale * domain_locale_new (const gchar *locale_id);
......@@ -89,7 +91,8 @@ static GHashTable *domain_hash = NULL;
void
domain_register (const gchar *domain_name,
const gchar *domain_uri)
const gchar *domain_uri,
const gchar *domain_root)
{
g_return_if_fail (domain_name != NULL);
g_return_if_fail (domain_uri != NULL);
......@@ -105,7 +108,7 @@ domain_register (const gchar *domain_name,
g_hash_table_insert (domain_hash,
g_strdup (domain_name),
domain_new (domain_name, domain_uri));
domain_new (domain_name, domain_uri, domain_root));
}
HelpDomain *
......@@ -204,12 +207,24 @@ domain_exit (void)
static HelpDomain *
domain_new (const gchar *domain_name,
const gchar *domain_uri)
const gchar *domain_uri,
const gchar *domain_root)
{
HelpDomain *domain = g_new0 (HelpDomain, 1);
domain->help_domain = g_strdup (domain_name);
domain->help_uri = g_strdup (domain_uri);
domain->help_root = g_strdup (domain_root);
if (domain_uri)
{
/* strip trailing slash */
gint len = strlen (domain_uri);
if (len &&
domain_uri[len - 1] == '/')
domain->help_uri[len - 1] = '\0';
}
return domain;
}
......@@ -224,6 +239,7 @@ domain_free (HelpDomain *domain)
g_free (domain->help_domain);
g_free (domain->help_uri);
g_free (domain->help_root);
g_free (domain);
}
......@@ -354,10 +370,9 @@ domain_locale_parse (HelpDomain *domain,
{
GMarkupParseContext *context;
DomainParser *parser;
gchar *basedir;
GIOChannel *io;
gchar *filename;
gboolean success;
GIOChannel *io;
g_return_val_if_fail (domain != NULL, FALSE);
g_return_val_if_fail (locale != NULL, FALSE);
......@@ -374,8 +389,10 @@ domain_locale_parse (HelpDomain *domain,
locale->help_missing = NULL;
}
basedir = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! basedir)
if (! domain->help_root)
domain->help_root = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! domain->help_root)
{
g_set_error (error, 0, 0,
"Cannot determine location of gimp-help.xml from '%s'",
......@@ -383,17 +400,16 @@ domain_locale_parse (HelpDomain *domain,
return FALSE;
}
filename = g_build_filename (basedir,
filename = g_build_filename (domain->help_root,
locale->locale_id,
"gimp-help.xml",
NULL);
g_free (basedir);
#ifdef GIMP_HELP_DEBUG
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
locale->locale_id,
filename,
domain->help_domain);
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
locale->locale_id,
filename,
domain->help_domain);
#endif
io = g_io_channel_new_file (filename, "r", error);
......
......@@ -45,6 +45,7 @@ struct _HelpDomain
{
gchar *help_domain;
gchar *help_uri;
gchar *help_root;
GHashTable *help_locales;
};
......@@ -60,7 +61,8 @@ struct _HelpLocale
/* local function prototypes */
static HelpDomain * domain_new (const gchar *domain_name,
const gchar *domain_uri);
const gchar *domain_uri,
const gchar *domain_root);
static void domain_free (HelpDomain *domain);
static HelpLocale * domain_locale_new (const gchar *locale_id);
......@@ -89,7 +91,8 @@ static GHashTable *domain_hash = NULL;
void
domain_register (const gchar *domain_name,
const gchar *domain_uri)
const gchar *domain_uri,
const gchar *domain_root)
{
g_return_if_fail (domain_name != NULL);
g_return_if_fail (domain_uri != NULL);
......@@ -105,7 +108,7 @@ domain_register (const gchar *domain_name,
g_hash_table_insert (domain_hash,
g_strdup (domain_name),
domain_new (domain_name, domain_uri));
domain_new (domain_name, domain_uri, domain_root));
}
HelpDomain *
......@@ -204,12 +207,24 @@ domain_exit (void)
static HelpDomain *
domain_new (const gchar *domain_name,
const gchar *domain_uri)
const gchar *domain_uri,
const gchar *domain_root)
{
HelpDomain *domain = g_new0 (HelpDomain, 1);
domain->help_domain = g_strdup (domain_name);
domain->help_uri = g_strdup (domain_uri);
domain->help_root = g_strdup (domain_root);
if (domain_uri)
{
/* strip trailing slash */
gint len = strlen (domain_uri);
if (len &&
domain_uri[len - 1] == '/')
domain->help_uri[len - 1] = '\0';
}
return domain;
}
......@@ -224,6 +239,7 @@ domain_free (HelpDomain *domain)
g_free (domain->help_domain);
g_free (domain->help_uri);
g_free (domain->help_root);
g_free (domain);
}
......@@ -354,10 +370,9 @@ domain_locale_parse (HelpDomain *domain,
{
GMarkupParseContext *context;
DomainParser *parser;
gchar *basedir;
GIOChannel *io;
gchar *filename;
gboolean success;
GIOChannel *io;
g_return_val_if_fail (domain != NULL, FALSE);
g_return_val_if_fail (locale != NULL, FALSE);
......@@ -374,8 +389,10 @@ domain_locale_parse (HelpDomain *domain,
locale->help_missing = NULL;
}
basedir = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! basedir)
if (! domain->help_root)
domain->help_root = g_filename_from_uri (domain->help_uri, NULL, NULL);
if (! domain->help_root)
{
g_set_error (error, 0, 0,
"Cannot determine location of gimp-help.xml from '%s'",
......@@ -383,17 +400,16 @@ domain_locale_parse (HelpDomain *domain,
return FALSE;
}
filename = g_build_filename (basedir,
filename = g_build_filename (domain->help_root,
locale->locale_id,
"gimp-help.xml",
NULL);
g_free (basedir);
#ifdef GIMP_HELP_DEBUG
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
locale->locale_id,
filename,
domain->help_domain);
g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
locale->locale_id,
filename,
domain->help_domain);
#endif
io = g_io_channel_new_file (filename, "r", error);
......
......@@ -157,11 +157,11 @@ run (const gchar *name,
{
gint i;
domain_register (GIMP_HELP_DEFAULT_DOMAIN, default_domain_uri);
domain_register (GIMP_HELP_DEFAULT_DOMAIN, default_domain_uri, NULL);
for (i = 0; i < num_domain_names; i++)
{
domain_register (domain_names[i], domain_uris[i]);
domain_register (domain_names[i], domain_uris[i], NULL);
}
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment