/* 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(); extern Sbuf *sbuf_new(); extern void sbuf_free(); extern void sbuf_reset(); extern void sbuf_initstatic(); extern void sbuf_freestatic(); /* get a stretchy buffer from a FILE * (emulating fgets but without sizes) */ extern char *sbuf_fgets(); /* copy a string into a stretchy buffer (returning string part) */ extern char *sbuf_strcpy(); /* fast string catenation into a stretchy buffer */ extern char *sbuf_strcat(); /* 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