fixed creation of config file, added new function

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

	* app/config/gimpconfigwriter.[ch]: fixed creation of config file,
	added new function gimp_config_writer_string() and improved
	gimp_config_writer_linefeed().

	* app/config/gimpconfig-serialize.c
	* app/core/gimpcontext.c
	* app/core/gimpdocumentlist.c: use gimp_config_writer_string()
	instead of escaping the string manually.

	* app/core/gimpunits.c (gimp_unitrc_save): use a GimpConfigWriter.

	* app/plug-in/plug-in-rc.[ch] (plug_in_rc_write)
	* app/plug-in/plug-ins.c: use a GimpConfigWriter.
This commit is contained in:
Sven Neumann 2003-03-10 15:48:16 +00:00 committed by Sven Neumann
parent 1522b841fa
commit 6f3f9556c4
15 changed files with 309 additions and 236 deletions

View File

@ -1,3 +1,19 @@
2003-03-10 Sven Neumann <sven@gimp.org>
* app/config/gimpconfigwriter.[ch]: fixed creation of config file,
added new function gimp_config_writer_string() and improved
gimp_config_writer_linefeed().
* app/config/gimpconfig-serialize.c
* app/core/gimpcontext.c
* app/core/gimpdocumentlist.c: use gimp_config_writer_string()
instead of escaping the string manually.
* app/core/gimpunits.c (gimp_unitrc_save): use a GimpConfigWriter.
* app/plug-in/plug-in-rc.[ch] (plug_in_rc_write)
* app/plug-in/plug-ins.c: use a GimpConfigWriter.
2003-03-10 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpdataeditor.[ch]: added "gboolean data_editable"

View File

@ -524,14 +524,9 @@ serialize_unknown_token (const gchar *key,
const gchar *value,
gpointer data)
{
GimpConfigWriter *writer = data;
gchar *escaped;
escaped = g_strescape (value, NULL);
GimpConfigWriter *writer = data;
gimp_config_writer_open (writer, key);
gimp_config_writer_printf (writer, "\"%s\"", escaped);
gimp_config_writer_string (writer, value);
gimp_config_writer_close (writer);
g_free (escaped);
}

View File

