00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef VBUF_H
00013 #define VBUF_H
00014
00015 #include "common.h"
00016
00017 #define SZ_MAX 4096
00018
00019
00020
00021
00022 struct varbuf {
00023 size_t dlen;
00024 size_t blen;
00025 char *buf;
00026 char *b;
00027 };
00028
00029
00030
00031 struct varstr {
00032 size_t dlen;
00033 size_t blen;
00034 char *buf;
00035 char *b;
00036 };
00037
00038
00039 typedef struct varbuf vbuf;
00040 typedef struct varstr vstr;
00041
00042 #define VBUF_STATIC(x,y) static vbuf *x = NULL; if(!x) x = vballoc(y);
00043 #define VSTR_STATIC(x,y) static vstr *x = NULL; if(!x) x = vsalloc(y);
00044
00045 int skip_nl( char *s );
00046 int find_nl( vstr *vs );
00047
00048
00049 struct varbuf *vballoc( size_t len );
00050 void vbfree( vbuf *vb );
00051 void vbclear( vbuf *vb );
00052 void vbresize( vbuf *vb, size_t len );
00053 size_t vbavail( vbuf *vb );
00054 void vbdump( vbuf *vb );
00055 void vbgrow( vbuf *vb, size_t len );
00056 void vbset( vbuf *vb, void *data, size_t len );
00057 void vbskipws( vbuf *vb );
00058 void vbappend( vbuf *vb, void *data, size_t length );
00059 void vbskip( vbuf *vb, size_t skip );
00060 void vboverwrite( vbuf *vbdest, vbuf *vbsrc );
00061
00062
00063 vstr *vsalloc( size_t len );
00064 char *vsb( vstr *vs );
00065 size_t vslen( vstr *vs );
00066 void vsfree( vstr *vs );
00067 void vsset( vstr *vs, char *s );
00068 void vsnset( vstr *vs, char *s, size_t n );
00069 void vsgrow( vstr *vs, size_t len );
00070 size_t vsavail( vstr *vs );
00071 void vscat( vstr *vs, char *str );
00072 void vsncat( vstr *vs, char *str, size_t len );
00073 void vsnprepend( vstr *vs, char *str, size_t len ) ;
00074 void vsskip( vstr *vs, size_t len );
00075 int vscmp( vstr *vs, char *str );
00076 void vsskipws( vstr *vs );
00077 void vs_printf( vstr *vs, char *fmt, ... );
00078 void vs_printfa( vstr *vs, char *fmt, ... );
00079 void vshexdump( vstr *vs, const char *b, size_t start, size_t stop, int ascii );
00080 int vscatprintf( vstr *vs, char *fmt, ... );
00081 void vsvprintf( vstr *vs, char *fmt, va_list ap );
00082 void vstrunc( vstr *vs, size_t off );
00083 int vslast( vstr *vs );
00084 void vscharcat( vstr *vs, int ch );
00085
00086
00087 void unicode_init();
00088 void unicode_close();
00089 size_t vb_utf16to8(vbuf *dest, const char *inbuf, int iblen);
00090 size_t vb_utf8to8bit(vbuf *dest, const char *inbuf, int iblen, const char* charset);
00091
00092 int vb_skipline( struct varbuf *vb );
00093
00094
00095 #endif // VBUF_H