/* Stretchy Buffer library. A stretchy buffer is a useful way of hiding the problems that come with wanting to read unknown amounts of stuff into a buffer. mjr. 1991 */ #ifndef _INCL_STRETCHYBUFFER_H typedef struct { char *bp; char *buf; int bc; /* remaining bytes */ unsigned bsiz; /* current buffer size */ int rct; int avg; } Sbuf; extern char _sbufgrow(char c, Sbuf *b); extern Sbuf *sbuf_new(void); extern void sbuf_free(Sbuf *b); extern void sbuf_reset(Sbuf *b); extern void sbuf_freestatic(Sbuf *b); extern void sbuf_initstatic(Sbuf *b); /* get a stretchy buffer from a FILE * (emulating fgets but without sizes) */ extern char *sbuf_fgets(Sbuf *s, FILE *f); /* copy a string into a stretchy buffer (returning string part) */ extern char *sbuf_strcpy(char *s, Sbuf *sb); /* fast string catenation into a stretchy buffer */ extern char *sbuf_strcat(char *s, Sbuf *sb); /* pseudo-functions */ #define sbuf_put(c,S) (--(S)->bc > 0 ? *(S)->bp++ = c : _sbufgrow(c,S)) #define sbuf_unput(S) (++(S)->bc, (S)->bp--) #define sbuf_len(S) ((int)(((S)->bp - 1) - (S)->buf)) #define sbuf_buf(S) ((S)->buf) #define _INCL_STRETCHYBUFFER_H #endif