| arbtree.h | | arbtree.h | |
| | | | |
| skipping to change at line 21 | | skipping to change at line 21 | |
| /* copy key (only for string keys!) */ | | /* copy key (only for string keys!) */ | |
| HXBT_CKEY = 1 << 1, | | HXBT_CKEY = 1 << 1, | |
| /* copy data (only for string data!) */ | | /* copy data (only for string data!) */ | |
| HXBT_CDATA = 1 << 2, | | HXBT_CDATA = 1 << 2, | |
| /* pointer to comparison routine passed */ | | /* pointer to comparison routine passed */ | |
| HXBT_CMPFN = 1 << 3, | | HXBT_CMPFN = 1 << 3, | |
| /* use direct integer comparison */ | | /* use direct integer comparison */ | |
| HXBT_ICMP = 1 << 4, | | HXBT_ICMP = 1 << 4, | |
| /* use strcmp() -- abbreviation for HXBT_CMPFN,strcmp */ | | /* use strcmp() -- abbreviation for HXBT_CMPFN,strcmp */ | |
| HXBT_SCMP = 1 << 5, | | HXBT_SCMP = 1 << 5, | |
|
| | | HXBT_SKEY = 1 << 5, /* init2 */ | |
| /* use CIDs for traverser */ | | /* use CIDs for traverser */ | |
| HXBT_CID = 1 << 6, | | HXBT_CID = 1 << 6, | |
|
| | | HXBT_SDATA = 1 << 7, /* init2 */ | |
| }; | | }; | |
| | | | |
| struct HXbtree_node { | | struct HXbtree_node { | |
| struct HXbtree_node *sub[2]; | | struct HXbtree_node *sub[2]; | |
|
| void *key, *data; | | union { | |
| | | void *key; | |
| | | const char *const skey; | |
| | | }; | |
| | | union { | |
| | | void *data; | |
| | | char *sdata; | |
| | | }; | |
| unsigned char color; | | unsigned char color; | |
| }; | | }; | |
| | | | |
| struct HXbtree { | | struct HXbtree { | |
|
| int (*cmpfn)(const void *, const void *); | | /* The size argument is needed for memcmp. */ | |
| | | int (*k_compare)(const void *, const void *, size_t); | |
| void *uptr; | | void *uptr; | |
| struct HXbtree_node *root; | | struct HXbtree_node *root; | |
| unsigned int items, tid; | | unsigned int items, tid; | |
|
| unsigned char opts; | | unsigned char flags; | |
| | | void *(*k_clone)(const void *, size_t); | |
| | | void (*k_free)(void *); | |
| | | void *(*d_clone)(const void *, size_t); | |
| | | void (*d_free)(void *); | |
| | | size_t key_size, data_size; | |
| }; | | }; | |
| | | | |
| extern struct HXbtree *HXbtree_init(unsigned int, ...); | | extern struct HXbtree *HXbtree_init(unsigned int, ...); | |
|
| | | extern struct HXbtree *HXbtree_init2(unsigned int, | |
| | | int (*)(const void *, const void *, size_t), | |
| | | void *(*)(const void *, size_t), void (*)(void *), | |
| | | void *(*)(const void *, size_t), void (*)(void *), | |
| | | size_t, size_t); | |
| extern struct HXbtree_node *HXbtree_add(struct HXbtree *, const void *, ...
); | | extern struct HXbtree_node *HXbtree_add(struct HXbtree *, const void *, ...
); | |
| extern struct HXbtree_node *HXbtree_find(const struct HXbtree *, const void
*); | | extern struct HXbtree_node *HXbtree_find(const struct HXbtree *, const void
*); | |
| extern void *HXbtree_get(const struct HXbtree *, const void *); | | extern void *HXbtree_get(const struct HXbtree *, const void *); | |
| extern void *HXbtree_del(struct HXbtree *, const void *); | | extern void *HXbtree_del(struct HXbtree *, const void *); | |
| extern void HXbtree_free(struct HXbtree *); | | extern void HXbtree_free(struct HXbtree *); | |
| extern void *HXbtrav_init(const struct HXbtree *); | | extern void *HXbtrav_init(const struct HXbtree *); | |
| extern struct HXbtree_node *HXbtraverse(void *); | | extern struct HXbtree_node *HXbtraverse(void *); | |
| extern void HXbtrav_free(void *); | | extern void HXbtrav_free(void *); | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| | | | |
End of changes. 6 change blocks. |
| 3 lines changed or deleted | | 23 lines changed or added | |
|
| defs.h | | defs.h | |
| #ifndef _LIBHX_DEFS_H | | #ifndef _LIBHX_DEFS_H | |
| #define _LIBHX_DEFS_H 1 | | #define _LIBHX_DEFS_H 1 | |
| | | | |
|
| #ifndef __cplusplus | | #ifdef __cplusplus | |
| | | # if defined(__GNUC__) && !defined(offsetof) | |
| | | # define offsetof(type, member) __builtin_offsetof(type, membe | |
| | | r) | |
| | | # endif | |
| | | # ifndef offsetof | |
| | | # define reinterpret_cast<long>(&(static_cast<type *>(NULL)->m | |
| | | ember)) | |
| | | # endif | |
| | | # ifndef containerof | |
| | | # define containerof(var, type, member) reinterpret_cast<type | |
| | | *>( \ | |
| | | reinterpret_cast<char *>(var) - offsetof(type, membe | |
| | | r)) | |
| | | # endif | |
| | | | |
| | | template<typename new_type> | |
| | | static inline new_type signed_cast(const char *expr) | |
| | | { | |
| | | return reinterpret_cast<new_type>(expr); | |
| | | } | |
| | | | |
| | | template<typename new_type> | |
| | | static inline new_type signed_cast(const signed char *expr) | |
| | | { | |
| | | return reinterpret_cast<new_type>(expr); | |
| | | } | |
| | | | |
| | | template<typename new_type> | |
| | | static inline new_type signed_cast(const unsigned char *expr) | |
| | | { | |
| | | return reinterpret_cast<new_type>(expr); | |
| | | } | |
| | | | |
| | | template<typename new_type> | |
| | | static inline new_type signed_cast(char *expr) | |
| | | { | |
| | | return reinterpret_cast<new_type>(expr); | |
| | | } | |
| | | | |
| | | template<typename new_type> | |
| | | static inline new_type signed_cast(signed char *expr) | |
| | | { | |
| | | return reinterpret_cast<new_type>(expr); | |
| | | } | |
| | | | |
| | | template<typename new_type> | |
| | | static inline new_type signed_cast(unsigned char *expr) | |
| | | { | |
| | | return reinterpret_cast<new_type>(expr); | |
| | | } | |
| | | #else | |
| /* N.B. signed_cast<> does not exist in C++. */ | | /* N.B. signed_cast<> does not exist in C++. */ | |
| # define __signed_cast_compatible(a, b) \ | | # define __signed_cast_compatible(a, b) \ | |
| __builtin_choose_expr( \ | | __builtin_choose_expr( \ | |
| __builtin_types_compatible_p(b, const char *) || \ | | __builtin_types_compatible_p(b, const char *) || \ | |
| __builtin_types_compatible_p(b, const signed char *)
|| \ | | __builtin_types_compatible_p(b, const signed char *)
|| \ | |
| __builtin_types_compatible_p(b, const unsigned char
*), \ | | __builtin_types_compatible_p(b, const unsigned char
*), \ | |
| /* if src has a const qualifier */ \ | | /* if src has a const qualifier */ \ | |
| __builtin_types_compatible_p(a, const char *) || \ | | __builtin_types_compatible_p(a, const char *) || \ | |
| __builtin_types_compatible_p(a, const signed char *)
|| \ | | __builtin_types_compatible_p(a, const signed char *)
|| \ | |
| __builtin_types_compatible_p(a, const unsigned char
*), \ | | __builtin_types_compatible_p(a, const unsigned char
*), \ | |
| /* and if it has none... */ \ | | /* and if it has none... */ \ | |
|
| | | __builtin_types_compatible_p(a, const char *) || \ | |
| | | __builtin_types_compatible_p(a, const signed char *) | |
| | | || \ | |
| | | __builtin_types_compatible_p(a, const unsigned char | |
| | | *) || \ | |
| __builtin_types_compatible_p(a, char *) || \ | | __builtin_types_compatible_p(a, char *) || \ | |
| __builtin_types_compatible_p(a, signed char *) || \ | | __builtin_types_compatible_p(a, signed char *) || \ | |
| __builtin_types_compatible_p(a, unsigned char *) \ | | __builtin_types_compatible_p(a, unsigned char *) \ | |
| ) | | ) | |
| | | | |
|
| # if defined(__GNUC__) && defined(HXDEV_EXT_CAST) | | # if defined(__GNUC__) && !defined(signed_cast) | |
| # ifndef signed_cast | | # define signed_cast(type, expr) ({ \ | |
| # define signed_cast(type, expr) ({ \ | | BUILD_BUG_ON(!__signed_cast_compatible(typeof(type), | |
| BUILD_BUG_ON(!__signed_cast_compatible(typeo | | typeof(expr))); \ | |
| f(type), typeof(expr))); \ | | (type)(expr); \ | |
| (type)(expr); \ | | }) | |
| }) | | # endif | |
| # endif | | # if defined(__GNUC__) && !defined(static_cast) | |
| | | # define static_cast(type, expr) \ | |
| /* | | ((struct { type x; }){expr}.x) | |
| * This one may cause shadow warnings when nested, or compil | | # endif | |
| e | | # if defined(__GNUC__) && !defined(const_cast1) | |
| * errors when used in declarations, and hence is normally | | # define __const_cast_strip1(expr) \ | |
| * disabled. | | typeof(*(struct { typeof(expr) x; }){0}.x) | |
| */ | | # define __const_cast_strip2(expr) \ | |
| # ifndef static_cast | | typeof(**(struct { typeof(expr) x; }){0}.x) | |
| # define static_cast(type, expr) ({ \ | | # define __const_cast_strip3(expr) \ | |
| if (0) { typeof(type) __p __attribute__((unu | | typeof(***(struct { typeof(expr) x; }){0}.x) | |
| sed)) = (expr); } \ | | # define const_cast1(new_type, expr) ({ \ | |
| (type)(expr); \ | | BUILD_BUG_ON(!__builtin_types_compatible_p(__const_c | |
| }) | | ast_strip1(expr), __const_cast_strip1(new_type))); \ | |
| # endif | | (new_type)(expr); \ | |
| | | }) | |
| | | # define const_cast2(new_type, expr) ({ \ | |
| | | BUILD_BUG_ON(!__builtin_types_compatible_p(__const_c | |
| | | ast_strip2(expr), __const_cast_strip2(new_type))); \ | |
| | | (new_type)(expr); \ | |
| | | }) | |
| | | # define const_cast3(new_type, expr) ({ \ | |
| | | BUILD_BUG_ON(!__builtin_types_compatible_p(__const_c | |
| | | ast_strip3(expr), __const_cast_strip3(new_type))); \ | |
| | | (new_type)(expr); \ | |
| | | }) | |
| # endif | | # endif | |
|
| | | | |
| # ifndef signed_cast | | # ifndef signed_cast | |
| # define signed_cast(type, expr) ((type)(expr)) | | # define signed_cast(type, expr) ((type)(expr)) | |
| # endif | | # endif | |
| # ifndef static_cast | | # ifndef static_cast | |
| # define static_cast(type, expr) ((type)(expr)) | | # define static_cast(type, expr) ((type)(expr)) | |
| # endif | | # endif | |
| # ifndef const_cast | | # ifndef const_cast | |
| # define const_cast(type, expr) ((type)(expr)) | | # define const_cast(type, expr) ((type)(expr)) | |
| # endif | | # endif | |
| # ifndef reinterpret_cast | | # ifndef reinterpret_cast | |
| | | | |
| skipping to change at line 54 | | skipping to change at line 113 | |
| # endif | | # endif | |
| # ifndef static_cast | | # ifndef static_cast | |
| # define static_cast(type, expr) ((type)(expr)) | | # define static_cast(type, expr) ((type)(expr)) | |
| # endif | | # endif | |
| # ifndef const_cast | | # ifndef const_cast | |
| # define const_cast(type, expr) ((type)(expr)) | | # define const_cast(type, expr) ((type)(expr)) | |
| # endif | | # endif | |
| # ifndef reinterpret_cast | | # ifndef reinterpret_cast | |
| # define reinterpret_cast(type, expr) ((type)(expr)) | | # define reinterpret_cast(type, expr) ((type)(expr)) | |
| # endif | | # endif | |
|
| | | # if defined(__GNUC__) && !defined(offsetof) | |
| | | # define offsetof(type, member) __builtin_offsetof(type, membe | |
| | | r) | |
| | | # endif | |
| | | # ifndef offsetof | |
| | | # define reinterpret_cast(long, &(static_cast(type *, NULL)->m | |
| | | ember)) | |
| | | # endif | |
| | | # ifndef containerof | |
| | | # define containerof(var, type, member) reinterpret_cast(type | |
| | | *, \ | |
| | | reinterpret_cast(char *, var) - offsetof(type, membe | |
| | | r)) | |
| | | # endif | |
| #endif | | #endif | |
| | | | |
|
| #ifndef offsetof | | | |
| # define offsetof(type, member) \ | | | |
| reinterpret_cast(long, &(static_cast(type *, NULL)->member)) | | | |
| #endif | | | |
| #ifndef containerof | | | |
| # define containerof(var, type, member) reinterpret_cast(type *, \ | | | |
| reinterpret_cast(const char *, var) - offsetof(type, member) | | | |
| ) | | | |
| #endif | | | |
| #ifndef ARRAY_SIZE | | #ifndef ARRAY_SIZE | |
| # define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) | | # define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) | |
| #endif | | #endif | |
| #ifndef BUILD_BUG_ON | | #ifndef BUILD_BUG_ON | |
| # define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(conditi
on)])) | | # define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(conditi
on)])) | |
| #endif | | #endif | |
| #ifndef O_BINARY | | #ifndef O_BINARY | |
| # define O_BINARY 0 | | # define O_BINARY 0 | |
| #endif | | #endif | |
| #ifndef S_IRUGO | | #ifndef S_IRUGO | |
| | | | |
End of changes. 6 change blocks. |
| 33 lines changed or deleted | | 104 lines changed or added | |
|
| libxml_helper.h | | libxml_helper.h | |
| #ifndef _LIBHX_LIBXML_HELPER_H | | #ifndef _LIBHX_LIBXML_HELPER_H | |
| #define _LIBHX_LIBXML_HELPER_H 1 | | #define _LIBHX_LIBXML_HELPER_H 1 | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| # include <cstring> | | # include <cstring> | |
| #else | | #else | |
| # include <string.h> | | # include <string.h> | |
| #endif | | #endif | |
|
| | | #include <libHX/defs.h> | |
| #include <libxml/parser.h> | | #include <libxml/parser.h> | |
| | | | |
|
| | | #ifdef __cplusplus | |
| | | extern "C" { | |
| | | #endif | |
| | | | |
| static inline int xml_strcmp(const xmlChar *a, const char *b) | | static inline int xml_strcmp(const xmlChar *a, const char *b) | |
| { | | { | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
|
| return strcmp(reinterpret_cast<const char *>(a), b); | | return strcmp(signed_cast<const char *>(a), b); | |
| #else | | #else | |
|
| return strcmp((const char *)a, b); | | return strcmp(signed_cast(const char *, a), b); | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| static inline char *xml_getprop(xmlNode *node, const char *attr) | | static inline char *xml_getprop(xmlNode *node, const char *attr) | |
| { | | { | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
|
| return reinterpret_cast<char *>(xmlGetProp(node, | | return signed_cast<char *>(xmlGetProp(node, | |
| reinterpret_cast<const xmlChar *>(attr))); | | signed_cast<const xmlChar *>(attr))); | |
| #else | | #else | |
|
| return (char *)xmlGetProp(node, (const xmlChar *)attr); | | return signed_cast(char *, xmlGetProp(node, | |
| | | signed_cast(const xmlChar *, attr))); | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| static inline xmlAttr *xml_newprop(xmlNode *node, const char *name, | | static inline xmlAttr *xml_newprop(xmlNode *node, const char *name, | |
| const char *value) | | const char *value) | |
| { | | { | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
|
| return xmlNewProp(node, reinterpret_cast<const xmlChar *>(name), | | return xmlNewProp(node, signed_cast<const xmlChar *>(name), | |
| reinterpret_cast<const xmlChar *>(value)); | | signed_cast<const xmlChar *>(value)); | |
| #else | | #else | |
|
| return xmlNewProp(node, (const xmlChar *)name, (const xmlChar *)valu | | return xmlNewProp(node, signed_cast(const xmlChar *, name), | |
| e); | | signed_cast(const xmlChar *, value)); | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| static inline xmlNode *xml_newnode(xmlNs *ns, const char *name) | | static inline xmlNode *xml_newnode(xmlNs *ns, const char *name) | |
| { | | { | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
|
| return xmlNewNode(ns, reinterpret_cast<const xmlChar *>(name)); | | return xmlNewNode(ns, signed_cast<const xmlChar *>(name)); | |
| #else | | #else | |
|
| return xmlNewNode(ns, (const xmlChar *)name); | | return xmlNewNode(ns, signed_cast(const xmlChar *, name)); | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| static inline xmlAttr *xml_setprop(xmlNode *node, const char *name, | | static inline xmlAttr *xml_setprop(xmlNode *node, const char *name, | |
| const char *value) | | const char *value) | |
| { | | { | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
|
| return xmlSetProp(node, reinterpret_cast<const xmlChar *>(name), | | return xmlSetProp(node, signed_cast<const xmlChar *>(name), | |
| reinterpret_cast<const xmlChar *>(value)); | | signed_cast<const xmlChar *>(value)); | |
| #else | | #else | |
|
| return xmlSetProp(node, (const xmlChar *)name, (const xmlChar *)valu | | return xmlSetProp(node, signed_cast(const xmlChar *, name), | |
| e); | | signed_cast(const xmlChar *, value)); | |
| #endif | | #endif | |
| } | | } | |
| | | | |
|
| | | #ifdef __cplusplus | |
| | | } /* extern "C" */ | |
| | | #endif | |
| | | | |
| #endif /* _LIBHX_LIBXML_HELPER_H */ | | #endif /* _LIBHX_LIBXML_HELPER_H */ | |
| | | | |
End of changes. 13 change blocks. |
| 15 lines changed or deleted | | 25 lines changed or added | |
|
| string.h | | string.h | |
| | | | |
| skipping to change at line 27 | | skipping to change at line 27 | |
| #endif | | #endif | |
| | | | |
| #ifndef __libhx_internal_hxmc_t_defined | | #ifndef __libhx_internal_hxmc_t_defined | |
| #define __libhx_internal_hxmc_t_defined 1 | | #define __libhx_internal_hxmc_t_defined 1 | |
| typedef char hxmc_t; | | typedef char hxmc_t; | |
| #endif | | #endif | |
| | | | |
| /* | | /* | |
| * HMC.C | | * HMC.C | |
| */ | | */ | |
|
| extern hxmc_t *HXmc_dup(const void *); | | | |
| extern hxmc_t *HXmc_strinit(const char *); | | extern hxmc_t *HXmc_strinit(const char *); | |
| extern hxmc_t *HXmc_meminit(const void *, size_t); | | extern hxmc_t *HXmc_meminit(const void *, size_t); | |
| extern hxmc_t *HXmc_strcpy(hxmc_t **, const char *); | | extern hxmc_t *HXmc_strcpy(hxmc_t **, const char *); | |
| extern hxmc_t *HXmc_memcpy(hxmc_t **, const void *, size_t); | | extern hxmc_t *HXmc_memcpy(hxmc_t **, const void *, size_t); | |
| extern size_t HXmc_length(const hxmc_t *); | | extern size_t HXmc_length(const hxmc_t *); | |
|
| | | extern hxmc_t *HXmc_setlen(hxmc_t **, size_t); | |
| extern hxmc_t *HXmc_trunc(hxmc_t **, size_t); | | extern hxmc_t *HXmc_trunc(hxmc_t **, size_t); | |
| extern hxmc_t *HXmc_strcat(hxmc_t **, const char *); | | extern hxmc_t *HXmc_strcat(hxmc_t **, const char *); | |
| extern hxmc_t *HXmc_memcat(hxmc_t **, const void *, size_t); | | extern hxmc_t *HXmc_memcat(hxmc_t **, const void *, size_t); | |
| extern hxmc_t *HXmc_strpcat(hxmc_t **, const char *); | | extern hxmc_t *HXmc_strpcat(hxmc_t **, const char *); | |
| extern hxmc_t *HXmc_mempcat(hxmc_t **, const void *, size_t); | | extern hxmc_t *HXmc_mempcat(hxmc_t **, const void *, size_t); | |
| extern hxmc_t *HXmc_strins(hxmc_t **, size_t, const char *); | | extern hxmc_t *HXmc_strins(hxmc_t **, size_t, const char *); | |
| extern hxmc_t *HXmc_memins(hxmc_t **, size_t, const void *, size_t); | | extern hxmc_t *HXmc_memins(hxmc_t **, size_t, const void *, size_t); | |
| extern hxmc_t *HXmc_memdel(hxmc_t *, size_t, size_t); | | extern hxmc_t *HXmc_memdel(hxmc_t *, size_t, size_t); | |
| extern void HXmc_free(hxmc_t *); | | extern void HXmc_free(hxmc_t *); | |
| | | | |
| | | | |
End of changes. 2 change blocks. |
| 1 lines changed or deleted | | 1 lines changed or added | |
|