]>
git.saurik.com Git - wxWidgets.git/blob - src/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 \*****************************************************************************/
37 #if !defined(NO_ZPIPE) && defined(WIN32)
39 # define pclose _pclose
40 # if defined(STAT_ZFILE)
47 LFUNC(OpenReadFile
, int, (char *filename
, xpmData
*mdata
));
48 LFUNC(xpmDataClose
, void, (xpmData
*mdata
));
52 XpmReadFileToImage(display
, filename
,
53 image_return
, shapeimage_return
, attributes
)
56 XImage
**image_return
;
57 XImage
**shapeimage_return
;
58 XpmAttributes
*attributes
;
65 xpmInitXpmImage(&image
);
66 xpmInitXpmInfo(&info
);
68 /* open file to read */
69 if ((ErrorStatus
= OpenReadFile(filename
, &mdata
)) != XpmSuccess
)
72 /* create the XImage from the XpmData */
74 xpmInitAttributes(attributes
);
75 xpmSetInfoMask(&info
, attributes
);
76 ErrorStatus
= xpmParseDataAndCreate(display
, &mdata
,
77 image_return
, shapeimage_return
,
78 &image
, &info
, attributes
);
80 ErrorStatus
= xpmParseDataAndCreate(display
, &mdata
,
81 image_return
, shapeimage_return
,
82 &image
, NULL
, attributes
);
84 if (ErrorStatus
>= 0) /* no fatal error */
85 xpmSetAttributes(attributes
, &image
, &info
);
86 XpmFreeXpmInfo(&info
);
90 /* free the XpmImage */
91 XpmFreeXpmImage(&image
);
97 XpmReadFileToXpmImage(filename
, image
, info
)
105 /* init returned values */
106 xpmInitXpmImage(image
);
107 xpmInitXpmInfo(info
);
109 /* open file to read */
110 if ((ErrorStatus
= OpenReadFile(filename
, &mdata
)) != XpmSuccess
)
111 return (ErrorStatus
);
113 /* create the XpmImage from the XpmData */
114 ErrorStatus
= xpmParseData(&mdata
, image
, info
);
116 xpmDataClose(&mdata
);
118 return (ErrorStatus
);
120 #endif /* CXPMPROG */
123 * open the given file to be read as an xpmData which is returned.
126 OpenReadFile(filename
, mdata
)
131 char *compressfile
, buf
[BUFSIZ
];
138 mdata
->stream
.file
= (stdin
);
139 mdata
->type
= XPMFILE
;
142 int len
= strlen(filename
);
143 if ((len
> 2) && !strcmp(".Z", filename
+ (len
- 2))) {
144 mdata
->type
= XPMPIPE
;
145 sprintf(buf
, "uncompress -c \"%s\"", filename
);
146 if (!(mdata
->stream
.file
= popen(buf
, "r")))
147 return (XpmOpenFailed
);
149 } else if ((len
> 3) && !strcmp(".gz", filename
+ (len
- 3))) {
150 mdata
->type
= XPMPIPE
;
151 sprintf(buf
, "gunzip -qc \"%s\"", filename
);
152 if (!(mdata
->stream
.file
= popen(buf
, "r")))
153 return (XpmOpenFailed
);
157 if (!(compressfile
= (char *) XpmMalloc(len
+ 4)))
158 return (XpmNoMemory
);
160 sprintf(compressfile
, "%s.Z", filename
);
161 if (!stat(compressfile
, &status
)) {
162 sprintf(buf
, "uncompress -c \"%s\"", compressfile
);
163 if (!(mdata
->stream
.file
= popen(buf
, "r"))) {
164 XpmFree(compressfile
);
165 return (XpmOpenFailed
);
167 mdata
->type
= XPMPIPE
;
169 sprintf(compressfile
, "%s.gz", filename
);
170 if (!stat(compressfile
, &status
)) {
171 sprintf(buf
, "gunzip -c \"%s\"", compressfile
);
172 if (!(mdata
->stream
.file
= popen(buf
, "r"))) {
173 XpmFree(compressfile
);
174 return (XpmOpenFailed
);
176 mdata
->type
= XPMPIPE
;
180 if (!(mdata
->stream
.file
= fopen(filename
, "r"))) {
181 #if !defined(NO_ZPIPE) && defined(STAT_ZFILE)
182 XpmFree(compressfile
);
184 return (XpmOpenFailed
);
186 mdata
->type
= XPMFILE
;
191 XpmFree(compressfile
);
196 mdata
->CommentLength
= 0;
205 * close the file related to the xpmData if any
211 switch (mdata
->type
) {
213 if (mdata
->stream
.file
!= (stdin
))
214 fclose(mdata
->stream
.file
);
218 pclose(mdata
->stream
.file
);