]>
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 \*****************************************************************************/
53 #if !defined(NO_ZPIPE) && defined(WIN32)
55 # define pclose _pclose
56 # if defined(STAT_ZFILE)
64 LFUNC(OpenReadFile
, int, (char *filename
, xpmData
*mdata
));
65 LFUNC(xpmDataClose
, void, (xpmData
*mdata
));
69 XpmReadFileToImage(display
, filename
,
70 image_return
, shapeimage_return
, attributes
)
73 XImage
**image_return
;
74 XImage
**shapeimage_return
;
75 XpmAttributes
*attributes
;
82 xpmInitXpmImage(&image
);
83 xpmInitXpmInfo(&info
);
85 /* open file to read */
86 if ((ErrorStatus
= OpenReadFile(filename
, &mdata
)) != XpmSuccess
)
89 /* create the XImage from the XpmData */
91 xpmInitAttributes(attributes
);
92 xpmSetInfoMask(&info
, attributes
);
93 ErrorStatus
= xpmParseDataAndCreate(display
, &mdata
,
94 image_return
, shapeimage_return
,
95 &image
, &info
, attributes
);
97 ErrorStatus
= xpmParseDataAndCreate(display
, &mdata
,
98 image_return
, shapeimage_return
,
99 &image
, NULL
, attributes
);
101 if (ErrorStatus
>= 0) /* no fatal error */
102 xpmSetAttributes(attributes
, &image
, &info
);
103 XpmFreeXpmInfo(&info
);
106 xpmDataClose(&mdata
);
107 /* free the XpmImage */
108 XpmFreeXpmImage(&image
);
110 return (ErrorStatus
);
114 XpmReadFileToXpmImage(filename
, image
, info
)
122 /* init returned values */
123 xpmInitXpmImage(image
);
124 xpmInitXpmInfo(info
);
126 /* open file to read */
127 if ((ErrorStatus
= OpenReadFile(filename
, &mdata
)) != XpmSuccess
)
128 return (ErrorStatus
);
130 /* create the XpmImage from the XpmData */
131 ErrorStatus
= xpmParseData(&mdata
, image
, info
);
133 xpmDataClose(&mdata
);
135 return (ErrorStatus
);
137 #endif /* CXPMPROG */
140 * open the given file to be read as an xpmData which is returned.
143 OpenReadFile(filename
, mdata
)
148 char *compressfile
, buf
[BUFSIZ
];
155 mdata
->stream
.file
= (stdin
);
156 mdata
->type
= XPMFILE
;
159 int len
= strlen(filename
);
160 if ((len
> 2) && !strcmp(".Z", filename
+ (len
- 2))) {
161 mdata
->type
= XPMPIPE
;
162 sprintf(buf
, "uncompress -c \"%s\"", filename
);
163 if (!(mdata
->stream
.file
= popen(buf
, "r")))
164 return (XpmOpenFailed
);
166 } else if ((len
> 3) && !strcmp(".gz", filename
+ (len
- 3))) {
167 mdata
->type
= XPMPIPE
;
168 sprintf(buf
, "gunzip -qc \"%s\"", filename
);
169 if (!(mdata
->stream
.file
= popen(buf
, "r")))
170 return (XpmOpenFailed
);
174 if (!(compressfile
= (char *) XpmMalloc(len
+ 4)))
175 return (XpmNoMemory
);
177 sprintf(compressfile
, "%s.Z", filename
);
178 if (!stat(compressfile
, &status
)) {
179 sprintf(buf
, "uncompress -c \"%s\"", compressfile
);
180 if (!(mdata
->stream
.file
= popen(buf
, "r"))) {
181 XpmFree(compressfile
);
182 return (XpmOpenFailed
);
184 mdata
->type
= XPMPIPE
;
186 sprintf(compressfile
, "%s.gz", filename
);
187 if (!stat(compressfile
, &status
)) {
188 sprintf(buf
, "gunzip -c \"%s\"", compressfile
);
189 if (!(mdata
->stream
.file
= popen(buf
, "r"))) {
190 XpmFree(compressfile
);
191 return (XpmOpenFailed
);
193 mdata
->type
= XPMPIPE
;
197 if (!(mdata
->stream
.file
= fopen(filename
, "r"))) {
198 #if !defined(NO_ZPIPE) && defined(STAT_ZFILE)
199 XpmFree(compressfile
);
201 return (XpmOpenFailed
);
203 mdata
->type
= XPMFILE
;
208 XpmFree(compressfile
);
213 mdata
->CommentLength
= 0;
222 * close the file related to the xpmData if any
228 switch (mdata
->type
) {
230 if (mdata
->stream
.file
!= (stdin
))
231 fclose(mdata
->stream
.file
);
235 pclose(mdata
->stream
.file
);