#ifndef _exp_buf_h_
#define _exp_buf_h_
typedef struct ExpBuf
{
char *dataStart;
char *dataEnd;
char *curr;
struct ExpBuf *next;
struct ExpBuf *prev;
char *blkStart;
char *blkEnd;
int readError;
int writeError;
} ExpBuf;
#if defined (DEBUG) || defined (USE_GEN_BUF)
#ifdef USE_GEN_BUF
void PutExpBufInGenBuf PROTO ((ExpBuf *eb,GenBuf *gb));
#endif
void ExpBufInit PROTO ((unsigned long dataBlkSize));
ExpBuf *ExpBufAllocBuf();
void ExpBufFreeBuf PROTO ((ExpBuf *ptr));
char *ExpBufAllocData();
void ExpBufFreeData PROTO ((char *ptr));
void ExpBufFreeBufAndData PROTO (( ExpBuf *b));
ExpBuf *ExpBufNext PROTO ((ExpBuf *b));
ExpBuf *ExpBufPrev PROTO ((ExpBuf *b));
void ExpBufResetInReadMode PROTO ((ExpBuf *b));
void ExpBufResetInWriteRvsMode PROTO ((ExpBuf *b));
int ExpBufAtEod PROTO ((ExpBuf *b));
int ExpBufFull PROTO ((ExpBuf *b));
int ExpBufHasNoData PROTO ((ExpBuf *b));
unsigned long ExpBufDataSize PROTO ((ExpBuf *b));
unsigned long ExpBufDataBlkSize PROTO ((ExpBuf *b));
char *ExpBufDataPtr PROTO ((ExpBuf *b));
#else
extern unsigned long expBufDataBlkSizeG;
#define ExpBufInit( size) expBufDataBlkSizeG = size;
#define ExpBufAllocBuf() ((ExpBuf *)malloc (sizeof (ExpBuf)))
#define ExpBufFreeBuf( ptr) free (ptr)
#define ExpBufAllocData() ((void *)malloc (expBufDataBlkSizeG))
#define ExpBufFreeData( ptr) free (ptr)
#define ExpBufFreeBufAndData( b) { ExpBufFreeData ((b)->blkStart); ExpBufFreeBuf (b); }
#define ExpBufNext( b) ((b)->next)
#define ExpBufPrev( b) ((b)->prev)
#define ExpBufResetInReadMode( b) { (b)->curr = (b)->dataStart; (b)->readError = 0; (b)->writeError = 1; }
#define ExpBufResetInWriteRvsMode( b) { (b)->dataStart = (b)->dataEnd = (b)->blkEnd; (b)->writeError = 0; (b)->readError = 1; }
#define ExpBufAtEod( b) ((b)->curr == (b)->dataEnd)
#define ExpBufFull( b) ((b)->dataStart == (b)->blkStart)
#define ExpBufHasNoData( b) ((b)->dataStart == (b)->dataEnd)
#define ExpBufDataSize( b) ((b)->dataEnd - (b)->dataStart)
#define ExpBufDataBlkSize( b) ((b)->blkEnd - (b)->blkStart)
#define ExpBufDataPtr( b) (ExpBufHasNoData (b)? NULL: (b)->dataStart)
#endif
#ifdef USE_GEN_BUF
int ExpBufReadError PROTO ((ExpBuf **b));
int ExpBufWriteError PROTO ((ExpBuf **b));
#else
#define ExpBufReadError( b) ((*b)->readError)
#define ExpBufWriteError( b) ((*b)->writeError)
#endif
ExpBuf *ExpBufAllocBufAndData();
void ExpBufInstallDataInBuf PROTO ((ExpBuf *b, char *data, unsigned long int len));
void ExpBufFreeBufAndDataList PROTO (( ExpBuf *b));
ExpBuf *ExpBufListLastBuf PROTO ((ExpBuf *b));
ExpBuf *ExpBufListFirstBuf PROTO ((ExpBuf *b));
void ExpBufCopyToFile PROTO ((ExpBuf *b, FILE *f));
void ExpBufSkip PROTO (( ExpBuf**, unsigned long len));
int ExpBufCopy PROTO (( char *dst, ExpBuf **b, unsigned long len));
unsigned char ExpBufPeekByte PROTO (( ExpBuf **b));
#if TTBL
int ExpBufPeekCopy PROTO ((char *dst, ExpBuf **b, unsigned long len));
char *ExpBufPeekSeg PROTO ((ExpBuf **b, unsigned long *len));
#endif
char *ExpBufGetSeg PROTO ((ExpBuf **b, unsigned long *len));
void ExpBufPutSegRvs PROTO ((ExpBuf **b, char *data, unsigned long len));
unsigned char ExpBufGetByte PROTO ((ExpBuf **b));
void ExpBufPutByteRvs PROTO ((ExpBuf **b, unsigned char byte));
#endif