]>
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 \*****************************************************************************/
49 #if !defined(NO_ZPIPE) && defined(WIN32)
51 # define pclose _pclose
52 # if defined(STAT_ZFILE)
60 LFUNC(OpenReadFile
, int, (char *filename
, xpmData
*mdata
));
61 LFUNC(xpmDataClose
, void, (xpmData
*mdata
));
65 XpmReadFileToImage(display
, filename
,
66 image_return
, shapeimage_return
, attributes
)
69 XImage
**image_return
;
70 XImage
**shapeimage_return
;
71 XpmAttributes
*attributes
;
78 xpmInitXpmImage(&image
);
79 xpmInitXpmInfo(&info
);
81 /* open file to read */
82 if ((ErrorStatus
= OpenReadFile(filename
, &mdata
)) != XpmSuccess
)
85 /* create the XImage from the XpmData */
87 xpmInitAttributes(attributes
);
88 xpmSetInfoMask(&info
, attributes
);
89 ErrorStatus
= xpmParseDataAndCreate(display
, &mdata
,
90 image_return
, shapeimage_return
,
91 &image
, &info
, attributes
);
93 ErrorStatus
= xpmParseDataAndCreate(display
, &mdata
,
94 image_return
, shapeimage_return
,
95 &image
, NULL
, attributes
);
97 if (ErrorStatus
>= 0) /* no fatal error */
98 xpmSetAttributes(attributes
, &image
, &info
);
99 XpmFreeXpmInfo(&info
);
102 xpmDataClose(&mdata
);
103 /* free the XpmImage */
104 XpmFreeXpmImage(&image
);
106 return (ErrorStatus
);
110 XpmReadFileToXpmImage(filename
, image
, info
)
118 /* init returned values */
119 xpmInitXpmImage(image
);
120 xpmInitXpmInfo(info
);
122 /* open file to read */
123 if ((ErrorStatus
= OpenReadFile(filename
, &mdata
)) != XpmSuccess
)
124 return (ErrorStatus
);
126 /* create the XpmImage from the XpmData */
127 ErrorStatus
= xpmParseData(&mdata
, image
, info
);
129 xpmDataClose(&mdata
);
131 return (ErrorStatus
);
133 #endif /* CXPMPROG */
136 * open the given file to be read as an xpmData which is returned.
139 OpenReadFile(filename
, mdata
)
144 char *compressfile
, buf
[BUFSIZ
];
151 mdata
->stream
.file
= (stdin
);
152 mdata
->type
= XPMFILE
;
155 int len
= strlen(filename
);
156 if ((len
> 2) && !strcmp(".Z", filename
+ (len
- 2))) {
157 mdata
->type
= XPMPIPE
;
158 sprintf(buf
, "uncompress -c \"%s\"", filename
);
159 if (!(mdata
->stream
.file
= popen(buf
, "r")))
160 return (XpmOpenFailed
);
162 } else if ((len
> 3) && !strcmp(".gz", filename
+ (len
- 3))) {
163 mdata
->type
= XPMPIPE
;
164 sprintf(buf
, "gunzip -qc \"%s\"", filename
);
165 if (!(mdata
->stream
.file
= popen(buf
, "r")))
166 return (XpmOpenFailed
);
170 if (!(compressfile
= (char *) XpmMalloc(len
+ 4)))
171 return (XpmNoMemory
);
173 sprintf(compressfile
, "%s.Z", filename
);
174 if (!stat(compressfile
, &status
)) {
175 sprintf(buf
, "uncompress -c \"%s\"", compressfile
);
176 if (!(mdata
->stream
.file
= popen(buf
, "r"))) {
177 XpmFree(compressfile
);
178 return (XpmOpenFailed
);
180 mdata
->type
= XPMPIPE
;
182 sprintf(compressfile
, "%s.gz", filename
);
183 if (!stat(compressfile
, &status
)) {
184 sprintf(buf
, "gunzip -c \"%s\"", compressfile
);
185 if (!(mdata
->stream
.file
= popen(buf
, "r"))) {
186 XpmFree(compressfile
);
187 return (XpmOpenFailed
);
189 mdata
->type
= XPMPIPE
;
193 if (!(mdata
->stream
.file
= fopen(filename
, "r"))) {
194 #if !defined(NO_ZPIPE) && defined(STAT_ZFILE)
195 XpmFree(compressfile
);
197 return (XpmOpenFailed
);
199 mdata
->type
= XPMFILE
;
204 XpmFree(compressfile
);
209 mdata
->CommentLength
= 0;
218 * close the file related to the xpmData if any
224 switch (mdata
->type
) {
226 if (mdata
->stream
.file
!= (stdin
))
227 fclose(mdata
->stream
.file
);
231 pclose(mdata
->stream
.file
);