10 #ifndef _CRT_SECURE_NO_DEPRECATE 
   11 #define _CRT_SECURE_NO_DEPRECATE 
   13 #undef _UNICODE  // JLBC 
   16 #define WIN32_LEAN_AND_MEAN 
   37 inline int mmin(
const int t1, 
const int t2) { 
return t1 < t2 ? t1 : t2; }
 
   55         {
nullptr, 0, 
nullptr}};
 
   72         {
_CXML(
"'"), 6, 
_CXML(
'\'')}, {
nullptr, 0, 
'\0'}};
 
   78 #define INDENTCHAR _CXML('\t') 
   88                         return _CXML(
"No error");
 
   90                         return _CXML(
"Warning: Unmatched end tag");
 
   92                         return _CXML(
"Warning: No XML tag found");
 
   94                         return _CXML(
"Error: No XML data");
 
   96                         return _CXML(
"Error: Missing start tag name");
 
   98                         return _CXML(
"Error: Missing end tag name");
 
  100                         return _CXML(
"Error: Unmatched end tag");
 
  102                         return _CXML(
"Error: Unmatched clear tag end");
 
  104                         return _CXML(
"Error: Unexpected token found");
 
  106                         return _CXML(
"Error: No elements found");
 
  108                         return _CXML(
"Error: File not found");
 
  110                         return _CXML(
"Error: First Tag not found");
 
  112                         return _CXML(
"Error: Unknown character entity");
 
  115                                 "Error: Character code above 255 is forbidden in MultiByte " 
  119                                 "Error: unable to convert between WideChar and MultiByte " 
  122                         return _CXML(
"Error: unable to open file for writing");
 
  124                         return _CXML(
"Error: cannot write into file");
 
  128                                 "Warning: Base64-string length is not a multiple of 4");
 
  130                         return _CXML(
"Warning: Base64-string is truncated");
 
  132                         return _CXML(
"Error: Base64-string contains an illegal character");
 
  134                         return _CXML(
"Error: Base64 decode output buffer is too small");
 
  136         return _CXML(
"Unknown");
 
  151 #ifdef XML_NO_WIDE_CHAR 
  154 #if defined(UNDER_CE) || !defined(_XMLWINDOWS) 
  156         const void* 
b, 
int len)  
 
  161         if ((((
unsigned long)
b) % 
sizeof(
wchar_t)) != 0) 
return FALSE;
 
  163         const wchar_t* 
s = (
const wchar_t*)
b;
 
  166         if (
len < (
int)
sizeof(wchar_t)) 
return FALSE;
 
  175         if (*((
unsigned short*)
s) == 0xFFFE)
 
  177         if (*((
unsigned short*)
s) == 0xFEFF)
 
  182         for (i = 0; i < 
len; i++)
 
  183                 if (
s[i] <= (
unsigned short)255) stats++;
 
  184         if (stats > 
len / 2) 
return TRUE;
 
  187         for (i = 0; i < 
len; i++)
 
  188                 if (!
s[i]) 
return TRUE;
 
  195         return (
char)IsTextUnicode((CONST LPVOID)
b, l, 
nullptr);
 
  208                 i = (int)MultiByteToWideChar(CP_UTF8, 0, 
s, -1, 
nullptr, 0);
 
  210                 i = (int)MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, 
s, -1, 
nullptr, 0);
 
  211         if (i < 0) 
return nullptr;
 
  212         wchar_t* d = (
wchar_t*)malloc((i + 1) * 
sizeof(
XMLCHAR));
 
  214                 i = (int)MultiByteToWideChar(CP_UTF8, 0, 
s, -1, d, i);
 
  216                 i = (int)MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, 
