~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/help/domain.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
4
 
 * The GIMP Help plug-in
5
 
 * Copyright (C) 1999-2004 Sven Neumann <sven@gimp.org>
6
 
 *                         Michael Natterer <mitch@gimp.org>
7
 
 *                         Henrik Brix Andersen <brix@gimp.org>
8
 
 *
9
 
 * This program is free software; you can redistribute it and/or modify
10
 
 * it under the terms of the GNU General Public License as published by
11
 
 * the Free Software Foundation; either version 2 of the License, or
12
 
 * (at your option) any later version.
13
 
 *
14
 
 * This program is distributed in the hope that it will be useful,
15
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 * GNU General Public License for more details.
18
 
 *
19
 
 * You should have received a copy of the GNU General Public License
20
 
 * along with this program; if not, write to the Free Software
21
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
 
 */
23
 
 
24
 
/*  This code is written so that it can also be compiled standalone.
25
 
 *  It shouldn't depend on libgimp.
26
 
 */
27
 
 
28
 
#include "config.h"
29
 
 
30
 
#include <string.h>
31
 
 
32
 
#include <glib.h>
33
 
 
34
 
#include "domain.h"
35
 
#include "help.h"
36
 
 
37
 
#ifdef DISABLE_NLS
38
 
#define _(String)  (String)
39
 
#else
40
 
#include "libgimp/stdplugins-intl.h"
41
 
#endif
42
 
 
43
 
 
44
 
struct _HelpDomain
45
 
{
46
 
  gchar      *help_domain;
47
 
  gchar      *help_uri;
48
 
  gchar      *help_root;
49
 
  GHashTable *help_locales;
50
 
};
51
 
 
52
 
typedef struct _HelpLocale HelpLocale;
53
 
struct _HelpLocale
54
 
{
55
 
  gchar      *locale_id;
56
 
  GHashTable *help_id_mapping;
57
 
  gchar      *help_missing;
58
 
};
59
 
 
60
 
 
61
 
/*  local function prototypes  */
62
 
 
63
 
static HelpDomain  * domain_new               (const gchar  *domain_name,
64
 
                                               const gchar  *domain_uri,
65
 
                                               const gchar  *domain_root);
66
 
static void          domain_free              (HelpDomain   *domain);
67
 
 
68
 
static HelpLocale  * domain_locale_new        (const gchar  *locale_id);
69
 
static void          domain_locale_free       (HelpLocale   *locale);
70
 
 
71
 
static HelpLocale  * domain_locale_lookup     (HelpDomain   *domain,
72
 
                                               const gchar  *locale_id);
73
 
static const gchar * domain_locale_map        (HelpLocale   *locale,
74
 
                                               const gchar  *help_id);
75
 
 
76
 
static gboolean      domain_locale_parse      (HelpDomain   *domain,
77
 
                                               HelpLocale   *locale,
78
 
                                               GError      **error);
79
 
 
80
 
static void          domain_error_set_message (GError      **error,
81
 
                                               const gchar  *format,
82
 
                                               const gchar  *filename);
83
 
 
84
 
static gchar        * filename_from_uri       (const gchar  *uri);
85
 
 
86
 
 
87
 
/*  private variables  */
88
 
 
89
 
static GHashTable  *domain_hash = NULL;
90
 
 
91
 
 
92
 
/*  public functions  */
93
 
 
94
 
void
95
 
domain_register (const gchar *domain_name,
96
 
                 const gchar *domain_uri,
97
 
                 const gchar *domain_root)
98
 
{
99
 
  g_return_if_fail (domain_name != NULL);
100
 
  g_return_if_fail (domain_uri != NULL);
101
 
 
102
 
#ifdef GIMP_HELP_DEBUG
103
 
  g_printerr ("help: registering help domain \"%s\" with base uri \"%s\"\n",
104
 
              domain_name, domain_uri);
105
 
#endif
106
 
 
107
 
  if (! domain_hash)
108
 
    domain_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
109
 
                                         g_free, (GDestroyNotify) domain_free);
110
 
 
111
 
  g_hash_table_insert (domain_hash,
112
 
                       g_strdup (domain_name),
113
 
                       domain_new (domain_name, domain_uri, domain_root));
114
 
}
115
 
 
116
 
HelpDomain *
117
 
domain_lookup (const gchar *domain_name)
118
 
{
119
 
  g_return_val_if_fail (domain_name, NULL);
120
 
 
121
 
  if (domain_hash)
122
 
    return g_hash_table_lookup (domain_hash, domain_name);
123
 
 
124
 
  return NULL;
125
 
}
126
 
 
127
 
