Mercurial > libpst
annotate src/vbuf.c @ 181:3b04745ff76d
prep for fedora build
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 10 Apr 2009 13:10:14 -0700 |
parents | ac6e22c8a9cf |
children | b65e8d0a088a |
rev | line source |
---|---|
73
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
1 |
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
2 #include "define.h" |
43 | 3 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
4 static int pst_skip_nl(char *s); // returns the width of the newline at s[0] |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
5 static int pst_find_nl(vstr *vs); // find newline of type type in b |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
6 |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
7 // vbuf functions |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
8 static void pst_vbfree(vbuf *vb); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
9 static void pst_vbclear(vbuf *vb); // ditch the data, keep the buffer |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
10 static void pst_vbresize(vbuf *vb, size_t len); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
11 static size_t pst_vbavail(vbuf *vb); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
12 static void pst_vbdump(vbuf *vb); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
13 static void pst_vbskipws(vbuf *vb); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
14 static void pst_vbskip(vbuf *vb, size_t skip); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
15 static void pst_vboverwrite(vbuf *vbdest, vbuf *vbsrc); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
16 |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
17 // vstr functions |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
18 static vstr *pst_vsalloc(size_t len); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
19 static char *pst_vsb(vstr *vs); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
20 static size_t pst_vslen(vstr *vs); //strlen |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
21 static void pst_vsfree(vstr *vs); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
22 static void pst_vsset(vstr *vs, char *s); // Store string s in vb |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
23 static void pst_vsnset(vstr *vs, char *s, size_t n); // Store string s in vb |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
24 static void pst_vsgrow(vstr *vs, size_t len); // grow buffer by len bytes, data are preserved |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
25 static size_t pst_vsavail(vstr *vs); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
26 static void pst_vscat(vstr *vs, char *str); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
27 static void pst_vsncat(vstr *vs, char *str, size_t len); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
28 static void pst_vsnprepend(vstr *vs, char *str, size_t len) ; |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
29 static void pst_vsskip(vstr *vs, size_t len); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
30 static int pst_vscmp(vstr *vs, char *str); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
31 static void pst_vsskipws(vstr *vs); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
32 static void pst_vs_printf(vstr *vs, char *fmt, ...); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
33 static void pst_vs_printfa(vstr *vs, char *fmt, ...); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
34 static void pst_vshexdump(vstr *vs, const char *b, size_t start, size_t stop, int ascii); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
35 static int pst_vscatprintf(vstr *vs, char *fmt, ...); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
36 static void pst_vsvprintf(vstr *vs, char *fmt, va_list ap); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
37 static void pst_vstrunc(vstr *vs, size_t off); // Drop chars [off..dlen] |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
38 static int pst_vslast(vstr *vs); // returns the last character stored in a vstr string |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
39 static void pst_vscharcat(vstr *vs, int ch); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
40 |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
41 static void pst_unicode_close(); |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
42 |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
43 static int pst_vb_skipline(vbuf *vb); // in: vb->b == "stuff\nmore_stuff"; out: vb->b == "more_stuff" |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
44 |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
45 |
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
46 |
43 | 47 |
73
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
48 #define ASSERT(x,...) { if( !(x) ) DIE(( __VA_ARGS__)); } |
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
49 |
43 | 50 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
51 static int pst_skip_nl(char *s) |
43 | 52 { |
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 if (s[0] == '\n') |
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 return 1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
55 if (s[0] == '\r' && s[1] == '\n') |
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 return 2; |
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 if (s[0] == '\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
|
58 return 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
|
59 return -1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
60 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
61 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
62 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
63 static int pst_find_nl(vstr * vs) |
43 | 64 { |
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
|
65 char *nextr, *nextn; |
43 | 66 |
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
|
67 nextr = memchr(vs->b, '\r', vs->dlen); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
68 nextn = memchr(vs->b, '\n', vs->dlen); |
43 | 69 |
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
|
70 //case 1: UNIX, we find \n first |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
71 if (nextn && (!nextr || (nextr > nextn))) { |
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
|
72 return nextn - vs->b; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
73 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
74 //case 2: DOS, we find \r\n |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
75 if (nextr && nextn && (nextn-nextr == 1)) { |
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
|
76 return nextr - vs->b; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
77 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
78 //case 3: we find nothing |
43 | 79 |
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
|
80 return -1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
81 } |
43 | 82 |
83 | |
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
|
84 // UTF8 <-> UTF16 <-> ISO8859 Character set conversion functions and (ack) their globals |
43 | 85 |
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
|
86 static int unicode_up = 0; |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
87 static iconv_t i16to8; |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
88 static const char *target_charset = NULL; |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
89 static int target_open_from = 0; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
90 static int target_open_to = 0; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
91 static iconv_t i8totarget = (iconv_t)-1; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
92 static iconv_t target2i8 = (iconv_t)-1; |
43 | 93 |
94 | |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
95 void pst_unicode_init() |
43 | 96 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
97 if (unicode_up) pst_unicode_close(); |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
98 i16to8 = iconv_open("utf-8", "utf-16le"); |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
99 if (i16to8 == (iconv_t)-1) { |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
100 WARN(("Couldn't open iconv descriptor for utf-16le to utf-8.\n")); |
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
|
101 exit(1); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
102 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
103 unicode_up = 1; |
43 | 104 } |
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
|
105 |
43 | 106 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
107 static void pst_unicode_close() |
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
|
108 { |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
109 iconv_close(i16to8); |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
110 if (target_open_from) iconv_close(i8totarget); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
111 if (target_open_to) iconv_close(target2i8); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
112 if (target_charset) free((char *)target_charset); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
113 target_charset = NULL; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
114 target_open_from = 0; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
115 target_open_to = 0; |
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
|
116 unicode_up = 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
|
117 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
118 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
119 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
120 static int utf16_is_terminated(const char *str, int length); |
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
121 static int utf16_is_terminated(const char *str, int length) |
43 | 122 { |
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
|
123 VSTR_STATIC(errbuf, 100); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
124 int len = -1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
125 int i; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
126 for (i = 0; i < length; i += 2) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
127 if (str[i] == 0 && str[i + 1] == 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
|
128 len = i; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
129 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
130 } |
43 | 131 |
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
|
132 if (-1 == len) { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
133 pst_vshexdump(errbuf, str, 0, length, 1); |
120
6395ced2b8b2
disable building pst2dii on cygwin
Carl Byington <carl@five-ten-sg.com>
parents:
116
diff
changeset
|
134 DEBUG_WARN(("String is not zero terminated (probably broken data from registry) %s.\n", errbuf->b)); |
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
|
135 } |
43 | 136 |
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
|
137 return (-1 == len) ? 0 : 1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
138 } |
43 | 139 |
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
|
140 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
141 size_t pst_vb_utf16to8(vbuf *dest, const char *inbuf, int iblen) |
43 | 142 { |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
143 size_t inbytesleft = iblen; |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
144 size_t icresult = (size_t)-1; |
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
|
145 size_t outbytesleft = 0; |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
146 char *outbuf = NULL; |
164
ab384fed78c5
Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
147 int myerrno; |
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
|
148 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
149 ASSERT(unicode_up, "vb_utf16to8() called before unicode started."); |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
150 pst_vbresize(dest, iblen); |
43 | 151 |
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
|
152 //Bad Things can happen if a non-zero-terminated utf16 string comes through here |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
153 if (!utf16_is_terminated(inbuf, iblen)) |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
154 return (size_t)-1; |
43 | 155 |
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
|
156 do { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
157 outbytesleft = dest->blen - dest->dlen; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
158 outbuf = dest->b + dest->dlen; |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
159 icresult = iconv(i16to8, (ICONV_CONST char**)&inbuf, &inbytesleft, &outbuf, &outbytesleft); |
164
ab384fed78c5
Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
160 myerrno = errno; |
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
|
161 dest->dlen = outbuf - dest->b; |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
162 if (inbytesleft) pst_vbgrow(dest, inbytesleft); |
164
ab384fed78c5
Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
163 } while ((size_t)-1 == icresult && E2BIG == myerrno); |
43 | 164 |
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
|
165 if (icresult == (size_t)-1) { |
164
ab384fed78c5
Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
166 DEBUG_WARN(("iconv failure: %s\n", strerror(myerrno))); |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
167 pst_unicode_init(); |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
168 return (size_t)-1; |
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
|
169 } |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
170 return (icresult) ? (size_t)-1 : 0; |
43 | 171 } |
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
|
172 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
173 |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
174 static void open_targets(const char* charset); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
175 static void open_targets(const char* charset) |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
176 { |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
177 if (!target_charset || strcasecmp(target_charset, charset)) { |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
178 if (target_open_from) iconv_close(i8totarget); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
179 if (target_open_to) iconv_close(target2i8); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
180 if (target_charset) free((char *)target_charset); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
181 target_charset = strdup(charset); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
182 target_open_from = 1; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
183 target_open_to = 1; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
184 i8totarget = iconv_open(target_charset, "utf-8"); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
185 if (i8totarget == (iconv_t)-1) { |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
186 target_open_from = 0; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
187 WARN(("Couldn't open iconv descriptor for utf-8 to %s.\n", target_charset)); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
188 } |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
189 target2i8 = iconv_open("utf-8", target_charset); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
190 if (target2i8 == (iconv_t)-1) { |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
191 target_open_to = 0; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
192 WARN(("Couldn't open iconv descriptor for %s to utf-8.\n", target_charset)); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
193 } |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
194 } |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
195 } |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
196 |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
197 |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
198 static size_t sbcs_conversion(vbuf *dest, const char *inbuf, int iblen, iconv_t conversion); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
199 static size_t sbcs_conversion(vbuf *dest, const char *inbuf, int iblen, iconv_t conversion) |
43 | 200 { |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
201 size_t inbytesleft = iblen; |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
202 size_t icresult = (size_t)-1; |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
203 size_t outbytesleft = 0; |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
204 char *outbuf = NULL; |
164
ab384fed78c5
Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
205 int myerrno; |
43 | 206 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
207 pst_vbresize(dest, 2*iblen); |
43 | 208 |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
209 do { |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
210 outbytesleft = dest->blen - dest->dlen; |
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
211 outbuf = dest->b + dest->dlen; |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
212 icresult = iconv(conversion, (ICONV_CONST char**)&inbuf, &inbytesleft, &outbuf, &outbytesleft); |
164
ab384fed78c5
Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
213 myerrno = errno; |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
214 dest->dlen = outbuf - dest->b; |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
215 if (inbytesleft) pst_vbgrow(dest, 2*inbytesleft); |
164
ab384fed78c5
Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
216 } while ((size_t)-1 == icresult && E2BIG == myerrno); |
43 | 217 |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
218 if (icresult == (size_t)-1) { |
164
ab384fed78c5
Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
219 DEBUG_WARN(("iconv failure: %s\n", strerror(myerrno))); |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
220 pst_unicode_init(); |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
221 return (size_t)-1; |
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
|
222 } |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
223 return (icresult) ? (size_t)-1 : 0; |
43 | 224 } |
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
|
225 |
43 | 226 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
227 size_t pst_vb_utf8to8bit(vbuf *dest, const char *inbuf, int iblen, const char* charset) |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
228 { |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
229 open_targets(charset); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
230 if (!target_open_from) return (size_t)-1; // failure to open the target |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
231 return sbcs_conversion(dest, inbuf, iblen, i8totarget); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
232 } |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
233 |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
234 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
235 size_t pst_vb_8bit2utf8(vbuf *dest, const char *inbuf, int iblen, const char* charset) |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
236 { |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
237 open_targets(charset); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
238 if (!target_open_to) return (size_t)-1; // failure to open the target |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
239 return sbcs_conversion(dest, inbuf, iblen, target2i8); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
240 } |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
241 |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
242 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
243 vbuf *pst_vballoc(size_t len) |
43 | 244 { |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
245 vbuf *result = malloc(sizeof(vbuf)); |
73
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
246 if (result) { |
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
247 result->dlen = 0; |
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
248 result->blen = 0; |
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
249 result->buf = NULL; |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
250 pst_vbresize(result, len); |
73
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
251 } |
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
252 else DIE(("malloc() failure")); |
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
|
253 return result; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
254 } |
43 | 255 |
256 | |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
257 static void pst_vbcheck(vbuf * vb) |
43 | 258 { |
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
|
259 ASSERT(vb->b >= vb->buf, "vbcheck(): data not inside 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
|
260 ASSERT((size_t)(vb->b - vb->buf) <= vb->blen, "vbcheck(): vb->b outside of buffer range."); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
261 ASSERT(vb->dlen <= vb->blen, "vbcheck(): data length > buffer length."); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
262 ASSERT(vb->blen < 1024 * 1024, "vbcheck(): blen is a bit large...hmmm."); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
263 } |
43 | 264 |
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
|
265 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
266 static void pst_vbfree(vbuf * vb) |
43 | 267 { |
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
|
268 free(vb->buf); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
269 free(vb); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
270 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
271 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
272 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
273 static void pst_vbclear(vbuf *vb) // ditch the data, keep the buffer |
43 | 274 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
275 pst_vbresize(vb, 0); |
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
|
276 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
277 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
278 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
279 static void pst_vbresize(vbuf *vb, size_t len) // DESTRUCTIVELY grow or shrink buffer |
43 | 280 { |
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
|
281 vb->dlen = 0; |
43 | 282 |
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
|
283 if (vb->blen >= len) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
284 vb->b = vb->buf; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
285 return; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
286 } |
43 | 287 |
73
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
288 vb->buf = realloc(vb->buf, len); |
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
289 vb->b = vb->buf; |
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
|
290 vb->blen = len; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
291 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
292 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
293 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
294 static size_t pst_vbavail(vbuf * vb) |
43 | 295 { |
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
|
296 return vb->blen - vb->dlen - (size_t)(vb->b - vb->buf); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
297 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
298 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
299 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
300 void pst_vbgrow(vbuf *vb, size_t len) // out: vbavail(vb) >= len, data are preserved |
43 | 301 { |
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
|
302 if (0 == len) |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
303 return; |
43 | 304 |
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
|
305 if (0 == vb->blen) { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
306 pst_vbresize(vb, 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
|
307 return; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
308 } |
43 | 309 |
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
|
310 if (vb->dlen + len > vb->blen) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
311 if (vb->dlen + len < vb->blen * 1.5) |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
312 len = vb->blen * 1.5; |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
313 char *nb = pst_malloc(vb->blen + len); |
73
3cb02cb1e6cd
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents:
70
diff
changeset
|
314 if (!nb) DIE(("malloc() failure")); |
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
|
315 vb->blen = vb->blen + len; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
316 memcpy(nb, vb->b, vb->dlen); |
43 | 317 |
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
|
318 free(vb->buf); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
319 vb->buf = nb; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
320 vb->b = vb->buf; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
321 } else { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
322 if (vb->b != vb->buf) |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
323 memcpy(vb->buf, vb->b, vb->dlen); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
324 } |
43 | 325 |
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
|
326 vb->b = vb->buf; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
327 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
328 ASSERT(pst_vbavail(vb) >= len, "vbgrow(): I have failed in my mission."); |
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
|
329 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
330 |
43 | 331 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
332 void pst_vbset(vbuf * vb, void *b, size_t len) // set vbuf b size=len, resize if necessary, relen = how much to over-allocate |
43 | 333 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
334 pst_vbresize(vb, 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
|
335 memcpy(vb->b, b, len); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
336 vb->dlen = len; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
337 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
338 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
339 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
340 static void pst_vsskipws(vstr * vs) |
43 | 341 { |
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
|
342 char *p = vs->b; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
343 while ((size_t)(p - vs->b) < vs->dlen && isspace(p[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
|
344 p++; |
43 | 345 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
346 pst_vbskip((vbuf *) vs, p - vs->b); |
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
|
347 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
348 |
43 | 349 |
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
|
350 // append len bytes of b to vbuf, resize if necessary |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
351 void pst_vbappend(vbuf *vb, void *b, size_t len) |
43 | 352 { |
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
|
353 if (0 == vb->dlen) { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
354 pst_vbset(vb, b, 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
|
355 return; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
356 } |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
357 pst_vbgrow(vb, 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
|
358 memcpy(vb->b + vb->dlen, b, len); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
359 vb->dlen += len; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
360 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
361 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
362 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
363 // dumps the first skip bytes from vbuf |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
364 static void pst_vbskip(vbuf *vb, size_t skip) |
43 | 365 { |
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
|
366 ASSERT(skip <= vb->dlen, "vbskip(): Attempt to seek past end of 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
|
367 vb->b += skip; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
368 vb->dlen -= skip; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
369 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
370 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
371 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
372 // overwrite vbdest with vbsrc |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
373 static void pst_vboverwrite(vbuf *vbdest, vbuf *vbsrc) |
43 | 374 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
375 pst_vbresize(vbdest, vbsrc->blen); |
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
|
376 memcpy(vbdest->b, vbsrc->b, vbsrc->dlen); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
377 vbdest->blen = vbsrc->blen; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
378 vbdest->dlen = vbsrc->dlen; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
379 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
380 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
381 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
382 static vstr *pst_vsalloc(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
|
383 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
384 vstr *result = (vstr *) pst_vballoc(len + 1); |
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
385 pst_vsset(result, ""); |
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
|
386 return result; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
387 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
388 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
389 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
390 static char *pst_vsstr(vstr * vs); |
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
391 static char *pst_vsstr(vstr * vs) |
43 | 392 { |
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
|
393 return vs->b; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
394 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
395 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
396 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
397 static size_t pst_vslen(vstr * vs) |
43 | 398 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
399 return strlen(pst_vsstr(vs)); |
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
|
400 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
401 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
402 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
403 static void pst_vsfree(vstr * vs) |
43 | 404 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
405 pst_vbfree((vbuf *) vs); |
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
|
406 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
407 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
408 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
409 static void pst_vscharcat(vstr * vb, int ch) |
43 | 410 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
411 pst_vbgrow((vbuf *) vb, 1); |
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
|
412 vb->b[vb->dlen - 1] = ch; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
413 vb->b[vb->dlen] = '\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
|
414 vb->dlen++; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
415 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
416 |
43 | 417 |
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
|
418 // prependappend string str to vbuf, vbuf must already contain a valid string |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
419 static void pst_vsnprepend(vstr * vb, char *str, size_t len) |
43 | 420 { |
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
|
421 ASSERT(vb->b[vb->dlen - 1] == '\0', "vsncat(): attempt to append string to non-string."); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
422 size_t sl = strlen(str); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
423 size_t n = (sl < len) ? sl : len; |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
424 pst_vbgrow((vbuf *) vb, n + 1); |
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
|
425 memmove(vb->b + n, vb->b, vb->dlen - 1); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
426 memcpy(vb->b, str, n); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
427 vb->dlen += n; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
428 vb->b[vb->dlen - 1] = '\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
|
429 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
430 |
43 | 431 |
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
|
432 // len < dlen-1 -> skip len chars, else DIE |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
433 static void pst_vsskip(vstr * vs, 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
|
434 { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
435 ASSERT(len < vs->dlen - 1, "Attempt to skip past end of string"); |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
436 pst_vbskip((vbuf *) vs, 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
|
437 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
438 |
43 | 439 |
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
|
440 // in: vb->b == "stuff\nmore_stuff"; out: vb->b == "more_stuff" |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
441 static int pst_vsskipline(vstr * vs) |
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
|
442 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
443 int nloff = pst_find_nl(vs); |
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
444 int nll = pst_skip_nl(vs->b + nloff); |
43 | 445 |
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
|
446 if (nloff < 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
|
447 //TODO: error |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
448 printf("vb_skipline(): there seems to be no newline here.\n"); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
449 return -1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
450 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
451 if (nll < 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
|
452 //TODO: error |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
453 printf("vb_skipline(): there seems to be no newline here...except there should be. :P\n"); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
454 return -1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
455 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
456 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
457 memmove(vs->b, vs->b + nloff + nll, vs->dlen - nloff - nll); |
43 | 458 |
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
|
459 vs->dlen -= nloff + nll; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
460 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
461 return 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
|
462 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
463 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
464 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
465 static int pst_vscatprintf(vstr * vs, char *fmt, ...) |
43 | 466 { |
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
|
467 int size; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
468 va_list ap; |
43 | 469 |
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
|
470 /* Guess we need no more than 100 bytes. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
471 //vsresize( vb, 100 ); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
472 if (!vs->b || vs->dlen == 0) { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
473 pst_vsset(vs, ""); |
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
|
474 } |
43 | 475 |
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
|
476 while (1) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
477 /* Try to print in the allocated space. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
478 va_start(ap, fmt); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
479 size = vsnprintf(vs->b + vs->dlen - 1, vs->blen - vs->dlen, fmt, ap); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
480 va_end(ap); |
43 | 481 |
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
|
482 /* If that worked, return the string. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
483 if ((size > -1) && ((size_t)size < vs->blen - vs->dlen)) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
484 vs->dlen += size; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
485 return size; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
486 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
487 /* Else try again with more space. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
488 if (size >= 0) /* glibc 2.1 */ |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
489 pst_vbgrow((vbuf *) vs, size + 1); /* precisely what is needed */ |
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
|
490 else /* glibc 2.0 */ |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
491 pst_vbgrow((vbuf *) vs, vs->blen); |
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
|
492 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
493 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
494 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
495 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
496 // returns the last character stored in a vstr |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
497 static int pst_vslast(vstr * vs) |
43 | 498 { |
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
|
499 if (vs->dlen < 1) |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
500 return -1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
501 if (vs->b[vs->dlen - 1] != '\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
|
502 return -1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
503 if (vs->dlen == 1) |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
504 return '\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
|
505 return vs->b[vs->dlen - 2]; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
506 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
507 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
508 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
509 // print over vb |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
510 static void pst_vs_printf(vstr * vs, char *fmt, ...) |
43 | 511 { |
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
|
512 int size; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
513 va_list ap; |
43 | 514 |
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
|
515 /* Guess we need no more than 100 bytes. */ |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
516 pst_vbresize((vbuf *) vs, 100); |
43 | 517 |
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
|
518 while (1) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
519 /* Try to print in the allocated space. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
520 va_start(ap, fmt); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
521 size = vsnprintf(vs->b, vs->blen, fmt, ap); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
522 va_end(ap); |
43 | 523 |
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
|
524 /* If that worked, return the string. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
525 if ((size > -1) && ((size_t)size < vs->blen)) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
526 vs->dlen = size + 1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
527 return; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
528 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
529 /* Else try again with more space. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
530 if (size >= 0) /* glibc 2.1 */ |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
531 pst_vbresize((vbuf *) vs, size + 1); /* precisely what is needed */ |
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
|
532 else /* glibc 2.0 */ |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
533 pst_vbresize((vbuf *) vs, vs->blen * 2); |
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
|
534 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
535 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
536 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
537 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
538 // printf append to vs |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
539 static void pst_vs_printfa(vstr * vs, char *fmt, ...) |
43 | 540 { |
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
|
541 int size; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
542 va_list ap; |
43 | 543 |
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
|
544 if (vs->blen - vs->dlen < 50) |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
545 pst_vbgrow((vbuf *) vs, 100); |
43 | 546 |
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
|
547 while (1) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
548 /* Try to print in the allocated space. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
549 va_start(ap, fmt); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
550 size = vsnprintf(vs->b + vs->dlen - 1, vs->blen - vs->dlen + 1, fmt, ap); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
551 va_end(ap); |
43 | 552 |
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
|
553 /* If that worked, return the string. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
554 if ((size > -1) && ((size_t)size < vs->blen)) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
555 vs->dlen += size; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
556 return; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
557 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
558 /* Else try again with more space. */ |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
559 if (size >= 0) /* glibc 2.1 */ |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
560 pst_vbgrow((vbuf *) vs, size + 1 - vs->dlen); /* precisely what is needed */ |
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
|
561 else /* glibc 2.0 */ |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
562 pst_vbgrow((vbuf *) vs, size); |
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
|
563 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
564 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
565 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
566 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
567 static void pst_vshexdump(vstr * vs, const char *b, size_t start, size_t stop, int ascii) |
43 | 568 { |
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
|
569 char c; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
570 int diff, i; |
43 | 571 |
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
|
572 while (start < stop) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
573 diff = stop - start; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
574 if (diff > 16) |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
575 diff = 16; |
43 | 576 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
577 pst_vs_printfa(vs, ":%08X ", start); |
43 | 578 |
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
|
579 for (i = 0; i < diff; i++) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
580 if (8 == i) |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
581 pst_vs_printfa(vs, " "); |
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
582 pst_vs_printfa(vs, "%02X ", (unsigned char) *(b + start + i)); |
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
|
583 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
584 if (ascii) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
585 for (i = diff; i < 16; i++) |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
586 pst_vs_printfa(vs, " "); |
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
|
587 for (i = 0; i < diff; i++) { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
588 c = *(b + start + i); |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
589 pst_vs_printfa(vs, "%c", isprint(c) ? c : '.'); |
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
|
590 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
591 } |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
592 pst_vs_printfa(vs, "\n"); |
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
|
593 start += 16; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
594 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
595 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
596 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
597 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
598 static void pst_vsset(vstr * vs, char *s) // Store string s in vs |
43 | 599 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
600 pst_vsnset(vs, s, strlen(s)); |
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
|
601 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
602 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
603 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
604 static void pst_vsnset(vstr * vs, char *s, size_t n) // Store string s in vs |
43 | 605 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
606 pst_vbresize((vbuf *) vs, n + 1); |
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
|
607 memcpy(vs->b, s, n); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
608 vs->b[n] = '\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
|
609 vs->dlen = n + 1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
610 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
611 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
612 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
613 static void pst_vsgrow(vstr * vs, size_t len) // grow buffer by len bytes, data are preserved |
43 | 614 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
615 pst_vbgrow((vbuf *) vs, 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
|
616 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
617 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
618 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
619 static size_t pst_vsavail(vstr * vs) |
43 | 620 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
621 return pst_vbavail((vbuf *) vs); |
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
|
622 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
623 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
624 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
625 static void pst_vsnset16(vstr * vs, char *s, size_t len) // Like vbstrnset, but for UTF16 |
43 | 626 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
627 pst_vbresize((vbuf *) vs, len + 1); |
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
|
628 memcpy(vs->b, s, len); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
629 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
630 vs->b[len] = '\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
|
631 vs->dlen = len + 1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
632 vs->b[len] = '\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
|
633 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
634 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
635 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
636 static void pst_vscat(vstr * vs, char *str) |
43 | 637 { |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
638 pst_vsncat(vs, str, strlen(str)); |
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
|
639 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
640 |
43 | 641 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
642 static int pst_vscmp(vstr * vs, char *str) |
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
|
643 { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
644 return strcmp(vs->b, str); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
645 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
646 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
647 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
648 static void pst_vsncat(vstr * vs, char *str, size_t len) // append string str to vstr, vstr must already contain a valid string |
43 | 649 { |
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
|
650 ASSERT(vs->b[vs->dlen - 1] == '\0', "vsncat(): attempt to append string to non-string."); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
651 size_t sl = strlen(str); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
652 size_t n = (sl < len) ? sl : len; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
653 //string append |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
654 pst_vbgrow((vbuf *) vs, n + 1); |
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
|
655 memcpy(vs->b + vs->dlen - 1, str, n); |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
656 vs->dlen += n; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
657 vs->b[vs->dlen - 1] = '\0'; |
43 | 658 } |
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
|
659 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
660 |
176
ac6e22c8a9cf
build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
661 static void pst_vstrunc(vstr * v, size_t off) // Drop chars [off..dlen] |
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
|
662 { |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
663 if (off >= v->dlen - 1) |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
664 return; //nothing to do |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
665 v->b[off] = '\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
|
666 v->dlen = off + 1; |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
667 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
668 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
669 |