s, -1, d, i);
 
  222         return _wfopen(filename, 
mode);
 
  227         return _wcsnicmp(c1, c2, l);
 
  231         return wcsncmp(c1, c2, l);
 
  236         return (
XMLSTR)wcsstr(c1, c2);
 
  240         return (
XMLSTR)wcscpy(c1, c2);
 
  245         UINT codePage = CP_ACP;
 
  247         int i = (int)WideCharToMultiByte(
 
  257         if (i < 0) 
return nullptr;
 
  258         char* d = (
char*)malloc(i + 1);
 
  280         return strnicmp(c1, c2, l);
 
  292         return strncmp(c1, c2, l);
 
  296         return (
XMLSTR)strstr(c1, c2);
 
  305 #ifdef XML_NO_WIDE_CHAR 
  310         const wchar_t* ss = 
s;
 
  311         int i = (int)wcsrtombs(
nullptr, &ss, 0, 
nullptr);
 
  312         if (i < 0) 
return nullptr;
 
  313         char* d = (
char*)malloc(i + 1);
 
  314         wcsrtombs(d, &
s, i, 
nullptr);
 
  323         int i = (int)mbsrtowcs(
nullptr, &ss, 0, 
nullptr);
 
  324         if (i < 0) 
return nullptr;
 
  325         wchar_t* d = (
wchar_t*)malloc((i + 1) * 
sizeof(wchar_t));
 
  326         mbsrtowcs(d, &
s, i, 
nullptr);
 
  336         return wsncasecmp(c1, c2, l);
 
  340         return wsncmp(c1, c2, l);
 
  347         return wcsncasecmp(c1, c2, l);
 
  351         return wcsncmp(c1, c2, l);
 
  355         return wcscasecmp(c1, c2);
 
  360         return (
XMLSTR)wcsstr(c1, c2);
 
  364         return (
XMLSTR)wcscpy(c1, c2);
 
  371                 f = 
fopen(filenameAscii, 
"rb");
 
  373                 f = 
fopen(filenameAscii, 
"wb");
 
  385         return strncasecmp(c1, c2, l);
 
  389         return strncmp(c1, c2, l);
 
  393         return strcasecmp(c1, c2);
 
  397         return (
XMLSTR)strstr(c1, c2);
 
  405 #pragma clang diagnostic push 
  406 #pragma clang diagnostic ignored "-Wunused-function" 
  407 static inline int _strnicmp(
const char* c1, 
const char* c2, 
int l)
 
  409         return strncasecmp(c1, c2, l);
 
  411 #pragma clang diagnostic pop 
  427         if (
t && (*
t)) 
return (
char)_wtoi(
t);
 
  432         if (
t && (*
t)) 
return _wtoi(
t);
 
  437         if (
t && (*
t)) 
return _wtol(
t);
 
  442         if (
t && (*
t)) wscanf(
t, 
"%f", &
v); 
 
  451         if (
t) 
return (
char)wstol(
t, 
nullptr, 10);
 
  456         if (
t) 
return (
int)wstol(
t, 
nullptr, 10);
 
  461         if (
t) 
return wstol(
t, 
nullptr, 10);
 
  468         if (
t) 
return (
char)wcstol(
t, 
nullptr, 10);
 
  473         if (
t) 
return (
int)wcstol(
t, 
nullptr, 10);
 
  478         if (
t) 
return wcstol(
t, 
nullptr, 10);
 
  484         if (
t && (*
t)) wscanf(
t, 
"%f", &
v); 
 
  491         if (
t && (*
t)) 
return (
char)atoi(
t);
 
  496         if (
t && (*
t)) 
return atoi(
t);
 
  501         if (
t && (*
t)) 
return atol(
t);
 
  506         if (
t && (*
t)) 
return atof(
t);
 
  517         if (
t && (*
t)) 
return *
t;
 
  537                 int l = (int)fread(bb, 1, 200, f);
 
  552                 char message[2000], *s1 = (
char *)
"", *s3 = (
char *)
"";
 
  556                         s1 = (
char*)
"First Tag should be '";
 
  563                         "XML Parsing error inside file '%S'.\n%S\nAt line %i, column " 
  566                         "XML Parsing error inside file '%s'.\n%s\nAt line %i, column " 
  574 #if defined(_XMLWINDOWS) && !defined(UNDER_CE) && \ 
  575         !defined(_XMLPARSER_NO_MESSAGEBOX_) 
  577                         nullptr, message, 
"XML Parsing error",
 
  578                         MB_OK | MB_ICONERROR | MB_TOPMOST);
 
  580                 printf(
"%s", message);
 
  606         0, 1, 1, 1, 1, 1, 1, 1,
 
  607         1, 1, 1, 1, 1, 1, 1, 1,  
 
  608         1, 1, 1, 1, 1, 1, 1, 1,
 
  609         1, 1, 1, 1, 1, 1, 1, 1,  
 
  610         1, 1, 1, 1, 1, 1, 1, 1,
 
  611         1, 1, 1, 1, 1, 1, 1, 1,  
 
  612         1, 1, 1, 1, 1, 1, 1, 1,
 
  613         1, 1, 1, 1, 1, 1, 1, 1,  
 
  614         1, 1, 1, 1, 1, 1, 1, 1,
 
  615         1, 1, 1, 1, 1, 1, 1, 1,  
 
  616         1, 1, 1, 1, 1, 1, 1, 1,
 
  617         1, 1, 1, 1, 1, 1, 1, 1,  
 
  618         1, 1, 1, 1, 1, 1, 1, 1,
 
  619         1, 1, 1, 1, 1, 1, 1, 1,  
 
  620         1, 1, 1, 1, 1, 1, 1, 1,
 
  621         1, 1, 1, 1, 1, 1, 1, 1,  
 
  622         1, 1, 1, 1, 1, 1, 1, 1,
 
  623         1, 1, 1, 1, 1, 1, 1, 1,  
 
  624         1, 1, 1, 1, 1, 1, 1, 1,
 
  625         1, 1, 1, 1, 1, 1, 1, 1,  
 
  626         1, 1, 1, 1, 1, 1, 1, 1,
 
  627         1, 1, 1, 1, 1, 1, 1, 1,  
 
  628         1, 1, 1, 1, 1, 1, 1, 1,
 
  629         1, 1, 1, 1, 1, 1, 1, 1,  
 
  630         1, 1, 2, 2, 2, 2, 2, 2,
 
  631         2, 2, 2, 2, 2, 2, 2, 2,  
 
  632         2, 2, 2, 2, 2, 2, 2, 2,
 
  633         2, 2, 2, 2, 2, 2, 2, 2,  
 
  634         3, 3, 3, 3, 3, 3, 3, 3,
 
  635         3, 3, 3, 3, 3, 3, 3, 3,  
 
  636         4, 4, 4, 4, 4, 1, 1, 1,
 
  637         1, 1, 1, 1, 1, 1, 1, 1  
 
  640         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  641         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  642         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  643         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  644         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  645         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  646         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  647         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  648         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  649         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
  650         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
 
  653         0, 1, 1, 1, 1, 1, 1, 1,
 
  654         1, 1, 1, 1, 1, 1, 1, 1,  
 
  655         1, 1, 1, 1, 1, 1, 1, 1,
 
  656         1, 1, 1, 1, 1, 1, 1, 1,  
 
  657         1, 1, 1, 1, 1, 1, 1, 1,
 
  658         1, 1, 1, 1, 1, 1, 1, 1,  
 
  659         1, 1, 1, 1, 1, 1, 1, 1,
 
  660         1, 1, 1, 1, 1, 1, 1, 1,  
 
  661         1, 1, 1, 1, 1, 1, 1, 1,
 
  662         1, 1, 1, 1, 1, 1, 1, 1,  
 
  663         1, 1, 1, 1, 1, 1, 1, 1,
 
  664         1, 1, 1, 1, 1, 1, 1, 1,  
 
  665         1, 1, 1, 1, 1, 1, 1, 1,
 
  666         1, 1, 1, 1, 1, 1, 1, 1,  
 
  667         1, 1, 1, 1, 1, 1, 1, 1,
 
  668         1, 1, 1, 1, 1, 1, 1, 1,  
 
  669         1, 2, 2, 2, 2, 2, 2, 2,
 
  670         2, 2, 2, 2, 2, 2, 2, 2,  
 
  671         2, 2, 2, 2, 2, 2, 2, 2,
 
  672         2, 2, 2, 2, 2, 2, 2, 2,  
 
  673         1, 1, 1, 1, 1, 1, 1, 1,
 
  674         1, 1, 1, 1, 1, 1, 1, 1,  
 
  675         1, 1, 1, 1, 1, 1, 1, 1,
 
  676         1, 1, 1, 1, 1, 1, 1, 1,  
 
  677         1, 1, 1, 1, 1, 1, 1, 1,
 
  678         1, 1, 1, 1, 1, 1, 1, 1,  
 
  679         1, 1, 1, 1, 1, 1, 1, 1,
 
  680         1, 1, 1, 1, 1, 1, 1, 1,  
 
  681         2, 2, 2, 2, 2, 2, 2, 2,
 
  682         2, 2, 2, 2, 2, 2, 2, 2,  
 
  683         1, 1, 1, 1, 1, 1, 1, 1,
 
  684         1, 1, 1, 1, 1, 1, 1, 1  
 
  688         0, 1, 1, 1, 1, 1, 1, 1,
 
  689         1, 1, 1, 1, 1, 1, 1, 1,  
 
  690         1, 1, 1, 1, 1, 1, 1, 1,
 
  691         1, 1, 1, 1, 1, 1, 1, 1,  
 
  692         1, 1, 1, 1, 1, 1, 1, 1,
 
  693         1, 1, 1, 1, 1, 1, 1, 1,  
 
  694         1, 1, 1, 1, 1, 1, 1, 1,
 
  695         1, 1, 1, 1, 1, 1, 1, 1,  
 
  696         1, 1, 1, 1, 1, 1, 1, 1,
 
  697         1, 1, 1, 1, 1, 1, 1, 1,  
 
  698         1, 1, 1, 1, 1, 1, 1, 1,
 
  699         1, 1, 1, 1, 1, 1, 1, 1,  
 
  700         1, 1, 1, 1, 1, 1, 1, 1,
 
  701         1, 1, 1, 1, 1, 1, 1, 1,  
 
  702         1, 1, 1, 1, 1, 1, 1, 1,
 
  703         1, 1, 1, 1, 1, 1, 1, 1,  
 
  704         1, 1, 1, 1, 1, 1, 1, 1,
 
  705         1, 1, 1, 1, 1, 1, 1, 1,  
 
  706         1, 1, 1, 1, 1, 1, 1, 1,
 
  707         1, 1, 1, 1, 1, 1, 1, 1,  
 
  708         1, 2, 2, 2, 2, 2, 2, 2,
 
  709         2, 2, 2, 2, 2, 2, 2, 2,  
 
  710         2, 2, 2, 2, 2, 2, 2, 2,
 
  711         2, 2, 2, 2, 2, 2, 2, 2,  
 
  712         2, 2, 2, 2, 2, 2, 2, 2,
 
  713         2, 2, 2, 2, 2, 2, 2, 2,  
 
  714         2, 2, 2, 2, 2, 2, 2, 2,
 
  715         2, 2, 2, 2, 2, 2, 2, 2,  
 
  716         2, 2, 2, 2, 2, 2, 2, 2,
 
  717         2, 2, 2, 2, 2, 2, 2, 2,  
 
  718         2, 2, 2, 2, 2, 2, 2, 2,
 
  719         1, 1, 1, 1, 1, 1, 1, 1  
 
  723         0, 1, 1, 1, 1, 1, 1, 1,
 
  724         1, 1, 1, 1, 1, 1, 1, 1,  
 
  725         1, 1, 1, 1, 1, 1, 1, 1,
 
  726         1, 1, 1, 1, 1, 1, 1, 1,  
 
  727         1, 1, 1, 1, 1, 1, 1, 1,
 
  728         1, 1, 1, 1, 1, 1, 1, 1,  
 
  729         1, 1, 1, 1, 1, 1, 1, 1,
 
  730         1, 1, 1, 1, 1, 1, 1, 1,  
 
  731         1, 1, 1, 1, 1, 1, 1, 1,
 
  732         1, 1, 1, 1, 1, 1, 1, 1,  
 
  733         1, 1, 1, 1, 1, 1, 1, 1,
 
  734         1, 1, 1, 1, 1, 1, 1, 1,  
 
  735         1, 1, 1, 1, 1, 1, 1, 1,
 
  736         1, 1, 1, 1, 1, 1, 1, 1,  
 
  737         1, 1, 1, 1, 1, 1, 1, 1,
 
  738         1, 1, 1, 1, 1, 1, 1, 1,  
 
  739         1, 2, 2, 2, 2, 2, 2, 2,
 
  740         2, 2, 2, 2, 2, 2, 2, 2,  
 
  741         2, 2, 2, 2, 2, 2, 2, 2,
 
  742         2, 2, 2, 2, 2, 2, 2, 2,  
 
  743         2, 2, 2, 2, 2, 2, 2, 2,
 
  744         2, 2, 2, 2, 2, 2, 2, 2,  
 
  745         2, 2, 2, 2, 2, 2, 2, 2,
 
  746         2, 2, 2, 2, 2, 2, 2, 2,  
 
  747         2, 2, 2, 2, 2, 2, 2, 2,
 
  748         2, 2, 2, 2, 2, 2, 2, 2,  
 
  749         2, 2, 2, 2, 2, 2, 2, 2,
 
  750         2, 2, 2, 2, 2, 2, 2, 2,  
 
  751         2, 2, 2, 2, 2, 2, 2, 2,
 
  752         2, 2, 2, 2, 2, 2, 2, 2,  
 
  753         2, 2, 2, 2, 2, 2, 2, 2,
 
  754         2, 2, 2, 2, 2, 2, 2, 1  
 
  800 using Attrib = 
