|
|
|
@ -15,18 +15,18 @@ typedef struct buffer {
|
|
|
|
|
#define BUFFER_INSIZE 8192
|
|
|
|
|
#define BUFFER_OUTSIZE 8192
|
|
|
|
|
|
|
|
|
|
extern void buffer_init(buffer* b,int (*op)(),int fd,char* y,unsigned int ylen);
|
|
|
|
|
void buffer_init(buffer* b,int (*op)(),int fd,char* y,unsigned int ylen);
|
|
|
|
|
|
|
|
|
|
extern int buffer_flush(buffer* b);
|
|
|
|
|
extern int buffer_put(buffer* b,const char* x,unsigned int len);
|
|
|
|
|
extern int buffer_putalign(buffer* b,const char* x,unsigned int len);
|
|
|
|
|
extern int buffer_putflush(buffer* b,const char* x,unsigned int len);
|
|
|
|
|
extern int buffer_puts(buffer* b,const char* x);
|
|
|
|
|
extern int buffer_putsalign(buffer* b,const char* x);
|
|
|
|
|
extern int buffer_putsflush(buffer* b,const char* x);
|
|
|
|
|
int buffer_flush(buffer* b);
|
|
|
|
|
int buffer_put(buffer* b,const char* x,unsigned int len);
|
|
|
|
|
int buffer_putalign(buffer* b,const char* x,unsigned int len);
|
|
|
|
|
int buffer_putflush(buffer* b,const char* x,unsigned int len);
|
|
|
|
|
int buffer_puts(buffer* b,const char* x);
|
|
|
|
|
int buffer_putsalign(buffer* b,const char* x);
|
|
|
|
|
int buffer_putsflush(buffer* b,const char* x);
|
|
|
|
|
|
|
|
|
|
extern int buffer_putspace(buffer* b);
|
|
|
|
|
extern int buffer_putnlflush(buffer* b); /* put \n and flush */
|
|
|
|
|
int buffer_putspace(buffer* b);
|
|
|
|
|
int buffer_putnlflush(buffer* b); /* put \n and flush */
|
|
|
|
|
|
|
|
|
|
#define buffer_PUTC(s,c) \
|
|
|
|
|
( ((s)->a != (s)->p) \
|
|
|
|
@ -34,16 +34,16 @@ extern int buffer_putnlflush(buffer* b); /* put \n and flush */
|
|
|
|
|
: buffer_put((s),&(c),1) \
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
extern int buffer_get(buffer* b,char* x,unsigned int len);
|
|
|
|
|
extern int buffer_feed(buffer* b);
|
|
|
|
|
extern int buffer_getc(buffer* b,char* x);
|
|
|
|
|
extern int buffer_getn(buffer* b,char* x,unsigned int len);
|
|
|
|
|
int buffer_get(buffer* b,char* x,unsigned int len);
|
|
|
|
|
int buffer_feed(buffer* b);
|
|
|
|
|
int buffer_getc(buffer* b,char* x);
|
|
|
|
|
int buffer_getn(buffer* b,char* x,unsigned int len);
|
|
|
|
|
|
|
|
|
|
/* read bytes until the destination buffer is full (len bytes), end of
|
|
|
|
|
* file is reached or the read char is in charset (setlen bytes). An
|
|
|
|
|
* empty line when looking for \n will write '\n' to x and return 0. If
|
|
|
|
|
* EOF is reached, \0 is written to the buffer */
|
|
|
|
|
extern int buffer_get_token(buffer* b,char* x,unsigned int len,const char* charset,unsigned int setlen);
|
|
|
|
|
int buffer_get_token(buffer* b,char* x,unsigned int len,const char* charset,unsigned int setlen);
|
|
|
|
|
#define buffer_getline(b,x,len) buffer_get_token((b),(x),(len),"\n",1)
|
|
|
|
|
|
|
|
|
|
/* this predicate is given the string as currently read from the buffer
|
|
|
|
@ -51,10 +51,10 @@ extern int buffer_get_token(buffer* b,char* x,unsigned int len,const char* chars
|
|
|
|
|
typedef int (*string_predicate)(const char* x,unsigned int len);
|
|
|
|
|
|
|
|
|
|
/* like buffer_get_token but the token ends when your predicate says so */
|
|
|
|
|
extern int buffer_get_token_pred(buffer* b,char* x,unsigned int len,string_predicate p);
|
|
|
|
|
int buffer_get_token_pred(buffer* b,char* x,unsigned int len,string_predicate p);
|
|
|
|
|
|
|
|
|
|
extern char *buffer_peek(buffer* b);
|
|
|
|
|
extern void buffer_seek(buffer* b,unsigned int len);
|
|
|
|
|
char *buffer_peek(buffer* b);
|
|
|
|
|
void buffer_seek(buffer* b,unsigned int len);
|
|
|
|
|
|
|
|
|
|
#define buffer_PEEK(s) ( (s)->x + (s)->p )
|
|
|
|
|
#define buffer_SEEK(s,len) ( (s)->p += (len) )
|
|
|
|
@ -65,22 +65,28 @@ extern void buffer_seek(buffer* b,unsigned int len);
|
|
|
|
|
: buffer_get((s),(c),1) \
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
extern int buffer_copy(buffer* out,buffer* in);
|
|
|
|
|
int buffer_copy(buffer* out,buffer* in);
|
|
|
|
|
|
|
|
|
|
extern int buffer_putulong(buffer *b,unsigned long l);
|
|
|
|
|
extern int buffer_put8long(buffer *b,unsigned long l);
|
|
|
|
|
extern int buffer_putxlong(buffer *b,unsigned long l);
|
|
|
|
|
extern int buffer_putlong(buffer *b,unsigned long l);
|
|
|
|
|
int buffer_putulong(buffer *b,unsigned long l);
|
|
|
|
|
int buffer_put8long(buffer *b,unsigned long l);
|
|
|
|
|
int buffer_putxlong(buffer *b,unsigned long l);
|
|
|
|
|
int buffer_putlong(buffer *b,signed long l);
|
|
|
|
|
|
|
|
|
|
extern buffer *buffer_0;
|
|
|
|
|
extern buffer *buffer_0small;
|
|
|
|
|
extern buffer *buffer_1;
|
|
|
|
|
extern buffer *buffer_1small;
|
|
|
|
|
extern buffer *buffer_2;
|
|
|
|
|
int buffer_putlonglong(buffer* b,signed long long l);
|
|
|
|
|
int buffer_putulonglong(buffer* b,unsigned long long l);
|
|
|
|
|
|
|
|
|
|
int buffer_puterror(buffer* b);
|
|
|
|
|
int buffer_puterror2(buffer* b, int errnum);
|
|
|
|
|
|
|
|
|
|
buffer *buffer_0;
|
|
|
|
|
buffer *buffer_0small;
|
|
|
|
|
buffer *buffer_1;
|
|
|
|
|
buffer *buffer_1small;
|
|
|
|
|
buffer *buffer_2;
|
|
|
|
|
|
|
|
|
|
#ifdef STRALLOC_H
|
|
|
|
|
/* write stralloc to buffer */
|
|
|
|
|
extern int buffer_putsa(buffer* b,stralloc* sa);
|
|
|
|
|
int buffer_putsa(buffer* b,stralloc* sa);
|
|
|
|
|
|
|
|
|
|
/* these "read token" functions return 0 if the token was complete or
|
|
|
|
|
* EOF was hit or -1 on error. In contrast to the non-stralloc token
|
|
|
|
@ -94,14 +100,14 @@ extern int buffer_putsa(buffer* b,stralloc* sa);
|
|
|
|
|
* data is available. */
|
|
|
|
|
|
|
|
|
|
/* read token from buffer to stralloc */
|
|
|
|
|
extern int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen);
|
|
|
|
|
int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen);
|
|
|
|
|
/* read line from buffer to stralloc */
|
|
|
|
|
extern int buffer_getline_sa(buffer* b,stralloc* sa);
|
|
|
|
|
int buffer_getline_sa(buffer* b,stralloc* sa);
|
|
|
|
|
|
|
|
|
|
typedef int (*sa_predicate)(stralloc* sa);
|
|
|
|
|
|
|
|
|
|
/* like buffer_get_token_sa but the token ends when your predicate says so */
|
|
|
|
|
extern int buffer_get_token_sa_pred(buffer* b,stralloc* sa,sa_predicate p);
|
|
|
|
|
int buffer_get_token_sa_pred(buffer* b,stralloc* sa,sa_predicate p);
|
|
|
|
|
|
|
|
|
|
/* make a buffer from a stralloc.
|
|
|
|
|
* Do not change the stralloc after this! */
|
|
|
|
|