@ -80,7 +80,7 @@ gimp_config_writer_new (const gchar *filename,
}
else
{
fd = open (filename, O_WRONLY);
fd = creat (filename, 0644);
if (fd == -1)
{
@ -190,11 +190,35 @@ gimp_config_writer_printf (GimpConfigWriter *writer,
g_free (buffer);
}
void
gimp_config_writer_string (GimpConfigWriter *writer,
const gchar *string)
{
g_return_if_fail (writer != NULL);
if (writer->error)
return;
if (string)
{
gchar *escaped = g_strescape (string, NULL);
g_string_append_printf (writer->buffer, " \"%s\"", escaped);
g_free (escaped);
}
else
{
g_string_append_len (writer->buffer, " \"\"", 3);
}
}
void
gimp_config_writer_revert (GimpConfigWriter *writer)
{
g_return_if_fail (writer != NULL);
g_return_if_fail (writer->depth > 0);
g_return_if_fail (writer->marker != -1);
if (writer->error)
return;
@ -202,6 +226,7 @@ gimp_config_writer_revert (GimpConfigWriter *writer)
g_string_truncate (writer->buffer, writer->marker);
writer->depth--;
writer->marker = -1;
}
void
@ -269,15 +294,21 @@ void
gimp_config_writer_linefeed (GimpConfigWriter *writer)
{
g_return_if_fail (writer != NULL);
g_return_if_fail (writer->depth == 0);
g_return_if_fail (writer->buffer->len == 0);
if (writer->error)
return;
if (write (writer->fd, "\n", 1) < 0)
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
if (writer->buffer->len == 0)
{
if (write (writer->fd, "\n", 1) < 0)
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
}
else
{
g_string_append_c (writer->buffer, '\n');
gimp_config_string_indent (writer->buffer, writer->depth);
}
}
void

View File

@ -50,6 +50,8 @@ void gimp_config_writer_print (GimpConfigWriter *writer,
void gimp_config_writer_printf (GimpConfigWriter *writer,
const gchar *format,
...);
void gimp_config_writer_string (GimpConfigWriter *writer,
const gchar *string);
void gimp_config_writer_revert (GimpConfigWriter *writer);
void gimp_config_writer_close (GimpConfigWriter *writer);

View File

@ -21,8 +21,6 @@
#include "config.h"
#include <stdio.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
@ -33,6 +31,7 @@
#include "gimpunit.h"
#include "gimpunits.h"
#include "config/gimpconfigwriter.h"
#include "config/gimpscanner.h"
#include "libgimp/gimpintl.h"
@ -167,27 +166,29 @@ gimp_unitrc_load (Gimp *gimp)
void
gimp_unitrc_save (Gimp *gimp)
{
gint i;
gchar *filename;
FILE *fp;
GimpConfigWriter *writer;
gchar *filename;
gint i;
g_return_if_fail (GIMP_IS_GIMP (gimp));
filename = gimp_personal_rc_file ("unitrc");
fp = fopen (filename, "w");
g_free (filename);
if (!fp)
return;
writer = gimp_config_writer_new (filename,
TRUE,
"GIMP units\n\n"
"This file contains the user unit database. "
"You can edit this list with the unit "
"editor. You are not supposed to edit it "
"manually, but of course you can do.\n"
"This file will be entirely rewritten every "
"time you quit the gimp.",
NULL);
fprintf (fp,
"# GIMP unitrc\n"
"#\n"
"# This file contains your user unit database. You can\n"
"# modify this list with the unit editor. You are not\n"
"# supposed to edit it manually, but of course you can do.\n"
"# This file will be entirely rewritten every time you\n"
"# quit the gimp.\n\n");
g_free (filename);
if (!writer)
return;
/* save user defined units */
for (i = gimp_unit_get_number_of_built_in_units ();
@ -198,28 +199,41 @@ gimp_unitrc_save (Gimp *gimp)
{
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
fprintf (fp,
"(unit-info \"%s\"\n"
" (factor %s)\n"
" (digits %d)\n"
" (symbol \"%s\")\n"
" (abbreviation \"%s\")\n"
" (singular \"%s\")\n"
" (plural \"%s\"))\n\n",
gimp_unit_get_identifier (i),
g_ascii_formatd (buf, sizeof (buf), "%f",
gimp_unit_get_factor (i)),
gimp_unit_get_digits (i),
gimp_unit_get_symbol (i),
gimp_unit_get_abbreviation (i),
gimp_unit_get_singular (i),
gimp_unit_get_plural (i));
gimp_config_writer_open (writer, "unit-info");
gimp_config_writer_string (writer, gimp_unit_get_identifier (i));
gimp_config_writer_open (writer, "factor");
gimp_config_writer_print (writer,
g_ascii_formatd (buf, sizeof (buf), "%f",
gimp_unit_get_factor (i)),
-1);
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "digits");
gimp_config_writer_printf (writer, "%d", gimp_unit_get_digits (i));
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "symbol");
gimp_config_writer_string (writer, gimp_unit_get_symbol (i));
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "abbreviation");
gimp_config_writer_string (writer, gimp_unit_get_abbreviation (i));
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "singular");
gimp_config_writer_string (writer, gimp_unit_get_singular (i));
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "plural");
gimp_config_writer_string (writer, gimp_unit_get_plural (i));
gimp_config_writer_close (writer);
gimp_config_writer_close (writer);
}
}
fprintf (fp, "# end of unitrc\n");
fclose (fp);
gimp_config_writer_finish (writer, "end of units", NULL);
}

View File

