rlm@1: /* rlm@1: ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ rlm@1: ** Buffered streams rlm@1: ** See Copyright Notice in lua.h rlm@1: */ rlm@1: rlm@1: rlm@1: #ifndef lzio_h rlm@1: #define lzio_h rlm@1: rlm@1: #include "lua.h" rlm@1: rlm@1: #include "lmem.h" rlm@1: rlm@1: rlm@1: #define EOZ (-1) /* end of stream */ rlm@1: rlm@1: typedef struct Zio ZIO; rlm@1: rlm@1: #define char2int(c) cast(int, cast(unsigned char, (c))) rlm@1: rlm@1: #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) rlm@1: rlm@1: typedef struct Mbuffer { rlm@1: char *buffer; rlm@1: size_t n; rlm@1: size_t buffsize; rlm@1: } Mbuffer; rlm@1: rlm@1: #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) rlm@1: rlm@1: #define luaZ_buffer(buff) ((buff)->buffer) rlm@1: #define luaZ_sizebuffer(buff) ((buff)->buffsize) rlm@1: #define luaZ_bufflen(buff) ((buff)->n) rlm@1: rlm@1: #define luaZ_resetbuffer(buff) ((buff)->n = 0) rlm@1: rlm@1: rlm@1: #define luaZ_resizebuffer(L, buff, size) \ rlm@1: (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ rlm@1: (buff)->buffsize = size) rlm@1: rlm@1: #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) rlm@1: rlm@1: rlm@1: LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); rlm@1: LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, rlm@1: void *data); rlm@1: LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ rlm@1: LUAI_FUNC int luaZ_lookahead (ZIO *z); rlm@1: rlm@1: rlm@1: rlm@1: /* --------- Private Part ------------------ */ rlm@1: rlm@1: struct Zio { rlm@1: size_t n; /* bytes still unread */ rlm@1: const char *p; /* current position in buffer */ rlm@1: lua_Reader reader; rlm@1: void* data; /* additional data */ rlm@1: lua_State *L; /* Lua state (for reader) */ rlm@1: }; rlm@1: rlm@1: rlm@1: LUAI_FUNC int luaZ_fill (ZIO *z); rlm@1: rlm@1: #endif