annotate src/vbuf.h @ 129:fc11b1d1ad34

fix initial from header in mbox format. start moving to PST_LE_GET* rather than LE*_CPU macros so we can eventually remove the pragma packing.
author Carl Byington <carl@five-ten-sg.com>
date Thu, 05 Feb 2009 12:09:04 -0800
parents 6395ced2b8b2
children e35fd42bac05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
2 *
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
3 * Functions that try to make dealing with buffers easier.
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
4 *
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
5 * vbuf
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
6 *
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
7 * vstr
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
8 * - should always contain a valid string
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
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
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
11
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
12 #ifndef VBUF_H
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
13 #define VBUF_H
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
14 #define SZ_MAX 4096
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
15 /***************************************************/
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
16
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
17
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
18 // 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
19 struct varbuf {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
20 size_t dlen; //length of data stored in buffer
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
21 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
22 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
23 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
24 };
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
25
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
26
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
27 // 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
28 struct varstr {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
29 size_t dlen; //length of data stored in buffer
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
30 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
31 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
32 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
33 };
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
34
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
35
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
36 typedef struct varbuf vbuf;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
37 typedef struct varstr vstr;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
38
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
39 #define VBUF_STATIC(x,y) static vbuf *x = NULL; if(!x) x = vballoc(y);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
40 #define VSTR_STATIC(x,y) static vstr *x = NULL; if(!x) x = vsalloc(y);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
41
116
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
42 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
43 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
44
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
45 // vbuf functions
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
46 struct varbuf *vballoc( size_t len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
47 void vbfree( vbuf *vb );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
48 void vbclear( vbuf *vb ); //ditch the data, keep the buffer
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
49 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
50 size_t vbavail( vbuf *vb );
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
51 void vbdump( vbuf *vb );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
52 void vbgrow( vbuf *vb, size_t len ); // grow buffer by len bytes, data are preserved
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
53 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
54 void vbskipws( vbuf *vb );
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
55 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
56 void vbskip( vbuf *vb, size_t skip );
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
57 void vboverwrite( vbuf *vbdest, vbuf *vbsrc );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
58
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
59 // vstr functions
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
60 vstr *vsalloc( size_t len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
61 char *vsb( vstr *vs );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
62 size_t vslen( vstr *vs ); //strlen
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
63 void vsfree( vstr *vs );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
64 void vsset( vstr *vs, char *s ); // Store string s in vb
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
65 void vsnset( vstr *vs, char *s, size_t n ); // Store string s in vb
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
66 void vsgrow( vstr *vs, size_t len ); // grow buffer by len bytes, data are preserved
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
67 size_t vsavail( vstr *vs );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
68 void vscat( vstr *vs, char *str );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
69 void vsncat( vstr *vs, char *str, size_t len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
70 void vsnprepend( vstr *vs, char *str, size_t len ) ;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
71 void vsskip( vstr *vs, size_t len );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
72 int vscmp( vstr *vs, char *str );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
73 void vsskipws( vstr *vs );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
74 void vs_printf( vstr *vs, char *fmt, ... );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
75 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
76 void vshexdump( vstr *vs, const char *b, size_t start, size_t stop, int ascii );
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
77 int vscatprintf( vstr *vs, char *fmt, ... );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
78 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
79 void vstrunc( vstr *vs, size_t off ); // Drop chars [off..dlen]
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
80 int vslast( vstr *vs ); // returns the last character stored in a vstr string
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
81 void vscharcat( vstr *vs, int ch );
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
82
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
83
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
84 void unicode_init();
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
85 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
86 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
87 size_t vb_utf8to8bit(vbuf *dest, const char *inbuf, int iblen, const char* charset);
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
88
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
89 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
90
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
91
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
92 // switch from maximal packing back to default packing
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
93 // undo the packing from common.h
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
94 #ifdef _MSC_VER
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
95 #pragma pack(pop)
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
96 #endif
129
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
97 #if defined(__GNUC__) || defined (__SUNPRO_C) || defined(__SUNPRO_CC)
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
98 #pragma pack()
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
99 #endif
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
100
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
101
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
102
fc11b1d1ad34 fix initial from header in mbox format.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
103 #endif // VBUF_H