#ifndef XPMI_h
#define XPMI_h
#include "xpm.h"
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#ifdef sequent
extern FILE *popen();
#endif
#include <X11/Xos.h>
#include <X11/Xfuncs.h>
#include <X11/Xmd.h>
#ifdef VMS
#include <unixio.h>
#include <file.h>
#endif
#define XpmFree(ptr) free(ptr)
#ifndef FOR_MSW
#define XpmMalloc(size) malloc((size))
#define XpmRealloc(ptr, size) realloc((ptr), (size))
#define XpmCalloc(nelem, elsize) calloc((nelem), (elsize))
#else
#define XpmMalloc(size) boundCheckingMalloc((long)(size))
#define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size))
#define XpmCalloc(nelem, elsize) \
boundCheckingCalloc((long)(nelem),(long) (elsize))
#endif
#if defined(SCO) || defined(__USLC__)
#include <stdint.h>
#endif
#include <limits.h>
#ifndef SIZE_MAX
# ifdef ULONG_MAX
# define SIZE_MAX ULONG_MAX
# else
# define SIZE_MAX UINT_MAX
# endif
#endif
#define XPMMAXCMTLEN BUFSIZ
typedef struct {
unsigned int type;
union {
FILE *file;
char **data;
} stream;
char *cptr;
unsigned int line;
int CommentLength;
char Comment[XPMMAXCMTLEN];
char *Bcmt, *Ecmt, Bos, Eos;
int format;
#ifdef CXPMPROG
int lineNum;
int charNum;
#endif
} xpmData;
#define XPMARRAY 0
#define XPMFILE 1
#define XPMPIPE 2
#define XPMBUFFER 3
#define EOL '\n'
#define TAB '\t'
#define SPC ' '
typedef struct {
char *type;
char *Bcmt;
char *Ecmt;
char Bos;
char Eos;
char *Strs;
char *Dec;
char *Boa;
char *Eoa;
} xpmDataType;
extern xpmDataType xpmDataTypes[];
typedef struct {
int r, g, b;
char *name;
} xpmRgbName;
#define MAX_RGBNAMES 1024
extern char *xpmColorKeys[];
#define TRANSPARENT_COLOR "None"
#define NKEYS 5
FUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
FUNC(xpmParseDataAndCreate, int, (Display *display, xpmData *data,
XImage **image_return,
XImage **shapeimage_return,
XpmImage *image, XpmInfo *info,
XpmAttributes *attributes));
FUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
FUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
FUNC(xpmInitXpmImage, void, (XpmImage *image));
FUNC(xpmInitXpmInfo, void, (XpmInfo *info));
FUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
FUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
FUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
XpmInfo *info));
#if !defined(FOR_MSW) && !defined(AMIGA)
FUNC(xpmCreatePixmapFromImage, void, (Display *display, Drawable d,
XImage *ximage, Pixmap *pixmap_return));
FUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
XImage **ximage_return,
unsigned int *width,
unsigned int *height));
#endif
typedef struct _xpmHashAtom {
char *name;
void *data;
} *xpmHashAtom;
typedef struct {
unsigned int size;
unsigned int limit;
unsigned int used;
xpmHashAtom *atomTable;
} xpmHashTable;
FUNC(xpmHashTableInit, int, (xpmHashTable *table));
FUNC(xpmHashTableFree, void, (xpmHashTable *table));
FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
#define HashAtomData(i) ((void *)(long)i)
#define HashColorIndex(slot) ((unsigned long)((*slot)->data))
#define USE_HASHTABLE (cpp > 2 && ncolors > 4)
FUNC(xpmNextString, int, (xpmData *mdata));
FUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
FUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
#define xpmGetC(mdata) \
((!mdata->type || mdata->type == XPMBUFFER) ? \
(*mdata->cptr++) : (getc(mdata->stream.file)))
FUNC(xpmNextWord, unsigned int,
(xpmData *mdata, char *buf, unsigned int buflen));
FUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
FUNC(xpmParseHeader, int, (xpmData *mdata));
FUNC(xpmParseValues, int, (xpmData *data, unsigned int *width,
unsigned int *height, unsigned int *ncolors,
unsigned int *cpp, unsigned int *x_hotspot,
unsigned int *y_hotspot, unsigned int *hotspot,
unsigned int *extensions));
FUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors,
unsigned int cpp, XpmColor **colorTablePtr,
xpmHashTable *hashtable));
FUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions,
unsigned int *nextensions));
FUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName *rgbn));
FUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
int red, int green, int blue));
FUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
#ifdef FOR_MSW
FUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b));
#endif
#ifndef AMIGA
FUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
register XImage *img));
FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
register XImage *img));
#define XYNORMALIZE(bp, img) \
if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
xpm_xynormalizeimagebits((unsigned char *)(bp), img)
#define ZNORMALIZE(bp, img) \
if (img->byte_order == MSBFirst) \
xpm_znormalizeimagebits((unsigned char *)(bp), img)
#define XYINDEX(x, y, img) \
((y) * img->bytes_per_line) + \
(((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
#define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
(((x) * img->bits_per_pixel) >> 3)
#define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2)
#define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1)
#define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x)
#define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3)
#endif
#ifdef __STDC__
#define Const const
#else
#define Const
#endif
#ifdef NEED_STRDUP
FUNC(xpmstrdup, char *, (char *s1));
#else
#undef xpmstrdup
#define xpmstrdup strdup
#endif
#ifdef NEED_STRCASECMP
FUNC(xpmstrcasecmp, int, (char *s1, char *s2));
#else
#undef xpmstrcasecmp
#define xpmstrcasecmp strcasecmp
#endif
FUNC(xpmatoui, unsigned int,
(char *p, unsigned int l, unsigned int *ui_return));
#endif