]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/xpm/RdFToI.c
2 * Copyright (C) 1989-95 GROUPE BULL
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
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.
26 /*****************************************************************************\
30 * Parse an XPM file and create the image and possibly its mask *
32 * Developed by Arnaud Le Hors *
33 \*****************************************************************************/
51 #if !defined(NO_ZPIPE) && defined(WIN32)
53 # define pclose _pclose
54 # if defined(STAT_ZFILE)
62 LFUNC(OpenReadFile
, int, (char *filename
, xpmData
*mdata
));
63 LFUNC(xpmDataClose
, void, (xpmData
*mdata
));
67 XpmReadFileToImage(display
, filename
,
68 image_return
, shapeimage_return
, attributes
)
71 XImage
**image_return
;
72 XImage
**shapeimage_return
;
73 XpmAttributes
*attributes
;
80 xpmInitXpmImage(&image
);
81 xpmInitXpmInfo(&info
);
83 /* open file to read */
84 if ((ErrorStatus
= OpenReadFile(filename
, &mdata
)) != XpmSuccess
)
87 /* create the XImage from the XpmData */
89 xpmInitAttributes(attributes
);
90 xpmSetInfoMask(&info
, attributes
);
91 ErrorStatus
= xpmParseDataAndCreate(display
, &mdata
,
92 image_return
, shapeimage_return
,
93 &image
, &info
, attributes
);
95 ErrorStatus
= xpmParseDataAndCreate(display
, &mdata
,
96 image_return
, shapeimage_return
,
97 &image
, NULL
, attributes
);
99 if (ErrorStatus
>= 0) /* no fatal error */
100 xpmSetAttributes(attributes
, &image
, &info
);
101 XpmFreeXpmInfo(&info
);
104 xpmDataClose(&mdata
);
105 /* free the XpmImage */
106 XpmFreeXpmImage(&image
);
108 return (ErrorStatus
);
112 XpmReadFileToXpmImage(filename
, image
, info
)
120 /* init returned values */
121 xpmInitXpmImage(image
);
122 xpmInitXpmInfo(info
);
124 /* open file to read */
125 if ((ErrorStatus
= OpenReadFile(filename
, &mdata
)) != XpmSuccess
)
126 return (ErrorStatus
);
128 /* create the XpmImage from the XpmData */
129 ErrorStatus
= xpmParseData(&mdata
, image
, info
);
131 xpmDataClose(&mdata
);
133 return (ErrorStatus
);
135 #endif /* CXPMPROG */
138 * open the given file to be read as an xpmData which is returned.
141 OpenReadFile(filename
, mdata
)
146 char *compressfile
, buf
[BUFSIZ
];
153 mdata
->stream
.file
= (stdin
);
154 mdata
->type
= XPMFILE
;
157 int len
= strlen(filename
);
158 if ((len
> 2) && !strcmp(".Z", filename
+ (len
- 2))) {
159 mdata
->type
= XPMPIPE
;
160 sprintf(buf
, "uncompress -c \"%s\"", filename
);
161 if (!(mdata
->stream
.file
= popen(buf
, "r")))
162 return (XpmOpenFailed
);
164 } else if ((len
> 3) && !strcmp(".gz", filename
+ (len
- 3))) {
165 mdata
->type
= XPMPIPE
;
166 sprintf(buf
, "gunzip -qc \"%s\"", filename
);
167 if (!(mdata
->stream
.file
= popen(buf
, "r")))
168 return (XpmOpenFailed
);
172 if (!(compressfile
= (char *) XpmMalloc(len
+ 4)))
173 return (XpmNoMemory
);
175 sprintf(compressfile
, "%s.Z", filename
);
176 if (!stat(compressfile
, &status
)) {
177 sprintf(buf
, "uncompress -c \"%s\"", compressfile
);
178 if (!(mdata
->stream
.file
= popen(buf
, "r"))) {
179 XpmFree(compressfile
);
180 return (XpmOpenFailed
);
182 mdata
->type
= XPMPIPE
;
184 sprintf(compressfile
, "%s.gz", filename
);
185 if (!stat(compressfile
, &status
)) {
186 sprintf(buf
, "gunzip -c \"%s\"", compressfile
);
187 if (!(mdata
->stream
.file
= popen(buf
, "r"))) {
188 XpmFree(compressfile
);
189 return (XpmOpenFailed
);
191 mdata
->type
= XPMPIPE
;
195 if (!(mdata
->stream
.file
= fopen(filename
, "r"))) {
196 #if !defined(NO_ZPIPE) && defined(STAT_ZFILE)
197 XpmFree(compressfile
);
199 return (XpmOpenFailed
);
201 mdata
->type
= XPMFILE
;
206 XpmFree(compressfile
);
211 mdata
->CommentLength
= 0;
220 * close the file related to the xpmData if any
226 switch (mdata
->type
) {
228 if (mdata
->stream
.file
!= (stdin
))
229 fclose(mdata
->stream
.file
);
233 pclose(mdata
->stream
.file
);