'LibPst'
vbuf.c File Reference
#include "define.h"
Include dependency graph for vbuf.c:

Go to the source code of this file.

Macros

#define ASSERT(x, ...)   { if( !(x) ) DIE(( __VA_ARGS__)); }
 

Functions

static void pst_vbresize (pst_vbuf *vb, size_t len)
 DESTRUCTIVELY grow or shrink buffer. More...
 
static size_t pst_vbavail (pst_vbuf *vb)
 
static void open_targets (const char *charset)
 
static size_t sbcs_conversion (pst_vbuf *dest, const char *inbuf, int iblen, iconv_t conversion)
 
static void pst_unicode_close ()
 
static int utf16_is_terminated (const char *str, int length)
 
pst_vbufpst_vballoc (size_t len)
 
void pst_vbgrow (pst_vbuf *vb, size_t len)
 out: vbavail(vb) >= len, data are preserved More...
 
void pst_vbset (pst_vbuf *vb, void *b, size_t len)
 set vbuf b size=len, resize if necessary, relen = how much to over-allocate More...
 
void pst_vbappend (pst_vbuf *vb, void *b, size_t len)
 append len bytes of b to vb, resize if necessary More...
 
void pst_unicode_init ()
 
size_t pst_vb_utf16to8 (pst_vbuf *dest, const char *inbuf, int iblen)
 
size_t pst_vb_utf8to8bit (pst_vbuf *dest, const char *inbuf, int iblen, const char *charset)
 
size_t pst_vb_8bit2utf8 (pst_vbuf *dest, const char *inbuf, int iblen, const char *charset)
 

Variables

static int unicode_up = 0
 
static iconv_t i16to8
 
static const char * target_charset = NULL
 
static int target_open_from = 0
 
static int target_open_to = 0
 
static iconv_t i8totarget = (iconv_t)-1
 
static iconv_t target2i8 = (iconv_t)-1
 

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   x,
  ... 
)    { if( !(x) ) DIE(( __VA_ARGS__)); }

Definition at line 13 of file vbuf.c.

Referenced by pst_vbgrow().

Function Documentation

◆ open_targets()

static void open_targets ( const char *  charset)
static

Definition at line 42 of file vbuf.c.

References DEBUG_WARN, i8totarget, target2i8, target_charset, target_open_from, and target_open_to.

Referenced by pst_vb_8bit2utf8(), and pst_vb_utf8to8bit().

◆ pst_unicode_close()

static void pst_unicode_close ( )
static

Definition at line 98 of file vbuf.c.

References i16to8, i8totarget, target2i8, target_charset, target_open_from, target_open_to, and unicode_up.

Referenced by pst_unicode_init().

◆ pst_unicode_init()

void pst_unicode_init ( )

Definition at line 202 of file vbuf.c.

References DEBUG_WARN, i16to8, pst_unicode_close(), and unicode_up.

Referenced by pst_open(), pst_vb_utf16to8(), and sbcs_conversion().

Here is the call graph for this function:

◆ pst_vb_8bit2utf8()

size_t pst_vb_8bit2utf8 ( pst_vbuf dest,
const char *  inbuf,
int  iblen,
const char *  charset 
)

Definition at line 254 of file vbuf.c.

References open_targets(), sbcs_conversion(), target2i8, and target_open_to.

Referenced by pst_convert_utf8().

Here is the call graph for this function:

◆ pst_vb_utf16to8()

size_t pst_vb_utf16to8 ( pst_vbuf dest,
const char *  inbuf,
int  iblen 
)

Definition at line 213 of file vbuf.c.

References pst_varbuf::b, pst_varbuf::blen, DEBUG_WARN, pst_varbuf::dlen, i16to8, ICONV_CONST, pst_unicode_init(), pst_vbgrow(), pst_vbresize(), unicode_up, and utf16_is_terminated().

Referenced by pst_parse_block().

Here is the call graph for this function:

◆ pst_vb_utf8to8bit()

size_t pst_vb_utf8to8bit ( pst_vbuf dest,
const char *  inbuf,
int  iblen,
const char *  charset 
)

Definition at line 246 of file vbuf.c.

References i8totarget, open_targets(), sbcs_conversion(), and target_open_from.

Referenced by convert_8bit(), and write_body_part().

Here is the call graph for this function:

◆ pst_vballoc()

pst_vbuf* pst_vballoc ( size_t  len)

Definition at line 130 of file vbuf.c.

References pst_varbuf::blen, pst_varbuf::buf, DIE, pst_varbuf::dlen, pst_malloc(), and pst_vbresize().

