app/config/gimpconfig-deserialize.c stricter parsing.

2001-12-10  Sven Neumann  <sven@gimp.org>

	* app/config/gimpconfig-deserialize.c
	* app/config/gimpconfig.c: stricter parsing.

	* app/config/test-config.c: more output.
This commit is contained in:
Sven Neumann 2001-12-10 12:32:28 +00:00 committed by Sven Neumann
parent b6461c996c
commit 69ec8e3bd4
6 changed files with 63 additions and 21 deletions

View File

@ -1,3 +1,10 @@
2001-12-10 Sven Neumann <sven@gimp.org>
* app/config/gimpconfig-deserialize.c
* app/config/gimpconfig.c: stricter parsing.
* app/config/test-config.c: more output.
2001-12-09 Sven Neumann <sven@gimp.org> 2001-12-09 Sven Neumann <sven@gimp.org>
* autogen.sh: check for pkg.m4. * autogen.sh: check for pkg.m4.

View File

@ -140,7 +140,7 @@ gimp_config_deserialize_properties (GObject *object,
{ {
g_scanner_get_next_token (scanner); g_scanner_get_next_token (scanner);
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL, g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
"parse error", TRUE); "Fatal parse error; I'm giving up.", TRUE);
} }
if (property_specs) if (property_specs)
@ -204,13 +204,18 @@ gimp_config_deserialize_property (GObject *object,
token = gimp_config_deserialize_any (&value, prop_spec, scanner); token = gimp_config_deserialize_any (&value, prop_spec, scanner);
} }
if (token == G_TOKEN_RIGHT_PAREN) if (token == G_TOKEN_RIGHT_PAREN &&
g_object_set_property (object, prop_spec->name, &value); g_scanner_peek_next_token (scanner) == token)
{
g_object_set_property (object, prop_spec->name, &value);
}
else else
g_warning ("Couldn't deserialize property %s::%s of type %s.", {
g_type_name (G_TYPE_FROM_INSTANCE (object)), g_warning ("Couldn't deserialize property %s::%s of type %s.",
prop_spec->name, g_type_name (G_TYPE_FROM_INSTANCE (object)),
g_type_name (prop_spec->value_type)); prop_spec->name,
g_type_name (prop_spec->value_type));
}
g_value_unset (&value); g_value_unset (&value);

View File

@ -144,8 +144,8 @@ gimp_config_deserialize (GObject *object,
scanner = g_scanner_new (NULL); scanner = g_scanner_new (NULL);
scanner->config->cset_identifier_first = ( G_CSET_a_2_z "-" G_CSET_A_2_Z ); scanner->config->cset_identifier_first = ( G_CSET_a_2_z );
scanner->config->cset_identifier_nth = ( G_CSET_a_2_z "-" G_CSET_A_2_Z ); scanner->config->cset_identifier_nth = ( G_CSET_a_2_z "-_" );
g_scanner_input_file (scanner, fd); g_scanner_input_file (scanner, fd);
scanner->input_name = filename; scanner->input_name = filename;

View File

@ -28,8 +28,11 @@
#define FILENAME "foorc" #define FILENAME "foorc"
static void notify_callback (GObject *object, static void notify_callback (GObject *object,
GParamSpec *pspec); GParamSpec *pspec);
static void output_unknown_token (const gchar *key,
const gchar *value,
gpointer data);
int int
@ -37,6 +40,7 @@ main (int argc,
char *argv[]) char *argv[])
{ {
GimpBaseConfig *config; GimpBaseConfig *config;
gboolean header = TRUE;
g_type_init (); g_type_init ();
@ -54,8 +58,11 @@ main (int argc,
g_signal_connect (G_OBJECT (config), "notify", g_signal_connect (G_OBJECT (config), "notify",
G_CALLBACK (notify_callback), G_CALLBACK (notify_callback),
NULL); NULL);
gimp_config_deserialize (G_OBJECT (config), "foorc", TRUE); gimp_config_deserialize (G_OBJECT (config), FILENAME, TRUE);
gimp_config_foreach_unknown_token (G_OBJECT (config),
output_unknown_token, &header);
g_object_unref (config); g_object_unref (config);
g_print ("Done.\n"); g_print ("Done.\n");
@ -95,3 +102,21 @@ notify_callback (GObject *object,
g_type_name (G_TYPE_FROM_INSTANCE (object)), pspec->name); g_type_name (G_TYPE_FROM_INSTANCE (object)), pspec->name);
} }
} }
static void
output_unknown_token (const gchar *key,
const gchar *value,
gpointer data)
{
gboolean *header = (gboolean *) data;
gchar *escaped = g_strescape (value, NULL);
if (*header)
{
g_print (" Unknown string tokens:\n");
*header = FALSE;
}
g_print (" %s \"%s\"\n", key, value);
g_free (escaped);
}

View File

@ -140,7 +140,7 @@ gimp_config_deserialize_properties (GObject *object,
{ {
g_scanner_get_next_token (scanner); g_scanner_get_next_token (scanner);
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL, g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
"parse error", TRUE); "Fatal parse error; I'm giving up.", TRUE);
} }
if (property_specs) if (property_specs)
@ -204,13 +204,18 @@ gimp_config_deserialize_property (GObject *object,
token = gimp_config_deserialize_any (&value, prop_spec, scanner); token = gimp_config_deserialize_any (&value, prop_spec, scanner);
} }
if (token == G_TOKEN_RIGHT_PAREN) if (token == G_TOKEN_RIGHT_PAREN &&
g_object_set_property (object, prop_spec->name, &value); g_scanner_peek_next_token (scanner) == token)
{
g_object_set_property (object, prop_spec->name, &value);
}
else else
g_warning ("Couldn't deserialize property %s::%s of type %s.", {
g_type_name (G_TYPE_FROM_INSTANCE (object)), g_warning ("Couldn't deserialize property %s::%s of type %s.",
prop_spec->name, g_type_name (G_TYPE_FROM_INSTANCE (object)),
g_type_name (prop_spec->value_type)); prop_spec->name,
g_type_name (prop_spec->value_type));
}
g_value_unset (&value); g_value_unset (&value);

View File

@ -144,8 +144,8 @@ gimp_config_deserialize (GObject *object,
scanner = g_scanner_new (NULL); scanner = g_scanner_new (NULL);
scanner->config->cset_identifier_first = ( G_CSET_a_2_z "-" G_CSET_A_2_Z ); scanner->config->cset_identifier_first = ( G_CSET_a_2_z );
scanner->config->cset_identifier_nth = ( G_CSET_a_2_z "-" G_CSET_A_2_Z ); scanner->config->cset_identifier_nth = ( G_CSET_a_2_z "-_" );
g_scanner_input_file (scanner, fd); g_scanner_input_file (scanner, fd);
scanner->input_name = filename; scanner->input_name = filename;