comparison src/vbuf.c @ 195:320cfcba8058

add python module interface to the shared library for easy scripting. the shared library must never write to stdout or stderr. fix pst_attach_to_mem so the caller does not need to initialize the buffer pointer.
author Carl Byington <carl@five-ten-sg.com>
date Mon, 20 Apr 2009 19:39:26 -0700
parents b65e8d0a088a
children 4fd5197aacc2
comparison
equal deleted inserted replaced
194:885b47107036 195:320cfcba8058
49 target_open_from = 1; 49 target_open_from = 1;
50 target_open_to = 1; 50 target_open_to = 1;
51 i8totarget = iconv_open(target_charset, "utf-8"); 51 i8totarget = iconv_open(target_charset, "utf-8");
52 if (i8totarget == (iconv_t)-1) { 52 if (i8totarget == (iconv_t)-1) {
53 target_open_from = 0; 53 target_open_from = 0;
54 WARN(("Couldn't open iconv descriptor for utf-8 to %s.\n", target_charset)); 54 DEBUG_WARN(("Couldn't open iconv descriptor for utf-8 to %s.\n", target_charset));
55 } 55 }
56 target2i8 = iconv_open("utf-8", target_charset); 56 target2i8 = iconv_open("utf-8", target_charset);
57 if (target2i8 == (iconv_t)-1) { 57 if (target2i8 == (iconv_t)-1) {
58 target_open_to = 0; 58 target_open_to = 0;
59 WARN(("Couldn't open iconv descriptor for %s to utf-8.\n", target_charset)); 59 DEBUG_WARN(("Couldn't open iconv descriptor for %s to utf-8.\n", target_charset));
60 } 60 }
61 } 61 }
62 } 62 }
63 63
64 64
199 void pst_unicode_init() 199 void pst_unicode_init()
200 { 200 {
201 if (unicode_up) pst_unicode_close(); 201 if (unicode_up) pst_unicode_close();
202 i16to8 = iconv_open("utf-8", "utf-16le"); 202 i16to8 = iconv_open("utf-8", "utf-16le");
203 if (i16to8 == (iconv_t)-1) { 203 if (i16to8 == (iconv_t)-1) {
204 WARN(("Couldn't open iconv descriptor for utf-16le to utf-8.\n")); 204 DEBUG_WARN(("Couldn't open iconv descriptor for utf-16le to utf-8.\n"));
205 exit(1);
206 } 205 }
207 unicode_up = 1; 206 unicode_up = 1;
208 } 207 }
209 208
210 209
214 size_t icresult = (size_t)-1; 213 size_t icresult = (size_t)-1;
215 size_t outbytesleft = 0; 214 size_t outbytesleft = 0;
216 char *outbuf = NULL; 215 char *outbuf = NULL;
217 int myerrno; 216 int myerrno;
218 217
219 ASSERT(unicode_up, "vb_utf16to8() called before unicode started."); 218 if (!unicode_up) return (size_t)-1; // failure to open iconv
220 pst_vbresize(dest, iblen); 219 pst_vbresize(dest, iblen);
221 220
222 //Bad Things can happen if a non-zero-terminated utf16 string comes through here 221 //Bad Things can happen if a non-zero-terminated utf16 string comes through here
223 if (!utf16_is_terminated(inbuf, iblen)) 222 if (!utf16_is_terminated(inbuf, iblen))
224 return (size_t)-1; 223 return (size_t)-1;