Mercurial > libpst
annotate src/vbuf.h @ 138:4b8c2c8a5829
Added tag stable-0-6-27 for changeset d9d4ae17a2c3
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Sat, 07 Feb 2009 10:26:56 -0800 |
parents | 5e4d6faada34 |
children | cda7c812ec01 |
rev | line source |
---|---|
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
1 /* vbuf.h - variable length buffer functions |
43 | 2 * |
3 * Functions that try to make dealing with buffers easier. | |
4 * | |
5 * vbuf | |
6 * | |
7 * vstr | |
8 * - should always contain a valid string | |
9 * | |
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
10 */ |
43 | 11 |
12 #ifndef VBUF_H | |
13 #define VBUF_H | |
132
5e4d6faada34
fix from Fridrich Strba for parallel make
Carl Byington <carl@five-ten-sg.com>
parents:
130
diff
changeset
|
14 |
5e4d6faada34
fix from Fridrich Strba for parallel make
Carl Byington <carl@five-ten-sg.com>
parents:
130
diff
changeset
|
15 #include "common.h" |
5e4d6faada34
fix from Fridrich Strba for parallel make
Carl Byington <carl@five-ten-sg.com>
parents:
130
diff
changeset
|
16 |
43 | 17 #define SZ_MAX 4096 |
18 /***************************************************/ | |
19 | |
20 | |
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
21 // Variable-length buffers |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
22 struct varbuf { |
43 | 23 size_t dlen; //length of data stored in buffer |
24 size_t blen; //length of buffer | |
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
25 char *buf; //buffer |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
26 char *b; //start of stored data |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
27 }; |
43 | 28 |
29 | |
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
30 // The exact same thing as a varbuf but should always contain at least '\0' |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
31 struct varstr { |
43 | 32 size_t dlen; //length of data stored in buffer |
33 size_t blen; //length of buffer | |
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
34 char *buf; //buffer |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
35 char *b; //start of stored data |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
36 }; |
43 | 37 |
38 | |
39 typedef struct varbuf vbuf; | |
40 typedef struct varstr vstr; | |
41 | |
42 #define VBUF_STATIC(x,y) static vbuf *x = NULL; if(!x) x = vballoc(y); | |
43 #define VSTR_STATIC(x,y) static vstr *x = NULL; if(!x) x = vsalloc(y); | |
44 | |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
45 int skip_nl( char *s ); // returns the width of the newline at s[0] |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
46 int find_nl( vstr *vs ); // find newline of type type in b |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
47 |
43 | 48 // vbuf functions |
49 struct varbuf *vballoc( size_t len ); | |
50 void vbfree( vbuf *vb ); | |
51 void vbclear( vbuf *vb ); //ditch the data, keep the buffer | |
52 void vbresize( vbuf *vb, size_t len ); | |
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
53 size_t vbavail( vbuf *vb ); |
43 | 54 void vbdump( vbuf *vb ); |
55 void vbgrow( vbuf *vb, size_t len ); // grow buffer by len bytes, data are preserved | |
56 void vbset( vbuf *vb, void *data, size_t len ); | |
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
57 void vbskipws( vbuf *vb ); |
43 | 58 void vbappend( vbuf *vb, void *data, size_t length ); |
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
59 void vbskip( vbuf *vb, size_t skip ); |
43 | 60 void vboverwrite( vbuf *vbdest, vbuf *vbsrc ); |
61 | |
62 // vstr functions | |
63 vstr *vsalloc( size_t len ); | |
64 char *vsb( vstr *vs ); | |
65 size_t vslen( vstr *vs ); //strlen | |
66 void vsfree( vstr *vs ); | |
67 void vsset( vstr *vs, char *s ); // Store string s in vb | |
68 void vsnset( vstr *vs, char *s, size_t n ); // Store string s in vb | |
69 void vsgrow( vstr *vs, size_t len ); // grow buffer by len bytes, data are preserved | |
70 size_t vsavail( vstr *vs ); | |
71 void vscat( vstr *vs, char *str ); | |
72 void vsncat( vstr *vs, char *str, size_t len ); | |
73 void vsnprepend( vstr *vs, char *str, size_t len ) ; | |
74 void vsskip( vstr *vs, size_t len ); | |
75 int vscmp( vstr *vs, char *str ); | |
76 void vsskipws( vstr *vs ); | |
77 void vs_printf( vstr *vs, char *fmt, ... ); | |
78 void vs_printfa( vstr *vs, char *fmt, ... ); | |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
79 void vshexdump( vstr *vs, const char *b, size_t start, size_t stop, int ascii ); |
43 | 80 int vscatprintf( vstr *vs, char *fmt, ... ); |
81 void vsvprintf( vstr *vs, char *fmt, va_list ap ); | |
70
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
82 void vstrunc( vstr *vs, size_t off ); // Drop chars [off..dlen] |
43 | 83 int vslast( vstr *vs ); // returns the last character stored in a vstr string |
84 void vscharcat( vstr *vs, int ch ); | |
85 | |
86 | |
87 void unicode_init(); | |
88 void unicode_close(); | |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
89 size_t vb_utf16to8(vbuf *dest, const char *inbuf, int iblen); |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
90 size_t vb_utf8to8bit(vbuf *dest, const char *inbuf, int iblen, const char* charset); |
43 | 91 |
92 int vb_skipline( struct varbuf *vb ); // in: vb->b == "stuff\nmore_stuff"; out: vb->b == "more_stuff" | |
129
fc11b1d1ad34
fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents:
120
diff
changeset
|
93 |
fc11b1d1ad34
fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents:
120
diff
changeset
|
94 |
fc11b1d1ad34
fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents:
120
diff
changeset
|
95 #endif // VBUF_H |