Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

vbuf.h

Go to the documentation of this file.
00001 /* vbuf.h - variable length buffer functions
00002  *
00003  * Functions that try to make dealing with buffers easier.
00004  *
00005  * vbuf
00006  *
00007  * vstr
00008  * - should always contain a valid string
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 // Variable-length buffers
00022 struct varbuf {
00023     size_t dlen;    //length of data stored in buffer
00024     size_t blen;    //length of buffer
00025     char *buf;      //buffer
00026     char *b;        //start of stored data
00027 };
00028 
00029 
00030 // The exact same thing as a varbuf but should always contain at least '\0'
00031 struct varstr {
00032     size_t dlen;    //length of data stored in buffer
00033     size_t blen;    //length of buffer
00034     char *buf;      //buffer
00035     char *b;        //start of stored data
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 );  // returns the width of the newline at s[0]
00046 int find_nl( vstr *vs ); // find newline of type type in b
00047 
00048 // vbuf functions
00049 struct varbuf *vballoc( size_t len );
00050 void vbfree(      vbuf *vb );
00051 void vbclear(     vbuf *vb ); //ditch the data, keep the buffer
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 ); // grow buffer by len bytes, data are preserved
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 // vstr functions
00063 vstr *vsalloc( size_t len );
00064 char *vsb(      vstr *vs );
00065 size_t vslen(     vstr *vs ); //strlen
00066 void vsfree(      vstr *vs );
00067 void vsset(       vstr *vs, char *s ); // Store string s in vb
00068 void vsnset(      vstr *vs, char *s, size_t n ); // Store string s in vb
00069 void vsgrow(      vstr *vs, size_t len ); // grow buffer by len bytes, data are preserved
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 ); // Drop chars [off..dlen]
00083 int  vslast(      vstr *vs ); // returns the last character stored in a vstr string
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 size_t vb_8bit2utf8(vbuf *dest, const char *inbuf, int iblen, const char* charset);
00092 
00093 int vb_skipline( struct varbuf *vb ); // in: vb->b == "stuff\nmore_stuff"; out: vb->b == "more_stuff"
00094 
00095 
00096 #endif // VBUF_H

Generated on Thu Mar 19 16:39:26 2009 for 'LibPst' by  doxygen 1.3.9.1