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

« back to all changes in this revision

Viewing changes to plug-ins/help/gimp-help-lookup.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
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * gimp-help-lookup - a standalone gimp-help ID to filename mapper
27
27
#include <glib.h>
28
28
 
29
29
#include "libgimpbase/gimpversion.h"
30
 
 
31
 
#include "domain.h"
32
 
#include "help.h"
33
 
#include "locales.h"
34
 
 
35
 
 
36
 
static gchar * lookup (const gchar *help_domain,
37
 
                       const gchar *help_locales,
38
 
                       const gchar *help_id);
39
 
 
40
 
static void
41
 
usage (const gchar *name)
 
30
#include "libgimpbase/gimpenv.h"
 
31
 
 
32
#include "gimphelp.h"
 
33
 
 
34
 
 
35
static void    show_version (void) G_GNUC_NORETURN;
 
36
 
 
37
static gchar * lookup       (const gchar *help_domain,
 
38
                             const gchar *help_locales,
 
39
                             const gchar *help_id);
 
40
 
 
41
 
 
42
static const gchar  *help_base    = NULL;
 
43
static       gchar  *help_root    = NULL;
 
44
static const gchar  *help_locales = NULL;
 
45
static const gchar **help_ids     = NULL;
 
46
 
 
47
 
 
48
static const GOptionEntry entries[] =
42
49
{
43
 
  g_print ("gimp-help-lookup version %s\n", GIMP_VERSION);
44
 
  g_print ("Looks up a help-id in the GIMP user manual.\n\n"
45
 
           "Usage: %s [options] [help-id]\n\n", name);
46
 
  g_print ("Valid options are:\n"
47
 
           "  -h, --help                  Output this help.\n"
48
 
           "  -v, --version               Output version info.\n"
49
 
           "  -b, --base <uri>            Speficies base URI.\n"
50
 
           "  -r, --root <directory>      Speficies root directory for index files.\n"
51
 
           "  -l, --lang <language-code>  Specifies help language.\n"
52
 
           "\n");
53
 
}
 
50
  { "version", 'v', 0,
 
51
    G_OPTION_ARG_CALLBACK, (GOptionArgFunc) show_version,
 
52
    "Show version information and exit", NULL
 
53
  },
 
54
  { "base", 'b', 0,
 
55
    G_OPTION_ARG_STRING, &help_base,
 
56
    "Speficies base URI", "URI"
 
57
  },
 
58
  { "root", 'r', 0,
 
59
    G_OPTION_ARG_FILENAME, &help_root,
 
60
    "Speficies root directory for index files", "DIR"
 
61
  },
 
62
  { "lang", 'l', 0,
 
63
    G_OPTION_ARG_STRING, &help_locales,
 
64
    "Specifies help language", "LANG"
 
65
  },
 
66
  {
 
67
    G_OPTION_REMAINING, 0, 0,
 
68
    G_OPTION_ARG_STRING_ARRAY, &help_ids,
 
69
    NULL, NULL
 
70
  },
 
71
  { NULL }
 
72
};
54
73
 
55
74
 
56
75
gint
57
76
main (gint   argc,
58
77
      gchar *argv[])