enum Attrib { eAttribName = 0, eAttribEquals, eAttribValue };
 
  807         XMLCSTR filename, 
const char* encoding, 
char nFormat)
 const 
  813         unsigned char h[2] = {0xFF, 0xFE};
 
  819                                 L
"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n",
 
  820                                 sizeof(
wchar_t) * 40, 1, f))
 
  830                         unsigned char h[3] = {0xEF, 0xBB, 0xBF};
 
  835                         encoding = 
"SHIFT-JIS";
 
  837                 if (!encoding) encoding = 
"ISO-8859-1";
 
  838                 if (
fprintf(f, 
"<?xml version=\"1.0\" encoding=\"%s\"?>\n", encoding) <
 
  846                         unsigned char h[3] = {0xEF, 0xBB, 0xBF};
 
  862         if (lpszData == 
nullptr) 
return nullptr;
 
  865         if (cbData == -1) cbData = (int)
xstrlen(lpszData);
 
  870                 lpszNew[cbData] = (
XMLCHAR)NULL;
 
  880         while ((ch = *
source) != 
'\0')
 
  925         while ((ch = *
source) != 
'\0')
 
  982         if (!
s) 
return nullptr;
 
  988         while ((lo > 0) && (*
s))
 
  992                         if ((lo > 2) && (
s[1] == 
_CXML(
'#')))
 
 1001                                 while ((*
s) && (*
s != 
_CXML(
';')) && ((lo--) > 0)) 
s++;
 
 1015                                         if ((lo >= entity->
l) &&
 
 1023                                 } 
while (entity->
s);
 
 1050                 if (*ss == 
_CXML(
'&'))
 
 1052                         if (ss[1] == 
_CXML(
'#'))
 
 1056                                 if ((*ss == 
_CXML(
'X')) || (*ss == 
_CXML(
'x')))
 
 1059                                         while (*ss != 
_CXML(
';'))
 
 1061                                                 if ((*ss >= 
_CXML(
'0')) && (*ss <= 
_CXML(
'9')))
 
 1062                                                         j = (j << 4) + *ss - 
_CXML(
'0');
 
 1063                                                 else if ((*ss >= 
_CXML(
'A')) && (*ss <= 
_CXML(
'F')))
 
 1064                                                         j = (j << 4) + *ss - 
_CXML(
'A') + 10;
 
 1065                                                 else if ((*ss >= 
_CXML(
'a')) && (*ss <= 
_CXML(
'f')))
 
 1066                                                         j = (j << 4) + *ss - 
_CXML(
'a') + 10;
 
 1078                                         while (*ss != 
_CXML(
';'))
 
 1080                                                 if ((*ss >= 
_CXML(
'0')) && (*ss <= 
_CXML(
'9')))
 
 1081                                                         j = (j * 10) + *ss - 
_CXML(
'0');
 
 1091 #ifndef _XMLWIDECHAR 
 1114                                 } 
