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

« back to all changes in this revision

Viewing changes to app/config/gimprc-deserialize.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
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * GimpRc deserialization routines
 
5
 * Copyright (C) 2001-2002  Sven Neumann <sven@gimp.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <glib-object.h>
 
25
 
 
26
#include "libgimpcolor/gimpcolor.h"
 
27
#include "libgimpmath/gimpmath.h"
 
28
#include "libgimpconfig/gimpconfig.h"
 
29
 
 
30
#include "config-types.h"
 
31
 
 
32
#include "gimprc-deserialize.h"
 
33
#include "gimprc-unknown.h"
 
34
 
 
35
#include "gimp-intl.h"
 
36
 
 
37
 
 
38
static GTokenType gimp_rc_deserialize_unknown (GimpConfig *config,
 
39
                                               GScanner   *scanner);
 
40
 
 
41
 
 
42
gboolean
 
43
gimp_rc_deserialize (GimpConfig *config,
 
44
                     GScanner   *scanner,
 
45
                     gint        nest_level,
 
46
                     gpointer    data)
 
47
{
 
48
  GObjectClass  *klass;
 
49
  GParamSpec   **property_specs;
 
50
  guint          n_property_specs;
 
51
  guint          i;
 
52
  guint          scope_id;
 
53
  guint          old_scope_id;
 
54
  GTokenType         token;
 
55
  GTokenType         next;
 
56
 
 
57
  g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
 
58
 
 
59
  klass = G_OBJECT_GET_CLASS (config);
 
60
 
 
61
  property_specs = g_object_class_list_properties (klass, &n_property_specs);
 
62
  if (! property_specs)
 
63
    return TRUE;
 
64
 
 
65
  scope_id = g_type_qname (G_TYPE_FROM_INSTANCE (config));
 
66
  old_scope_id = g_scanner_set_scope (scanner, scope_id);
 
67
 
 
68
  for (i = 0; i < n_property_specs; i++)
 
69
    {
 
70
      GParamSpec *prop_spec = property_specs[i];
 
71
 
 
72
      if (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE)
 
73
        {
 
74
          g_scanner_scope_add_symbol (scanner, scope_id,
 
75
                                      prop_spec->name, prop_spec);
 
76
        }
 
77
    }
 
78
 
 
79
  g_free (property_specs);
 
80
 
 
81
  g_object_freeze_notify (G_OBJECT (config));
 
82
 
 
83
  token = G_TOKEN_LEFT_PAREN;
 
84
 
 
85
  while (TRUE)
 
86
    {
 
87
      next = g_scanner_peek_next_token (scanner);
 
88
 
 
89
      if (next != token &&
 
90
          ! (token == G_TOKEN_SYMBOL && next == G_TOKEN_IDENTIFIER))
 
91
        {
 
92
          break;
 
93
        }
 
94
 
 
95
      token = g_scanner_get_next_token (scanner);
 
96
 
 
97
      switch (token)
 
98
        {
 
99
        case G_TOKEN_LEFT_PAREN:
 
100
          token = G_TOKEN_SYMBOL;
 
101
          break;
 
102
 
 
103
        case G_TOKEN_IDENTIFIER:
 
104
          token = gimp_rc_deserialize_unknown (config, scanner);
 
105
          break;
 
106
 
 
107
        case G_TOKEN_SYMBOL:
 
108
          token = gimp_config_deserialize_property (config,
 
109
                                                    scanner, nest_level);
 
110
          break;
 
111
 
 
112
        case G_TOKEN_RIGHT_PAREN:
 
113
          token = G_TOKEN_LEFT_PAREN;
 
114
          break;
 
115
 
 
116
        default: /* do nothing */
 
117
          break;
 
118
        }
 
119
    }
 
120
 
 
121
  g_scanner_set_scope (scanner, old_scope_id);
 
122
 
 
123
  g_object_thaw_notify (G_OBJECT (config));
 
124
 
 
125
  if (token == G_TOKEN_NONE)
 
126
    return FALSE;
 
127
 
 
128
  /* If the unknown token value couldn't be parsed the default error
 
129
     message is rather confusing.  We try to produce something more
 
130
     meaningful here ...
 
131
   */
 
132
  if (token == G_TOKEN_STRING && next == G_TOKEN_IDENTIFIER)
 
133
    {
 
134
      g_scanner_unexp_token (scanner, G_TOKEN_SYMBOL, NULL, NULL, NULL,
 
135
                             _("fatal parse error"), TRUE);
 
136
      return FALSE;
 
137
    }
 
138
 
 
139
  return gimp_config_deserialize_return (scanner, token, nest_level);
 
140
}
 
141
 
 
142
static GTokenType
 
143
gimp_rc_deserialize_unknown (GimpConfig *config,
 
144
                             GScanner   *scanner)
 
145
{
 
146
  gchar *key;
 
147
  guint  old_scope_id;
 
148
 
 
149
  old_scope_id = g_scanner_set_scope (scanner, 0);
 
150
 
 
151
  if (g_scanner_peek_next_token (scanner) != G_TOKEN_STRING)
 
152
    return G_TOKEN_STRING;
 
153
 
 
154
  key = g_strdup (scanner->value.v_identifier);
 
155
 
 
156
  g_scanner_get_next_token (scanner);
 
157
 
 
158
  g_scanner_set_scope (scanner, old_scope_id);
 
159
 
 
160
  if (! g_utf8_validate (scanner->value.v_string, -1, NULL))
 
161
    {
 
162
      g_scanner_error (scanner,
 
163
                       _("value for token %s is not a valid UTF-8 string"),
 
164
                       key);
 
165
      g_free (key);
 
166
      return G_TOKEN_NONE;
 
167
    }
 
168
 
 
169
  gimp_rc_add_unknown_token (config, key, scanner->value.v_string);
 
170
  g_free (key);
 
171
 
 
172
  return G_TOKEN_RIGHT_PAREN;
 
173
}