]> git.lizzy.rs Git - metalua.git/blob - src/binlibs/pluto/pdep/lzio.h
CRLF fsckup
[metalua.git] / src / binlibs / pluto / pdep / lzio.h
1 /*
2 ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
3 ** Buffered streams
4 ** See Copyright Notice in lua.h
5 */
6
7
8 #ifndef lzio_h
9 #define lzio_h
10
11 #include "lua.h"
12
13
14 #define EOZ     (-1)                    /* end of stream */
15
16 typedef struct Zio ZIO;
17
18 #define char2int(c)     cast(int, cast(unsigned char, (c)))
19
20 #define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : pdep_fill(z))
21
22 typedef struct Mbuffer {
23   char *buffer;
24   size_t n;
25   size_t buffsize;
26 } Mbuffer;
27
28 #define pdep_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
29
30 #define pdep_buffer(buff)       ((buff)->buffer)
31 #define pdep_sizebuffer(buff)   ((buff)->buffsize)
32 #define pdep_bufflen(buff)      ((buff)->n)
33
34 #define pdep_resetbuffer(buff) ((buff)->n = 0)
35
36
37 #define pdep_resizebuffer(L, buff, size) \
38         (pdep_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
39         (buff)->buffsize = size)
40
41 #define pdep_freebuffer(L, buff)        pdep_resizebuffer(L, buff, 0)
42
43
44 LUAI_FUNC char *pdep_openspace (lua_State *L, Mbuffer *buff, size_t n);
45 LUAI_FUNC void pdep_init (lua_State *L, ZIO *z, lua_Reader reader,
46                                         void *data);
47 LUAI_FUNC size_t pdep_read (ZIO* z, void* b, size_t n); /* read next n bytes */
48 LUAI_FUNC int pdep_lookahead (ZIO *z);
49
50
51
52 /* --------- Private Part ------------------ */
53
54 struct Zio {
55   size_t n;                     /* bytes still unread */
56   const char *p;                /* current position in buffer */
57   lua_Reader reader;
58   void* data;                   /* additional data */
59   lua_State *L;                 /* Lua state (for reader) */
60 };
61
62
63 LUAI_FUNC int pdep_fill (ZIO *z);
64
65 #endif