#ifndef _VSTRING_H_INCLUDED_
#define _VSTRING_H_INCLUDED_
#include <stdarg.h>
#include <vbuf.h>
typedef struct VSTRING {
VBUF vbuf;
int maxlen;
} VSTRING;
extern VSTRING *vstring_alloc(int);
extern void vstring_ctl(VSTRING *,...);
extern VSTRING *vstring_truncate(VSTRING *, int);
extern VSTRING *vstring_free(VSTRING *);
extern VSTRING *vstring_strcpy(VSTRING *, const char *);
extern VSTRING *vstring_strncpy(VSTRING *, const char *, int);
extern VSTRING *vstring_strcat(VSTRING *, const char *);
extern VSTRING *vstring_strncat(VSTRING *, const char *, int);
extern VSTRING *vstring_memcpy(VSTRING *, const char *, int);
extern VSTRING *vstring_memcat(VSTRING *, const char *, int);
extern VSTRING *PRINTFLIKE(2, 3) vstring_sprintf(VSTRING *, const char *,...);
extern VSTRING *PRINTFLIKE(2, 3) vstring_sprintf_append(VSTRING *, const char *,...);
extern char *vstring_export(VSTRING *);
extern VSTRING *vstring_import(char *);
#define VSTRING_CTL_MAXLEN 1
#define VSTRING_CTL_END 0
#define VSTRING_SPACE(vp, len) ((vp)->vbuf.space(&(vp)->vbuf, len))
#define vstring_str(vp) ((char *) (vp)->vbuf.data)
#define VSTRING_LEN(vp) ((vp)->vbuf.ptr - (vp)->vbuf.data)
#define vstring_end(vp) ((char *) (vp)->vbuf.ptr)
#define VSTRING_TERMINATE(vp) { if ((vp)->vbuf.cnt <= 0) \
VSTRING_SPACE((vp),1); \
*(vp)->vbuf.ptr = 0; }
#define VSTRING_RESET(vp) { (vp)->vbuf.ptr = (vp)->vbuf.data; \
(vp)->vbuf.cnt = (vp)->vbuf.len; }
#define VSTRING_ADDCH(vp, ch) VBUF_PUT(&(vp)->vbuf, ch)
#define VSTRING_SKIP(vp) { while ((vp)->vbuf.cnt > 0 && *(vp)->vbuf.ptr) \
(vp)->vbuf.ptr++, (vp)->vbuf.cnt--; }
#define vstring_avail(vp) ((vp)->vbuf.cnt)
#define VSTRING_AT_OFFSET(vp, offset) { \
(vp)->vbuf.ptr = (vp)->vbuf.data + (offset); \
(vp)->vbuf.cnt = (vp)->vbuf.len - (offset); \
}
extern VSTRING *vstring_vsprintf(VSTRING *, const char *, va_list);
extern VSTRING *vstring_vsprintf_append(VSTRING *, const char *, va_list);
#endif