rpm  4.5
lzio.h
Go to the documentation of this file.
1 /*
2 ** $Id: lzio.h,v 1.1 2004/03/16 21:58:30 niemeyer 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 
19 #define char2int(c) cast(int, cast(unsigned char, (c)))
20 
21 #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
22 
23 #define zname(z) ((z)->name)
24 
25 void luaZ_init (ZIO *z, lua_Chunkreader reader, void *data, const char *name)
26  /*@modifies z @*/;
27 size_t luaZ_read (ZIO* z, void* b, size_t n) /* read next n bytes */
28  /*@modifies z, *b @*/;
29 int luaZ_lookahead (ZIO *z)
30  /*@modifies z @*/;
31 
32 
33 
34 typedef struct Mbuffer {
35 /*@relnull@*/
36  char *buffer;
37  size_t buffsize;
38 } Mbuffer;
39 
40 
41 char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n)
42  /*@modifies L, buff @*/;
43 
44 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
45 
46 #define luaZ_sizebuffer(buff) ((buff)->buffsize)
47 #define luaZ_buffer(buff) ((buff)->buffer)
48 
49 #define luaZ_resizebuffer(L, buff, size) \
50  (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
51  (buff)->buffsize = size)
52 
53 #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
54 
55 
56 /* --------- Private Part ------------------ */
57 
58 struct Zio {
59  size_t n; /* bytes still unread */
60 /*@relnull@*/
61  const char *p; /* current position in buffer */
62  lua_Chunkreader reader;
63  void* data; /* additional data */
64  const char *name;
65 };
66 
67 
68 int luaZ_fill (ZIO *z)
69  /*@modifies z @*/;
70 
71 #endif