2003-11-01 06:35:29 +01:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2006-01-08 02:25:02 +01:00
|
|
|
* Copyright 1997 - 2000 by Eric House (xwords@eehouse.org). All rights reserved.
|
2003-11-01 06:35:29 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _XWSTREAM_H_
|
|
|
|
#define _XWSTREAM_H_
|
|
|
|
|
|
|
|
#include "comtypes.h"
|
2005-08-21 16:33:38 +02:00
|
|
|
#include "memstream.h"
|
2003-11-01 06:35:29 +01:00
|
|
|
/* #include "xptypes.h" */
|
|
|
|
|
|
|
|
#define START_OF_STREAM 0
|
|
|
|
#define END_OF_STREAM -1
|
|
|
|
|
|
|
|
typedef XP_U32 XWStreamPos; /* low 3 bits are bit offset; rest byte offset */
|
|
|
|
enum { POS_READ, POS_WRITE };
|
|
|
|
typedef XP_U8 PosWhich;
|
|
|
|
|
2006-11-14 07:40:36 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
# define DBG_LINE_FILE_FORMAL , XP_U16 lin, const char* fil
|
|
|
|
# define DBG_LINE_FILE_PARM , __LINE__, __FILE__
|
|
|
|
#else
|
|
|
|
# define DBG_LINE_FILE_FORMAL
|
|
|
|
# define DBG_LINE_FILE_PARM
|
|
|
|
#endif
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
typedef struct StreamCtxVTable {
|
|
|
|
void (*m_stream_destroy)( XWStreamCtxt* dctx );
|
|
|
|
|
|
|
|
XP_U8 (*m_stream_getU8)( XWStreamCtxt* dctx );
|
|
|
|
void (*m_stream_getBytes)( XWStreamCtxt* dctx, void* where,
|
|
|
|
XP_U16 count );
|
|
|
|
XP_U16 (*m_stream_getU16)( XWStreamCtxt* dctx );
|
|
|
|
XP_U32 (*m_stream_getU32)( XWStreamCtxt* dctx );
|
|
|
|
XP_U32 (*m_stream_getBits)( XWStreamCtxt* dctx, XP_U16 nBits );
|
|
|
|
|
|
|
|
void (*m_stream_putU8)( XWStreamCtxt* dctx, XP_U8 byt );
|
2006-08-23 06:44:55 +02:00
|
|
|
void (*m_stream_putBytes)( XWStreamCtxt* dctx, const void* whence,
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16 count );
|
2009-03-29 20:26:59 +02:00
|
|
|
void (*m_stream_catString)( XWStreamCtxt* dctx, const char* whence );
|
2003-11-01 06:35:29 +01:00
|
|
|
void (*m_stream_putU16)( XWStreamCtxt* dctx, XP_U16 data );
|
|
|
|
void (*m_stream_putU32)( XWStreamCtxt* dctx, XP_U32 data );
|
2006-11-14 07:40:36 +01:00
|
|
|
void (*m_stream_putBits)( XWStreamCtxt* dctx, XP_U16 nBits, XP_U32 bits
|
|
|
|
DBG_LINE_FILE_FORMAL );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
void (*m_stream_copyFromStream)( XWStreamCtxt* dctx, XWStreamCtxt* src,
|
|
|
|
XP_U16 nBytes );
|
|
|
|
|
|
|
|
XWStreamPos (*m_stream_getPos)( XWStreamCtxt* dctx, PosWhich which );
|
|
|
|
XWStreamPos (*m_stream_setPos)( XWStreamCtxt* dctx, XWStreamPos newpos,
|
|
|
|
PosWhich which );
|
|
|
|
|
|
|
|
void (*m_stream_open)( XWStreamCtxt* dctx );
|
|
|
|
void (*m_stream_close)( XWStreamCtxt* dctx );
|
|
|
|
|
2009-10-01 06:09:46 +02:00
|
|
|
XP_U16 (*m_stream_getSize)( const XWStreamCtxt* dctx );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
/* void (*m_stream_makeReturnAddr)( XWStreamCtxt* dctx, XP_PlayerAddr* addr, */
|
2008-05-31 05:26:16 +02:00
|
|
|
/* XP_U16* addrLen ); */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
XP_PlayerAddr (*m_stream_getAddress)( XWStreamCtxt* dctx );
|
|
|
|
void (*m_stream_setAddress)( XWStreamCtxt* dctx, XP_PlayerAddr channelNo );
|
|
|
|
|
2004-06-24 07:19:31 +02:00
|
|
|
void (*m_stream_setVersion)( XWStreamCtxt* dctx, XP_U16 vers );
|
|
|
|
XP_U16 (*m_stream_getVersion)( XWStreamCtxt* dctx );
|
2005-08-21 16:33:38 +02:00
|
|
|
|
|
|
|
void (*m_stream_setOnCloseProc)( XWStreamCtxt* dctx,
|
|
|
|
MemStreamCloseCallback proc );
|
2003-11-01 06:35:29 +01:00
|
|
|
} StreamCtxVTable;
|
|
|
|
|
|
|
|
|
|
|
|
struct XWStreamCtxt {
|
|
|
|
StreamCtxVTable* vtable;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define stream_destroy(sc) \
|
|
|
|
(sc)->vtable->m_stream_destroy(sc)
|
|
|
|
|
|
|
|
#define stream_getU8(sc) \
|
|
|
|
(sc)->vtable->m_stream_getU8(sc)
|
|
|
|
|
|
|
|
#define stream_getBytes(sc, wh, c ) \
|
|
|
|
(sc)->vtable->m_stream_getBytes((sc), (wh), (c))
|
|
|
|
|
|
|
|
#define stream_getU16(sc) \
|
|
|
|
(sc)->vtable->m_stream_getU16(sc)
|
|
|
|
|
|
|
|
#define stream_getU32(sc) \
|
|
|
|
(sc)->vtable->m_stream_getU32(sc)
|
|
|
|
|
|
|
|
#define stream_getBits(sc, n) \
|
|
|
|
(sc)->vtable->m_stream_getBits((sc), (n))
|
|
|
|
|
|
|
|
#define stream_putU8(sc, b) \
|
|
|
|
(sc)->vtable->m_stream_putU8((sc), (b))
|
|
|
|
|
|
|
|
#define stream_putBytes( sc, w, c ) \
|
|
|
|
(sc)->vtable->m_stream_putBytes((sc), (w), (c))
|
|
|
|
|
2009-03-29 20:26:59 +02:00
|
|
|
#define stream_catString( sc, w ) \
|
|
|
|
(sc)->vtable->m_stream_catString((sc), (w))
|
2006-04-25 15:31:15 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
#define stream_putU16(sc, d) \
|
|
|
|
(sc)->vtable->m_stream_putU16((sc), (d))
|
|
|
|
|
|
|
|
#define stream_putU32(sc, d) \
|
|
|
|
(sc)->vtable->m_stream_putU32((sc), (d))
|
|
|
|
|
|
|
|
#define stream_putBits(sc, n, b) \
|
2006-11-14 07:40:36 +01:00
|
|
|
(sc)->vtable->m_stream_putBits((sc), (n), (b) DBG_LINE_FILE_PARM )
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
#define stream_copyFromStream( sc, src, nb ) \
|
|
|
|
(sc)->vtable->m_stream_copyFromStream((sc), (src), (nb))
|
|
|
|
|
|
|
|
#define stream_getPos(sc, w) \
|
|
|
|
(sc)->vtable->m_stream_getPos((sc), (w))
|
|
|
|
|
|
|
|
#define stream_setPos(sc, p, w) \
|
|
|
|
(sc)->vtable->m_stream_setPos((sc), (p), (w))
|
|
|
|
|
|
|
|
#define stream_open(sc) \
|
|
|
|
(sc)->vtable->m_stream_open((sc))
|
|
|
|
|
|
|
|
#define stream_close(sc) \
|
|
|
|
(sc)->vtable->m_stream_close((sc))
|
|
|
|
|
|
|
|
#define stream_getSize(sc) \
|
|
|
|
(sc)->vtable->m_stream_getSize((sc))
|
|
|
|
|
|
|
|
#define stream_makeReturnAddr(sc,addr,len) \
|
|
|
|
(sc)->vtable->m_stream_makeReturnAddr((sc),(addr),(len))
|
|
|
|
|
|
|
|
#define stream_getAddress(sc) \
|
|
|
|
(sc)->vtable->m_stream_getAddress((sc))
|
|
|
|
|
|
|
|
#define stream_setAddress(sc,ch) \
|
|
|
|
(sc)->vtable->m_stream_setAddress((sc),(ch))
|
|
|
|
|
2004-06-24 07:19:31 +02:00
|
|
|
#define stream_setVersion(sc,ch) \
|
|
|
|
(sc)->vtable->m_stream_setVersion((sc),(ch))
|
|
|
|
|
|
|
|
#define stream_getVersion(sc) \
|
|
|
|
(sc)->vtable->m_stream_getVersion((sc))
|
|
|
|
|
2005-08-21 16:33:38 +02:00
|
|
|
#define stream_setOnCloseProc(sc, p) \
|
|
|
|
(sc)->vtable->m_stream_setOnCloseProc((sc), (p))
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
#endif /* _XWSTREAM_H_ */
|