@ -1010,7 +1010,7 @@ gimp_context_serialize_property (GObject *object,
case GIMP_CONTEXT_PROP_PATTERN:
case GIMP_CONTEXT_PROP_GRADIENT:
case GIMP_CONTEXT_PROP_PALETTE:
serialize_obj = g_value_get_object (value);
serialize_obj = g_value_get_object (value);
break;
default:
@ -1019,11 +1019,7 @@ gimp_context_serialize_property (GObject *object,
if (serialize_obj)
{
gchar *escaped;
escaped = g_strescape (gimp_object_get_name (serialize_obj), NULL);
gimp_config_writer_printf (writer, "\"%s\"", escaped);
g_free (escaped);
gimp_config_writer_string (writer, gimp_object_get_name (serialize_obj));
}
else
{

View File

@ -111,14 +111,8 @@ gimp_document_list_serialize (GObject *object,
for (list = GIMP_LIST (object)->list; list; list = list->next)
{
gchar *escaped;
gimp_config_writer_open (writer, document_symbol);
escaped = g_strescape (GIMP_OBJECT (list->data)->name, NULL);
gimp_config_writer_printf (writer, "\"%s\"", escaped);
g_free (escaped);
gimp_config_writer_string (writer, GIMP_OBJECT (list->data)->name);
gimp_config_writer_close (writer);
}

View File

@ -21,8 +21,6 @@
#include "config.h"
#include <stdio.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
@ -33,6 +31,7 @@
#include "gimpunit.h"
#include "gimpunits.h"
#include "config/gimpconfigwriter.h"
#include "config/gimpscanner.h"
#include "libgimp/gimpintl.h"
@ -167,27 +166,29 @@ gimp_unitrc_load (Gimp *gimp)
void
gimp_unitrc_save (Gimp *gimp)
{
gint i;
gchar *filename;
FILE *fp;
GimpConfigWriter *writer;
gchar *filename;
gint i;
g_return_if_fail (GIMP_IS_GIMP (gimp));
filename = gimp_personal_rc_file ("unitrc");
fp = fopen (filename, "w");
g_free (filename);
if (!fp)
return;
writer = gimp_config_writer_new (filename,
TRUE,
"GIMP units\n\n"
"This file contains the user unit database. "
"You can edit this list with the unit "
"editor. You are not supposed to edit it "
"manually, but of course you can do.\n"
"This file will be entirely rewritten every "
"time you quit the gimp.",
NULL);
fprintf (fp,
"# GIMP unitrc\n"
"#\n"
"# This file contains your user unit database. You can\n"
"# modify this list with the unit editor. You are not\n"
"# supposed to edit it manually, but of course you can do.\n"
"# This file will be entirely rewritten every time you\n"
"# quit the gimp.\n\n");
g_free (filename);
if (!writer)
return;
/* save user defined units */
for (i = gimp_unit_get_number_of_built_in_units ();
@ -198,28 +199,41 @@ gimp_unitrc_save (Gimp *gimp)
{
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
fprintf (fp,
"(unit-info \"%s\"\n"
" (factor %s)\n"
" (digits %d)\n"
" (symbol \"%s\")\n"
" (abbreviation \"%s\")\n"
" (singular \"%s\")\n"
" (plural \"%s\"))\n\n",
gimp_unit_get_identifier (i),
g_ascii_formatd (buf, sizeof (buf), "%f",
gimp_unit_get_factor (i)),
gimp_unit_get_digits (i),
gimp_unit_get_symbol (i),
gimp_unit_get_abbreviation (i),
gimp_unit_get_singular (i),
gimp_unit_get_plural (i));
gimp_config_writer_open (writer, "unit-info");
gimp_config_writer_string (writer, gimp_unit_get_identifier (i));
gimp_config_writer_open (writer, "factor");
gimp_config_writer_print (writer,
g_ascii_formatd (buf, sizeof (buf), "%f",
gimp_unit_get_factor (i)),
-1);
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "digits");
gimp_config_writer_printf (writer, "%d", gimp_unit_get_digits (i));
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "symbol");
gimp_config_writer_string (writer, gimp_unit_get_symbol (i));
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "abbreviation");
gimp_config_writer_string (writer, gimp_unit_get_abbreviation (i));
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "singular");
gimp_config_writer_string (writer, gimp_unit_get_singular (i));
gimp_config_writer_close (writer);
gimp_config_writer_open (writer, "plural");
gimp_config_writer_string (writer, gimp_unit_get_plural (i));
gimp_config_writer_close (writer);
gimp_config_writer_close (writer);
}
}
fprintf (fp, "# end of unitrc\n");
fclose (fp);
gimp_config_writer_finish (writer, "end of units", NULL);
}

View File