gchar *
128
 
domain_map (HelpDomain   *domain,
129
 
            GList        *help_locales,
130
 
            const gchar  *help_id)
131
 
{
132
 
  HelpLocale  *locale = NULL;
133
 
  const gchar *ref    = NULL;
134
 
  GList       *list;
135
 
 
136
 
  g_return_val_if_fail (domain != NULL, NULL);
137
 
  g_return_val_if_fail (help_locales != NULL, NULL);
138
 
  g_return_val_if_fail (help_id != NULL, NULL);
139
 
 
140
 
  /*  first pass: look for a reference matching the help_id  */
141
 
  for (list = help_locales; list && !ref; list = list->next)
142
 
    {
143
 
      locale = domain_locale_lookup (domain, (const gchar *) list->data);
144
 
      ref = domain_locale_map (locale, help_id);
145
 
    }
146
 
 
147
 
  /*  second pass: look for a fallback                 */
148
 
  for (list = help_locales; list && !ref; list = list->next)
149
 
    {
150
 
      locale = domain_locale_lookup (domain, (const gchar *) list->data);
151
 
      ref = locale->help_missing;
152
 
    }
153
 
 
154
 
  if (ref)
155
 
    {
156
 
      return g_strconcat (domain->help_uri,  "/",
157
 
                          locale->locale_id, "/",
158
 
                          ref,
159
 
                          NULL);
160
 
    }
161
 
  else  /*  try to assemble a useful error message  */
162
 
    {
163
 
      GError *error = NULL;
164
 
 
165
 
#ifdef GIMP_HELP_DEBUG
166
 
      g_printerr ("help: help_id lookup and all fallbacks failed for '%s'\n",
167
 
                  help_id);
168
 
#endif
169
 
 
170
 
      locale = domain_locale_lookup (domain, GIMP_HELP_DEFAULT_LOCALE);
171
 
 
172
 
      if (! domain_locale_parse (domain, locale, &error))
173
 
        {
174
 
          const gchar *msg;
175
 
 
176
 
          if (error->code == G_FILE_ERROR_NOENT)
177
 
            msg = _("The GIMP help files are not installed.");
178
 
          else
179
 
            msg = _("There is a problem with the GIMP help files.");
180
 
 
181
 
          g_message ("%s\n\n%s\n\n%s",
182
 
                     msg,
183
 
                     error->message,
184
 
                     _("Please check your installation."));
185
 
 
186
 
          g_error_free (error);
187
 
 
188
 
          help_exit ();
189
 
        }
190
 
      else
191
 
        {
192
 
          g_message (_("Help ID '%s' unknown"), help_id);
193
 
        }
194
 
 
195
 
      return NULL;
196
 
    }
197
 
}
198
 
 
199
 
void
200
 
domain_exit (void)
201
 
{
202
 
  if (domain_hash)
203
 
    {
204
 
      g_hash_table_destroy (domain_hash);
205
 
      domain_hash = NULL;
206
 
    }
207
 
}
208
 
 
209
 
 
210
 
/*  private functions  */
211
 
 
212
 
static HelpDomain *
213
 
domain_new (const gchar *domain_name,
214
 
            const gchar *domain_uri,
215
 
            const gchar *domain_root)
216
 
{
217
 
  HelpDomain *domain = g_new0 (HelpDomain, 1);
218
 
 
219
 
  domain->help_domain = g_strdup (domain_name);
220
 
  domain->help_uri    = g_strdup (domain_uri);
221
 
  domain->help_root   = g_strdup (domain_root);
222
 
 
223
 
  if (domain_uri)
224
 
    {
225
 
      /*  strip trailing slash  */
226
 
      gint len = strlen (domain_uri);
227
 
 
228
 
      if (len &&
229
 
          domain_uri[len - 1] == '/')
230
 
        domain->help_uri[len - 1] = '\0';
231
 
    }
232
 
 
233
 
  return domain;
234
 
}
235
 
 
236
 
static void
237
 
domain_free (HelpDomain *domain)
238
 
{
239
 
  g_return_if_fail (domain != NULL);
240
 
 
241
 
  if (domain->help_locales)
242
 
    g_hash_table_destroy (domain->help_locales);
243
 
 
244
 
  g_free (domain->help_domain);
245
 
  g_free (domain->help_uri);
246
 
  g_free (domain->help_root);
247
 
  g_free (domain);
248
 
}
249
 
 
250
 
 
251
 
