]> git.saurik.com Git - wxWidgets.git/blame - src/xpm/Attrib.c
compilation fix for DJGPP
[wxWidgets.git] / src / xpm / Attrib.c
CommitLineData
e6ed776f
GRG
1/*
2 * Copyright (C) 1989-95 GROUPE BULL
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 *
21 * Except as contained in this notice, the name of GROUPE BULL shall not be
22 * used in advertising or otherwise to promote the sale, use or other dealings
23 * in this Software without prior written authorization from GROUPE BULL.
24 */
25
26/*****************************************************************************\
27* Attrib.c: *
28* *
29* XPM library *
30* Functions related to the XpmAttributes structure *
31* *
32* Developed by Arnaud Le Hors *
33\*****************************************************************************/
34
35#include "XpmI.h"
36
37/* 3.2 backward compatibility code */
38LFUNC(CreateOldColorTable, int, (XpmColor *ct, int ncolors,
39 XpmColor ***oldct));
40
41LFUNC(FreeOldColorTable, void, (XpmColor **colorTable, int ncolors));
42
43/*
44 * Create a colortable compatible with the old style colortable
45 */
ea258ad3
DW
46#ifdef __OS2__
47/* Visual Age cannot deal with old, non-ansi, code */
48static int
49CreateOldColorTable(XpmColor* ct, int ncolors, XpmColor*** oldct)
50#else
e6ed776f
GRG
51static int
52CreateOldColorTable(ct, ncolors, oldct)
53 XpmColor *ct;
54 int ncolors;
55 XpmColor ***oldct;
ea258ad3 56#endif
e6ed776f
GRG
57{
58 XpmColor **colorTable, **color;
59 int a;
60
61 colorTable = (XpmColor **) XpmMalloc(ncolors * sizeof(XpmColor *));
62 if (!colorTable) {
63 *oldct = NULL;
64 return (XpmNoMemory);
65 }
66 for (a = 0, color = colorTable; a < ncolors; a++, color++, ct++)
67 *color = ct;
68 *oldct = colorTable;
69 return (XpmSuccess);
70}
71
ea258ad3
DW
72#ifdef __OS2__
73/* Visual Age cannot deal with old, non-ansi, code */
74static void FreeOldColorTable(XpmColor** colorTable, int ncolors)
75#else
e6ed776f
GRG
76static void
77FreeOldColorTable(colorTable, ncolors)
78 XpmColor **colorTable;
79 int ncolors;
ea258ad3 80#endif
e6ed776f
GRG
81{
82 int a, b;
83 XpmColor **color;
84 char **sptr;
85
86 if (colorTable) {
87 for (a = 0, color = colorTable; a < ncolors; a++, color++) {
88 for (b = 0, sptr = (char **) *color; b <= NKEYS; b++, sptr++)
89 if (*sptr)
90 XpmFree(*sptr);
91 }
92 XpmFree(*colorTable);
93 XpmFree(colorTable);
94 }
95}
96
97/* end 3.2 bc */
98
99/*
100 * Free the computed color table
101 */
ea258ad3
DW
102#ifdef __OS2__
103/* Visual Age cannot deal with old, non-ansi, code */
104void xpmFreeColorTable(XpmColor* colorTable, int ncolors)
105#else
e6ed776f
GRG
106void
107xpmFreeColorTable(colorTable, ncolors)
108 XpmColor *colorTable;
109 int ncolors;
ea258ad3 110#endif
e6ed776f
GRG
111{
112 int a, b;
113 XpmColor *color;
114 char **sptr;
115
116 if (colorTable) {
117 for (a = 0, color = colorTable; a < ncolors; a++, color++) {
118 for (b = 0, sptr = (char **) color; b <= NKEYS; b++, sptr++)
119 if (*sptr)
120 XpmFree(*sptr);
121 }
122 XpmFree(colorTable);
123 }
124}
125
126/*
127 * Free array of extensions
128 */
ea258ad3
DW
129#ifdef __OS2__
130/* Visual Age cannot deal with old, non-ansi, code */
131void XpmFreeExtensions(XpmExtension* extensions, int nextensions)
132#else
e6ed776f
GRG
133void
134XpmFreeExtensions(extensions, nextensions)
135 XpmExtension *extensions;
136 int nextensions;
ea258ad3 137#endif
e6ed776f
GRG
138{
139 unsigned int i, j, nlines;
140 XpmExtension *ext;
141 char **sptr;
142
143 if (extensions) {
f6bcfd97 144 for (i = 0, ext = extensions; i < (unsigned)nextensions; i++, ext++) {
e6ed776f
GRG
145 if (ext->name)
146 XpmFree(ext->name);
147 nlines = ext->nlines;
148 for (j = 0, sptr = ext->lines; j < nlines; j++, sptr++)
149 if (*sptr)
150 XpmFree(*sptr);
151 if (ext->lines)
152 XpmFree(ext->lines);
153 }
154 XpmFree(extensions);
155 }
156}
157
158/*
159 * Return the XpmAttributes structure size
160 */
161
162int
163XpmAttributesSize()
164{
165 return sizeof(XpmAttributes);
166}
167
168/*
169 * Init returned data to free safely later on
170 */
ea258ad3
DW
171#ifdef __OS2__
172/* Visual Age cannot deal with old, non-ansi, code */
173void
174xpmInitAttributes(XpmAttributes* attributes)
175#else
e6ed776f
GRG
176void
177xpmInitAttributes(attributes)
178 XpmAttributes *attributes;
ea258ad3 179#endif
e6ed776f
GRG
180{
181 if (attributes) {
182 attributes->pixels = NULL;
183 attributes->npixels = 0;
184 attributes->colorTable = NULL;
185 attributes->ncolors = 0;
186/* 3.2 backward compatibility code */
187 attributes->hints_cmt = NULL;
188 attributes->colors_cmt = NULL;
189 attributes->pixels_cmt = NULL;
190/* end 3.2 bc */
191 if (attributes->valuemask & XpmReturnExtensions) {
192 attributes->extensions = NULL;
193 attributes->nextensions = 0;
194 }
195 if (attributes->valuemask & XpmReturnAllocPixels) {
196 attributes->alloc_pixels = NULL;
197 attributes->nalloc_pixels = 0;
198 }
199 }
200}
201
202/*
203 * Fill in the XpmAttributes with the XpmImage and the XpmInfo
204 */
ea258ad3
DW
205#ifdef __OS2__
206/* Visual Age cannot deal with old, non-ansi, code */
207void xpmSetAttributes(XpmAttributes* attributes, XpmImage* image, XpmInfo* info)
208#else
e6ed776f
GRG
209void
210xpmSetAttributes(attributes, image, info)
211 XpmAttributes *attributes;
212 XpmImage *image;
213 XpmInfo *info;
ea258ad3 214#endif
e6ed776f
GRG
215{
216 if (attributes->valuemask & XpmReturnColorTable) {
217 attributes->colorTable = image->colorTable;
218 attributes->ncolors = image->ncolors;
219
220 /* avoid deletion of copied data */
221 image->ncolors = 0;
222 image->colorTable = NULL;
223 }
224/* 3.2 backward compatibility code */
225 else if (attributes->valuemask & XpmReturnInfos) {
226 int ErrorStatus;
227
228 ErrorStatus = CreateOldColorTable(image->colorTable, image->ncolors,
229 (XpmColor ***)
230 &attributes->colorTable);
231
232 /* if error just say we can't return requested data */
233 if (ErrorStatus != XpmSuccess) {
234 attributes->valuemask &= ~XpmReturnInfos;
235 if (!(attributes->valuemask & XpmReturnPixels)) {
236 XpmFree(attributes->pixels);
237 attributes->pixels = NULL;
238 attributes->npixels = 0;
239 }
240 attributes->ncolors = 0;
241 } else {
242 attributes->ncolors = image->ncolors;
243 attributes->hints_cmt = info->hints_cmt;
244 attributes->colors_cmt = info->colors_cmt;
245 attributes->pixels_cmt = info->pixels_cmt;
246
247 /* avoid deletion of copied data */
248 image->ncolors = 0;
249 image->colorTable = NULL;
250 info->hints_cmt = NULL;
251 info->colors_cmt = NULL;
252 info->pixels_cmt = NULL;
253 }
254 }
255/* end 3.2 bc */
256 if (attributes->valuemask & XpmReturnExtensions) {
257 attributes->extensions = info->extensions;
258 attributes->nextensions = info->nextensions;
259
260 /* avoid deletion of copied data */
261 info->extensions = NULL;
262 info->nextensions = 0;
263 }
264 if (info->valuemask & XpmHotspot) {
265 attributes->valuemask |= XpmHotspot;
266 attributes->x_hotspot = info->x_hotspot;
267 attributes->y_hotspot = info->y_hotspot;
268 }
269 attributes->valuemask |= XpmCharsPerPixel;
270 attributes->cpp = image->cpp;
271 attributes->valuemask |= XpmSize;
272 attributes->width = image->width;
273 attributes->height = image->height;
274}
275
276/*
277 * Free the XpmAttributes structure members
278 * but the structure itself
279 */
ea258ad3
DW
280#ifdef __OS2__
281/* Visual Age cannot deal with old, non-ansi, code */
282void XpmFreeAttributes(XpmAttributes* attributes)
283#else
e6ed776f
GRG
284void
285XpmFreeAttributes(attributes)
286 XpmAttributes *attributes;
ea258ad3 287#endif
e6ed776f
GRG
288{
289 if (attributes->valuemask & XpmReturnPixels && attributes->npixels) {
290 XpmFree(attributes->pixels);
291 attributes->pixels = NULL;
292 attributes->npixels = 0;
293 }
294 if (attributes->valuemask & XpmReturnColorTable) {
295 xpmFreeColorTable(attributes->colorTable, attributes->ncolors);
296 attributes->colorTable = NULL;
297 attributes->ncolors = 0;
298 }
299/* 3.2 backward compatibility code */
300 else if (attributes->valuemask & XpmInfos) {
301 if (attributes->colorTable) {
302 FreeOldColorTable((XpmColor **) attributes->colorTable,
303 attributes->ncolors);
304 attributes->colorTable = NULL;
305 attributes->ncolors = 0;
306 }
307 if (attributes->hints_cmt) {
308 XpmFree(attributes->hints_cmt);
309 attributes->hints_cmt = NULL;
310 }
311 if (attributes->colors_cmt) {
312 XpmFree(attributes->colors_cmt);
313 attributes->colors_cmt = NULL;
314 }
315 if (attributes->pixels_cmt) {
316 XpmFree(attributes->pixels_cmt);
317 attributes->pixels_cmt = NULL;
318 }
319 if (attributes->pixels) {
320 XpmFree(attributes->pixels);
321 attributes->pixels = NULL;
322 attributes->npixels = 0;
323 }
324 }
325/* end 3.2 bc */
326 if (attributes->valuemask & XpmReturnExtensions
327 && attributes->nextensions) {
328 XpmFreeExtensions(attributes->extensions, attributes->nextensions);
329 attributes->extensions = NULL;
330 attributes->nextensions = 0;
331 }
332 if (attributes->valuemask & XpmReturnAllocPixels
333 && attributes->nalloc_pixels) {
334 XpmFree(attributes->alloc_pixels);
335 attributes->alloc_pixels = NULL;
336 attributes->nalloc_pixels = 0;
337 }
338 attributes->valuemask = 0;
339}