while (entity->
s);
 
 1147 #define XML_isSPACECHAR(ch)                                              \ 
 1148         ((ch == _CXML('\n')) || (ch == _CXML(' ')) || (ch == _CXML('\t')) || \ 
 1149          (ch == _CXML('\r'))) 
 1157         if (!cclose) 
return 1;
 
 1159         if (
xstrnicmp(cclose, copen, l) != 0) 
return 1;
 
 1172         if (ch != 0) pXML->
nIndex++;
 
 1187         int indexStart, nFoundMatch, nIsText = 
FALSE;
 
 1188         result.
pClr = 
nullptr;  
 
 1193                 indexStart = pXML->
nIndex;
 
 1228                                 nFoundMatch = 
FALSE;
 
 1238                                         if (ch == 
_CXML(
'<')) 
break;
 
 1242                                 if (nFoundMatch == 
FALSE)
 
 1244                                         pXML->
nIndex = indexStart + 1;
 
 1272                                 if (chTemp == 
_CXML(
'/'))
 
 1280                                 else if (chTemp == 
_CXML(
'?'))
 
 1302                                 if (chTemp == 
_CXML(
'>'))
 
 1332                                 else if (ch == 
_CXML(
'/'))
 
 1341                                         if (ch == 
_CXML(
'>'))
 
 1356                 *pcbToken = pXML->
nIndex - indexStart;
 
 1363                 result.
pStr = 
nullptr;
 
 1376         if (
d->lpszName && (lpszName != 
d->lpszName)) free((
void*)
d->lpszName);
 
 1377         d->lpszName = lpszName;
 
 1392         d->lpszName = 
nullptr;
 
 1400         d->pParent = pParent;
 
 1401         d->pChild = 
nullptr;
 
 1403         d->pClear = 
nullptr;
 
 1404         d->pAttribute = 
nullptr;
 
 1405         d->pOrder = 
nullptr;
 
 1419 #define MEMORYINCREASE 50 
 1425 static inline void* 
myRealloc(
void* 
p, 
int newsize, 
int memInc, 
int sizeofElem)
 
 1429                 if (memInc) 
return malloc(memInc * sizeofElem);
 
 1430                 return malloc(sizeofElem);
 
 1432         if ((memInc == 0) || ((newsize % memInc) == 0))
 
 1433                 p = realloc(
p, (newsize + memInc) * sizeofElem);
 
 1446         if (
index < 0) 
return -1;
 
 1447         int i = 0, j = (int)((
index << 2) + xxtype), *o = 
d->pOrder;
 
 1448         while (o[i] != j) i++;
 
 1456         int n = 
d->nChild + 
d->nText + 
d->nClear, *o = 
d->pOrder,
 
 1458         memmove(o + i, o + i + 1, (
n - i) * 
sizeof(
int));
 
 1460                 if ((o[i] & 3) == (
int)
t) o[i] -= 4;
 
 1469         int memoryIncrease, 