static
252
 
HelpLocale *
253
 
domain_locale_new (const gchar *locale_id)
254
 
{
255
 
  HelpLocale *locale = g_new0 (HelpLocale, 1);
256
 
 
257
 
  locale->locale_id = g_strdup (locale_id);
258
 
 
259
 
  return locale;
260
 
}
261
 
 
262
 
static void
263
 
domain_locale_free (HelpLocale *locale)
264
 
{
265
 
  if (locale->help_id_mapping)
266
 
    g_hash_table_destroy (locale->help_id_mapping);
267
 
 
268
 
  g_free (locale->locale_id);
269
 
  g_free (locale->help_missing);
270
 
}
271
 
 
272
 
static HelpLocale *
273
 
domain_locale_lookup (HelpDomain  *domain,
274
 
                      const gchar *locale_id)
275
 
{
276
 
  HelpLocale *locale = NULL;
277
 
 
278
 
  if (domain->help_locales)
279
 
    locale = g_hash_table_lookup (domain->help_locales, locale_id);
280
 
  else
281
 
    domain->help_locales =
282
 
      g_hash_table_new_full (g_str_hash, g_str_equal,
283
 
                             g_free,
284
 
                             (GDestroyNotify) domain_locale_free);
285
 
 
286
 
  if (locale)
287
 
    return locale;
288
 
 
289
 
  locale = domain_locale_new (locale_id);
290
 
  g_hash_table_insert (domain->help_locales, g_strdup (locale_id), locale);
291
 
 
292
 
  domain_locale_parse (domain, locale, NULL);
293
 
 
294
 
  return locale;
295
 
}
296
 
 
297
 
static const gchar *
298
 
domain_locale_map (HelpLocale  *locale,
299
 
                   const gchar *help_id)
300
 
{
301
 
  if (! locale->help_id_mapping)
302
 
    return NULL;
303
 
 
304
 
  return g_hash_table_lookup (locale->help_id_mapping, help_id);
305
 
}
306
 
 
307
 
 
308
 
/*  the domain mapping parser  */
309
 
 
310
 
typedef enum
311
 
{
312
 
  DOMAIN_START,
313
 
  DOMAIN_IN_HELP,
314
 
  DOMAIN_IN_ITEM,
315
 
  DOMAIN_IN_MISSING,
316
 
  DOMAIN_IN_UNKNOWN
317
 
} DomainParserState;
318
 
 
319
 
typedef struct
320
 
{
321
 
  const gchar       *filename;
322
 
  DomainParserState  state;
323
 
  DomainParserState  last_known_state;
324
 
  gint               markup_depth;
325
 
  gint               unknown_depth;
326
 
  GString           *value;
327
 
 
328
 
  HelpDomain        *domain;
329
 
  HelpLocale        *locale;
330
 
  gchar             *id_attr_name;
331
 
} DomainParser;
332
 
 
333
 
static gboolean  domain_parser_parse       (GMarkupParseContext  *context,
334
 
                                            GIOChannel           *io,
335
 
                                            GError              **error);
336
 
static void  domain_parser_start_element   (GMarkupParseContext  *context,
337
 
                                            const gchar          *element_name,
338
 
                                            const gchar         **attribute_names,
339
 
                                            const gchar         **attribute_values,
340
 
                                            gpointer              user_data,
341
 
                                            GError              **error);
342
 
static void  domain_parser_end_element     (GMarkupParseContext  *context,
343
 
                                            const gchar          *element_name,
344
 
                                            gpointer              user_data,
345
 
                                            GError              **error);
346
 
static void  domain_parser_error           (GMarkupParseContext  *context,
347
 
                                            GError               *error,
348
 
                                            gpointer              user_data);
349
 
static void  domain_parser_start_unknown   (DomainParser         *parser);
350
 
static void  domain_parser_end_unknown     (DomainParser         *parser);
351
 
static void  domain_parser_parse_namespace (DomainParser  *parser,
352
 
                                            const gchar  **names,
353
 
                                            const gchar  **values);
354
 
static void  domain_parser_parse_item      (DomainParser         *parser,
355
 
                                            const gchar         **names,
356
 
                                            const gchar         **values);
357
 
static void  domain_parser_parse_missing   (DomainParser         *parser,
358
 
                                            const gchar         **names,
359
 
                                            const gchar         **values);
360
 
 
361
 
static const GMarkupParser markup_parser =
362
 
