2 * Copyright (C) 1998 Arnaud LE HORS
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 * Arnaud LE HORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18 * IN 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 Arnaud LE HORS 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 Arnaud LE HORS.
26 /*****************************************************************************\
29 * Check XPM File program *
31 * Developed by Arnaud Le Hors *
32 \*****************************************************************************/
44 #define gettext(a) (a)
48 #define xpmGetC(data) sGetc(data, data->stream.file)
50 #define Ungetc sUngetc
54 * special getc and ungetc counting read lines and characters
55 * note that 's' could stand both for "special" and "slow" ;-)
58 sGetc(xpmData *data, FILE *file)
60 int c = getc(data->stream.file);
71 sUngetc(xpmData *data, int c, FILE *file)
73 ungetc(c, data->stream.file);
82 /* include all the code we need (yeah, I know, quite ugly...) */
85 #include "RdFToI.c" /* only for OpenReadFile and xpmDataClose */
99 switch (ErrorStatus) {
103 /* L10N_Comments : Error produced when filename does not exist
104 or insufficient permissions to open (i.e. cxpm /no/such/file ) */
105 error = gettext("Cannot open file");
108 /* L10N_Comments : Error produced when filename can be read, but
109 is not an XPM file (i.e. cxpm /dev/null ) */
110 error = gettext("Invalid XPM file");
113 /* L10N_Comments : Error produced when filename can be read, but
114 is too big for memory
115 (i.e. limit datasize 32 ; cxpm /usr/dt/backdrops/Crochet.pm ) */
116 error = gettext("Not enough memory");
119 /* L10N_Comments : Error produced when filename can be read, but
120 contains an invalid color specification (need to create test case)*/
121 error = gettext("Failed to parse color");
126 /* L10N_Comments : Wrapper around above Xpm errors - %s is
127 replaced with the contents of the error message retrieved above */
128 fprintf(stderr, gettext("Xpm Error: %s.\n"), error);
129 if (ErrorStatus == XpmFileInvalid && data)
130 /* L10N_Comments : Error produced when filename can be read, but
131 is not an XPM file (i.e. cxpm /dev/null ) */
132 fprintf(stderr, gettext("Error found line %d near character %d\n"),
140 main(int argc, char **argv)
148 setlocale(LC_ALL,"");
149 bindtextdomain("cxpm",LOCALEDIR);
154 if (!strcmp(argv[1], "-?") || !strncmp(argv[1], "-h", 2)) {
155 /* L10N_Comments : Usage message produced by running cxpm -h
156 %s will be replaced by argv[0] (program name) */
157 fprintf(stderr, gettext("Usage: %s [filename]\n"), argv[0]);
165 xpmInitXpmImage(&image);
167 if ((ErrorStatus = OpenReadFile(filename, &data)) != XpmSuccess)
168 ErrorMessage(ErrorStatus, NULL);
170 ErrorStatus = xpmParseData(&data, &image, NULL);
171 ErrorMessage(ErrorStatus, &data);
174 XpmFreeXpmImage(&image);