Commit 3ab2e648 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

removed gimp_scanner_parse_string_list() since the format it read wasn't

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

	* app/config/gimpscanner.[ch]: removed gimp_scanner_parse_string_list()
	since the format it read wasn't proper s-expressions syntax.

	* app/config/gimpconfigwriter.c: a couple of minor cleanups.

	* app/gui/color-history.[ch]
	* app/gui/session.c
	* app/widgets/gimpdialogfactory.[ch]: use GimpConfigWriter to
	write the sessionrc. Had to do some minor changes to the file
	format.
parent a85179e7
2003-03-10 Sven Neumann <sven@gimp.org>
* app/config/gimpscanner.[ch]: removed gimp_scanner_parse_string_list()
since the format it read wasn't proper s-expressions syntax.
* app/config/gimpconfigwriter.c: a couple of minor cleanups.
* app/gui/color-history.[ch]
* app/gui/session.c
* app/widgets/gimpdialogfactory.[ch]: use GimpConfigWriter to
write the sessionrc. Had to do some minor changes to the file
format.
2003-03-10 Michael Natterer <mitch@gimp.org>
* app/core/gimppalette.[ch]: added GimpData::duplicate()
......@@ -24,6 +24,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
......@@ -128,6 +129,7 @@ gimp_config_writer_open (GimpConfigWriter *writer,
const gchar *name)
{
g_return_if_fail (writer != NULL);
g_return_if_fail (name != NULL);
if (writer->error)
return;
......@@ -160,9 +162,11 @@ gimp_config_writer_print (GimpConfigWriter *writer,
if (len < 0)
len = strlen (string);
g_string_append_c (writer->buffer, ' ');
g_string_append_len (writer->buffer, string, len);
if (len)
{
g_string_append_c (writer->buffer, ' ');
g_string_append_len (writer->buffer, string, len);
}
}
void
......@@ -179,12 +183,11 @@ gimp_config_writer_printf (GimpConfigWriter *writer,
if (writer->error)
return;
g_string_append_c (writer->buffer, ' ');
va_start (args, format);
buffer = g_strdup_vprintf (format, args);
va_end (args);
g_string_append_c (writer->buffer, ' ');
g_string_append (writer->buffer, buffer);
g_free (buffer);
......@@ -245,7 +248,8 @@ gimp_config_writer_close (GimpConfigWriter *writer)
g_string_append_c (writer->buffer, '\n');
if (write (writer->fd, writer->buffer->str, writer->buffer->len) < 0)
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_set_error (&writer->error,
GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
g_string_truncate (writer->buffer, 0);
......@@ -301,7 +305,8 @@ gimp_config_writer_linefeed (GimpConfigWriter *writer)
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_set_error (&writer->error,
GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
}
else
......@@ -328,7 +333,8 @@ gimp_config_writer_comment (GimpConfigWriter *writer,
gimp_config_serialize_comment (writer->buffer, comment);
if (write (writer->fd, writer->buffer->str, writer->buffer->len) < 0)
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_set_error (&writer->error,
GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
g_string_truncate (writer->buffer, 0);
......
......@@ -336,67 +336,6 @@ gimp_scanner_parse_color (GScanner *scanner,
return (token == G_TOKEN_NONE);
}
gboolean
gimp_scanner_parse_string_list (GScanner *scanner,
GList **dest)
{
GTokenType token;
GList *list = NULL;
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_STRING;
break;
case G_TOKEN_STRING:
do
{
list = g_list_append (list, g_strdup (scanner->value.v_string));
token = g_scanner_peek_next_token (scanner);
if (token == G_TOKEN_STRING)
g_scanner_get_next_token (scanner);
}
while (token == G_TOKEN_STRING);
token = G_TOKEN_RIGHT_PAREN;
break;
case G_TOKEN_RIGHT_PAREN:
token = G_TOKEN_NONE; /* indicates success */
goto finish;
default: /* do nothing */
break;
}
}
finish:
if (token != G_TOKEN_NONE)
{
g_list_foreach (list, (GFunc) g_free, NULL);
g_list_free (list);
list = NULL;
g_scanner_get_next_token (scanner);
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
_("fatal parse error"), TRUE);
}
else
{
*dest = list;
}
return (token == G_TOKEN_NONE);
}
/* private functions */
......
......@@ -42,8 +42,6 @@ gboolean gimp_scanner_parse_float (GScanner *scanner,
gdouble *dest);
gboolean gimp_scanner_parse_color (GScanner *scanner,
GimpRGB *dest);
gboolean gimp_scanner_parse_string_list (GScanner *scanner,
GList **dest);
#endif /* __GIMP_SCANNER_H__ */
......@@ -27,6 +27,8 @@
#include "gui-types.h"
#include "config/gimpconfigwriter.h"
#include "color-history.h"
......@@ -55,33 +57,35 @@ color_history_add_from_rc (GimpRGB *color)
}
void
color_history_write (FILE *fp)
color_history_write (GimpConfigWriter *writer)
{
gint i;
if (! color_history_initialized)
color_history_init ();
fprintf (fp, "(color-history");
gimp_config_writer_open (writer, "color-history");
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
{
gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_formatd (buf[0],
g_ascii_formatd (buf[0],
G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].r);
g_ascii_formatd (buf[1],
g_ascii_formatd (buf[1],
G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].g);
g_ascii_formatd (buf[2],
g_ascii_formatd (buf[2],
G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].b);
g_ascii_formatd (buf[3],
g_ascii_formatd (buf[3],
G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].a);
fprintf (fp, "\n (color-rgba %s %s %s %s)",
buf[0], buf[1], buf[2], buf[3]);
gimp_config_writer_open (writer, "color-rgba");
gimp_config_writer_printf (writer, "%s %s %s %s",
buf[0], buf[1], buf[2], buf[3]);
gimp_config_writer_close (writer);
}
fprintf (fp, ")\n\n");
gimp_config_writer_close (writer);
}
void
......
......@@ -22,19 +22,17 @@
#ifndef __COLOR_HISTORY_H__
#define __COLOR_HISTORY_H__
#include <stdio.h> /* FILE */
#define COLOR_HISTORY_SIZE 16
gint color_history_add (const GimpRGB *rgb);
void color_history_set (gint index,
const GimpRGB *rgb);
void color_history_get (gint index,
GimpRGB *rgb);
gint color_history_add (const GimpRGB *rgb);
void color_history_set (gint index,
const GimpRGB *rgb);
void color_history_get (gint index,
GimpRGB *rgb);
void color_history_add_from_rc (GimpRGB *color);
void color_history_write (FILE *fp);
void color_history_add_from_rc (GimpRGB *color);
void color_history_write (GimpConfigWriter *writer);
#endif /* __COLOR_HISTORY_H__ */
......@@ -34,6 +34,7 @@
#include "core/gimp.h"
#include "config/gimpconfigwriter.h"
#include "config/gimpscanner.h"
#include "widgets/gimpdialogfactory.h"
......@@ -46,9 +47,10 @@
/* local function prototypes */
static GTokenType session_info_deserialize (GScanner *scanner,
Gimp *gimp);
static GTokenType session_info_deserialize (GScanner *scanner,
Gimp *gimp);
static GTokenType session_info_dock_deserialize (GScanner *scanner,
GimpSessionInfo *info);
/* public functions */
......@@ -62,7 +64,9 @@ enum
SESSION_INFO_SIZE,
SESSION_INFO_OPEN,
SESSION_INFO_AUX,
SESSION_INFO_DOCK
SESSION_INFO_DOCK,
SESSION_INFO_DOCK_BOOK
};
void
......@@ -106,6 +110,9 @@ session_init (Gimp *gimp)
g_scanner_scope_add_symbol (scanner, SESSION_INFO, "dock",
GINT_TO_POINTER (SESSION_INFO_DOCK));
g_scanner_scope_add_symbol (scanner, SESSION_INFO_DOCK, "book",
GINT_TO_POINTER (SESSION_INFO_DOCK_BOOK));
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
......@@ -191,35 +198,42 @@ session_restore (Gimp *gimp)
void
session_save (Gimp *gimp)
{
gchar *filename;
FILE *fp;
GimpConfigWriter *writer;
gchar *filename;
g_return_if_fail (GIMP_IS_GIMP (gimp));
filename = gimp_personal_rc_file ("sessionrc");
fp = fopen (filename, "wt");
g_free (filename);
if (!fp)
writer = gimp_config_writer_new (filename,
TRUE,
"GIMP sessionrc\n\n"
"This file takes session-specific info "
"(that is info, you want to keep between "
"two gimp-sessions). 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. If this "
"file isn't found, defaults are used.",
NULL);
if (!writer)
return;
fprintf (fp, ("# GIMP sessionrc\n"
"# This file takes session-specific info (that is info,\n"
"# you want to keep between two gimp-sessions). You are\n"
"# not supposed to edit it manually, but of course you\n"
"# can do. This file will be entirely rewritten every time\n"
"# you quit the gimp. If this file isn't found, defaults\n"
"# are used.\n\n"));
gimp_dialog_factories_session_save (fp);
gimp_dialog_factories_session_save (writer);
gimp_config_writer_linefeed (writer);
/* save last tip shown */
fprintf (fp, "(last-tip-shown %d)\n\n",
GIMP_GUI_CONFIG (gimp->config)->last_tip + 1);
gimp_config_writer_open (writer, "last-tip-shown");
gimp_config_writer_printf (writer, "%d",
GIMP_GUI_CONFIG (gimp->config)->last_tip + 1);
gimp_config_writer_close (writer);
gimp_config_writer_linefeed (writer);
color_history_write (fp);
color_history_write (writer);
fclose (fp);
gimp_config_writer_finish (writer, "end of sessionrc", NULL);
}
......@@ -234,6 +248,7 @@ session_info_deserialize (GScanner *scanner,
GTokenType token;
gchar *factory_name;
gchar *entry_name;
gchar *string;
token = G_TOKEN_STRING;
......@@ -301,29 +316,22 @@ session_info_deserialize (GScanner *scanner,
break;
case SESSION_INFO_AUX:
if (! gimp_scanner_parse_string_list (scanner, &info->aux_info))
{
token = G_TOKEN_NONE;
goto error;
}
while (gimp_scanner_parse_string (scanner, &string))
info->aux_info = g_list_append (info->aux_info, string);
break;
case SESSION_INFO_DOCK:
if (info->toplevel_entry)
goto error;
while (g_scanner_peek_next_token (scanner) == G_TOKEN_LEFT_PAREN)
{
GList *list = NULL;
g_scanner_set_scope (scanner, SESSION_INFO_DOCK);
token = session_info_dock_deserialize (scanner, info);
if (! gimp_scanner_parse_string_list (scanner, &list))
{
token = G_TOKEN_NONE;
goto error;
}
if (token == G_TOKEN_LEFT_PAREN)
g_scanner_set_scope (scanner, SESSION_INFO);
else
goto error;
info->sub_dialogs = g_list_append (info->sub_dialogs, list);
}
break;
default:
......@@ -370,3 +378,54 @@ session_info_deserialize (GScanner *scanner,
return token;
}
static GTokenType
session_info_dock_deserialize (GScanner *scanner,
GimpSessionInfo *info)
{
GList *list;
gchar *string;
GTokenType token;
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_SYMBOL;
break;
case G_TOKEN_SYMBOL:
switch (GPOINTER_TO_INT (scanner->value.v_symbol))
{
case SESSION_INFO_DOCK_BOOK:
list = NULL;
while (gimp_scanner_parse_string (scanner, &string))
list = g_list_append (list, string);
if (list)
info->sub_dialogs = g_list_append (info->sub_dialogs, list);
token = G_TOKEN_RIGHT_PAREN;
break;
default:
return token;
}
break;
case G_TOKEN_RIGHT_PAREN:
token = G_TOKEN_LEFT_PAREN;
break;
default:
break;
}
}
return token;
}
......@@ -32,6 +32,8 @@
#include "core/gimpcontext.h"
#include "config/gimpconfigwriter.h"
#include "gimpcontainerview.h"
#include "gimpcontainerview-utils.h"
#include "gimpcursor.h"
......@@ -75,7 +77,7 @@ static void gimp_dialog_factory_finalize (GObject *object
static void gimp_dialog_factories_save_foreach (gchar *name,
GimpDialogFactory *factory,
FILE *fp);
GimpConfigWriter *writer);
static void gimp_dialog_factories_restore_foreach (gchar *name,
GimpDialogFactory *factory,
gpointer data);
......@@ -886,17 +888,17 @@ gimp_dialog_factory_remove_dialog (GimpDialogFactory *factory,
}
void
gimp_dialog_factories_session_save (FILE *file)
gimp_dialog_factories_session_save (GimpConfigWriter *writer)
{
GimpDialogFactoryClass *factory_class;
g_return_if_fail (file != NULL);
g_return_if_fail (writer != NULL);
factory_class = g_type_class_peek (GIMP_TYPE_DIALOG_FACTORY);
g_hash_table_foreach (factory_class->factories,
(GHFunc) gimp_dialog_factories_save_foreach,
file);
writer);
}
void
......@@ -999,7 +1001,7 @@ gimp_dialog_factories_unidle (void)
static void
gimp_dialog_factories_save_foreach (gchar *name,
GimpDialogFactory *factory,
FILE *fp)
GimpConfigWriter *writer)
{
GList *list;
......@@ -1022,22 +1024,31 @@ gimp_dialog_factories_save_foreach (gchar *name,
gimp_dialog_factory_get_window_info (info->widget, info);
if (info->toplevel_entry)
{
dialog_name = info->toplevel_entry->identifier;
}
dialog_name = info->toplevel_entry->identifier;
else
{
dialog_name = "dock";
}
dialog_name = "dock";
fprintf (fp, "(session-info \"%s\" \"%s\"\n", name, dialog_name);
fprintf (fp, " (position %d %d)", info->x, info->y);
gimp_config_writer_open (writer, "session-info");
gimp_config_writer_string (writer, name);
gimp_config_writer_string (writer, dialog_name);
gimp_config_writer_open (writer, "position");
gimp_config_writer_printf (writer, "%d %d", info->x, info->y);
gimp_config_writer_close (writer);
if (info->width > 0 && info->height > 0)
fprintf (fp, "\n (size %d %d)", info->width, info->height);
{
gimp_config_writer_open (writer, "size");
gimp_config_writer_printf (writer, "%d %d",
info->width, info->height);
gimp_config_writer_close (writer);
}
if (info->open)
fprintf (fp, "\n (open-on-exit)");
{
gimp_config_writer_open (writer, "open-on-exit");
gimp_config_writer_close (writer);
}
/* save aux-info */
if (info->widget)
......@@ -1048,21 +1059,12 @@ gimp_dialog_factories_save_foreach (gchar *name,
{
GList *aux;
fprintf (fp, "\n (aux-info (");
gimp_config_writer_open (writer, "aux-info");
for (aux = info->aux_info; aux; aux = g_list_next (aux))
{
gchar *str;
str = (gchar *) aux->data;
gimp_config_writer_string (writer, (gchar *) aux->data);
if (aux->prev)
fprintf (fp, " \"%s\"", str);
else
fprintf (fp, "\"%s\"", str);
}
fprintf (fp, "))");
gimp_config_writer_close (writer);
g_list_foreach (info->aux_info, (GFunc) g_free, NULL);
g_list_free (info->aux_info);
......@@ -1077,7 +1079,7 @@ gimp_dialog_factories_save_foreach (gchar *name,
dock = GIMP_DOCK (info->widget);
fprintf (fp, "\n (dock ");
gimp_config_writer_open (writer, "dock");
for (books = dock->dockbooks; books; books = g_list_next (books))
{
......@@ -1087,7 +1089,7 @@ gimp_dialog_factories_save_foreach (gchar *name,
dockbook = (GimpDockbook *) books->data;
fprintf (fp, "(");
gimp_config_writer_open (writer, "book");
children = gtk_container_get_children (GTK_CONTAINER (dockbook));
......@@ -1106,6 +1108,8 @@ gimp_dialog_factories_save_foreach (gchar *name,
GimpContainerView *view;
gint preview_size = -1;
gimp_config_writer_linefeed (writer);
view = gimp_container_view_get_by_dockable (dockable);
if (view && view->preview_size >= GIMP_PREVIEW_SIZE_TINY)
......@@ -1116,29 +1120,27 @@ gimp_dialog_factories_save_foreach (gchar *name,
if (preview_size > 0 &&
preview_size != entry->preview_size)
{
fprintf (fp, "\"%s@%d\"",
entry->identifier, preview_size);
gimp_config_writer_printf (writer, "\"%s@%d\"",
entry->identifier,
preview_size);
}
else
{
fprintf (fp, "\"%s\"",
entry->identifier);
gimp_config_writer_printf (writer, "\"%s\"",
entry->identifier);
}
if (pages->next)
fprintf (fp, " ");
}
}
g_list_free (children);
fprintf (fp, ")%s", books->next ? "\n " : "");
gimp_config_writer_close (writer); /* book */
}
fprintf (fp, ")");
gimp_config_writer_close (writer); /* dock */
}
fprintf (fp, ")\n\n");
gimp_config_writer_close (writer); /* session-info */
}
}
......
......@@ -23,8 +23,6 @@
#define __GIMP_DIALOG_FACTORY_H__
#include <stdio.h>
#include "core/gimpobject.h"
......@@ -145,7 +143,7 @@ void gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
void gimp_dialog_factory_remove_dialog (GimpDialogFactory *factory,
GtkWidget *dialog);
void gimp_dialog_factories_session_save (FILE *file);
void gimp_dialog_factories_session_save (GimpConfigWriter *writer);
void gimp_dialog_factories_session_restore (void);
void gimp_dialog_factories_session_clear (void);
......
......@@ -24,6 +24,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
......@@ -128,6 +129,7 @@ gimp_config_writer_open (GimpConfigWriter *writer,
const gchar *name)
{
g_return_if_fail (writer != NULL);
g_return_if_fail (name != NULL);
if (writer->error)
return;
......@@ -160,9 +162,11 @@ gimp_config_writer_print (GimpConfigWriter *writer,
if (len < 0)
len = strlen (string);
g_string_append_c (writer->buffer, ' ');
g_string_append_len (writer->buffer, string, len);
if (len)
{
g_string_append_c (writer->buffer, ' ');
g_string_append_len (writer->buffer, string, len);
}
}
void
......@@ -179,12 +183,11 @@ gimp_config_writer_printf (GimpConfigWriter *writer,
if (writer->error)
return;
g_string_append_c (writer->buffer, ' ');
va_start (args, format);
buffer = g_strdup_vprintf (format, args);
va_end (args);
g_string_append_c (writer->buffer, ' ');
g_string_append (writer->buffer, buffer);
g_free (buffer);
......@@ -245,7 +248,8 @@ gimp_config_writer_close (GimpConfigWriter *writer)
g_string_append_c (writer->buffer, '\n');
if (write (writer->fd, writer->buffer->str, writer->buffer->len) < 0)
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_set_error (&writer->error,
GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
g_string_truncate (writer->buffer, 0);
......@@ -301,7 +305,8 @@ gimp_config_writer_linefeed (GimpConfigWriter *writer)
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_set_error (&writer->error,
GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
}
else
......@@ -328,7 +333,8 @@ gimp_config_writer_comment (GimpConfigWriter *writer,
gimp_config_serialize_comment (writer->buffer, comment);
if (write (writer->fd, writer->buffer->str, writer->buffer->len) < 0)
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_set_error (&writer->error,
GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
g_strerror (errno));
g_string_truncate (writer->buffer, 0);
......
......@@ -336,67 +336,6 @@ gimp_scanner_parse_color (GScanner *scanner,
return (token == G_TOKEN_NONE);
}
gboolean
gimp_scanner_parse_string_list (GScanner *scanner,
GList **dest)
{
GTokenType token;
GList *list = NULL;
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_STRING;
break;
case G_TOKEN_STRING:
do
{
list = g_list_append