Referenced by convert_8bit(), pst_convert_utf8(), pst_parse_block(), and write_body_part().

Here is the call graph for this function:

◆ pst_vbappend()

void pst_vbappend ( pst_vbuf vb,
void *  b,
size_t  len 
)

append len bytes of b to vb, resize if necessary

Definition at line 190 of file vbuf.c.

References pst_varbuf::b, pst_varbuf::dlen, pst_vbgrow(), and pst_vbset().

Referenced by pst_parse_block().

Here is the call graph for this function:

◆ pst_vbavail()

static size_t pst_vbavail ( pst_vbuf vb)
static

Definition at line 35 of file vbuf.c.

References pst_varbuf::b, pst_varbuf::blen, pst_varbuf::buf, and pst_varbuf::dlen.

Referenced by pst_vbgrow().

◆ pst_vbgrow()

void pst_vbgrow ( pst_vbuf vb,
size_t  len 
)

out: vbavail(vb) >= len, data are preserved

Definition at line 146 of file vbuf.c.

References ASSERT, pst_varbuf::b, pst_varbuf::blen, pst_varbuf::buf, DIE, pst_varbuf::dlen, pst_malloc(), pst_vbavail(), and pst_vbresize().

Referenced by convert_8bit(), pst_vb_utf16to8(), pst_vbappend(), sbcs_conversion(), and write_body_part().

Here is the call graph for this function:

◆ pst_vbresize()

static void pst_vbresize ( pst_vbuf vb,
size_t  len 
)
static

DESTRUCTIVELY grow or shrink buffer.

Definition at line 19 of file vbuf.c.

References pst_varbuf::b, pst_varbuf::blen, pst_varbuf::buf, and pst_varbuf::dlen.

Referenced by pst_vb_utf16to8(), pst_vballoc(), pst_vbgrow(), pst_vbset(), and sbcs_conversion().

◆ pst_vbset()

void pst_vbset ( pst_vbuf vb,
void *  b,
size_t  len 
)

set vbuf b size=len, resize if necessary, relen = how much to over-allocate

Definition at line 180 of file vbuf.c.

References pst_varbuf::b, pst_varbuf::dlen, and pst_vbresize().

Referenced by pst_parse_block(), and pst_vbappend().

Here is the call graph for this function:

◆ sbcs_conversion()

static size_t sbcs_conversion ( pst_vbuf dest,
const char *  inbuf,
int  iblen,
iconv_t  conversion 
)
static

Definition at line 66 of file vbuf.c.

References pst_varbuf::b, pst_varbuf::blen, conversion, DEBUG_ENT, DEBUG_RET, DEBUG_WARN, pst_varbuf::dlen, ICONV_CONST, pst_unicode_init(), pst_vbgrow(), and pst_vbresize().

Referenced by pst_vb_8bit2utf8(), and pst_vb_utf8to8bit().

Here is the call graph for this function:

◆ utf16_is_terminated()

static int utf16_is_terminated ( const char *  str,
int  length 
)
static

Definition at line 112 of file vbuf.c.

References DEBUG_WARN.

Referenced by pst_vb_utf16to8().

Variable Documentation

◆ i16to8

iconv_t i16to8
static

Definition at line 5 of file vbuf.c.

Referenced by pst_unicode_close(), pst_unicode_init(), and pst_vb_utf16to8().

◆ i8totarget

iconv_t i8totarget = (iconv_t)-1
static

Definition at line 9 of file vbuf.c.

Referenced by open_targets(), pst_unicode_close(), and pst_vb_utf8to8bit().

◆ target2i8

iconv_t target2i8 = (iconv_t)-1
static

Definition at line 10 of file vbuf.c.

Referenced by open_targets(), pst_unicode_close(), and pst_vb_8bit2utf8().

◆ target_charset

const char* target_charset = NULL
static

Definition at line 6 of file vbuf.c.

Referenced by open_targets(), and pst_unicode_close().

◆ target_open_from

int target_open_from = 0
static

Definition at line 7 of file vbuf.c.

Referenced by open_targets(), pst_unicode_close(), and pst_vb_utf8to8bit().

◆ target_open_to

int target_open_to = 0
static

Definition at line 8 of file vbuf.c.

Referenced by open_targets(), pst_unicode_close(), and pst_vb_8bit2utf8().

◆ unicode_up

int unicode_up = 0
static

Definition at line 4 of file vbuf.c.

Referenced by pst_unicode_close(), pst_unicode_init(), and pst_vb_utf16to8().