{
363
 
  domain_parser_start_element,
364
 
  domain_parser_end_element,
365
 
  NULL,  /*  characters   */
366
 
  NULL,  /*  passthrough  */
367
 
  domain_parser_error
368
 
};
369
 
 
370
 
static gboolean
371
 
domain_locale_parse (HelpDomain  *domain,
372
 
                     HelpLocale  *locale,
373
 
                     GError     **error)
374
 
{
375
 
  GMarkupParseContext *context;
376
 
  DomainParser        *parser;
377
 
  GIOChannel          *io;
378
 
  gchar               *filename;
379
 
  gboolean             success;
380
 
 
381
 
  g_return_val_if_fail (domain != NULL, FALSE);
382
 
  g_return_val_if_fail (locale != NULL, FALSE);
383
 
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
384
 
 
385
 
  if (locale->help_id_mapping)
386
 
    {
387
 
      g_hash_table_destroy (locale->help_id_mapping);
388
 
      locale->help_id_mapping = NULL;
389
 
    }
390
 
  if (locale->help_missing)
391
 
    {
392
 
      g_free (locale->help_missing);
393
 
      locale->help_missing = NULL;
394
 
    }
395
 
 
396
 
  if (! domain->help_root)
397
 
    domain->help_root = filename_from_uri (domain->help_uri);
398
 
 
399
 
  if (! domain->help_root)
400
 
    {
401
 
      g_set_error (error, 0, 0,
402
 
                   "Cannot determine location of gimp-help.xml from '%s'",
403
 
                   domain->help_uri);
404
 
      return FALSE;
405
 
    }
406
 
 
407
 
  filename = g_build_filename (domain->help_root,
408
 
                               locale->locale_id,
409
 
                               "gimp-help.xml",
410
 
                               NULL);
411
 
 
412
 
#ifdef GIMP_HELP_DEBUG
413
 
  g_printerr ("help (%s): parsing '%s' for domain \"%s\"\n",
414
 
              locale->locale_id,
415
 
              filename,
416
 
              domain->help_domain);
417
 
#endif
418
 
 
419
 
  io = g_io_channel_new_file (filename, "r", error);
420
 
  if (! io)
421
 
    {
422
 
      domain_error_set_message (error,
423
 
                                _("Could not open '%s' for reading: %s"),
424
 
                                filename);
425
 
      g_free (filename);
426
 
      return FALSE;
427
 
    }
428
 
 
429
 
  parser = g_new0 (DomainParser, 1);
430
 
 
431
 
  parser->filename     = filename;
432
 
  parser->value        = g_string_new (NULL);
433
 
  parser->id_attr_name = g_strdup ("id");
434
 
  parser->domain       = domain;
435
 
  parser->locale       = locale;
436
 
 
437
 
  context = g_markup_parse_context_new (&markup_parser, 0, parser, NULL);
438
 
 
439
 
  success = domain_parser_parse (context, io, error);
440
 
 
441
 
  g_markup_parse_context_free (context);
442
 
  g_io_channel_unref (io);
443
 
 
444
 
  g_string_free (parser->value, TRUE);
445
 
  g_free (parser->id_attr_name);
446
 
  g_free (parser);
447
 
 
448
 
  if (! success)
449
 
    domain_error_set_message (error, _("Parse error in '%s':\n%s"), filename);
450
 
 
451
 
  g_free (filename);
452
 
 
453
 
  return success;
454
 
}
455
 
 
456
 
static gboolean
457
 
domain_parser_parse (GMarkupParseContext  *context,
458
 
                     GIOChannel           *io,
459
 
                     GError              **error)
460
 
{
461
 
  GIOStatus  status;
462
 
  gsize      len;
463
 
  gchar      buffer[4096];
464
 
 
465
 
  while (TRUE)
466
 
    {
467
 
      status = g_io_channel_read_chars (io,
468
 
                                        buffer, sizeof (buffer), &len, error);
469
 
 
470
 
      switch (status)
471
 
        {
472
 
        case G_IO_STATUS_ERROR:
473
 
          return FALSE;
474
 
        case G_IO_STATUS_EOF:
475
 
          return g_markup_parse_context_end_parse (context, error);
476
 
        case G_IO_STATUS_NORMAL:
477
 
          if (! g_markup_parse_context_parse (context, buffer, len, error))
478
 
            return FALSE;
479
 
          break;
480
 
        case G_IO_STATUS_AGAIN:
481
 
          break;
482
 
        }
483
 
    }
484
 
 
485
 
  return TRUE;
486
 
}
487
 
 
488
 
