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.
25
/* $XFree86: xc/extras/Xpm/cxpm/cxpm.c,v 1.2 2001/08/01 00:44:34 tsi Exp $ */
27
/*****************************************************************************\
30
* Check XPM File program *
32
* Developed by Arnaud Le Hors *
33
\*****************************************************************************/
37
#include "../lib/XpmI.h"
40
#define xpmGetC(data) sGetc(data, data->stream.file)
42
#define Ungetc sUngetc
46
* special getc and ungetc counting read lines and characters
47
* note that 's' could stand both for "special" and "slow" ;-)
53
int c = getc(data->stream.file);
68
ungetc(c, data->stream.file);
77
/* include all the code we need (yeah, I know, quite ugly...) */
78
#include "../lib/data.c"
79
#include "../lib/parse.c"
80
#include "../lib/RdFToI.c" /* only for OpenReadFile and xpmDataClose */
81
#include "../lib/hashtab.c"
82
#include "../lib/misc.c"
83
#include "../lib/Attrib.c"
84
#include "../lib/Image.c"
87
ErrorMessage(ErrorStatus, data)
94
switch (ErrorStatus) {
98
error = "Cannot open file";
101
error = "Invalid XPM file";
104
error = "Not enough memory";
107
error = "Failed to parse color";
112
fprintf(stderr, "Xpm Error: %s.\n", error);
113
if (ErrorStatus == XpmFileInvalid && data)
114
fprintf(stderr, "Error found line %d near character %d\n",
132
if (!strcmp(argv[1], "-?") || !strncmp(argv[1], "-h", 2)) {
133
fprintf(stderr, "Usage: %s [filename]\n", argv[0]);
141
xpmInitXpmImage(&image);
143
if ((ErrorStatus = OpenReadFile(filename, &data)) != XpmSuccess)
144
ErrorMessage(ErrorStatus, NULL);
146
ErrorStatus = xpmParseData(&data, &image, NULL);
147
ErrorMessage(ErrorStatus, &data);
150
XpmFreeXpmImage(&image);