@ -135,7 +135,7 @@ plug_ins_init (Gimp *gimp,
(* status_callback) (_("Resource configuration"), filename, -1);
plug_in_rc_parse (gimp, filename);
/* query any plug-ins that have changed since we last wrote out
/* Query any plug-ins that have changed since we last wrote out
* the pluginrc file.
*/
(* status_callback) (_("Querying new Plug-ins"), "", 0);
@ -206,10 +206,17 @@ plug_ins_init (Gimp *gimp,
/* write the pluginrc file if necessary */
if (gimp->write_pluginrc)
{
GError *error = NULL;
if (gimp->be_verbose)
g_print (_("writing \"%s\"\n"), filename);
plug_in_rc_write (gimp->plug_in_defs, filename);
if (! plug_in_rc_write (gimp->plug_in_defs, filename, &error))
{
g_message ("%s", error->message);
g_error_free (error);
}
gimp->write_pluginrc = FALSE;
}
@ -295,7 +302,7 @@ plug_ins_init (Gimp *gimp,
(proc_def->db_info.proc_type == GIMP_EXTENSION))
{
if (gimp->be_verbose)
g_print (_("Starting extension: \"%s\""), proc_def->db_info.name);
g_print (_("Starting extension: \"%s\"\n"), proc_def->db_info.name);
(* status_callback) (NULL, proc_def->db_info.name, nth / n_plugins);

View File

@ -21,12 +21,11 @@
#include "config.h"
#include <stdio.h>
#include <glib-object.h>
#include "plug-in-types.h"
#include "config/gimpconfigwriter.h"
#include "config/gimpscanner.h"
#include "core/gimp.h"
@ -380,57 +379,26 @@ plug_in_has_init_deserialize (GScanner *scanner,
/* serialize functions */
static void
plug_in_write_rc_string (FILE *fp,
gchar *str)
{
fputc ('"', fp);
if (str)
while (*str)
{
if (*str == '\n')
{
fputc ('\\', fp);
fputc ('n', fp);
}
else if (*str == '\r')
{
fputc ('\\', fp);
fputc ('r', fp);
}
else if (*str == '\032') /* ^Z is problematic on Windows */
{
fputc ('\\', fp);
fputc ('z', fp);
}
else
{
if ((*str == '"') || (*str == '\\'))
fputc ('\\', fp);
fputc (*str, fp);
}
str += 1;
}
fputc ('"', fp);
}
gboolean
plug_in_rc_write (GSList *plug_in_defs,
const gchar *filename)
plug_in_rc_write (GSList *plug_in_defs,
const gchar *filename,
GError **error)
{
FILE *fp;
PlugInDef *plug_in_def;
PlugInProcDef *proc_def;
GSList *list;
GSList *tmp2;
gint i;
GimpConfigWriter *writer;
PlugInDef *plug_in_def;
PlugInProcDef *proc_def;
GSList *list;
GSList *list2;
gint i;
g_return_val_if_fail (filename != NULL, FALSE);
fp = fopen (filename, "w");
if (!fp)
writer = gimp_config_writer_new (filename,
FALSE,
"GIMP plug-ins\n\n"
"This file can safely be removed and will "
"be automatically regenerated by querying "
"the installed plugins.",
error);
if (!writer)
return FALSE;
for (list = plug_in_defs; list; list = list->next)
@ -439,102 +407,102 @@ plug_in_rc_write (GSList *plug_in_defs,
if (plug_in_def->proc_defs)
{
fprintf (fp, "(plug-in-def ");
plug_in_write_rc_string (fp, plug_in_def->prog);
fprintf (fp, " %ld", (long) plug_in_def->mtime);
gimp_config_writer_open (writer, "plug-in-def");
gimp_config_writer_string (writer, plug_in_def->prog);
gimp_config_writer_printf (writer, "%ld", plug_in_def->mtime);
tmp2 = plug_in_def->proc_defs;
if (tmp2)
fprintf (fp, "\n");
while (tmp2)
for (list2 = plug_in_def->proc_defs; list2; list2 = list2->next)
{
proc_def = tmp2->data;
tmp2 = tmp2->next;
proc_def = list2->data;
fprintf (fp, "\t(proc-def \"%s\" %d\n",
proc_def->db_info.name, proc_def->db_info.proc_type);
fprintf (fp, "\t\t");
plug_in_write_rc_string (fp, proc_def->db_info.blurb);
fprintf (fp, "\n\t\t");
plug_in_write_rc_string (fp, proc_def->db_info.help);
fprintf (fp, "\n\t\t");
plug_in_write_rc_string (fp, proc_def->db_info.author);
fprintf (fp, "\n\t\t");
plug_in_write_rc_string (fp, proc_def->db_info.copyright);
fprintf (fp, "\n\t\t");
plug_in_write_rc_string (fp, proc_def->db_info.date);
fprintf (fp, "\n\t\t");
plug_in_write_rc_string (fp, proc_def->menu_path);
fprintf (fp, "\n\t\t");
plug_in_write_rc_string (fp, proc_def->extensions);
fprintf (fp, "\n\t\t");
plug_in_write_rc_string (fp, proc_def->prefixes);
fprintf (fp, "\n\t\t");
plug_in_write_rc_string (fp, proc_def->magics);
fprintf (fp, "\n\t\t");
plug_in_write_rc_string (fp, proc_def->image_types);
fprintf (fp, "\n\t\t%d %d\n",
proc_def->db_info.num_args, proc_def->db_info.num_values);
gimp_config_writer_open (writer, "proc-def");
gimp_config_writer_printf (writer, "\"%s\" %d",
proc_def->db_info.name,
proc_def->db_info.proc_type);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->db_info.blurb);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->db_info.help);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->db_info.author);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->db_info.copyright);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->db_info.date);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->menu_path);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->extensions);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->prefixes);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->magics);
gimp_config_writer_linefeed (writer);
gimp_config_writer_string (writer, proc_def->image_types);
gimp_config_writer_linefeed (writer);
gimp_config_writer_printf (writer, "%d %d",
proc_def->db_info.num_args,
proc_def->db_info.num_values);
for (i = 0; i < proc_def->db_info.num_args; i++)
{
fprintf (fp, "\t\t(proc-arg %d ",
proc_def->db_info.args[i].arg_type);
gimp_config_writer_open (writer, "proc-arg");
gimp_config_writer_printf (writer, "%d",
proc_def->db_info.args[i].arg_type);
plug_in_write_rc_string (fp, proc_def->db_info.args[i].name);
plug_in_write_rc_string (fp, proc_def->db_info.args[i].description);
gimp_config_writer_string (writer,
proc_def->db_info.args[i].name);
gimp_config_writer_string (writer,
proc_def->db_info.args[i].description);
fprintf (fp, ")%s",
(proc_def->db_info.num_values ||
(i < (proc_def->db_info.num_args - 1))) ? "\n" : "");
gimp_config_writer_close (writer);
}
for (i = 0; i < proc_def->db_info.num_values; i++)
{
fprintf (fp, "\t\t(proc-arg %d ",
proc_def->db_info.values[i].arg_type);
gimp_config_writer_open (writer, "proc-arg");
gimp_config_writer_printf (writer, "%d",
proc_def->db_info.values[i].arg_type);
plug_in_write_rc_string (fp, proc_def->db_info.values[i].name);
plug_in_write_rc_string (fp, proc_def->db_info.values[i].description);
gimp_config_writer_string (writer,
proc_def->db_info.values[i].name);
gimp_config_writer_string (writer,
proc_def->db_info.values[i].description);
fprintf (fp, ")%s", (i < (proc_def->db_info.num_values - 1)) ? "\n" : "");
gimp_config_writer_close (writer);
}
fprintf (fp, ")");
if (tmp2)
fprintf (fp, "\n");
gimp_config_writer_close (writer);
}
if (plug_in_def->locale_domain)
{
fprintf (fp, "\n\t(locale-def \"%s\"", plug_in_def->locale_domain);
gimp_config_writer_open (writer, "locale-def");
gimp_config_writer_string (writer, plug_in_def->locale_domain);
if (plug_in_def->locale_path)
fprintf (fp, " \"%s\")", plug_in_def->locale_path);
else
fprintf (fp, ")");
gimp_config_writer_string (writer, plug_in_def->locale_path);
gimp_config_writer_close (writer);
}
if (plug_in_def->help_path)
{
fprintf (fp, "\n\t(help-def \"%s\")", plug_in_def->help_path);
gimp_config_writer_open (writer, "help-def");
gimp_config_writer_string (writer, plug_in_def->help_path);
gimp_config_writer_close (writer);
}
if (plug_in_def->has_init)
{
fprintf (fp, "\n\t(has-init)");
gimp_config_writer_open (writer, "has-init");
gimp_config_writer_close (writer);
}
fprintf (fp, ")\n");
if (list->next)
fprintf (fp, "\n");
}
gimp_config_writer_close (writer);
}
}
fclose (fp);
return TRUE;
return gimp_config_writer_finish (writer, "end of plug-ins", error);
}

