1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* GimpRc deserialization routines
5
* Copyright (C) 2001-2002 Sven Neumann <sven@gimp.org>
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.
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.
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.
24
#include <glib-object.h>
26
#include "libgimpcolor/gimpcolor.h"
27
#include "libgimpmath/gimpmath.h"
28
#include "libgimpconfig/gimpconfig.h"
30
#include "config-types.h"
32
#include "gimprc-deserialize.h"
33
#include "gimprc-unknown.h"
35
#include "gimp-intl.h"
38
static GTokenType gimp_rc_deserialize_unknown (GimpConfig *config,
43
gimp_rc_deserialize (GimpConfig *config,
49
GParamSpec **property_specs;
50
guint n_property_specs;
57
g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
59
klass = G_OBJECT_GET_CLASS (config);
61
property_specs = g_object_class_list_properties (klass, &n_property_specs);
65
scope_id = g_type_qname (G_TYPE_FROM_INSTANCE (config));
66
old_scope_id = g_scanner_set_scope (scanner, scope_id);
68
for (i = 0; i < n_property_specs; i++)
70
GParamSpec *prop_spec = property_specs[i];
72
if (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE)
74
g_scanner_scope_add_symbol (scanner, scope_id,
75
prop_spec->name, prop_spec);
79
g_free (property_specs);
81
g_object_freeze_notify (G_OBJECT (config));
83
token = G_TOKEN_LEFT_PAREN;
87
next = g_scanner_peek_next_token (scanner);
90
! (token == G_TOKEN_SYMBOL && next == G_TOKEN_IDENTIFIER))
95
token = g_scanner_get_next_token (scanner);
99
case G_TOKEN_LEFT_PAREN:
100
token = G_TOKEN_SYMBOL;
103
case G_TOKEN_IDENTIFIER:
104
token = gimp_rc_deserialize_unknown (config, scanner);
108
token = gimp_config_deserialize_property (config,
109
scanner, nest_level);
112
case G_TOKEN_RIGHT_PAREN:
113
token = G_TOKEN_LEFT_PAREN;
116
default: /* do nothing */
121
g_scanner_set_scope (scanner, old_scope_id);
123
g_object_thaw_notify (G_OBJECT (config));
125
if (token == G_TOKEN_NONE)
128
/* If the unknown token value couldn't be parsed the default error
129
message is rather confusing. We try to produce something more
132
if (token == G_TOKEN_STRING && next == G_TOKEN_IDENTIFIER)
134
g_scanner_unexp_token (scanner, G_TOKEN_SYMBOL, NULL, NULL, NULL,
135
_("fatal parse error"), TRUE);
139
return gimp_config_deserialize_return (scanner, token, nest_level);
143
gimp_rc_deserialize_unknown (GimpConfig *config,
149
old_scope_id = g_scanner_set_scope (scanner, 0);
151
if (g_scanner_peek_next_token (scanner) != G_TOKEN_STRING)
152
return G_TOKEN_STRING;
154
key = g_strdup (scanner->value.v_identifier);
156
g_scanner_get_next_token (scanner);
158
g_scanner_set_scope (scanner, old_scope_id);
160
if (! g_utf8_validate (scanner->value.v_string, -1, NULL))
162
g_scanner_error (scanner,
163
_("value for token %s is not a valid UTF-8 string"),
169
gimp_rc_add_unknown_token (config, key, scanner->value.v_string);
172
return G_TOKEN_RIGHT_PAREN;