1*7c568831SAndroid Build Coastguard Worker 2*7c568831SAndroid Build Coastguard WorkerImplementation notes: 3*7c568831SAndroid Build Coastguard Worker 4*7c568831SAndroid Build Coastguard Worker This is a true OS/400 implementation, not a PASE implementation (for PASE, 5*7c568831SAndroid Build Coastguard Workeruse an AIX implementation). 6*7c568831SAndroid Build Coastguard Worker 7*7c568831SAndroid Build Coastguard Worker The biggest problem with OS/400 is EBCDIC. The current libxml2 implementation 8*7c568831SAndroid Build Coastguard Workeruses UTF-8 internally. To ease encoding conversion between the calling 9*7c568831SAndroid Build Coastguard Workerapplications and libxml2, supplementary "convert and latch" functions are 10*7c568831SAndroid Build Coastguard Workerprovided (See below). To bind the EBCDIC OS/400 system calls and libxml2, 11*7c568831SAndroid Build Coastguard Workeran ASCII run-time environment (QADRT) has been used and wrapper functions have 12*7c568831SAndroid Build Coastguard Workerbeen designed. 13*7c568831SAndroid Build Coastguard Worker 14*7c568831SAndroid Build Coastguard WorkerOther problems are: 15*7c568831SAndroid Build Coastguard Worker- Source code line length: to be stored in DB2 members, source files may not 16*7c568831SAndroid Build Coastguard Worker have lines longer than 100 characters. Some header and documentation files 17*7c568831SAndroid Build Coastguard Worker have been modified accordingly. 18*7c568831SAndroid Build Coastguard Worker- va_list dereferencing: the OS/400 implementation of va_list type is an array 19*7c568831SAndroid Build Coastguard Worker but the compiler forbids explicit array dereferencing. Source files have 20*7c568831SAndroid Build Coastguard Worker been updated accordingly. 21*7c568831SAndroid Build Coastguard Worker- Depending on the compilation/execution environment, it is possible that 22*7c568831SAndroid Build Coastguard Worker stdin/stdout/stderr are not associated with a file descriptor; as a side 23*7c568831SAndroid Build Coastguard Worker effect, open() may return a file descriptor value 0, 1 or 2 that is NOT 24*7c568831SAndroid Build Coastguard Worker a C standard file. Thus using such a number may be inaccurate. 25*7c568831SAndroid Build Coastguard Worker- iconv_open() arguments: OS/400 uses non-standard encoding names and does not 26*7c568831SAndroid Build Coastguard Worker support standard names. For this reason, a name wrapper has been designed. 27*7c568831SAndroid Build Coastguard Worker- dlopen() (support for xmodule): the function and its corollaries are not 28*7c568831SAndroid Build Coastguard Worker provided by the OS/400 library. However a local implementation is provided. 29*7c568831SAndroid Build Coastguard Worker 30*7c568831SAndroid Build Coastguard Worker 31*7c568831SAndroid Build Coastguard WorkerCompiling on OS/400: 32*7c568831SAndroid Build Coastguard Worker 33*7c568831SAndroid Build Coastguard Worker_ As a prerequisite, QADRT development environment must be installed. 34*7c568831SAndroid Build Coastguard Worker_ Install the libxml2 source directory in IFS. 35*7c568831SAndroid Build Coastguard Worker_ Enter shell (QSH) 36*7c568831SAndroid Build Coastguard Worker_ Change current directory to the libxml2 installation directory 37*7c568831SAndroid Build Coastguard Worker_ Change current directory to ./os400 38*7c568831SAndroid Build Coastguard Worker_ Edit file iniscript.sh. You may want to change tunable configuration 39*7c568831SAndroid Build Coastguard Worker parameters, like debug info generation, optimisation level, listing option, 40*7c568831SAndroid Build Coastguard Worker target library, zlib availability, etc. 41*7c568831SAndroid Build Coastguard Worker_ Copy any file in the current directory to makelog (i.e.: 42*7c568831SAndroid Build Coastguard Worker cp initscript.sh makelog): this is intended to create the makelog file with 43*7c568831SAndroid Build Coastguard Worker an ASCII CCSID! 44*7c568831SAndroid Build Coastguard Worker_ Enter the command "sh make.sh >makelog 2>&1' 45*7c568831SAndroid Build Coastguard Worker_ Examine the makelog file to check for compilation errors. 46*7c568831SAndroid Build Coastguard Worker 47*7c568831SAndroid Build Coastguard Worker Leaving file initscript.sh unchanged, this will produce the following 48*7c568831SAndroid Build Coastguard WorkerOS/400 objects: 49*7c568831SAndroid Build Coastguard Worker_ Library LIBXML2. All other objects will be stored in this library. 50*7c568831SAndroid Build Coastguard Worker_ Modules for all libxml2 units, with full debug info and no code optimization. 51*7c568831SAndroid Build Coastguard Worker_ Binding directory LIBXML2_A, to be used at calling program link time for 52*7c568831SAndroid Build Coastguard Worker statically binding the modules (specify BNDSRVPGM(QADRTTS QGLDCLNT QGLDBRDR) 53*7c568831SAndroid Build Coastguard Worker when creating a program using LIBXML2_A). 54*7c568831SAndroid Build Coastguard Worker_ Service program LIBXML2. To be used at calling program run-time 55*7c568831SAndroid Build Coastguard Worker when this program has dynamically bound libxml2 at link time. 56*7c568831SAndroid Build Coastguard Worker_ Binding directory LIBXML2. To be used to dynamically bind libxml2 when 57*7c568831SAndroid Build Coastguard Worker linking a calling program. 58*7c568831SAndroid Build Coastguard Worker_ Source file LIBXML. It contains all the header members needed to compile a 59*7c568831SAndroid Build Coastguard Worker C/C++ module using libxml2. 60*7c568831SAndroid Build Coastguard Worker_ Standard and additional C/C++ libxml2 header members (possibly renamed) in 61*7c568831SAndroid Build Coastguard Worker file LIBXML. 62*7c568831SAndroid Build Coastguard Worker_ IFS directory /libxml2 with subdirectory include/libxml containing all 63*7c568831SAndroid Build Coastguard Worker C/C++ header files for IFS-based compilation. 64*7c568831SAndroid Build Coastguard Worker_ Source file LIBXMLRPG. It contains all the include members needed to compile a 65*7c568831SAndroid Build Coastguard Worker ILE/RPG module/program using libxml2 (ILE/RPG binding). 66*7c568831SAndroid Build Coastguard Worker_ ILE/RPG binding include members (possibly renamed) in file LIBXMLRPG. 67*7c568831SAndroid Build Coastguard Worker_ IFS subdirectory /libxml2/include/libxmlrpg containing all ILE/RPG include 68*7c568831SAndroid Build Coastguard Worker files for IFS-based compilation. 69*7c568831SAndroid Build Coastguard Worker 70*7c568831SAndroid Build Coastguard Worker 71*7c568831SAndroid Build Coastguard WorkerRenamed header files in DB2 members: 72*7c568831SAndroid Build Coastguard Worker DB2 member names are limited to 10 characters, thus the following C/C++ 73*7c568831SAndroid Build Coastguard Workerheader members are renamed as: 74*7c568831SAndroid Build Coastguard Worker parserInternals.h --> PARSERINTE 75*7c568831SAndroid Build Coastguard Worker schemasInternals.h --> SCHEMASINT 76*7c568831SAndroid Build Coastguard Worker xmlautomata.h --> XMLAUTOMAT 77*7c568831SAndroid Build Coastguard Worker xmlschemastype.h --> SCHMTYPES 78*7c568831SAndroid Build Coastguard Worker xpathInternals.h --> XPATHINTER 79*7c568831SAndroid Build Coastguard WorkerIFS header files are NOT renamed. 80*7c568831SAndroid Build Coastguard WorkerILE/RPG headers are processed likewise. 81*7c568831SAndroid Build Coastguard Worker 82*7c568831SAndroid Build Coastguard Worker 83*7c568831SAndroid Build Coastguard WorkerSpecial programming consideration: 84*7c568831SAndroid Build Coastguard Worker 85*7c568831SAndroid Build Coastguard WorkerQADRT being used, the following points must be considered: 86*7c568831SAndroid Build Coastguard Worker_ If static binding is used, service program QADRTTS must be linked too. 87*7c568831SAndroid Build Coastguard Worker_ The EBCDIC CCSID used by QADRT is 37 by default, NOT THE JOB'S CCSID. If 88*7c568831SAndroid Build Coastguard Worker another EBCDIC CCSID is required, it must be set via a locale through a call 89*7c568831SAndroid Build Coastguard Worker to setlocale_a (QADRT's setlocale() ASCII wrapper) with category LC_ALL or 90*7c568831SAndroid Build Coastguard Worker LC_CTYPE, or by setting environment variable QADRT_ENV_LOCALE to the locale 91*7c568831SAndroid Build Coastguard Worker object path before executing the program. 92*7c568831SAndroid Build Coastguard Worker_ Always use *IFSIO or *IFS64IO to compile calling programs. 93*7c568831SAndroid Build Coastguard Worker 94*7c568831SAndroid Build Coastguard Worker 95*7c568831SAndroid Build Coastguard Worker 96*7c568831SAndroid Build Coastguard WorkerSupplementary (non libxml2 standard) support procedures for OS/400. 97*7c568831SAndroid Build Coastguard Worker 98*7c568831SAndroid Build Coastguard Worker As cited above, there are some procedures to ease encoding conversion of 99*7c568831SAndroid Build Coastguard Workerlibxml2 function arguments and results: the mechanism is based on 100*7c568831SAndroid Build Coastguard Workerdictionaries. The functions convert a string, latch the result in a dictionary 101*7c568831SAndroid Build Coastguard Workerto ensure its persistence and return its address. It is the caller's 102*7c568831SAndroid Build Coastguard Workerresponsibility to clean the dictionary when it becomes too big or disappears. 103*7c568831SAndroid Build Coastguard Worker 104*7c568831SAndroid Build Coastguard WorkerThe procedures are: 105*7c568831SAndroid Build Coastguard Worker 106*7c568831SAndroid Build Coastguard Worker#include <libxml/transcode.h> 107*7c568831SAndroid Build Coastguard Worker 108*7c568831SAndroid Build Coastguard Workerconst char * xmlTranscodeResult(const xmlChar * s, 109*7c568831SAndroid Build Coastguard Worker const char * encoding, 110*7c568831SAndroid Build Coastguard Worker xmlDictPtr * dict, 111*7c568831SAndroid Build Coastguard Worker void (*freeproc)(const void *)); 112*7c568831SAndroid Build Coastguard Worker 113*7c568831SAndroid Build Coastguard Workerconst xmlChar * xmlTranscodeString(const char * s, 114*7c568831SAndroid Build Coastguard Worker const char * encoding, 115*7c568831SAndroid Build Coastguard Worker xmlDictPtr * dict); 116*7c568831SAndroid Build Coastguard Worker 117*7c568831SAndroid Build Coastguard Workerconst xmlChar * xmlTranscodeWString(const char * s, 118*7c568831SAndroid Build Coastguard Worker const char * encoding, 119*7c568831SAndroid Build Coastguard Worker xmlDictPtr * dict); 120*7c568831SAndroid Build Coastguard Worker 121*7c568831SAndroid Build Coastguard Workerconst xmlChar * xmlTranscodeWString(const char * s, 122*7c568831SAndroid Build Coastguard Worker const char * encoding, 123*7c568831SAndroid Build Coastguard Worker xmlDictPtr * dict); 124*7c568831SAndroid Build Coastguard Worker 125*7c568831SAndroid Build Coastguard Workerwhere: 126*7c568831SAndroid Build Coastguard Workers is the string to translate. 127*7c568831SAndroid Build Coastguard Workerencoding is the alternate character encoding. If null, the current job's 128*7c568831SAndroid Build Coastguard Worker encoding (CCSID) is used. 129*7c568831SAndroid Build Coastguard Workerdict is the address of the latching directory. If NULL, the procedure 130*7c568831SAndroid Build Coastguard Worker functions as a simple non-latching encoding converter and 131*7c568831SAndroid Build Coastguard Worker its result value should be freed by the caller. 132*7c568831SAndroid Build Coastguard Workerfreeproc is a procedure to release the original string, or NULL. 133*7c568831SAndroid Build Coastguard Worker 134*7c568831SAndroid Build Coastguard WorkerxmlTranscodeResult() converts from UTF-8 to the given alternate encoding. 135*7c568831SAndroid Build Coastguard WorkerxmlTranscodeString() converts from the given 8-bit encoding to UTF-8 (note that 136*7c568831SAndroid Build Coastguard Worker UTF-8 itself is considered as a 8-bit encoding). 137*7c568831SAndroid Build Coastguard WorkerxmlTranscodeWString() converts from the given 16-bit encoding to UTF-8. 138*7c568831SAndroid Build Coastguard WorkerxmlTranscodeHString() converts from the given 32-bit encoding to UTF-8. 139*7c568831SAndroid Build Coastguard Worker 140*7c568831SAndroid Build Coastguard Worker 141*7c568831SAndroid Build Coastguard WorkerTo shorten statements using these functions, shorthands are defined: 142*7c568831SAndroid Build Coastguard Worker 143*7c568831SAndroid Build Coastguard WorkerxmlTR for xmlTranscodeResult 144*7c568831SAndroid Build Coastguard WorkerxmlTS for xmlTranscodeString 145*7c568831SAndroid Build Coastguard WorkerxmlTW for xmlTranscodeWString 146*7c568831SAndroid Build Coastguard WorkerxmlTH for xmlTranscodeHstring 147*7c568831SAndroid Build Coastguard Worker 148*7c568831SAndroid Build Coastguard WorkerThese shorthands may be disabled by defining XML_NO_SHORT_NAMES before 149*7c568831SAndroid Build Coastguard Workerlibxml/transcode.h inclusion. 150*7c568831SAndroid Build Coastguard Worker 151*7c568831SAndroid Build Coastguard WorkerA directory pointer must be preset to NULL before the first call using it to 152*7c568831SAndroid Build Coastguard Workerone of the above procedure. 153*7c568831SAndroid Build Coastguard Worker 154*7c568831SAndroid Build Coastguard WorkerTo release a latching directory, use function 155*7c568831SAndroid Build Coastguard Worker 156*7c568831SAndroid Build Coastguard Workervoid xmlZapDict(xmlDictPtr * dict); 157*7c568831SAndroid Build Coastguard Worker 158*7c568831SAndroid Build Coastguard Worker 159*7c568831SAndroid Build Coastguard WorkerExample: 160*7c568831SAndroid Build Coastguard Worker 161*7c568831SAndroid Build Coastguard Worker#include <libxml/transcode.h> 162*7c568831SAndroid Build Coastguard Worker#include <libxml/tree.h> 163*7c568831SAndroid Build Coastguard Worker 164*7c568831SAndroid Build Coastguard WorkerxmlDocPtr mySimpleXMLDoc(char * element, char * text) 165*7c568831SAndroid Build Coastguard Worker{ 166*7c568831SAndroid Build Coastguard Worker xmlDocPtr doc; 167*7c568831SAndroid Build Coastguard Worker xmlNodePtr node; 168*7c568831SAndroid Build Coastguard Worker xmlDictPtr dict = NULL; 169*7c568831SAndroid Build Coastguard Worker 170*7c568831SAndroid Build Coastguard Worker /* element and text are encoded in the current job's encoding. */ 171*7c568831SAndroid Build Coastguard Worker 172*7c568831SAndroid Build Coastguard Worker doc = xmlNewDoc(); 173*7c568831SAndroid Build Coastguard Worker xmlNewTextChild((xmlNodePtr) doc, NULL, xmlTS(element, NULL, 174*7c568831SAndroid Build Coastguard Worker &dict), xmlTS(text, NULL, &dict)); 175*7c568831SAndroid Build Coastguard Worker xmlZapDict(&dict); 176*7c568831SAndroid Build Coastguard Worker return doc; 177*7c568831SAndroid Build Coastguard Worker} 178*7c568831SAndroid Build Coastguard Worker 179*7c568831SAndroid Build Coastguard Worker 180*7c568831SAndroid Build Coastguard WorkerAdditionally, a formatter into latched/dynamic storage is provided: 181*7c568831SAndroid Build Coastguard Worker 182*7c568831SAndroid Build Coastguard Workerconst char * xmlVasprintf(xmlDictPtr * dict, 183*7c568831SAndroid Build Coastguard Worker const char * encoding, 184*7c568831SAndroid Build Coastguard Worker const xmlChar * fmt, 185*7c568831SAndroid Build Coastguard Worker va_list args); 186*7c568831SAndroid Build Coastguard Worker 187*7c568831SAndroid Build Coastguard Worker 188*7c568831SAndroid Build Coastguard Workerxmllint and xmlcatalog programs: 189*7c568831SAndroid Build Coastguard Worker 190*7c568831SAndroid Build Coastguard Worker These programs are fully implemented at the qshell level, with standard 191*7c568831SAndroid Build Coastguard Workercommand line options. Links to these are installed in sub-directory bin of 192*7c568831SAndroid Build Coastguard Workerthe IFS installation directory. 193*7c568831SAndroid Build Coastguard Worker CL command interfaces to these programs are also provided with limited 194*7c568831SAndroid Build Coastguard Workersupport. In particular, interactive mode is not supported and argument count 195*7c568831SAndroid Build Coastguard Workerand lengths are limited by the CL command syntax. 196*7c568831SAndroid Build Coastguard Worker 197*7c568831SAndroid Build Coastguard Worker 198*7c568831SAndroid Build Coastguard WorkerILE/RPG binding: 199*7c568831SAndroid Build Coastguard Worker 200*7c568831SAndroid Build Coastguard Worker All standard types and procedures are provided. Since ILE/RPG does not 201*7c568831SAndroid Build Coastguard Workersupport macros, they have not been ported. However some of them are emulated 202*7c568831SAndroid Build Coastguard Workeras functions: these are the more useful ones (xmlXPathNodeSetGetLength, 203*7c568831SAndroid Build Coastguard WorkerxmlXPathNodeSetItem, xmlXPathNodeSetIsEmpty, htmlDefaultSubelement, 204*7c568831SAndroid Build Coastguard WorkerhtmlElementAllowedHereDesc, htmlRequiredAttrs) and the global/threaded 205*7c568831SAndroid Build Coastguard Workervariables access macros. These variables can be read with function 206*7c568831SAndroid Build Coastguard Workerget_xxx(void), where xxxx is the name of the variable; they may be set by 207*7c568831SAndroid Build Coastguard Workercalling function set_xxxx(value), where value is of the same type as the 208*7c568831SAndroid Build Coastguard Workervariable. 209*7c568831SAndroid Build Coastguard Worker 210*7c568831SAndroid Build Coastguard Worker The C va_list is not implemented as such in ILE/RPG. Functions implementing 211*7c568831SAndroid Build Coastguard Workerva_list and associated methods are provided: 212*7c568831SAndroid Build Coastguard Worker 213*7c568831SAndroid Build Coastguard Worker /include "libxmlrpg/xmlstdarg" 214*7c568831SAndroid Build Coastguard Worker 215*7c568831SAndroid Build Coastguard Worker d xmlVaStart pr 216*7c568831SAndroid Build Coastguard Worker d list like(xmlVaList) 217*7c568831SAndroid Build Coastguard Worker d lastargaddr * value 218*7c568831SAndroid Build Coastguard Worker d lastargsize 10u 0 value 219*7c568831SAndroid Build Coastguard Worker 220*7c568831SAndroid Build Coastguard Worker d xmlVaArg pr 221*7c568831SAndroid Build Coastguard Worker d list like(xmlVaList) 222*7c568831SAndroid Build Coastguard Worker d dest * value 223*7c568831SAndroid Build Coastguard Worker d argsize 10i 0 value 224*7c568831SAndroid Build Coastguard Worker 225*7c568831SAndroid Build Coastguard Worker d xmlVaEnd pr 226*7c568831SAndroid Build Coastguard Worker d list like(xmlVaList) 227