int* _pos, 
int nc, 
void* 
p, 
int size,
 
 1475         int n = 
d->nChild + 
d->nText + 
d->nClear;
 
 1477                 (
int*)
myRealloc(
d->pOrder, 
n + 1, memoryIncrease * 3, 
sizeof(
int));
 
 1478         int pos = *_pos, *o = 
d->pOrder;
 
 1480         if ((pos < 0) || (pos >= 
n))
 
 1483                 o[
n] = (int)((nc << 2) + xtype);
 
 1488         memmove(o + i + 1, o + i, (
n - i) * 
sizeof(
int));
 
 1490         while ((pos < 
n) && ((o[pos] & 3) != (
int)xtype)) pos++;
 
 1494                 o[
n] = (int)((nc << 2) + xtype);
 
 1499         for (i = pos + 1; i <= 
n; i++)
 
 1500                 if ((o[i] & 3) == (int)xtype) o[i] += 4;
 
 1502         *_pos = pos = o[pos] >> 2;
 
 1504                 ((
char*)
p) + (pos + 1) * 
size, ((
char*)
p) + pos * 
size,
 
 1512         int memoryIncrease, 
XMLSTR lpszName, 
char isDeclaration, 
int pos)
 
 1516                 memoryIncrease, &pos, 
d->nChild, 
d->pChild, 
sizeof(
XMLNode),
 
 1518         d->pChild[pos].d = 
nullptr;
 
 1521         return d->pChild[pos];
 
 1526         int memoryIncrease, 
XMLSTR lpszName, 
XMLSTR lpszValuev)
 
 1535         int nc = 
d->nAttribute;
 
 1537                 d->pAttribute, (nc + 1), memoryIncrease, 
sizeof(
XMLAttribute));
 
 1548         if (!lpszValue) 
return nullptr;
 
 1556         d->pText[pos] = lpszValue;
 
 1573                 memoryIncrease, &pos, 
d->nClear, 
d->pClear, 
sizeof(
XMLClear),
 
 1603                         if (*pCh == 
_CXML(
'<'))
 
 1606                                 lpszTemp = 
xstrstr(lpXML, docTypeEnd);
 
 1609                         else if (*pCh == 
_CXML(
'>'))
 
 1627                 cbTemp = (int)(lpszTemp - lpXML);
 
 1646                 d->pOrder = (
int*)realloc(
 
 1647                         d->pOrder, (
d->nChild + 
d->nText + 
d->nClear) * 
sizeof(int));
 
 1663         if (!lpszText) 
return 0;
 
 1667         int cbText = (int)(tokenPStr - lpszText);
 
 1692                 int n = 
d->nChild + 
d->nText + 
d->nClear - 1, *o = 
d->pOrder;
 
 1702                                 d->pText[i] = (
XMLSTR)realloc(
 
 1703                                         (
void*)
d->pText[i], (
n + n2) * 
sizeof(
XMLCHAR));
 
 1704                                 if (!
d->pText[i]) 
return 1;
 
 1727         enum Attrib attrib = eAttribName;
 
 1796 #ifdef APPROXIMATE_PARSING 
 1923                                                         lpszTemp = token.
pStr;
 
 1940 #ifdef STRICT_PARSING 
 1992                                                                         lpszTemp = token.
pStr;
 
 1994                                                                         attrib = eAttribEquals;
 
 2042                                                                         lpszTemp = token.
pStr;
 
 2056                                                                         if (
d->isDeclaration &&
 
 2057                                                                                 (lpszTemp[cbTemp - 1]) == 
_CXML(
'?'))
 
 2060                                                                                 if (
d->pParent && 
d->pParent->pParent)
 
 2092                                                                         attrib = eAttribValue;
 
 2123                                                                         if (
d->isDeclaration &&
 
 2124                                                                                 (token.
pStr[cbToken - 1]) == 
_CXML(
'?'))
 
 2141                                                                                                 attrVal, cbToken, pXML);
 
 2142                                                                                         if (!attrVal) 
return FALSE;
 
 2152                                                                         attrib = eAttribName;
 
 2175                         if ((!
d->isDeclaration) && (
d->pParent))
 
 2177 #ifdef STRICT_PARSING 
 2198                                           nullptr, 0,    
nullptr, 0, 
TRUE};
 
 2200         pResults->
nLine = 1;
 
 2202         while (xml.
nIndex < nUpto)
 
 2205                 if (ch != 
_CXML(
'\n'))
 
 2223                         pResults->
nLine = 0;
 
 2231                                           nullptr, 0,           
nullptr, 0, 
TRUE};
 
 2253                                         pResults->
nLine = 0;
 
 2287                 pResults->
nLine = 0;
 
 2297         int l = ftell(f), headerSz = 0;
 
 2305         unsigned char* buf = (
unsigned char*)malloc(l + 4);
 
 2306         int really_read = (int)fread(buf, 1, l, f);  
 
 2307         if (really_read != l) buf[0] = 
'\0';
 
 2319                         if ((buf[0] == 0xef) && (buf[1] == 0xbb) && (buf[2] == 0xbf))
 
 2325                                 myMultiByteToWideChar((
const char*)(buf + headerSz), ce);
 
 2327                         buf = (
unsigned char*)
b2;
 
 2332                         if ((buf[0] == 0xef) && (buf[1] == 0xff)) headerSz = 2;
 
 2333                         if ((buf[0] == 0xff) && (buf[1] == 0xfe)) headerSz = 2;
 
 2341                         if ((buf[0] == 0xef) && (buf[1] == 0xff)) headerSz = 2;
 
 2342                         if ((buf[0] == 0xff) && (buf[1] == 0xfe)) headerSz = 2;
 
 2345                         buf = (
unsigned char*)
b2;
 
 2350                         if ((buf[0] == 0xef) && (buf[1] == 0xbb) && (buf[2] == 0xbf))
 
 2368         while (l--) *(dest++) = 