View File

@ -23,10 +23,11 @@
#define __PLUG_IN_RC_H__
gboolean plug_in_rc_parse (Gimp *gimp,
const gchar *filename);
gboolean plug_in_rc_write (GSList *proc_defs,
const gchar *filename);
gboolean plug_in_rc_parse (Gimp *gimp,
const gchar *filename);
gboolean plug_in_rc_write (GSList *proc_defs,
const gchar *filename,
GError **error);
#endif /* __PLUG_IN_RC_H__ */

View File

@ -135,7 +135,7 @@ plug_ins_init (Gimp *gimp,
(* status_callback) (_("Resource configuration"), filename, -1);
plug_in_rc_parse (gimp, filename);
/* query any plug-ins that have changed since we last wrote out
/* Query any plug-ins that have changed since we last wrote out
* the pluginrc file.
*/
(* status_callback) (_("Querying new Plug-ins"), "", 0);
@ -206,10 +206,17 @@ plug_ins_init (Gimp *gimp,
/* write the pluginrc file if necessary */
if (gimp->write_pluginrc)
{
GError *error = NULL;
if (gimp->be_verbose)
g_print (_("writing \"%s\"\n"), filename);
plug_in_rc_write (gimp->plug_in_defs, filename);
if (! plug_in_rc_write (gimp->plug_in_defs, filename, &error))
{
g_message ("%s", error->message);
g_error_free (error);
}
gimp->write_pluginrc = FALSE;
}
@ -295,7 +302,7 @@ plug_ins_init (Gimp *gimp,
(proc_def->db_info.proc_type == GIMP_EXTENSION))
{
if (gimp->be_verbose)
g_print (_("Starting extension: \"%s\""), proc_def->db_info.name);
g_print (_("Starting extension: \"%s\"\n"), proc_def->db_info.name);
(* status_callback) (NULL, proc_def->db_info.name, nth / n_plugins);

View File

@ -524,14 +524,9 @@ serialize_unknown_token (const gchar *key,
const gchar *value,
gpointer data)
{
GimpConfigWriter *writer = data;
gchar *escaped;
escaped = g_strescape (value, NULL);
GimpConfigWriter *writer = data;
gimp_config_writer_open (writer, key);
gimp_config_writer_printf (writer, "\"%s\"", escaped);
gimp_config_writer_string (writer, value);
gimp_config_writer_close (writer);
g_free (escaped);
}

View File

@ -80,7 +80,7 @@ gimp_config_writer_new (const gchar *filename,
}
else
{
fd = open (filename, O_WRONLY);
fd = creat (filename, 0644);
if (fd == -1)
{
@ -190,11 +190,35 @@ gimp_config_writer_printf (GimpConfigWriter *writer,
g_free (buffer);
}
void
gimp_config_writer_string (GimpConfigWriter *writer,
const gchar *string)
{
g_return_if_fail (writer != NULL);
if (writer->error)
return;
if (string)
{
gchar *escaped = g_strescape (string, NULL);
g_string_append_printf (writer->buffer, " \"%s\"", escaped);
g_free (escaped);
}
else
{
g_string_append_len (writer->buffer, " \"\"", 3);
}
}
void
gimp_config_writer_revert (GimpConfigWriter *writer)
{
g_return_if_fail (writer != NULL);
g_return_if_fail (writer->depth > 0);
g_return_if_fail (writer->marker != -1);
if (writer->error)
return;
@ -202,6 +226,7 @@ gimp_config_writer_revert (GimpConfigWriter *writer)
g_string_truncate (writer->buffer, writer->marker);
writer->depth--;
writer->marker = -1;
}
void
@ -269,15 +294,21 @@ void
gimp_config_writer_linefeed (GimpConfigWriter *writer)
{
g_return_if_fail (writer != NULL);
g_return_if_fail (writer->depth == 0);
g_return_if_fail (writer->buffer->len == 0);
if (writer->error)
return;
if (write (writer->fd, "\n", 1) < 0)
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
if (writer->buffer->len == 0)
{
if (write (writer->fd, "\n", 1) < 0)
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
}
else
{
g_string_append_c (writer->buffer, '\n');
gimp_config_string_indent (writer->buffer, writer->depth);
}
}
void

View File

@ -50,6 +50,8 @@ void gimp_config_writer_print (GimpConfigWriter *writer,
void gimp_config_writer_printf (GimpConfigWriter *writer,
const gchar *format,
...);
void gimp_config_writer_string (GimpConfigWriter *writer,
const gchar *string);
void gimp_config_writer_revert (GimpConfigWriter *writer);
void gimp_config_writer_close (GimpConfigWriter *writer);