static void
489
 
domain_parser_start_element (GMarkupParseContext *context,
490
 
                             const gchar         *element_name,
491
 
                             const gchar        **attribute_names,
492
 
                             const gchar        **attribute_values,
493
 
                             gpointer             user_data,
494
 
                             GError             **error)
495
 
{
496
 
  DomainParser *parser = (DomainParser *) user_data;
497
 
 
498
 
  switch (parser->state)
499
 
    {
500
 
    case DOMAIN_START:
501
 
      if (strcmp (element_name, "gimp-help") == 0)
502
 
        {
503
 
          parser->state = DOMAIN_IN_HELP;
504
 
          domain_parser_parse_namespace (parser,
505
 
                                         attribute_names, attribute_values);
506
 
        }
507
 
      else
508
 
        domain_parser_start_unknown (parser);
509
 
      break;
510
 
 
511
 
    case DOMAIN_IN_HELP:
512
 
      if (strcmp (element_name, "help-item") == 0)
513
 
        {
514
 
          parser->state = DOMAIN_IN_ITEM;
515
 
          domain_parser_parse_item (parser,
516
 
                                    attribute_names, attribute_values);
517
 
        }
518
 
      else if (strcmp (element_name, "help-missing") == 0)
519
 
        {
520
 
          parser->state = DOMAIN_IN_MISSING;
521
 
          domain_parser_parse_missing (parser,
522
 
                                       attribute_names, attribute_values);
523
 
        }
524
 
      else
525
 
        domain_parser_start_unknown (parser);
526
 
      break;
527
 
 
528
 
    case DOMAIN_IN_ITEM:
529
 
    case DOMAIN_IN_MISSING:
530
 
    case DOMAIN_IN_UNKNOWN:
531
 
      domain_parser_start_unknown (parser);
532
 
      break;
533
 
    }
534
 
}
535
 
 
536
 
static void
537
 
domain_parser_end_element (GMarkupParseContext *context,
538
 
                           const gchar         *element_name,
539
 
                           gpointer             user_data,
540
 
                           GError             **error)
541
 
{
542
 
  DomainParser *parser = (DomainParser *) user_data;
543
 
 
544
 
  switch (parser->state)
545
 
    {
546
 
    case DOMAIN_START:
547
 
      g_warning ("domain_parser: This shouldn't happen.");
548
 
      break;
549
 
 
550
 
    case DOMAIN_IN_HELP:
551
 
      parser->state = DOMAIN_START;
552
 
      break;
553
 
 
554
 
    case DOMAIN_IN_ITEM:
555
 
    case DOMAIN_IN_MISSING:
556
 
      parser->state = DOMAIN_IN_HELP;
557
 
      break;
558
 
 
559
 
    case DOMAIN_IN_UNKNOWN:
560
 
      domain_parser_end_unknown (parser);
561
 
      break;
562
 
    }
563
 
}
564
 
 
565
 
static void
566
 
domain_parser_error (GMarkupParseContext *context,
567
 
                     GError              *error,
568
 
                     gpointer             user_data)
569
 
{
570
 
  DomainParser *parser = (DomainParser *) user_data;
571
 
 
572
 
  g_printerr ("help (parsing %s): %s", parser->filename, error->message);
573
 
}
574
 
 
575
 
static void
576
 
domain_parser_start_unknown (DomainParser *parser)
577
 
{
578
 
  if (parser->unknown_depth == 0)
579
 
    parser->last_known_state = parser->state;
580
 
 
581
 
  parser->state = DOMAIN_IN_UNKNOWN;
582
 
  parser->unknown_depth++;
583
 
}
584
 
 
585
 
static void
586
 
domain_parser_end_unknown (DomainParser *parser)
587
 
{
588
 
  g_assert (parser->unknown_depth > 0 && parser->state == DOMAIN_IN_UNKNOWN);
589
 
 
590
 
  parser->unknown_depth--;
591
 
 
592
 
  if (parser->unknown_depth == 0)
593
 
    parser->state = parser->last_known_state;
594
 
}
595
 
 
596
 
static void
597
 
domain_parser_parse_namespace (DomainParser  *parser,
598
 
                               const gchar  **names,
599
 
                               const gchar  **values)
600
 
