~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to libgimpbase/gimpparasite.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
3
3
 *
4
4
 * gimpparasite.c
5
 
 * Copyright (C) 1998 Jay Cox <jaycox@earthlink.net>
 
5
 * Copyright (C) 1998 Jay Cox <jaycox@gimp.org>
6
6
 *
7
7
 * This library is free software; you can redistribute it and/or
8
8
 * modify it under the terms of the GNU Lesser General Public
31
31
#include <glib-object.h>
32
32
 
33
33
#ifdef G_OS_WIN32
34
 
#include <process.h>            /* For _getpid() */
 
34
#include <process.h>                /* For _getpid() */
35
35
#endif
36
36
 
37
37
#include "gimpbasetypes.h"
39
39
#include "gimpparasite.h"
40
40
 
41
41
 
 
42
/*
 
43
 * GIMP_TYPE_PARASITE
 
44
 */
 
45
 
 
46
GType
 
47
gimp_parasite_get_type (void)
 
48
{
 
49
  static GType type = 0;
 
50
 
 
51
  if (! type)
 
52
    type = g_boxed_type_register_static ("GimpParasite",
 
53
                                         (GBoxedCopyFunc) gimp_parasite_copy,
 
54
                                         (GBoxedFreeFunc) gimp_parasite_free);
 
55
 
 
56
  return type;
 
57
}
 
58
 
 
59
 
 
60
/*
 
61
 * GIMP_TYPE_PARAM_PARASITE
 
62
 */
 
63
 
 
64
#define GIMP_PARAM_SPEC_PARASITE(pspec)    (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_PARASITE, GimpParamSpecParasite))
 
65
 
 
66
typedef struct _GimpParamSpecParasite GimpParamSpecParasite;
 
67
 
 
68
struct _GimpParamSpecParasite
 
69
{
 
70
  GParamSpecBoxed parent_instance;
 
71
};
 
72
 
 
73
static void       gimp_param_parasite_class_init  (GParamSpecClass *class);
 
74
static void       gimp_param_parasite_init        (GParamSpec      *pspec);
 
75
static gboolean   gimp_param_parasite_validate    (GParamSpec      *pspec,
 
76
                                                   GValue          *value);
 
77
static gint       gimp_param_parasite_values_cmp  (GParamSpec      *pspec,
 
78
                                                   const GValue    *value1,
 
79
                                                   const GValue    *value2);
 
80
 
 
81
GType
 
82
gimp_param_parasite_get_type (void)
 
83
{
 
84
  static GType type = 0;
 
85
 
 
86
  if (! type)
 
87
    {
 
88
      const GTypeInfo type_info =
 
89
      {
 
90
        sizeof (GParamSpecClass),
 
91
        NULL, NULL,
 
92
        (GClassInitFunc) gimp_param_parasite_class_init,
 
93
        NULL, NULL,
 
94
        sizeof (GimpParamSpecParasite),
 
95
        0,
 
96
        (GInstanceInitFunc) gimp_param_parasite_init
 
97
      };
 
98
 
 
99
      type = g_type_register_static (G_TYPE_PARAM_BOXED,
 
100
                                     "GimpParamParasite",
 
101
                                     &type_info, 0);
 
102
    }
 
103
 
 
104
  return type;
 
105
}
 
106
 
 
107
static void
 
108
gimp_param_parasite_class_init (GParamSpecClass *class)
 
109
{
 
110
  class->value_type     = GIMP_TYPE_PARASITE;
 
111
  class->value_validate = gimp_param_parasite_validate;
 
112
  class->values_cmp     = gimp_param_parasite_values_cmp;
 
113
}
 
114
 
 
115
static void
 
116
gimp_param_parasite_init (GParamSpec *pspec)
 
117
{
 
118
}
 
119
 
 
120
static gboolean
 
121
gimp_param_parasite_validate (GParamSpec *pspec,
 
122
                              GValue     *value)
 
