~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to libgimpbase/gimpparasite.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpparasite.c
 
5
 * Copyright (C) 1998 Jay Cox <jaycox@earthlink.net>
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Library General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the
 
19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
 
 
25
#include <stdio.h>
 
26
#ifdef HAVE_UNISTD_H
 
27
#include <unistd.h>
 
28
#endif
 
29
#include <string.h>
 
30
 
 
31
#include <glib-object.h>
 
32
 
 
33
#ifdef G_OS_WIN32
 
34
#include <process.h>            /* For _getpid() */
 
35
#endif
 
36
 
 
37
#include "gimpbasetypes.h"
 
38
 
 
39
#include "gimpparasite.h"
 
40
 
 
41
 
 
42
#ifdef DEBUG
 
43
static void
 
44
gimp_parasite_print (GimpParasite *parasite)
 
45
{
 
46
  if (parasite == NULL)
 
47
    {
 
48
      g_print ("pid %d: attempt to print a null parasite\n", getpid ());
 
49
      return;
 
50
    }
 
51
 
 
52
  g_print ("pid %d: parasite: %p\n", getpid (), parasite);
 
53
 
 
54
  if (parasite->name)
 
55
    g_print ("\tname: %s\n", parasite->name);
 
56
  else
 
57
    g_print ("\tname: NULL\n");
 
58
 
 
59
  g_print ("\tflags: %d\n", parasite->flags);
 
60
  g_print ("\tsize: %d\n", parasite->size);
 
61
  if (parasite->size > 0)
 
62
    g_print ("\tdata: %p\n", parasite->data);
 
63
}
 
64
#endif
 
65
 
 
66
GimpParasite *
 
67
gimp_parasite_new (const gchar    *name,
 
68
                   guint32         flags,
 
69
                   guint32         size,
 
70
                   gconstpointer   data)
 
71
{
 
72
  GimpParasite *parasite;
 
73
 
 
74
  if (!name)
 
75
    return NULL;
 
76
 
 
77
  parasite = g_new (GimpParasite, 1);
 
78
  parasite->name  = g_strdup (name);
 
79
  parasite->flags = (flags & 0xFF);
 
80
  parasite->size  = size;
 
81
  if (size)
 
82
    parasite->data = g_memdup (data, size);
 
83
  else
 
84
    parasite->data = NULL;
 
85
 
 
86
  return parasite;
 
87
}
 
88
 
 
89
void
 
90
gimp_parasite_free (GimpParasite *parasite)
 
91
{
 
92
  if (parasite == NULL)
 
93
    return;
 
94
 
 
95
  if (parasite->name)
 
96
    g_free (parasite->name);
 
97
  if (parasite->data)
 
98
    g_free (parasite->data);
 
99
 
 
100
  g_free (parasite);
 
101
}
 
102
 
 
103
gboolean
 
104
gimp_parasite_is_type (const GimpParasite *parasite,
 
105
                       const gchar        *name)
 
106
{
 
107
  if (!parasite || !parasite->name)
 
108
    return FALSE;
 
109
 
 
110
  return (strcmp (parasite->name, name) == 0);
 
111
}
 
112
 
 
113
GimpParasite *
 
114
gimp_parasite_copy (const GimpParasite *parasite)
 
115
{
 
116
  if (parasite == NULL)
 
117
    return NULL;
 
118
 
 
119
  return gimp_parasite_new (parasite->name, parasite->flags,
 
120
                            parasite->size, parasite->data);
 
121
}
 
122
 
 
123
gboolean
 
124
gimp_parasite_compare (const GimpParasite *a,
 
125
                       const GimpParasite *b)
 
126
{
 
127
  if (a && b &&
 
128
      a->name && b->name &&
 
129
      strcmp (a->name, b->name) == 0 &&
 
130
      a->flags == b->flags &&
 
131
      a->size == b->size)
 
132
    {
 
133
      if (a->data == NULL && b->data == NULL)
 
134
        return TRUE;
 
135
      else if (a->data && b->data && memcmp (a->data, b->data, a->size) == 0)
 
136
        return TRUE;
 
137
    }
 
138
 
 
139
  return FALSE;
 
140
}
 
141
 
 
142
gulong
 
143
gimp_parasite_flags (const GimpParasite *parasite)
 
144
{
 
145
  if (parasite == NULL)
 
146
    return 0;
 
147
 
 
148
  return parasite->flags;
 
149
}
 
150
 
 
151
gboolean
 
152
gimp_parasite_is_persistent (const GimpParasite *parasite)
 
153
{
 
154
  if (parasite == NULL)
 
155
    return FALSE;
 
156
 
 
157
  return (parasite->flags & GIMP_PARASITE_PERSISTENT);
 
158
}
 
159
 
 
160
gboolean
 
161
gimp_parasite_is_undoable (const GimpParasite *parasite)
 
162
{
 
163
  if (parasite == NULL)
 
164
    return FALSE;
 
165
 
 
166
  return (parasite->flags & GIMP_PARASITE_UNDOABLE);
 
167
}
 
168
 
 
169
gboolean
 
170
gimp_parasite_has_flag (const GimpParasite *parasite,
 
171
                        gulong              flag)
 
172
{
 
173
  if (parasite == NULL)
 
174
    return FALSE;
 
175
 
 
176
  return (parasite->flags & flag);
 
177
}
 
178
 
 
179
const gchar *
 
180
gimp_parasite_name (const GimpParasite *parasite)
 
181
{
 
182
  if (parasite)
 
183
    return parasite->name;
 
184
 
 
185
  return NULL;
 
186
}
 
187
 
 
188
gconstpointer
 
189
gimp_parasite_data (const GimpParasite *parasite)
 
190
{
 
191
  if (parasite)
 
192
    return parasite->data;
 
193
 
 
194
  return NULL;
 
195
}
 
196
 
 
197
glong
 
198
gimp_parasite_data_size (const GimpParasite *parasite)
 
199
{
 
200
  if (parasite)
 
201
    return parasite->size;
 
202
 
 
203
  return 0;
 
204
}