c;
 
 2380         int cb = nFormat < 0 ? 0 : nFormat;
 
 2382         int nChildFormat = -1;
 
 2383         int nElementI = pEntry->nChild + pEntry->nText + pEntry->nClear;
 
 2385         if ((nFormat >= 0) && (nElementI == 1) && (pEntry->nText == 1) &&
 
 2386                 (!pEntry->isDeclaration))
 
 2391 #define LENSTR(lpsz) (lpsz ? xstrlen(lpsz) : 0) 
 2394         cbElement = (int)
LENSTR(pEntry->lpszName);
 
 2403                         lpszMarker[nResult++] = 
_CXML(
'<');
 
 2404                         if (pEntry->isDeclaration) lpszMarker[nResult++] = 
_CXML(
'?');
 
 2405                         xstrcpy(&lpszMarker[nResult], pEntry->lpszName);
 
 2406                         nResult += cbElement;
 
 2407                         lpszMarker[nResult++] = 
_CXML(
' ');
 
 2411                         nResult += cbElement + 2 + cb;
 
 2412                         if (pEntry->isDeclaration) nResult++;
 
 2417                 for (i = 0; i < pEntry->nAttribute; i++)
 
 2432                                                 lpszMarker[nResult] = 
_CXML(
'=');
 
 2433                                                 lpszMarker[nResult + 1] = 
_CXML(
'"');
 
 2436                                                                 &lpszMarker[nResult + 2], pAttr->
lpszValue);
 
 2437                                                 lpszMarker[nResult + cb + 2] = 
_CXML(
'"');
 
 2441                                 if (lpszMarker) lpszMarker[nResult] = 
_CXML(
' ');
 
 2447                 if (pEntry->isDeclaration)
 
 2451                                 lpszMarker[nResult - 1] = 
_CXML(
'?');
 
 2452                                 lpszMarker[nResult] = 
_CXML(
'>');
 
 2457                                 if (lpszMarker) lpszMarker[nResult] = 
_CXML(
'\n');
 
 2465                         if (lpszMarker) lpszMarker[nResult - 1] = 
_CXML(
'>');
 
 2468                                 if (lpszMarker) lpszMarker[nResult] = 
_CXML(
'\n');
 
 2480                 if (cbElement && (!pEntry->isDeclaration))
 
 2481                         nChildFormat = nFormat + 1;
 
 2483                         nChildFormat = nFormat;
 
 2487         for (i = 0; i < nElementI; i++)
 
 2489                 j = pEntry->pOrder[i];
 
 2496                                 XMLCSTR pChild = pEntry->pText[j >> 2];
 
 2505                                                                 &lpszMarker[nResult], 
INDENTCHAR, nFormat + 1);
 
 2507                                                                 &lpszMarker[nResult + nFormat + 1], pChild);
 
 2508                                                         lpszMarker[nResult + nFormat + 1 + cb] =
 
 2511                                                 nResult += cb + nFormat + 2;
 
 2517                                                                 &lpszMarker[nResult], pChild);
 
 2527                                 XMLClear* pChild = pEntry->pClear + (j >> 2);
 
 2537                                                                 &lpszMarker[nResult], 
INDENTCHAR, nFormat + 1);
 
 2539                                                                 &lpszMarker[nResult + nFormat + 1],
 
 2542                                                 nResult += cb + nFormat + 1;
 
 2572                                         if (lpszMarker) lpszMarker[nResult] = 
_CXML(
'\n');
 
 2583                                         pEntry->pChild[j >> 2].d,
 
 2584                                         lpszMarker ? lpszMarker + nResult : 0, nChildFormat);
 
 2592         if ((cbElement) && (!pEntry->isDeclaration))
 
 2607                                 lpszMarker[nResult] = 
_CXML(
'<');
 
 2608                                 lpszMarker[nResult + 1] = 
_CXML(
'/');
 
 2610                                 xstrcpy(&lpszMarker[nResult], pEntry->lpszName);
 
 2611                                 nResult += cbElement;
 
 2613                                 lpszMarker[nResult] = 
_CXML(
'>');
 
 2618                                         lpszMarker[nResult + 1] = 
_CXML(
'\n');
 
 2625                                         nResult += cbElement + 4 + nFormat;
 
 2626                                 else if (nFormat == -1)
 
 2627                                         nResult += cbElement + 3;
 
 2629                                         nResult += cbElement + 4;
 
 2639                                 lpszMarker[nResult] = 
_CXML(
'/');
 
 2640                                 lpszMarker[nResult + 1] = 
_CXML(
'>');
 
 2641                                 if (nFormat != -1) lpszMarker[nResult + 2] = 
_CXML(
'\n');
 
 2643                         nResult += nFormat == -1 ? 2 : 3;
 
 2665                 if (pnSize) *pnSize = 0;
 
 2669         XMLSTR lpszResult = 
nullptr;
 
 2674         nFormat = nFormat ? 0 : -1;
 
 2680         lpszResult[cbStr] = 
_CXML(
'\0');
 
 2681         if (pnSize) *pnSize = cbStr;
 
 2689         while (((
void*)(pa[i].
d)) != ((
void*)
d)) i++;
 
 2690         d->pParent->nChild--;
 
 2691         if (
d->pParent->nChild)
 
 2692                 memmove(pa + i, pa + i + 1, (
d->pParent->nChild - i) * 
sizeof(
XMLNode));
 
 2696                 d->pParent->pChild = 
nullptr;
 
 2713                 d->pParent = 
nullptr;
 
 2721         if ((dd->ref_count == 0) || force)
 
 2726                 for (i = 0; i < dd->nChild; i++)
 
 2728                         pc = dd->pChild + i;
 
 2729                         pc->