123
{
 
124
  GimpParasite *parasite = value->data[0].v_pointer;
 
125
 
 
126
  if (! parasite)
 
127
    {
 
128
      return TRUE;
 
129
    }
 
130
  else if (parasite->name == NULL                          ||
 
131
           ! g_utf8_validate (parasite->name, -1, NULL)    ||
 
132
           (parasite->size == 0 && parasite->data != NULL) ||
 
133
           (parasite->size >  0 && parasite->data == NULL))
 
134
    {
 
135
      g_value_set_boxed (value, NULL);
 
136
      return TRUE;
 
137
    }
 
138
 
 
139
  return FALSE;
 
140
}
 
141
 
 
142
static gint
 
143
gimp_param_parasite_values_cmp (GParamSpec   *pspec,
 
144
                                const GValue *value1,
 
145
                                const GValue *value2)
 
146
{
 
147
  GimpParasite *parasite1 = value1->data[0].v_pointer;
 
148
  GimpParasite *parasite2 = value2->data[0].v_pointer;
 
149
 
 
150
  /*  try to return at least *something*, it's useless anyway...  */
 
151
 
 
152
  if (! parasite1)
 
153
    return parasite2 != NULL ? -1 : 0;
 
154
  else if (! parasite2)
 
155
    return parasite1 != NULL;
 
156
  else
 
157
    return gimp_parasite_compare (parasite1, parasite2);
 
158
}
 
159
 
 
160
GParamSpec *
 
161
gimp_param_spec_parasite (const gchar *name,
 
162
                          const gchar *nick,
 
163
                          const gchar *blurb,
 
164
                          GParamFlags  flags)
 
165
{
 
166
  GimpParamSpecParasite *parasite_spec;
 
167
 
 
168
  parasite_spec = g_param_spec_internal (GIMP_TYPE_PARAM_PARASITE,
 
169
                                         name, nick, blurb, flags);
 
170
 
 
171
  return G_PARAM_SPEC (parasite_spec);
 
172
}
 
173
 
 
174
 
42
175
#ifdef DEBUG
43
176
static void
44
177
gimp_parasite_print (GimpParasite *parasite)
65
198
 
66
199
GimpParasite *
67
200
gimp_parasite_new (const gchar    *name,
68
 
                   guint32         flags,
69
 
                   guint32         size,
70
 
                   gconstpointer   data)
 
201
                   guint32         flags,
 
202
                   guint32         size,
 
203
                   gconstpointer   data)
71
204
{
72
205
  GimpParasite *parasite;
73
206
 
102
235
 
103
236
gboolean
104
237
gimp_parasite_is_type (const GimpParasite *parasite,
105
 
                       const gchar        *name)
 
238
                       const gchar        *name)
106
239
{
107
240
  if (!parasite || !parasite->name)
108
241
    return FALSE;
117
250
    return NULL;
118
251
 
119
252
  return gimp_parasite_new (parasite->name, parasite->flags,
120
 
                            parasite->size, parasite->data);
 
253
                            parasite->size, parasite->data);
121
254
}
122
255
 
123
256
gboolean
124
257
gimp_parasite_compare (const GimpParasite *a,
125
 
                       const GimpParasite *b)
 
258
                       const GimpParasite *b)
126
259
{
127
260
  if (a && b &&
128
261
      a->name && b->name &&
131
264
      a->size == b->size)
132
265
    {
133
266
      if (a->data == NULL && b->data == NULL)
134
 
        return TRUE;
 
267
        return TRUE;
135
268
      else if (a->data && b->data && memcmp (a->data, b->data, a->size) == 0)
136
 
        return TRUE;
 
269
        return TRUE;
137
270
    }
138
271
 
139
272
  return FALSE;
168
301
 
169
302
gboolean
170
303
gimp_parasite_has_flag (const GimpParasite *parasite,
171
 
                        gulong              flag)
 
304
                        gulong              flag)
172
305
{
173
306
  if (parasite == NULL)
174
307
    return FALSE;