1*eda14cbcSMatt Macy /* BEGIN CSTYLED */ 2*eda14cbcSMatt Macy /* 3*eda14cbcSMatt Macy ** $Id: lzio.h,v 1.26.1.1 2013/04/12 18:48:47 roberto Exp $ 4*eda14cbcSMatt Macy ** Buffered streams 5*eda14cbcSMatt Macy ** See Copyright Notice in lua.h 6*eda14cbcSMatt Macy */ 7*eda14cbcSMatt Macy 8*eda14cbcSMatt Macy 9*eda14cbcSMatt Macy #ifndef lzio_h 10*eda14cbcSMatt Macy #define lzio_h 11*eda14cbcSMatt Macy 12*eda14cbcSMatt Macy #include <sys/lua/lua.h> 13*eda14cbcSMatt Macy 14*eda14cbcSMatt Macy #include "lmem.h" 15*eda14cbcSMatt Macy 16*eda14cbcSMatt Macy 17*eda14cbcSMatt Macy #define EOZ (-1) /* end of stream */ 18*eda14cbcSMatt Macy 19*eda14cbcSMatt Macy typedef struct Zio ZIO; 20*eda14cbcSMatt Macy 21*eda14cbcSMatt Macy #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 22*eda14cbcSMatt Macy 23*eda14cbcSMatt Macy 24*eda14cbcSMatt Macy typedef struct Mbuffer { 25*eda14cbcSMatt Macy char *buffer; 26*eda14cbcSMatt Macy size_t n; 27*eda14cbcSMatt Macy size_t buffsize; 28*eda14cbcSMatt Macy } Mbuffer; 29*eda14cbcSMatt Macy 30*eda14cbcSMatt Macy #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 31*eda14cbcSMatt Macy 32*eda14cbcSMatt Macy #define luaZ_buffer(buff) ((buff)->buffer) 33*eda14cbcSMatt Macy #define luaZ_sizebuffer(buff) ((buff)->buffsize) 34*eda14cbcSMatt Macy #define luaZ_bufflen(buff) ((buff)->n) 35*eda14cbcSMatt Macy 36*eda14cbcSMatt Macy #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37*eda14cbcSMatt Macy 38*eda14cbcSMatt Macy 39*eda14cbcSMatt Macy #define luaZ_resizebuffer(L, buff, size) \ 40*eda14cbcSMatt Macy (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 41*eda14cbcSMatt Macy (buff)->buffsize = size) 42*eda14cbcSMatt Macy 43*eda14cbcSMatt Macy #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 44*eda14cbcSMatt Macy 45*eda14cbcSMatt Macy 46*eda14cbcSMatt Macy LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 47*eda14cbcSMatt Macy LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48*eda14cbcSMatt Macy void *data); 49*eda14cbcSMatt Macy LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 50*eda14cbcSMatt Macy 51*eda14cbcSMatt Macy 52*eda14cbcSMatt Macy 53*eda14cbcSMatt Macy /* --------- Private Part ------------------ */ 54*eda14cbcSMatt Macy 55*eda14cbcSMatt Macy struct Zio { 56*eda14cbcSMatt Macy size_t n; /* bytes still unread */ 57*eda14cbcSMatt Macy const char *p; /* current position in buffer */ 58*eda14cbcSMatt Macy lua_Reader reader; /* reader function */ 59*eda14cbcSMatt Macy void* data; /* additional data */ 60*eda14cbcSMatt Macy lua_State *L; /* Lua state (for reader) */ 61*eda14cbcSMatt Macy }; 62*eda14cbcSMatt Macy 63*eda14cbcSMatt Macy 64*eda14cbcSMatt Macy LUAI_FUNC int luaZ_fill (ZIO *z); 65*eda14cbcSMatt Macy 66*eda14cbcSMatt Macy #endif 67*eda14cbcSMatt Macy /* END CSTYLED */ 68