{
601
 
  for (; *names && *values; names++, values++)
602
 
    {
603
 
      if (! strncmp (*names, "xmlns:", 6) &&
604
 
          ! strcmp (*values, parser->domain->help_domain))
605
 
        {
606
 
          g_free (parser->id_attr_name);
607
 
          parser->id_attr_name = g_strdup_printf ("%s:id", *names + 6);
608
 
 
609
 
#ifdef GIMP_HELP_DEBUG
610
 
          g_printerr ("help (%s): id attribute name for \"%s\" is \"%s\"\n",
611
 
                      parser->locale->locale_id,
612
 
                      parser->domain->help_domain,
613
 
                      parser->id_attr_name);
614
 
#endif
615
 
        }
616
 
    }
617
 
}
618
 
 
619
 
static void
620
 
domain_parser_parse_item (DomainParser  *parser,
621
 
                          const gchar  **names,
622
 
                          const gchar  **values)
623
 
{
624
 
  const gchar *id  = NULL;
625
 
  const gchar *ref = NULL;
626
 
 
627
 
  for (; *names && *values; names++, values++)
628
 
    {
629
 
      if (! strcmp (*names, parser->id_attr_name))
630
 
        id = *values;
631
 
 
632
 
      if (! strcmp (*names, "ref"))
633
 
        ref = *values;
634
 
    }
635
 
 
636
 
  if (id && ref)
637
 
    {
638
 
      if (! parser->locale->help_id_mapping)
639
 
        parser->locale->help_id_mapping = g_hash_table_new_full (g_str_hash,
640
 
                                                                 g_str_equal,
641
 
                                                                 g_free,
642
 
                                                                 g_free);
643
 
 
644
 
      g_hash_table_insert (parser->locale->help_id_mapping,
645
 
                           g_strdup (id), g_strdup (ref));
646
 
 
647
 
#ifdef GIMP_HELP_DEBUG
648
 
      g_printerr ("help (%s): added mapping \"%s\" -> \"%s\"\n",
649
 
                  parser->locale->locale_id, id, ref);
650
 
#endif
651
 
    }
652
 
}
653
 
 
654
 
static void
655
 
domain_parser_parse_missing (DomainParser  *parser,
656
 
                             const gchar  **names,
657
 
                             const gchar  **values)
658
 
{
659
 
  const gchar *ref = NULL;
660
 
 
661
 
  for (; *names && *values; names++, values++)
662
 
    {
663
 
      if (! strcmp (*names, "ref"))
664
 
        ref = *values;
665
 
    }
666
 
 
667
 
  if (ref &&
668
 
      parser->locale->help_missing == NULL)
669
 
    {
670
 
      parser->locale->help_missing = g_strdup (ref);
671
 
 
672
 
#ifdef GIMP_HELP_DEBUG
673
 
      g_printerr ("help (%s): added fallback for missing help -> \"%s\"\n",
674
 
                  parser->locale->locale_id, ref);
675
 
#endif
676
 
    }
677
 
}
678
 
 
679
 
static void
680
 
domain_error_set_message (GError      **error,
681
 
                          const gchar  *format,
682
 
                          const gchar  *filename)
683
 
{
684
 
  if (error && *error)
685
 
    {
686
 
      gchar *name = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
687
 
      gchar *msg  = g_strdup_printf (format, name, (*error)->message);
688
 
 
689
 
      g_free (name);
690
 
 
691
 
      g_free ((*error)->message);
692
 
      (*error)->message = msg;
693
 
    }
694
 
}
695
 
 
696
 
static gchar *
697
 
filename_from_uri (const gchar *uri)
698
 
{
699
 
  gchar *filename;
700
 
  gchar *hostname;
701
 
 
702
 
  g_return_val_if_fail (uri != NULL, NULL);
703
 
 
704
 
  filename = g_filename_from_uri (uri, &hostname, NULL);
705
 
 
706
 
  if (!filename)
707
 
    return NULL;
708
 
 
709
 
  if (hostname)
710
 
    {
711
 
      /*  we have a file: URI with a hostname                           */
712
 
#ifdef G_OS_WIN32
713
 
      /*  on Win32, create a valid UNC path and use it as the filename  */
714
 
 
715
 
      gchar *tmp = g_build_filename ("//", hostname, filename, NULL);
716
 
 
717
 
      g_free (filename);
718
 
      filename = tmp;
719
 
#else
720
 
      /*  otherwise return NULL, caller should use URI then             */
721
 
      g_free (filename);
722
 
      filename = NULL;
723
 
#endif
724
 
 
725
 
      g_free (hostname);
726
 
    }
727
 
 
728
 
  return filename;
729
 
}