d->pParent = 
nullptr;
 
 2734                 for (i = 0; i < dd->nText; i++) free((
void*)dd->pText[i]);
 
 2736                 for (i = 0; i < dd->nClear; i++) free((
void*)dd->pClear[i].lpszValue);
 
 2738                 for (i = 0; i < dd->nAttribute; i++)
 
 2740                         free((
void*)dd->pAttribute[i].lpszName);
 
 2741                         if (dd->pAttribute[i].lpszValue)
 
 2742                                 free((
void*)dd->pAttribute[i].lpszValue);
 
 2746                 myFree((
void*)dd->lpszName);
 
 2751                 dd->pChild = 
nullptr;
 
 2752                 dd->pText = 
nullptr;
 
 2753                 dd->pClear = 
nullptr;
 
 2754                 dd->pAttribute = 
nullptr;
 
 2755                 dd->pOrder = 
nullptr;
 
 2756                 dd->lpszName = 
nullptr;
 
 2757                 dd->pParent = 
nullptr;
 
 2759         if (dd->ref_count == 0)
 
 2777                 if (
d) (
d->ref_count)++;
 
 2786         if (
d) (
d->ref_count)++;
 
 2794         int n = 
d->nAttribute;
 
 2801                         p->pAttribute[
n].lpszName = 
stringDup(
d->pAttribute[
n].lpszName);
 
 2802                         p->pAttribute[
n].lpszValue = 
stringDup(
d->pAttribute[
n].lpszValue);
 
 2807                 n = (
d->nChild + 
d->nText + 
d->nClear) * 
sizeof(
int);
 
 2808                 p->pOrder = (
int*)malloc(
n);
 
 2825                         p->pClear[
n].lpszCloseTag = 
d->pClear[
n].lpszCloseTag;
 
 2826                         p->pClear[
n].lpszOpenTag = 
d->pClear[
n].lpszOpenTag;
 
 2837                         p->pChild[
n].d = 
nullptr;
 
 2838                         p->pChild[
n] = 
d->pChild[
n].deepCopy();
 
 2839                         p->pChild[
n].d->pParent = 
p;
 
 2848         if ((!dc) || (!
d)) 
return childNode;
 
 2871         d->pChild[pos].d = dc;
 
 2878         if ((!
d) || (i < 0) || (i >= 
d->nAttribute)) 
return;
 
 2881         free((
void*)
p->lpszName);
 
 2882         if (
p->lpszValue) free((
void*)
p->lpszValue);
 
 2888                 d->pAttribute = 
nullptr;
 
 2908                 if (lpszNewValue) free(lpszNewValue);
 
 2909                 if (lpszNewName) free(lpszNewName);
 
 2912         if (i >= 
d->nAttribute)
 
 2918         if (
p->lpszValue && 
p->lpszValue != lpszNewValue) free((
void*)
p->lpszValue);
 
 2919         p->lpszValue = lpszNewValue;
 
 2920         if (lpszNewName && 
p->lpszName != lpszNewName)
 
 2922                 free((
void*)
p->lpszName);
 
 2923                 p->lpszName = lpszNewName;
 
 2958         int i, l = 
d->nText;
 
 2965         for (i = 0; i < l; i++)
 
 2966                 if (lpszValue == 
p[i]) 
return i;
 
 2972         if ((!
d) || (i < 0) || (i >= 
d->nText)) 
return;
 
 2977                 memmove(
p, 
p + 1, (
d->nText - i) * 
sizeof(
XMLCSTR));
 
 2995                 if (lpszNewValue) free(lpszNewValue);
 
 3000         if (*
p != lpszNewValue)
 
 3005         return lpszNewValue;
 
 3012                 if (lpszNewValue) free(lpszNewValue);
 
 3022         if ((!
d) || (i < 0) || (i >= 
d->nClear)) 
return;
 
 3025         free((
void*)
p->lpszValue);
 
 3027                 memmove(
p, 
p + 1, (
d->nClear - i) * 
sizeof(
XMLClear));
 
 3031                 d->pClear = 
nullptr;
 
 3039         int i, l = 
d->nClear;
 
 3046         for (i = 0; i < l; i++)
 
 3047                 if (lpszValue == 
p[i].lpszValue) 
return i;
 
 3064                 if (lpszNewContent) free(lpszNewContent);
 
 3069         if (lpszNewContent != 
p->lpszValue)
 
 3071                 free((
void*)
p->lpszValue);
 
 3072                 p->lpszValue = lpszNewContent;
 
 3081                 if (lpszNewContent) free(lpszNewContent);
 
 3100         int i, j = 0, 
n = 
d->nChild;
 
 3102         for (i = 0; i < 
n; i++)
 
 3113         int i = 0, 
n = 
d->nChild;
 
 3149         if (path) free(path);
 
 3156         if ((!path) || (!(*path))) 
return *
this;
 
 3161         tend1 = 
xstrstr(path, sepString);
 
 3168                         if (createIfMissing)
 
 3175                 tend1 = 
xstrstr(path, sepString);
 
 3184         if (i >= 
d->nText) i = 
d->nText - 1;
 
 3189         if (i >= 
d->nClear) i = 
d->nClear - 1;
 
 3194         if (i >= 
d->nChild) i = 
d->nChild - 1;
 
 3212         if ((!
d) || (!
x.d)) 
return -1;
 
 3227                 if (j < 0) 
return -1;
 
 3249                                         t = 
x.getAttribute(attributeName, &j);
 
 3259                                 if (
x.isAttributeSet(attributeName))
 
 3266         } 
while (!
x.isEmpty());
 
 3273         if (!
d) 
return nullptr;
 
 3274         int i = 0, 
n = 
d->nAttribute;
 
 3292         int i, 
n = 
d->nAttribute;
 
 3294         for (i = 0; i < 
n; i++)
 
 3307         if (!
d) 
return nullptr;
 
 3324                 c.attrib = 
