Commit bd577006 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

cosmetics, untabified.

2004-11-23  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpparasitelist.c: cosmetics, untabified.

	* libgimpbase/gimpparasiteio.[ch]: added g_return_if_fail()'s
	to all functions.

	(gimp_pixpipe_params_parse): changed "gchar*" param to "const
	gchar*" (sortof API change, but these files are most probably only
	used by GIMP itself). Still uses strtok() on the internal copy,
	but at least not on the passed string.

	* plug-ins/common/csource.c
	* plug-ins/common/gif.c
	* plug-ins/common/gih.c
	* plug-ins/common/jpeg.c
	* plug-ins/common/png.c
	* plug-ins/common/tiff.c: use parasite getters instead of
	accessing the scruct members directly. Always use g_strndup()
	instead of just g_strdup() to get strings stored in parasites
	because there is no guarantee that they are nul-terminated.
parent f6288226
2004-11-23 Michael Natterer <mitch@gimp.org>
* app/core/gimpparasitelist.c: cosmetics, untabified.
* libgimpbase/gimpparasiteio.[ch]: added g_return_if_fail()'s
to all functions.
(gimp_pixpipe_params_parse): changed "gchar*" param to "const
gchar*" (sortof API change, but these files are most probably only
used by GIMP itself). Still uses strtok() on the internal copy,
but at least not on the passed string.
* plug-ins/common/csource.c
* plug-ins/common/gif.c
* plug-ins/common/gih.c
* plug-ins/common/jpeg.c
* plug-ins/common/png.c
* plug-ins/common/tiff.c: use parasite getters instead of
accessing the scruct members directly. Always use g_strndup()
instead of just g_strdup() to get strings stored in parasites
because there is no guarantee that they are nul-terminated.
2004-11-23 Sven Neumann <sven@gimp.org>
* plug-ins/imagemap/imap_file.c (do_file_save_as_dialog): do
......
......@@ -58,12 +58,12 @@ static gint64 gimp_parasite_list_get_memsize (GimpObject *object,
static void gimp_parasite_list_config_iface_init (gpointer iface,
gpointer iface_data);
static gboolean gimp_parasite_list_serialize (GimpConfig *list,
GimpConfigWriter *writer,
gpointer data);
GimpConfigWriter *writer,
gpointer data);
static gboolean gimp_parasite_list_deserialize (GimpConfig *list,
GScanner *scanner,
gint nest_level,
gpointer data);
GScanner *scanner,
gint nest_level,
gpointer data);
static void parasite_serialize (const gchar *key,
GimpParasite *parasite,
......@@ -96,14 +96,14 @@ gimp_parasite_list_get_type (void)
static const GTypeInfo list_info =
{
sizeof (GimpParasiteListClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_parasite_list_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpParasiteList),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_parasite_list_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_parasite_list_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpParasiteList),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_parasite_list_init,
};
static const GInterfaceInfo list_iface_info =
{
......@@ -113,8 +113,8 @@ gimp_parasite_list_get_type (void)
};
list_type = g_type_register_static (GIMP_TYPE_OBJECT,
"GimpParasiteList",
&list_info, 0);
"GimpParasiteList",
&list_info, 0);
g_type_add_interface_static (list_type, GIMP_TYPE_CONFIG,
&list_iface_info);
}
......@@ -125,33 +125,30 @@ gimp_parasite_list_get_type (void)
static void
gimp_parasite_list_class_init (GimpParasiteListClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
parasite_list_signals[ADD] =
g_signal_new ("add",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpParasiteListClass, add),
NULL, NULL,
gimp_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpParasiteListClass, add),
NULL, NULL,
gimp_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
parasite_list_signals[REMOVE] =
g_signal_new ("remove",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpParasiteListClass, remove),
NULL, NULL,
gimp_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpParasiteListClass, remove),
NULL, NULL,
gimp_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
object_class->finalize = gimp_parasite_list_finalize;
......@@ -197,11 +194,8 @@ gimp_parasite_list_get_memsize_foreach (gpointer key,
gpointer p,
gpointer m)
{
GimpParasite *parasite;
gint64 *memsize;
parasite = (GimpParasite *) p;
memsize = (gint64 *) m;
GimpParasite *parasite = p;
gint64 *memsize = m;
*memsize += (sizeof (GimpParasite) +
strlen (parasite->name) + 1 +
......@@ -212,11 +206,9 @@ static gint64
gimp_parasite_list_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpParasiteList *list;
GimpParasiteList *list = GIMP_PARASITE_LIST (object);
gint64 memsize = 0;
list = GIMP_PARASITE_LIST (object);
if (list->table)
{
memsize += gimp_g_hash_table_get_memsize (list->table);
......@@ -238,7 +230,7 @@ gimp_parasite_list_serialize (GimpConfig *list,
if (GIMP_PARASITE_LIST (list)->table)
g_hash_table_foreach (GIMP_PARASITE_LIST (list)->table,
(GHFunc) parasite_serialize,
writer);
writer);
return TRUE;
}
......@@ -353,7 +345,7 @@ gimp_parasite_list_copy (const GimpParasiteList *list)
void
gimp_parasite_list_add (GimpParasiteList *list,
GimpParasite *parasite)
GimpParasite *parasite)
{
g_return_if_fail (GIMP_IS_PARASITE_LIST (list));
g_return_if_fail (parasite != NULL);
......@@ -371,7 +363,7 @@ gimp_parasite_list_add (GimpParasiteList *list,
void
gimp_parasite_list_remove (GimpParasiteList *list,
const gchar *name)
const gchar *name)
{
GimpParasite *parasite;
......@@ -382,13 +374,13 @@ gimp_parasite_list_remove (GimpParasiteList *list,
parasite = gimp_parasite_list_find (list, name);
if (parasite)
{
g_hash_table_remove (list->table, name);
{
g_hash_table_remove (list->table, name);
g_signal_emit (list, parasite_list_signals[REMOVE], 0, parasite);
g_signal_emit (list, parasite_list_signals[REMOVE], 0, parasite);
gimp_parasite_free (parasite);
}
gimp_parasite_free (parasite);
}
}
}
......@@ -410,7 +402,7 @@ gimp_parasite_list_persistent_length (GimpParasiteList *list)
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), 0);
if (!list->table)
if (! list->table)
return 0;
gimp_parasite_list_foreach (list,
......@@ -421,12 +413,12 @@ gimp_parasite_list_persistent_length (GimpParasiteList *list)
void
gimp_parasite_list_foreach (GimpParasiteList *list,
GHFunc function,
gpointer user_data)
GHFunc function,
gpointer user_data)
{
g_return_if_fail (GIMP_IS_PARASITE_LIST (list));
if (!list->table)
if (! list->table)
return;
g_hash_table_foreach (list->table, function, user_data);
......@@ -434,14 +426,14 @@ gimp_parasite_list_foreach (GimpParasiteList *list,
GimpParasite *
gimp_parasite_list_find (GimpParasiteList *list,
const gchar *name)
const gchar *name)
{
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), NULL);
if (list->table)
return (GimpParasite *) g_hash_table_lookup (list->table, name);
else
return NULL;
return NULL;
}
......@@ -465,8 +457,7 @@ parasite_serialize (const gchar *key,
gimp_parasite_name (parasite),
gimp_parasite_flags (parasite));
/*
* the current methodology is: never move the parasiterc from one
/* the current methodology is: never move the parasiterc from one
* system to another. If you want to do this you should probably
* write out parasites which contain any non-alphanumeric(+some)
* characters as \xHH sequences altogether.
......
......@@ -41,6 +41,8 @@ gimp_pixpipe_params_init (GimpPixPipeParams *params)
{
gint i;
g_return_if_fail (params != NULL);
params->step = 100;
params->ncells = 1;
params->cellwidth = 1;
......@@ -61,13 +63,19 @@ gimp_pixpipe_params_init (GimpPixPipeParams *params)
}
void
gimp_pixpipe_params_parse (gchar *string,
gimp_pixpipe_params_parse (const gchar *string,
GimpPixPipeParams *params)
{
gchar *copy;
gchar *p, *q, *r;
gint i;
q = string;
g_return_if_fail (string != NULL);
g_return_if_fail (params != NULL);
copy = g_strdup (string);
q = copy;
while ((p = strtok (q, " \r\n")) != NULL)
{
q = NULL;
......@@ -145,15 +153,20 @@ gimp_pixpipe_params_parse (gchar *string,
if (r)
*r = ':';
}
g_free (copy);
}
gchar *
gimp_pixpipe_params_build (GimpPixPipeParams *params)
{
GString *s = g_string_new (NULL);
GString *s;
gchar *str;
gint i;
gint i;
g_return_val_if_fail (params != NULL, NULL);
s = g_string_new (NULL);
g_string_printf (s, "ncells:%d cellwidth:%d cellheight:%d "
"step:%d dim:%d cols:%d rows:%d placement:%s",
......
......@@ -59,7 +59,7 @@ typedef struct
void gimp_pixpipe_params_init (GimpPixPipeParams *params);
/* Parse a string into a GimpPixPipeParams */
void gimp_pixpipe_params_parse (gchar *parameters,
void gimp_pixpipe_params_parse (const gchar *parameters,
GimpPixPipeParams *params);
/* Build a string representation of GimpPixPipeParams */
......
......@@ -158,7 +158,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (image_ID, "gimp-comment");
if (parasite)
{
config.comment = g_strdup (parasite->data);
config.comment = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
x = config.comment;
......
......@@ -1316,24 +1316,19 @@ save_dialog (gint32 image_ID)
g_object_unref (text_buffer);
if (globalcomment != NULL)
{
g_free (globalcomment);
}
if (globalcomment)
g_free (globalcomment);
#ifdef FACEHUGGERS
GIF2_CMNT = gimp_image_parasite_find (image_ID, "gimp-comment");
if (GIF2_CMNT)
{
globalcomment = g_malloc (GIF2_CMNT->size+1);
memcpy (globalcomment, GIF2_CMNT->data, GIF2_CMNT->size);
globalcomment[GIF2_CMNT->size] = 0;
}
globalcomment = g_strndup (gimp_parasite_data (GIF2_CMNT),
gimp_parasite_data_size (GIF2_CMNT));
else
{
#endif
globalcomment = gimp_get_default_comment ();
globalcomment = gimp_get_default_comment ();
#ifdef FACEHUGGERS
}
gimp_parasite_free (GIF2_CMNT);
#endif
......
......@@ -349,7 +349,8 @@ run (const gchar *name,
gimp_image_parasite_find (orig_image_ID,
"gimp-brush-pipe-parameters");
if (pipe_parasite)
gimp_pixpipe_params_parse (pipe_parasite->data, &gihparams);
gimp_pixpipe_params_parse (gimp_parasite_data (pipe_parasite),
&gihparams);
if (!gih_save_dialog (image_ID))
status = GIMP_PDB_CANCEL;
......@@ -398,7 +399,8 @@ run (const gchar *name,
"gimp-brush-pipe-parameters");
gimp_pixpipe_params_init (&gihparams);
if (pipe_parasite)
gimp_pixpipe_params_parse (pipe_parasite->data, &gihparams);
gimp_pixpipe_params_parse (gimp_parasite_data (pipe_parasite),
&gihparams);
break;
}
......
......@@ -546,7 +546,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
if (parasite)
{
image_comment = g_strdup (parasite->data);
image_comment = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......@@ -555,7 +556,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "exif-data");
if (parasite)
{
exif_data = exif_data_new_from_data (parasite->data, parasite->size);
exif_data = exif_data_new_from_data (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......
......@@ -1299,7 +1299,7 @@ save_image (const gchar *filename,
parasite = gimp_image_parasite_find (orig_image_ID, "gamma");
if (parasite)
{
gamma = g_ascii_strtod (parasite->data, NULL);
gamma = g_ascii_strtod (gimp_parasite_data (parasite), NULL);
gimp_parasite_free (parasite);
}
......
......@@ -329,7 +329,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image, "gimp-comment");
if (parasite)
{
image_comment = g_strdup (parasite->data);
image_comment = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......@@ -342,10 +343,10 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image, "tiff-save-options");
if (parasite)
{
tsvals.compression =
((TiffSaveVals *) parasite->data)->compression;
tsvals.save_transp_pixels =
((TiffSaveVals *) parasite->data)->save_transp_pixels;
const TiffSaveVals *pvals = gimp_parasite_data (parasite);
tsvals.compression = pvals->compression;
tsvals.save_transp_pixels = pvals->save_transp_pixels;
}
gimp_parasite_free (parasite);
......@@ -386,10 +387,10 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image, "tiff-save-options");
if (parasite)
{
tsvals.compression =
((TiffSaveVals *) parasite->data)->compression;
tsvals.save_transp_pixels =
((TiffSaveVals *) parasite->data)->save_transp_pixels;
const TiffSaveVals *pvals = gimp_parasite_data (parasite);
tsvals.compression = pvals->compression;
tsvals.save_transp_pixels = pvals->save_transp_pixels;
}
gimp_parasite_free (parasite);
break;
......
......@@ -546,7 +546,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
if (parasite)
{
image_comment = g_strdup (parasite->data);
image_comment = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......@@ -555,7 +556,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "exif-data");
if (parasite)
{
exif_data = exif_data_new_from_data (parasite->data, parasite->size);
exif_data = exif_data_new_from_data (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......
......@@ -546,7 +546,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
if (parasite)
{
image_comment = g_strdup (parasite->data);
image_comment = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......@@ -555,7 +556,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "exif-data");
if (parasite)
{
exif_data = exif_data_new_from_data (parasite->data, parasite->size);
exif_data = exif_data_new_from_data (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......
......@@ -546,7 +546,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
if (parasite)
{
image_comment = g_strdup (parasite->data);
image_comment = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......@@ -555,7 +556,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "exif-data");
if (parasite)
{
exif_data = exif_data_new_from_data (parasite->data, parasite->size);
exif_data = exif_data_new_from_data (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......
......@@ -546,7 +546,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
if (parasite)
{
image_comment = g_strdup (parasite->data);
image_comment = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......@@ -555,7 +556,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "exif-data");
if (parasite)
{
exif_data = exif_data_new_from_data (parasite->data, parasite->size);
exif_data = exif_data_new_from_data (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......
......@@ -546,7 +546,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
if (parasite)
{
image_comment = g_strdup (parasite->data);
image_comment = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......@@ -555,7 +556,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "exif-data");
if (parasite)
{
exif_data = exif_data_new_from_data (parasite->data, parasite->size);
exif_data = exif_data_new_from_data (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......
......@@ -546,7 +546,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "gimp-comment");
if (parasite)
{
image_comment = g_strdup (parasite->data);
image_comment = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......@@ -555,7 +556,8 @@ run (const gchar *name,
parasite = gimp_image_parasite_find (orig_image_ID, "exif-data");
if (parasite)
{
exif_data = exif_data_new_from_data (parasite->data, parasite->size);
exif_data = exif_data_new_from_data (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment