misc/liblua/lzio.h
changeset 10017 de822cd3df3a
parent 2812 0a24853de796
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    11 #include "lua.h"
    11 #include "lua.h"
    12 
    12 
    13 #include "lmem.h"
    13 #include "lmem.h"
    14 
    14 
    15 
    15 
    16 #define EOZ	(-1)			/* end of stream */
    16 #define EOZ (-1)            /* end of stream */
    17 
    17 
    18 typedef struct Zio ZIO;
    18 typedef struct Zio ZIO;
    19 
    19 
    20 #define char2int(c)	cast(int, cast(unsigned char, (c)))
    20 #define char2int(c) cast(int, cast(unsigned char, (c)))
    21 
    21 
    22 #define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : luaZ_fill(z))
    22 #define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : luaZ_fill(z))
    23 
    23 
    24 typedef struct Mbuffer {
    24 typedef struct Mbuffer {
    25   char *buffer;
    25   char *buffer;
    27   size_t buffsize;
    27   size_t buffsize;
    28 } Mbuffer;
    28 } Mbuffer;
    29 
    29 
    30 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
    30 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
    31 
    31 
    32 #define luaZ_buffer(buff)	((buff)->buffer)
    32 #define luaZ_buffer(buff)   ((buff)->buffer)
    33 #define luaZ_sizebuffer(buff)	((buff)->buffsize)
    33 #define luaZ_sizebuffer(buff)   ((buff)->buffsize)
    34 #define luaZ_bufflen(buff)	((buff)->n)
    34 #define luaZ_bufflen(buff)  ((buff)->n)
    35 
    35 
    36 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
    36 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
    37 
    37 
    38 
    38 
    39 #define luaZ_resizebuffer(L, buff, size) \
    39 #define luaZ_resizebuffer(L, buff, size) \
    40 	(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
    40     (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
    41 	(buff)->buffsize = size)
    41     (buff)->buffsize = size)
    42 
    42 
    43 #define luaZ_freebuffer(L, buff)	luaZ_resizebuffer(L, buff, 0)
    43 #define luaZ_freebuffer(L, buff)    luaZ_resizebuffer(L, buff, 0)
    44 
    44 
    45 
    45 
    46 LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
    46 LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
    47 LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
    47 LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
    48                                         void *data);
    48                                         void *data);
    49 LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n);	/* read next n bytes */
    49 LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
    50 LUAI_FUNC int luaZ_lookahead (ZIO *z);
    50 LUAI_FUNC int luaZ_lookahead (ZIO *z);
    51 
    51 
    52 
    52 
    53 
    53 
    54 /* --------- Private Part ------------------ */
    54 /* --------- Private Part ------------------ */
    55 
    55 
    56 struct Zio {
    56 struct Zio {
    57   size_t n;			/* bytes still unread */
    57   size_t n;         /* bytes still unread */
    58   const char *p;		/* current position in buffer */
    58   const char *p;        /* current position in buffer */
    59   lua_Reader reader;
    59   lua_Reader reader;
    60   void* data;			/* additional data */
    60   void* data;           /* additional data */
    61   lua_State *L;			/* Lua state (for reader) */
    61   lua_State *L;         /* Lua state (for reader) */
    62 };
    62 };
    63 
    63 
    64 
    64 
    65 LUAI_FUNC int luaZ_fill (ZIO *z);
    65 LUAI_FUNC int luaZ_fill (ZIO *z);
    66 
    66