59
78
{
60
 
  const gchar *help_base    = g_getenv (GIMP_HELP_ENV_URI);
61
 
  const gchar *help_locales = GIMP_HELP_DEFAULT_LOCALE;
62
 
  const gchar *help_id      = GIMP_HELP_DEFAULT_ID;
63
 
  const gchar *help_root    = DATADIR G_DIR_SEPARATOR_S GIMP_HELP_PREFIX;
64
 
  gchar       *uri;
65
 
  gint         i;
66
 
 
67
 
  for (i = 1; i < argc; i++)
 
79
  GOptionContext *context;
 
80
  gchar          *uri;
 
81
  GError         *error = NULL;
 
82
 
 
83
  help_base = g_getenv (GIMP_HELP_ENV_URI);
 
84
  help_root = g_build_path (G_DIR_SEPARATOR_S, gimp_data_directory (), GIMP_HELP_PREFIX, NULL);
 
85
 
 
86
  context = g_option_context_new ("HELP-ID");
 
87
  g_option_context_add_main_entries (context, entries, NULL);
 
88
  if (! g_option_context_parse (context, &argc, &argv, &error))
68
89
    {
69
 
      if (! strlen (argv[i]))
70
 
        continue;
71
 
 
72
 
      if (*argv[i] == '-')
73
 
        {
74
 
          const gchar *opt = argv[i] + 1;
75
 
 
76
 
          if (*opt == '-')
77
 
            opt++;
78
 
 
79
 
          switch (g_ascii_tolower (*opt))
80
 
            {
81
 
            case 'v':
82
 
              g_print ("gimp-help-lookup version %s\n", GIMP_VERSION);
83
 
              exit (EXIT_SUCCESS);
84
 
 
85
 
            case 'b':
86
 
              if (i + 1 < argc)
87
 
                {
88
 
                  help_base = argv[++i];
89
 
                  continue;
90
 
                }
91
 
              break;
92
 
 
93
 
            case 'r':
94
 
              if (i + 1 < argc)
95
 
                {
96
 
                  help_root = argv[++i];
97
 
                  continue;
98
 
                }
99
 
              break;
100
 
 
101
 
            case 'l':
102
 
              if (i + 1 < argc)
103
 
                {
104
 
                  help_locales = argv[++i];
105
 
                  continue;
106
 
                }
107
 
              break;
108
 
 
109
 
            case 'h':
110
 
            case '?':
111
 
              usage (argv[0]);
112
 
              exit (EXIT_SUCCESS);
113
 
            }
114
 
 
115
 
          g_printerr ("Error parsing the command-line options, try --help\n");
116
 
          exit (EXIT_FAILURE);
117
 
        }
118
 
      else
119
 
        {
120
 
          help_id = argv[i];
121
 
        }
 
90
      g_print ("%s\n", error->message);
 
91
      g_error_free (error);
 
92
      return EXIT_FAILURE;
122
93
    }
123
94
 
124
95
  if (help_base)
126
97
  else
127
98
    uri = g_filename_to_uri (help_root, NULL, NULL);
128
99
 
129
 
  domain_register (GIMP_HELP_DEFAULT_DOMAIN, uri, help_root);
 
100
  gimp_help_register_domain (GIMP_HELP_DEFAULT_DOMAIN, uri, help_root);
130
101
  g_free (uri);
131
102
 
132
 
  uri = lookup (GIMP_HELP_DEFAULT_DOMAIN, help_locales, help_id);
 
103
  uri = lookup (GIMP_HELP_DEFAULT_DOMAIN,
 
104
                help_locales ? help_locales : GIMP_HELP_DEFAULT_LOCALE,
 
105
                help_ids     ? help_ids[0]  : GIMP_HELP_DEFAULT_ID);
133
106
 
134
107
  if (uri)
135
108
    {
137
110
      g_free (uri);
138
111
    }
139
112
 
 
113
  g_option_context_free (context);
 
114
  g_free (help_root);
 
115
 
140
116
  return uri ? EXIT_SUCCESS : EXIT_FAILURE;
141
117
}
142
118
 
143
 
void
144
 
help_exit (void)
145
 
{
146
 
  /* nothing */
147
 
}
148
 
 
149
119
static gchar *
150
120
lookup (const gchar *help_domain,
151
121
        const gchar *help_locales,
152
122
        const gchar *help_id)
153
123
{
154
 
  HelpDomain *domain = domain_lookup (help_domain);
 
124
  GimpHelpDomain *domain = gimp_help_lookup_domain (help_domain);
155
125
 
156
126
  if (domain)
157
127
    {
158
 
      GList *locales  = locales_parse (help_locales);
159
 
      gchar *full_uri = domain_map (domain, locales, help_id);
 
128
      GList *locales  = gimp_help_parse_locales (help_locales);
 
129
      gchar *full_uri = gimp_help_domain_map (domain, locales, help_id,
 
130
                                              NULL, NULL);
160
131
 
161
132
      g_list_foreach (locales, (GFunc) g_free, NULL);
162
133
      g_list_free (locales);
166
137
 
167
138
  return NULL;
168
139
}
 
140
 
 
141
static void
 
142
show_version (void)
 
143
{
 
144
  g_print ("gimp-help-lookup version %s\n", GIMP_VERSION);
 
145
  exit (EXIT_SUCCESS);
 
146
}