Home | History | Annotate | Download | only in os400
      1 /**
      2 ***     Additional procedures for ILE/RPG support.
      3 ***
      4 ***     See Copyright for the status of this software.
      5 ***
      6 ***     Author: Patrick Monnerat <pm (at) datasphere.ch>, DATASPHERE S.A.
      7 **/
      8 
      9 #include <sys/types.h>
     10 
     11 #include <stdarg.h>
     12 
     13 #include "libxml/xmlmemory.h"
     14 #include "libxml/xpath.h"
     15 #include "libxml/parser.h"
     16 #include "libxml/HTMLparser.h"
     17 
     18 #include "rpgsupport.h"
     19 
     20 
     21 /**
     22 ***     ILE/RPG cannot directly derefence a pointer and has no macros.
     23 ***     The following additional procedures supply these functions.
     24 ***     In addition, the following code is adjusted for threads control at
     25 ***             compile time via the C macros.
     26 **/
     27 
     28 #define THREADED_VAR(name, type)                                        \
     29                 type __get_##name(void) { return name; }                \
     30                 void __set_##name(type arg) { name = arg; }
     31 
     32 
     33 THREADED_VAR(xmlFree, xmlFreeFunc)
     34 
     35 void
     36 __call_xmlFree(void * mem)
     37 
     38 {
     39         xmlFree(mem);
     40 }
     41 
     42 
     43 THREADED_VAR(xmlMalloc, xmlMallocFunc)
     44 
     45 void *
     46 __call_xmlMalloc(size_t size)
     47 
     48 {
     49         return xmlMalloc(size);
     50 }
     51 
     52 
     53 THREADED_VAR(xmlMallocAtomic, xmlMallocFunc)
     54 
     55 void *
     56 __call_xmlMallocAtomic(size_t size)
     57 
     58 {
     59         return xmlMallocAtomic(size);
     60 }
     61 
     62 
     63 THREADED_VAR(xmlRealloc, xmlReallocFunc)
     64 
     65 void *
     66 __call_xmlRealloc(void * mem, size_t size)
     67 
     68 {
     69         return xmlRealloc(mem, size);
     70 }
     71 
     72 
     73 THREADED_VAR(xmlMemStrdup, xmlStrdupFunc)
     74 
     75 char *
     76 __call_xmlMemStrdup(const char * str)
     77 
     78 {
     79         return xmlMemStrdup(str);
     80 }
     81 
     82 
     83 #ifdef LIBXML_DOCB_ENABLED
     84 THREADED_VAR(docbDefaultSAXHandler, xmlSAXHandlerV1)
     85 #endif
     86 
     87 
     88 #ifdef LIBXML_HTML_ENABLED
     89 THREADED_VAR(htmlDefaultSAXHandler, xmlSAXHandlerV1)
     90 #endif
     91 
     92 
     93 THREADED_VAR(xmlLastError, xmlError)
     94 
     95 THREADED_VAR(oldXMLWDcompatibility, int)
     96 THREADED_VAR(xmlBufferAllocScheme, xmlBufferAllocationScheme)
     97 THREADED_VAR(xmlDefaultBufferSize, int)
     98 THREADED_VAR(xmlDefaultSAXHandler, xmlSAXHandlerV1)
     99 THREADED_VAR(xmlDefaultSAXLocator, xmlSAXLocator)
    100 THREADED_VAR(xmlDoValidityCheckingDefaultValue, int)
    101 
    102 /* No caller to xmlGenericError() because the argument list is unknown. */
    103 THREADED_VAR(xmlGenericError, xmlGenericErrorFunc)
    104 
    105 
    106 THREADED_VAR(xmlStructuredError, xmlStructuredErrorFunc)
    107 
    108 void
    109 __call_xmlStructuredError(void * userData, xmlErrorPtr error)
    110 
    111 {
    112         xmlStructuredError(userData, error);
    113 }
    114 
    115 THREADED_VAR(xmlGenericErrorContext, void *)
    116 THREADED_VAR(xmlStructuredErrorContext, void *)
    117 THREADED_VAR(xmlGetWarningsDefaultValue, int)
    118 THREADED_VAR(xmlIndentTreeOutput, int)
    119 THREADED_VAR(xmlTreeIndentString, const char *)
    120 THREADED_VAR(xmlKeepBlanksDefaultValue, int)
    121 THREADED_VAR(xmlLineNumbersDefaultValue, int)
    122 THREADED_VAR(xmlLoadExtDtdDefaultValue, int)
    123 THREADED_VAR(xmlParserDebugEntities, int)
    124 THREADED_VAR(xmlParserVersion, const char *)
    125 THREADED_VAR(xmlPedanticParserDefaultValue, int)
    126 THREADED_VAR(xmlSaveNoEmptyTags, int)
    127 THREADED_VAR(xmlSubstituteEntitiesDefaultValue, int)
    128 
    129 
    130 THREADED_VAR(xmlRegisterNodeDefaultValue, xmlRegisterNodeFunc)
    131 
    132 void
    133 __call_xmlRegisterNodeDefaultValue(xmlNodePtr node)
    134 
    135 {
    136         xmlRegisterNodeDefaultValue(node);
    137 }
    138 
    139 
    140 THREADED_VAR(xmlDeregisterNodeDefaultValue, xmlDeregisterNodeFunc)
    141 
    142 void
    143 __call_xmlDeregisterNodeDefaultValue(xmlNodePtr node)
    144 
    145 {
    146         xmlDeregisterNodeDefaultValue(node);
    147 }
    148 
    149 
    150 THREADED_VAR(xmlParserInputBufferCreateFilenameValue, xmlParserInputBufferCreateFilenameFunc)
    151 
    152 xmlParserInputBufferPtr
    153 __call_xmlParserInputBufferCreateFilenameValue(const char *URI,
    154                                                         xmlCharEncoding enc)
    155 
    156 {
    157         return xmlParserInputBufferCreateFilenameValue(URI, enc);
    158 }
    159 
    160 
    161 THREADED_VAR(xmlOutputBufferCreateFilenameValue, xmlOutputBufferCreateFilenameFunc)
    162 
    163 xmlOutputBufferPtr
    164 __call_xmlOutputBufferCreateFilenameValue(const char *URI,
    165                         xmlCharEncodingHandlerPtr encoder, int compression)
    166 
    167 {
    168         return xmlOutputBufferCreateFilenameValue(URI, encoder, compression);
    169 }
    170 
    171 
    172 
    173 /**
    174 ***     va_list support.
    175 **/
    176 
    177 void
    178 __xmlVaStart(char * * list, char * lastargaddr, size_t lastargsize)
    179 
    180 {
    181         list[1] = lastargaddr + lastargsize;
    182 }
    183 
    184 
    185 void *
    186 __xmlVaArg(char * * list, void * dest, size_t argsize)
    187 
    188 {
    189         size_t align;
    190 
    191         if (!argsize)
    192                 return (void *) NULL;
    193 
    194         for (align = 16; align > argsize; align >>= 1)
    195                 ;
    196 
    197         align--;
    198         list[0] = list[1] + (align - (((size_t) list[0] - 1) & align));
    199         list[1] = list[0] + argsize;
    200 
    201         if (dest)
    202                 memcpy(dest, list[0], argsize);
    203 
    204         return (void *) list[0];
    205 }
    206 
    207 
    208 void
    209 __xmlVaEnd(char * * list)
    210 
    211 {
    212         /* Nothing to do. */
    213 }
    214 
    215 
    216 #ifdef LIBXML_XPATH_ENABLED
    217 
    218 int
    219 __xmlXPathNodeSetGetLength(const xmlNodeSet * ns)
    220 
    221 {
    222         return xmlXPathNodeSetGetLength(ns);
    223 }
    224 
    225 
    226 xmlNodePtr
    227 __xmlXPathNodeSetItem(const xmlNodeSet * ns, int index)
    228 
    229 {
    230         return xmlXPathNodeSetItem(ns, index);
    231 }
    232 
    233 
    234 int
    235 __xmlXPathNodeSetIsEmpty(const xmlNodeSet * ns)
    236 
    237 {
    238         return xmlXPathNodeSetIsEmpty(ns);
    239 }
    240 
    241 #endif
    242 
    243 
    244 #ifdef LIBXML_HTML_ENABLED
    245 
    246 const char *
    247 __htmlDefaultSubelement(const htmlElemDesc * elt)
    248 
    249 {
    250         return htmlDefaultSubelement(elt);
    251 }
    252 
    253 
    254 int
    255 __htmlElementAllowedHereDesc(const htmlElemDesc * parent,
    256                                                 const htmlElemDesc * elt)
    257 
    258 {
    259         return htmlElementAllowedHereDesc(parent, elt);
    260 }
    261 
    262 
    263 const char * *
    264 __htmlRequiredAttrs(const htmlElemDesc * elt)
    265 
    266 {
    267         return htmlRequiredAttrs(elt);
    268 }
    269 
    270 #endif
    271