d->pAttribute[i];
 
 3329         i = (
d->pOrder[i]) >> 2;
 
 3333                         c.child = 
d->pChild[i];
 
 3336                         c.text = 
d->pText[i];
 
 3339                         c.clear = 
d->pClear[i];
 
 3349         if (!
d) 
return nullptr;
 
 3365         return d->nAttribute;
 
 3375         return d->nAttribute + 
d->nChild + 
d->nText + 
d->nClear;
 
 3380         return d->pClear[i];
 
 3385         return d->pAttribute[i];
 
 3389         if ((!
d) || (i >= 
d->nAttribute)) 
return nullptr;
 
 3390         return d->pAttribute[i].lpszName;
 
 3394         if ((!
d) || (i >= 
d->nAttribute)) 
return nullptr;
 
 3395         return d->pAttribute[i].lpszValue;
 
 3399         if ((!
d) || (i >= 
d->nText)) 
return nullptr;
 
 3405         return d->pChild[i];
 
 3415         return d->isDeclaration;
 
 3455         return addClear_priv(0, lpszValue, lpszOpen, lpszClose, pos);
 
 3503         char _dropWhiteSpace, 
char _removeCommentsInMiddleOfText)
 
 3511         switch (_characterEncoding)
 
 3542         void* buf, 
int l, 
char useXMLEncodingAttribute)
 
 3550         unsigned char* 
b = (
unsigned char*)buf;
 
 3551         if ((
b[0] == 0xef) && (
b[1] == 0xbb) && (
b[2] == 0xbf))
 
 3561                                 if ((i < l) && (
b[i] & 0xC0) != 0x80)
 
 3569                                 if ((i < l) && (
b[i] & 0xC0) != 0x80)
 
 3577                                 if ((i < l) && (
b[i] & 0xC0) != 0x80)
 
 3590         if (!useXMLEncodingAttribute) 
return bestGuess;
 
 3597         b = (
unsigned char*)strstr(bb, 
"encoding");
 
 3598         if (!
b) 
return bestGuess;
 
 3602         if (*
b != 
'=') 
return bestGuess;
 
 3606         if ((*
b != 
'\'') && (*
b != 
'"')) 
return bestGuess;
 
 3611         if ((
xstrnicmp((
char*)
b, 
"utf-8", 5) == 0) ||
 
 3618         if ((
xstrnicmp((
char*)
b, 
"shiftjis", 8) == 0) ||
 
 3619                 (
xstrnicmp((
char*)
b, 
"shift-jis", 9) == 0) ||
 
 3630 #undef XML_isSPACECHAR 
 3641         _CXML(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
 
 3647         99, 98, 98, 98, 98, 98, 98, 98, 98, 97, 97, 98, 98, 97, 98, 98,
 
 3648         98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  
 
 3649         98, 98, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 62, 98, 98,
 
 3650         98, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 98, 98,  
 
 3651         98, 96, 98, 98, 98, 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10,
 
 3652         11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,  
 
 3653         25, 98, 98, 98, 98, 98, 98, 26, 27, 28, 29, 30, 31, 32, 33, 34,
 
 3654         35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,  
 
 3655         49, 50, 51, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
 
 3656         98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  
 
 3657         98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
 
 3658         98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  
 
 3659         98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
 
 3660         98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  
 
 3661         98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,
 
 3662         98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98,  
 
 3663         98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98  
 
 3676         unsigned int i = ((inlen - 1) / 3 * 4 + 4 + 1);
 
 3677         if (formatted) i += inlen / 54;
 
 3682         unsigned char* inbuf, 
unsigned int inlen, 
char formatted)
 
 3684         int i = 
encodeLength(inlen, formatted), k = 17, eLen = inlen / 3, j;
 
 3687         for (i = 0; i < eLen; i++)
 
 3691                 j = (inbuf[0] << 16) | (inbuf[1] << 8) | inbuf[2];
 
 3702                                 *(curr++) = 
_CXML(
'\n');
 
 3708         eLen = inlen - eLen * 3;  
 
 3718                 j = (inbuf[0] << 8) | inbuf[1];
 
 3754         if (
size == 0) 
return 0;
 
 3761         return (
unsigned int)((
size * 3) / 4);
 
 3773 #define BASE64DECODE_READ_NEXT_CHAR(c)                       \ 
 3776                 if (data[i] > 255)                                   \ 
 3781                 c = base64DecodeTable[(unsigned char)data[i++]];     \ 
 3782         } while (c == 97);                                       \ 
 3785                 if (xe) *xe = eXMLErrorBase64DecodeIllegalCharacter; \ 
 3789 #define BASE64DECODE_READ_NEXT_CHAR(c)                       \ 
 3792                 c = base64DecodeTable[(unsigned char)data[i++]];     \ 
 3793         } while (c == 97);                                       \ 
 3796                 if (xe) *xe = eXMLErrorBase64DecodeIllegalCharacter; \ 
 3808                         if (
p == (
int)
len) 
return 2;
 
 3814                 if ((d == 99) || (d == 96))
 
 3824                 buf[
p++] = (
unsigned char)((
c << 2) | ((d >> 4) & 0x3));
 
 3834                         if (
c == 96) 
return 2;
 
 3843                 buf[
p++] = (
unsigned char)(((d << 4) & 0xf0) | ((
c >> 2) & 0xf));
 
 3853                         if (d == 96) 
return 2;
 
 3862                 buf[
p++] = (
unsigned char)(((
c << 6) & 0xc0) | d);
 
 3865 #undef BASE64DECODE_READ_NEXT_CHAR 
 3869         if ((!
buf) && (newsize))
 
 3871                 buf = malloc(newsize);
 
 3877                 buf = realloc(
buf, newsize);
 
 3887         if (outlen) *outlen = 
len;
 
 3888         if (!
len) 
return nullptr;
 
 3894         return (
unsigned char*)
buf;