GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit d457b9eb authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/config/Makefile.am new files featuring a simple config file writer.

2003-03-05  Sven Neumann  <sven@gimp.org>

	* app/config/Makefile.am
	* app/config/gimpconfigwriter.[ch]: new files featuring a simple
	config file writer.

	* app/config/gimpconfig-serialize.[ch]
	* app/config/gimpconfig.[ch]: changed the serialize routines to
	use a GimpConfigWriter instead of passing around a file descriptor
	and the indentation level.

	* app/config/config-types.h
	* app/config/gimpconfig-deserialize.c
	* app/config/gimpconfig-dump.c
	* app/config/gimpconfig-utils.c
	* app/config/gimprc.c
	* app/config/gimpscanner.c
	* app/config/test-config.c
	* app/core/gimp-documents.c
	* app/core/gimp-parasites.c
	* app/core/gimpcontainer.c
	* app/core/gimpcontext.c
	* app/core/gimpdocumentlist.c
	* app/core/gimpparasitelist.c
	* app/gui/test-commands.c
	* app/tools/tool_options.c
	* app/widgets/gimpdevices.c: changed accordingly.

	* libgimpwidgets/gimpwidgets.c: documentation updates.

	* app/core/gimpitem.c: removed a redundant type-check.
parent 614ff006
2003-03-05 Sven Neumann <sven@gimp.org>
* app/config/Makefile.am
* app/config/gimpconfigwriter.[ch]: new files featuring a simple
config file writer.
* app/config/gimpconfig-serialize.[ch]
* app/config/gimpconfig.[ch]: changed the serialize routines to
use a GimpConfigWriter instead of passing around a file descriptor
and the indentation level.
* app/config/config-types.h
* app/config/gimpconfig-deserialize.c
* app/config/gimpconfig-dump.c
* app/config/gimpconfig-utils.c
* app/config/gimprc.c
* app/config/gimpscanner.c
* app/config/test-config.c
* app/core/gimp-documents.c
* app/core/gimp-parasites.c
* app/core/gimpcontainer.c
* app/core/gimpcontext.c
* app/core/gimpdocumentlist.c
* app/core/gimpparasitelist.c
* app/gui/test-commands.c
* app/tools/tool_options.c
* app/widgets/gimpdevices.c: changed accordingly.
* libgimpwidgets/gimpwidgets.c: documentation updates.
* app/core/gimpitem.c: removed a redundant type-check.
2003-03-05 Michael Natterer <mitch@gimp.org>
* themes/Default/images/stock-channels-16.png
......@@ -19,6 +19,8 @@ libappconfig_a_SOURCES = \
gimpconfig-types.h \
gimpconfig-utils.c \
gimpconfig-utils.h \
gimpconfigwriter.c \
gimpconfigwriter.h \
gimpbaseconfig.c \
gimpbaseconfig.h \
gimpcoreconfig.c \
......
......@@ -30,5 +30,7 @@ typedef struct _GimpGuiConfig GimpGuiConfig;
typedef struct _GimpPluginConfig GimpPluginConfig;
typedef struct _GimpRc GimpRc;
typedef struct _GimpConfigWriter GimpConfigWriter;
#endif /* __CONFIG_TYPES_H__ */
......@@ -34,6 +34,8 @@
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "config-types.h"
#include "gimpconfig.h"
#include "gimpconfig-deserialize.h"
#include "gimpconfig-params.h"
......
......@@ -40,6 +40,7 @@
#include "gimpconfig-params.h"
#include "gimpconfig-serialize.h"
#include "gimpconfig-types.h"
#include "gimpconfigwriter.h"
#include "gimprc.h"
......@@ -52,15 +53,14 @@ typedef enum
} DumpFormat;
static gint dump_gimprc (DumpFormat format,
gint fd);
static void dump_gimprc_system (GObject *rc,
gint fd);
static void dump_gimprc_manpage (GObject *rc,
gint fd);
static gchar * dump_describe_param (GParamSpec *param_spec);
static void dump_with_linebreaks (gint fd,
const gchar *text);
static gint dump_gimprc (DumpFormat format);
static void dump_gimprc_system (GObject *rc,
GimpConfigWriter *writer);
static void dump_gimprc_manpage (GObject *rc,
GimpConfigWriter *writer);
static gchar * dump_describe_param (GParamSpec *param_spec);
static void dump_with_linebreaks (gint fd,
const gchar *text);
int
......@@ -102,14 +102,14 @@ main (int argc,
}
}
return dump_gimprc (format, 1);
return dump_gimprc (format);
}
static gint
dump_gimprc (DumpFormat format,
gint fd)
dump_gimprc (DumpFormat format)
{
GObject *rc;
GimpConfigWriter *writer;
GObject *rc;
if (format == DUMP_NONE)
return EXIT_SUCCESS;
......@@ -120,23 +120,30 @@ dump_gimprc (DumpFormat format,
"module-load-inhibit", "foo", /* for completeness */
NULL);
writer = gimp_config_writer_new_from_fd (1);
switch (format)
{
case DUMP_DEFAULT:
g_print ("# Dump of the GIMP default configuration\n\n");
gimp_config_serialize_properties (rc, 1, 0);
gimp_config_writer_comment (writer,
"Dump of the GIMP default configuration");
gimp_config_writer_linefeed (writer);
gimp_config_serialize_properties (rc, writer);
g_print ("\n");
break;
case DUMP_COMMENT:
dump_gimprc_system (rc, fd);
dump_gimprc_system (rc, writer);
break;
case DUMP_MANPAGE:
dump_gimprc_manpage (rc, fd);
dump_gimprc_manpage (rc, writer);
break;
default:
break;
}
gimp_config_writer_finish (writer, NULL, NULL);
g_object_unref (rc);
return EXIT_SUCCESS;
......@@ -144,33 +151,31 @@ dump_gimprc (DumpFormat format,
static const gchar *system_gimprc_header =
"# This is the system-wide gimprc file. Any change made in this file\n"
"# will affect all users of this system, provided that they are not\n"
"# overriding the default values in their personal gimprc file.\n"
"#\n"
"# Lines that start with a '#' are comments. Blank lines are ignored.\n"
"#\n"
"# By default everything in this file is commented out. The file then\n"
"# documents the default values and shows what changes are possible.\n"
"This is the system-wide gimprc file. Any change made in this file "
"will affect all users of this system, provided that they are not "
"overriding the default values in their personal gimprc file.\n"
"\n"
"# The variable ${gimp_dir} is set to the value of the environment\n"
"# variable GIMP_DIRECTORY or, if that is not set, the compiled-in\n"
"# default value is used. If GIMP_DIRECTORY is not an absolute path,\n"
"# it is interpreted relative to your home directory.\n"
"\n";
"Lines that start with a '#' are comments. Blank lines are ignored.\n"
"\n"
"By default everything in this file is commented out. The file then "
"documents the default values and shows what changes are possible.\n"
"\n"
"The variable ${gimp_dir} is set to the value of the environment "
"variable GIMP_DIRECTORY or, if that is not set, the compiled-in "
"default value is used. If GIMP_DIRECTORY is not an absolute path, "
"it is interpreted relative to your home directory.";
static void
dump_gimprc_system (GObject *rc,
gint fd)
dump_gimprc_system (GObject *rc,
GimpConfigWriter *writer)
{
GObjectClass *klass;
GParamSpec **property_specs;
GString *str;
guint n_property_specs;
guint i;
str = g_string_new (system_gimprc_header);
write (fd, str->str, str->len);
gimp_config_writer_comment (writer, system_gimprc_header);
gimp_config_writer_linefeed (writer);
klass = G_OBJECT_GET_CLASS (rc);
property_specs = g_object_class_list_properties (klass, &n_property_specs);
......@@ -183,25 +188,23 @@ dump_gimprc_system (GObject *rc,
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
g_string_truncate (str, 0);
comment = dump_describe_param (prop_spec);
if (comment)
{
gimp_config_serialize_comment (str, comment);
gimp_config_writer_comment (writer, comment);
g_free (comment);
g_string_append (str, "#\n");
write (writer->fd, "#\n", 2);
}
g_string_append (str, "# ");
write (fd, str->str, str->len);
/* kids, don't try this at home! */
write (writer->fd, "# ", 2);
if (gimp_config_serialize_property (rc, prop_spec, fd, 0))
write (fd, "\n", 1);
gimp_config_serialize_property (rc, prop_spec, writer);
gimp_config_writer_linefeed (writer);
}
g_free (property_specs);
g_string_free (str, TRUE);
}
......@@ -292,15 +295,15 @@ static const gchar *man_page_footer =
static void
dump_gimprc_manpage (GObject *rc,
gint fd)
dump_gimprc_manpage (GObject *rc,
GimpConfigWriter *writer)
{
GObjectClass *klass;
GParamSpec **property_specs;
guint n_property_specs;
guint i;
write (fd, man_page_header, strlen (man_page_header));
write (writer->fd, man_page_header, strlen (man_page_header));
klass = G_OBJECT_GET_CLASS (rc);
property_specs = g_object_class_list_properties (klass, &n_property_specs);
......@@ -313,16 +316,16 @@ dump_gimprc_manpage (GObject *rc,
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
write (fd, ".TP\n", strlen (".TP\n"));
write (writer->fd, ".TP\n", strlen (".TP\n"));
if (gimp_config_serialize_property (rc, prop_spec, fd, 0))
if (gimp_config_serialize_property (rc, prop_spec, writer))
{
write (fd, "\n", 1);
write (writer->fd, "\n", 1);
desc = dump_describe_param (prop_spec);
dump_with_linebreaks (fd, desc);
write (fd, "\n", 1);
dump_with_linebreaks (writer->fd, desc);
write (writer->fd, "\n", 1);
g_free (desc);
}
......@@ -330,8 +333,8 @@ dump_gimprc_manpage (GObject *rc,
g_free (property_specs);
write (fd, man_page_path, strlen (man_page_path));
write (fd, man_page_footer, strlen (man_page_footer));
write (writer->fd, man_page_path, strlen (man_page_path));
write (writer->fd, man_page_footer, strlen (man_page_footer));
}
......
......@@ -36,11 +36,14 @@
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "config-types.h"
#include "gimpconfig.h"
#include "gimpconfig-params.h"
#include "gimpconfig-serialize.h"
#include "gimpconfig-types.h"
#include "gimpconfig-utils.h"
#include "gimpconfigwriter.h"
static void serialize_unknown_token (const gchar *key,
......@@ -51,14 +54,13 @@ static void serialize_unknown_token (const gchar *key,
/**
* gimp_config_serialize_properties:
* @object: a #GObject.
* @fd: a file descriptor to write to.
* @writer: a #GimpConfigWriter.
*
* This function writes all object properties to the file descriptor @fd.
* This function writes all object properties to the @writer.
**/
gboolean
gimp_config_serialize_properties (GObject *object,
gint fd,
gint indent_level)
gimp_config_serialize_properties (GObject *object,
GimpConfigWriter *writer)
{
GObjectClass *klass;
GParamSpec **property_specs;
......@@ -81,8 +83,7 @@ gimp_config_serialize_properties (GObject *object,
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
if (! gimp_config_serialize_property (object, prop_spec,
fd, indent_level))
if (! gimp_config_serialize_property (object, prop_spec, writer))
return FALSE;
}
......@@ -94,15 +95,14 @@ gimp_config_serialize_properties (GObject *object,
/**
* gimp_config_serialize_changed_properties:
* @object: a #GObject.
* @fd: a file descriptor to write to.
* @writer: a #GimpConfigWriter.
*
* This function writes all object properties that have been changed from
* their default values to the file descriptor @fd.
* their default values to the @writer.
**/
gboolean
gimp_config_serialize_changed_properties (GObject *object,
gint fd,
gint indent_level)
gimp_config_serialize_changed_properties (GObject *object,
GimpConfigWriter *writer)
{
GObjectClass *klass;
GParamSpec **property_specs;
......@@ -131,8 +131,7 @@ gimp_config_serialize_changed_properties (GObject *object,
if (! g_param_value_defaults (prop_spec, &value))
{
if (! gimp_config_serialize_property (object, prop_spec,
fd, indent_level))
if (! gimp_config_serialize_property (object, prop_spec, writer))
return FALSE;
}
......@@ -148,17 +147,16 @@ gimp_config_serialize_changed_properties (GObject *object,
* gimp_config_serialize_properties_diff:
* @object: a #GObject.
* @compare: a #GObject of the same type as @object.
* @fd: a file descriptor to write to.
* @writer: a #GimpConfigWriter.
*
* This function compares @object and @compare and writes all
* properties of @object that have different values than @compare to
* the file descriptor @fd.
* the @writer.
**/
gboolean
gimp_config_serialize_properties_diff (GObject *object,
GObject *compare,
gint fd,
gint indent_level)
gimp_config_serialize_properties_diff (GObject *object,
GObject *compare,
GimpConfigWriter *writer)
{
GObjectClass *klass;
GList *diff;
......@@ -183,8 +181,7 @@ gimp_config_serialize_properties_diff (GObject *object,
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
if (! gimp_config_serialize_property (object, prop_spec,
fd, indent_level))
if (! gimp_config_serialize_property (object, prop_spec, writer))
return FALSE;
}
......@@ -195,24 +192,20 @@ gimp_config_serialize_properties_diff (GObject *object,
gboolean
gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
gint fd,
gint indent_level)
gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GimpConfigWriter *writer)
{
GTypeClass *owner_class;
GimpConfigInterface *config_iface;
GimpConfigInterface *parent_iface = NULL;
GString *str;
GValue value = { 0, };
gboolean success = FALSE;
if (! (param_spec->flags & GIMP_PARAM_SERIALIZE))
return FALSE;
str = g_string_new (NULL);
gimp_config_string_indent (str, indent_level);
g_string_append_printf (str, "(%s ", param_spec->name);
gimp_config_writer_open (writer, param_spec->name);
g_value_init (&value, param_spec->value_type);
g_object_get_property (object, param_spec->name, &value);
......@@ -249,7 +242,7 @@ gimp_config_serialize_property (GObject *object,
param_spec->param_id,
(const GValue *) &value,
param_spec,
str))
writer))
{
success = TRUE;
}
......@@ -273,48 +266,45 @@ gimp_config_serialize_property (GObject *object,
success = TRUE;
if (gimp_config_iface)
{
g_string_append_c (str, '\n');
write (fd, str->str, str->len);
g_string_truncate (str, 0);
success = gimp_config_iface->serialize (prop_object,
fd, indent_level + 1,
NULL);
success = TRUE;
}
success = gimp_config_iface->serialize (prop_object, writer, NULL);
}
else
{
GString *str = g_string_new (NULL);
success = gimp_config_serialize_value (&value, str, TRUE);
}
if (success)
gimp_config_writer_print (writer, str->str, str->len);
g_string_free (str, TRUE);
}
}
if (success)
{
g_string_append (str, ")\n");
if (write (fd, str->str, str->len) == -1)
success = FALSE;
gimp_config_writer_close (writer);
}
if (! success)
else
{
gimp_config_writer_revert (writer);
/* don't warn for empty string properties */
if (G_VALUE_HOLDS_STRING (&value))
success = TRUE;
{
success = TRUE;
}
else
g_warning ("couldn't serialize property %s::%s of type %s",
g_type_name (G_TYPE_FROM_INSTANCE (object)),
param_spec->name,
g_type_name (param_spec->value_type));
{
g_warning ("couldn't serialize property %s::%s of type %s",
g_type_name (G_TYPE_FROM_INSTANCE (object)),
param_spec->name,
g_type_name (param_spec->value_type));
}
}
g_value_unset (&value);
g_string_free (str, TRUE);
return success;
}
......@@ -467,25 +457,21 @@ gimp_config_serialize_value (const GValue *value,
/**
* gimp_config_serialize_unknown_tokens:
* @object: a #GObject.
* @fd: a file descriptor to write to.
* @writer: a #GimpConfigWriter.
*
* Writes all unknown tokens attached to #object to the file descriptor @fd.
* See gimp_config_add_unknown_token().
* Writes all unknown tokens attached to #object to the @writer. See
* gimp_config_add_unknown_token().
**/
gboolean
gimp_config_serialize_unknown_tokens (GObject *object,
gint fd,
gint indent_level)
gimp_config_serialize_unknown_tokens (GObject *object,
GimpConfigWriter *writer)
{
GString *str;
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
str = g_string_new (NULL);
gimp_config_foreach_unknown_token (object, serialize_unknown_token, str);
gimp_config_writer_linefeed (writer);
gimp_config_foreach_unknown_token (object, serialize_unknown_token, writer);
return (write (fd, str->str, str->len) != -1);
return TRUE;
}
......@@ -538,9 +524,14 @@ serialize_unknown_token (const gchar *key,
const gchar *value,
gpointer data)
{
gchar *escaped = g_strescape (value, NULL);
GimpConfigWriter *writer = data;
gchar *escaped;
escaped = g_strescape (value, NULL);
g_string_append_printf ((GString *) data, "(%s \"%s\")\n", key, escaped);
gimp_config_writer_open (writer, key);
gimp_config_writer_printf (writer, "\"%s\"", escaped);
gimp_config_writer_close (writer);
g_free (escaped);
}
......@@ -23,28 +23,25 @@
#define __GIMP_CONFIG_SERIALIZE_H__
gboolean gimp_config_serialize_properties (GObject *object,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_changed_properties (GObject *object,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_properties_diff (GObject *object,
GObject *compare,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_unknown_tokens (GObject *object,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_properties (GObject *object,
GimpConfigWriter *writer);
gboolean gimp_config_serialize_changed_properties (GObject *object,
GimpConfigWriter *writer);
gboolean gimp_config_serialize_properties_diff (GObject *object,
GObject *compare,
GimpConfigWriter *writer);
gboolean gimp_config_serialize_unknown_tokens (GObject *object,
GimpConfigWriter *writer);
gboolean gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GimpConfigWriter *writer);
gboolean gimp_config_serialize_value (const GValue *value,
GString *str,
gboolean escaped);
void gimp_config_serialize_comment (GString *str,
const gchar *comment);
gboolean gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_value (const GValue *value,
GString *str,
gboolean escaped);
void gimp_config_serialize_comment (GString *str,
const gchar *comment);
#endif /* __GIMP_CONFIG_SERIALIZE_H__ */
......@@ -27,6 +27,8 @@
#include "libgimpbase/gimpenv.h"
#include "config-types.h"
#include "gimpconfig.h"
#include "gimpconfig-utils.h"
......
......@@ -21,28 +21,19 @@
#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <glib-object.h>
#ifdef G_OS_WIN32
#include <io.h>
#endif
#include "libgimpcolor/gimpcolor.h"
#include "config-types.h"
#include "gimpconfig.h"
#include "gimpconfig-serialize.h"
#include "gimpconfig-deserialize.h"
#include "gimpconfig-utils.h"
#include "gimpconfigwriter.h"
#include "gimpscanner.h"
#include "libgimp/gimpintl.h"
......@@ -52,20 +43,19 @@
* The GimpConfig serialization and deserialization interface.
*/
static void gimp_config_iface_init (GimpConfigInterface *gimp_config_iface);
static void gimp_config_iface_init (GimpConfigInterface *gimp_config_iface);
static gboolean gimp_config_iface_serialize (GObject *object,
gint fd,
gint indent_level,
gpointer data);
static gboolean gimp_config_iface_deserialize (GObject *object,
GScanner *scanner,
gint nest_level,
gpointer data);
static GObject *gimp_config_iface_duplicate (GObject *object);
static gboolean gimp_config_iface_equal (GObject *a,
GObject *b);
static void gimp_config_iface_reset (GObject *object);
static gboolean gimp_config_iface_serialize (GObject *object,
GimpConfigWriter *writer,
gpointer data);
static gboolean gimp_config_iface_deserialize (GObject *object,
GScanner *scanner,
gint nest_level,
gpointer data);
static GObject *gimp_config_iface_duplicate (GObject *object);
static gboolean gimp_config_iface_equal (GObject *a,
GObject *b);
static void gimp_config_iface_reset (GObject *object);
GType
......@@ -106,12 +96,11 @@ gimp_config_iface_init (GimpConfigInterface *gimp_config_iface)
}
static gboolean
gimp_config_iface_serialize (GObject *object,
gint fd,
gint indent_level,
gpointer data)
gimp_config_iface_serialize (GObject *object,
GimpConfigWriter *writer,
gpointer data)
{
return gimp_config_serialize_properties (object, fd, indent_level);
return gimp_config_serialize_properties (object, writer);
}
static gboolean
......@@ -185,8 +174,8 @@ gimp_config_iface_reset (GObject *object)
* gimp_config_serialize: