HDF5 Extras  0.0.1
Convenience Functions for using HDF5 Better
Data Structures | Macros | Typedefs | Functions
bstrlib.h File Reference
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>

Go to the source code of this file.

Data Structures

struct  bstrList
 
struct  tagbstring
 

Macros

#define BSTR_ERR   (-1)
 
#define BSTR_OK   (0)
 
#define BSTR_BS_BUFF_LENGTH_GET   (0)
 
#define cstr2bstr   bfromcstr
 
#define bstrchr(b, c)   bstrchrp ((b), (c), 0)
 
#define bstrrchr(b, c)   bstrrchrp ((b), (c), blength(b)-1)
 
#define bvformata(ret, b, fmt, lastarg)
 
#define blengthe(b, e)   (((b) == (void *)0 || (b)->slen < 0) ? (int)(e) : ((b)->slen))
 
#define blength(b)   (blengthe ((b), 0))
 
#define bdataofse(b, o, e)   (((b) == (void *)0 || (b)->data == (void*)0) ? (char *)(e) : ((char *)(b)->data) + (o))
 
#define bdataofs(b, o)   (bdataofse ((b), (o), (void *)0))
 
#define bdatae(b, e)   (bdataofse (b, 0, e))
 
#define bdata(b)   (bdataofs (b, 0))
 
#define bchare(b, p, e)   ((((unsigned)(p)) < (unsigned)blength(b)) ? ((b)->data[(p)]) : (e))
 
#define bchar(b, p)   bchare ((b), (p), '\0')
 
#define bsStaticMlen(q, m)   {(m), (int) sizeof(q)-1, (unsigned char *) ("" q "")}
 
#define bsStatic(q)   bsStaticMlen(q,-__LINE__)
 
#define bsstatic(q)   &(struct tagbstring)bsStatic(q)
 
#define bsStaticBlkParms(q)   ((void *)("" q "")), ((int) sizeof(q)-1)
 
#define cstr2tbstr   btfromcstr
 
#define btfromcstr(t, s)
 
#define blk2tbstr(t, s, l)
 
#define btfromblk(t, s, l)   blk2tbstr(t,s,l)
 
#define bmid2tbstr(t, b, p, l)
 
#define btfromblkltrimws(t, s, l)
 
#define btfromblkrtrimws(t, s, l)
 
#define btfromblktrimws(t, s, l)
 
#define bwriteprotect(t)   { if ((t).mlen >= 0) (t).mlen = -1; }
 
#define bwriteallow(t)   { if ((t).mlen == -1) (t).mlen = (t).slen + ((t).slen == 0); }
 
#define biswriteprotected(t)   ((t).mlen <= 0)
 

Typedefs

typedef struct tagbstringbstring
 
typedef const struct tagbstringconst_bstring
 
typedef int(* bNgetc) (void *parm)
 
typedef size_t(* bNread) (void *buff, size_t elsize, size_t nelem, void *parm)
 

Functions

bstring bfromcstr (const char *str)
 
bstring bfromcstralloc (int mlen, const char *str)
 
bstring blk2bstr (const void *blk, int len)
 
char * bstr2cstr (const_bstring s, char z)
 
int bcstrfree (char *s)
 
bstring bstrcpy (const_bstring b1)
 
int bassign (bstring a, const_bstring b)
 
int bassignmidstr (bstring a, const_bstring b, int left, int len)
 
int bassigncstr (bstring a, const char *str)
 
int bassignblk (bstring a, const void *s, int len)
 
int bdestroy (bstring b)
 
int balloc (bstring s, int len)
 
int ballocmin (bstring b, int len)
 
bstring bmidstr (const_bstring b, int left, int len)
 
int bconcat (bstring b0, const_bstring b1)
 
int bconchar (bstring b0, char c)
 
int bcatcstr (bstring b, const char *s)
 
int bcatblk (bstring b, const void *s, int len)
 
int binsert (bstring s1, int pos, const_bstring s2, unsigned char fill)
 
int binsertch (bstring s1, int pos, int len, unsigned char fill)
 
int breplace (bstring b1, int pos, int len, const_bstring b2, unsigned char fill)
 
int bdelete (bstring s1, int pos, int len)
 
int bsetstr (bstring b0, int pos, const_bstring b1, unsigned char fill)
 
int btrunc (bstring b, int n)
 
int bstricmp (const_bstring b0, const_bstring b1)
 
int bstrnicmp (const_bstring b0, const_bstring b1, int n)
 
int biseqcaseless (const_bstring b0, const_bstring b1)
 
int bisstemeqcaselessblk (const_bstring b0, const void *blk, int len)
 
int biseq (const_bstring b0, const_bstring b1)
 
int bisstemeqblk (const_bstring b0, const void *blk, int len)
 
int biseqcstr (const_bstring b, const char *s)
 
int biseqcstrcaseless (const_bstring b, const char *s)
 
int bstrcmp (const_bstring b0, const_bstring b1)
 
int bstrncmp (const_bstring b0, const_bstring b1, int n)
 
int binstr (const_bstring s1, int pos, const_bstring s2)
 
int binstrr (const_bstring s1, int pos, const_bstring s2)
 
int binstrcaseless (const_bstring s1, int pos, const_bstring s2)
 
int binstrrcaseless (const_bstring s1, int pos, const_bstring s2)
 
int bstrchrp (const_bstring b, int c, int pos)
 
int bstrrchrp (const_bstring b, int c, int pos)
 
int binchr (const_bstring b0, int pos, const_bstring b1)
 
int binchrr (const_bstring b0, int pos, const_bstring b1)
 
int bninchr (const_bstring b0, int pos, const_bstring b1)
 
int bninchrr (const_bstring b0, int pos, const_bstring b1)
 
int bfindreplace (bstring b, const_bstring find, const_bstring repl, int pos)
 
int bfindreplacecaseless (bstring b, const_bstring find, const_bstring repl, int pos)
 
struct bstrListbstrListCreate (void)
 
int bstrListDestroy (struct bstrList *sl)
 
int bstrListAlloc (struct bstrList *sl, int msz)
 
int bstrListAllocMin (struct bstrList *sl, int msz)
 
struct bstrListbsplit (const_bstring str, unsigned char splitChar)
 
struct bstrListbsplits (const_bstring str, const_bstring splitStr)
 
struct bstrListbsplitstr (const_bstring str, const_bstring splitStr)
 
bstring bjoin (const struct bstrList *bl, const_bstring sep)
 
int bsplitcb (const_bstring str, unsigned char splitChar, int pos, int(*cb)(void *parm, int ofs, int len), void *parm)
 
int bsplitscb (const_bstring str, const_bstring splitStr, int pos, int(*cb)(void *parm, int ofs, int len), void *parm)
 
int bsplitstrcb (const_bstring str, const_bstring splitStr, int pos, int(*cb)(void *parm, int ofs, int len), void *parm)
 
int bpattern (bstring b, int len)
 
int btoupper (bstring b)
 
int btolower (bstring b)
 
int bltrimws (bstring b)
 
int brtrimws (bstring b)
 
int btrimws (bstring b)
 
bstring bformat (const char *fmt,...)
 
int bformata (bstring b, const char *fmt,...)
 
int bassignformat (bstring b, const char *fmt,...)
 
int bvcformata (bstring b, int count, const char *fmt, va_list arglist)
 
bstring bgets (bNgetc getcPtr, void *parm, char terminator)
 
bstring bread (bNread readPtr, void *parm)
 
int bgetsa (bstring b, bNgetc getcPtr, void *parm, char terminator)
 
int bassigngets (bstring b, bNgetc getcPtr, void *parm, char terminator)
 
int breada (bstring b, bNread readPtr, void *parm)
 
struct bStreambsopen (bNread readPtr, void *parm)
 
void * bsclose (struct bStream *s)
 
int bsbufflength (struct bStream *s, int sz)
 
int bsreadln (bstring b, struct bStream *s, char terminator)
 
int bsreadlns (bstring r, struct bStream *s, const_bstring term)
 
int bsread (bstring b, struct bStream *s, int n)
 
int bsreadlna (bstring b, struct bStream *s, char terminator)
 
int bsreadlnsa (bstring r, struct bStream *s, const_bstring term)
 
int bsreada (bstring b, struct bStream *s, int n)
 
int bsunread (struct bStream *s, const_bstring b)
 
int bspeek (bstring r, const struct bStream *s)
 
int bssplitscb (struct bStream *s, const_bstring splitStr, int(*cb)(void *parm, int ofs, const_bstring entry), void *parm)
 
int bssplitstrcb (struct bStream *s, const_bstring splitStr, int(*cb)(void *parm, int ofs, const_bstring entry), void *parm)
 
int bseof (const struct bStream *s)
 

Macro Definition Documentation

#define blk2tbstr (   t,
  s,
 
)
Value:
{ \
(t).data = (unsigned char *) (s); \
(t).slen = l; \
(t).mlen = -1; \
}
#define bmid2tbstr (   t,
  b,
  p,
 
)
Value:
{ \
const_bstring bstrtmp_s = (b); \
if (bstrtmp_s && bstrtmp_s->data && bstrtmp_s->slen >= 0) { \
int bstrtmp_left = (p); \
int bstrtmp_len = (l); \
if (bstrtmp_left < 0) { \
bstrtmp_len += bstrtmp_left; \
bstrtmp_left = 0; \
} \
if (bstrtmp_len > bstrtmp_s->slen - bstrtmp_left) \
bstrtmp_len = bstrtmp_s->slen - bstrtmp_left; \
if (bstrtmp_len <= 0) { \
(t).data = (unsigned char *)""; \
(t).slen = 0; \
} else { \
(t).data = bstrtmp_s->data + bstrtmp_left; \
(t).slen = bstrtmp_len; \
} \
} else { \
(t).data = (unsigned char *)""; \
(t).slen = 0; \
} \
(t).mlen = -__LINE__; \
}
#define btfromblkltrimws (   t,
  s,
 
)
Value:
{ \
int bstrtmp_idx = 0, bstrtmp_len = (l); \
unsigned char * bstrtmp_s = (s); \
if (bstrtmp_s && bstrtmp_len >= 0) { \
for (; bstrtmp_idx < bstrtmp_len; bstrtmp_idx++) { \
if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
} \
} \
(t).data = bstrtmp_s + bstrtmp_idx; \
(t).slen = bstrtmp_len - bstrtmp_idx; \
(t).mlen = -__LINE__; \
}
#define btfromblkrtrimws (   t,
  s,
 
)
Value:
{ \
int bstrtmp_len = (l) - 1; \
unsigned char * bstrtmp_s = (s); \
if (bstrtmp_s && bstrtmp_len >= 0) { \
for (; bstrtmp_len >= 0; bstrtmp_len--) { \
if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
} \
} \
(t).data = bstrtmp_s; \
(t).slen = bstrtmp_len + 1; \
(t).mlen = -__LINE__; \
}
#define btfromblktrimws (   t,
  s,
 
)
Value:
{ \
int bstrtmp_idx = 0, bstrtmp_len = (l) - 1; \
unsigned char * bstrtmp_s = (s); \
if (bstrtmp_s && bstrtmp_len >= 0) { \
for (; bstrtmp_idx <= bstrtmp_len; bstrtmp_idx++) { \
if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
} \
for (; bstrtmp_len >= bstrtmp_idx; bstrtmp_len--) { \
if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
} \
} \
(t).data = bstrtmp_s + bstrtmp_idx; \
(t).slen = bstrtmp_len + 1 - bstrtmp_idx; \
(t).mlen = -__LINE__; \
}
#define btfromcstr (   t,
 
)
Value:
{ \
(t).data = (unsigned char *) (s); \
(t).slen = ((t).data) ? ((int) (strlen) ((char *)(t).data)) : 0; \
(t).mlen = -1; \
}
#define bvformata (   ret,
  b,
  fmt,
  lastarg 
)
Value:
{ \
bstring bstrtmp_b = (b); \
const char * bstrtmp_fmt = (fmt); \
int bstrtmp_r = BSTR_ERR, bstrtmp_sz = 16; \
for (;;) { \
va_list bstrtmp_arglist; \
va_start (bstrtmp_arglist, lastarg); \
bstrtmp_r = bvcformata (bstrtmp_b, bstrtmp_sz, bstrtmp_fmt, bstrtmp_arglist); \
va_end (bstrtmp_arglist); \
if (bstrtmp_r >= 0) { /* Everything went ok */ \
bstrtmp_r = BSTR_OK; \
break; \
} else if (-bstrtmp_r <= bstrtmp_sz) { /* A real error? */ \
bstrtmp_r = BSTR_ERR; \
break; \
} \
bstrtmp_sz = -bstrtmp_r; /* Doubled or target size */ \
} \
ret = bstrtmp_r; \
}