Changeset 187
- Timestamp:
- Jul 8, 2002, 6:53:23 PM (23 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/helpers/xml.h
r186 r187 638 638 639 639 /* 640 *@@ STATICSYSTEMID: 641 * specification of a supported static system 642 * ID, which is most helpful with predefined 643 * DTD's. 644 * 645 * An array of this structure can be passed to 646 * xmlCreateDOM to avoid having to supply an 647 * external entity reference callback. 648 * 649 * This has one system ID with a corresponding 650 * contents (normally a DTD) so the 651 * implementation's external entity handler can 652 * parse the doctype automatically. 653 * 654 *@@added V0.9.20 (2002-07-06) [umoeller] 655 */ 656 657 typedef struct _STATICSYSTEMID 658 { 659 PCSZ pcszSystemId; 660 // possible system ID specified in DTD, e.g. "warpin.dtd" 661 // (without quotes) 662 663 PCSZ pcszContent; 664 // corresponding external DTD subset without square brackets, 665 // e.g. "<!ELEMENT job EMPTY >\n" 666 // (without quotes) 667 668 } STATICSYSTEMID, *PSTATICSYSTEMID; 669 670 /* 640 671 *@@ XMLDOM: 641 672 * DOM instance returned by xmlCreateDOM. … … 681 712 PFNEXTERNALHANDLER pfnExternalHandler; 682 713 PVOID pvCallbackUser; 714 const STATICSYSTEMID *paSystemIds; 715 ULONG cSystemIds; 683 716 684 717 XML_Parser pParser; … … 702 735 703 736 APIRET xmlCreateDOM(ULONG flParserFlags, 737 const STATICSYSTEMID *paSystemIds, 738 ULONG cSystemIds, 704 739 PFNGETCPDATA pfnGetCPData, 705 740 PFNEXTERNALHANDLER pfnExternalHandler, -
trunk/src/helpers/encodings.c
r186 r187 2 2 /* 3 3 *@@sourcefile encodings.c: 4 * character encoding translations. 4 * character encoding support. Handles all kinds 5 * of legacy codepages (including most OS/2 codepage) 6 * and Unicode in the form of UTF-8 and translations 7 * between then. 5 8 * 6 9 * See encCreateCodec for an introduction. -
trunk/src/helpers/xml.c
r186 r187 1902 1902 * 1903 1903 *@@added V0.9.14 (2001-08-09) [umoeller] 1904 *@@changed V0.9.20 (2002-07-06) [umoeller]: added automatic doctype support 1904 1905 */ 1905 1906 … … 1915 1916 int i = 0; // return error per default 1916 1917 1917 APIRET arc = NO_ERROR;1918 1919 1918 // store the previous parser because 1920 1919 // all the callbacks use the parser pointer … … 1922 1921 pDom->pParser = NULL; 1923 1922 1924 if ( (pDom->pfnExternalHandler) 1923 if ( ( (pDom->pfnExternalHandler) 1924 || (pDom->cSystemIds) // V0.9.20 (2002-07-06) [umoeller] 1925 ) 1925 1926 // create sub-parser and replace the one 1926 1927 // in the DOM with it … … 1930 1931 ) 1931 1932 { 1932 if ((arc = pDom->pfnExternalHandler(pDom, 1933 pDom->pParser, 1934 pcszSystemId, 1935 pcszPublicId))) 1936 { 1937 // error: 1938 // now this needs special handling, since we're 1939 // dealing with a sub-handler here... 1940 1941 if (arc == -1) 1942 // parser error: well, then xmlSetError has been 1943 // called from somewhere in the callbacks already, 1944 // and we can safely ignore this 1945 ; 1933 // run through the predefined doctypes given to us 1934 // in xmlCreateDOM, if any 1935 // V0.9.20 (2002-07-06) [umoeller] 1936 BOOL fCallExternal = TRUE; 1937 ULONG ul; 1938 1939 for (ul = 0; 1940 ul < pDom->cSystemIds; 1941 ++ul) 1942 { 1943 const STATICSYSTEMID *pThis = &pDom->paSystemIds[ul]; 1944 if (!strcmp(pThis->pcszSystemId, pcszSystemId)) 1945 { 1946 // this one matches: 1947 // then parse the corresponding entry given 1948 // to us 1949 if (XML_Parse(pDom->pParser, 1950 pThis->pcszContent, 1951 strlen(pThis->pcszContent), 1952 TRUE)) 1953 i = 1; // success 1954 1955 fCallExternal = FALSE; 1956 1957 break; 1958 } 1959 } 1960 1961 if ( (fCallExternal) // not handled above 1962 && (pDom->pfnExternalHandler) // user handler set 1963 ) 1964 { 1965 APIRET arc; 1966 1967 if (!(arc = pDom->pfnExternalHandler(pDom, 1968 pDom->pParser, 1969 pcszSystemId, 1970 pcszPublicId))) 1971 i = 1; // success 1946 1972 else 1947 1973 { 1948 pDom->arcDOM = arc; 1949 if (pcszSystemId) 1974 // error: 1975 // now this needs special handling, since we're 1976 // dealing with a sub-handler here... 1977 1978 if (arc == -1) 1979 // parser error: well, then xmlSetError has been 1980 // called from somewhere in the callbacks already, 1981 // and we can safely ignore this 1982 ; 1983 else 1950 1984 { 1951 if (!pDom->pxstrFailingNode) 1952 pDom->pxstrFailingNode = xstrCreate(0); 1953 xstrcpy(pDom->pxstrFailingNode, pcszSystemId, 0); 1985 pDom->arcDOM = arc; 1986 if (pcszSystemId) 1987 { 1988 if (!pDom->pxstrFailingNode) 1989 pDom->pxstrFailingNode = xstrCreate(0); 1990 xstrcpy(pDom->pxstrFailingNode, pcszSystemId, 0); 1991 } 1992 pDom->pcszErrorDescription = xmlDescribeError(arc); 1993 pDom->ulErrorLine = XML_GetCurrentLineNumber(pDom->pParser); 1994 pDom->ulErrorColumn = XML_GetCurrentColumnNumber(pDom->pParser); 1954 1995 } 1955 pDom->pcszErrorDescription = xmlDescribeError(arc);1956 pDom->ulErrorLine = XML_GetCurrentLineNumber(pDom->pParser);1957 pDom->ulErrorColumn = XML_GetCurrentColumnNumber(pDom->pParser);1958 1996 } 1959 1997 } 1960 1961 i = 1; // success1962 1998 } 1963 1999 else 1964 2000 xmlSetError(pDom, 1965 (!arc) ? ERROR_DOM_INVALID_EXTERNAL_HANDLER : arc,2001 ERROR_DOM_INVALID_EXTERNAL_HANDLER, 1966 2002 NULL, 1967 2003 FALSE); … … 2336 2372 * not all @expat features are supported yet. 2337 2373 * 2374 * flParserFlags is any combination of the following: 2375 * 2376 * -- DF_PARSECOMMENTS: XML @comments are to be returned in 2377 * the DOM tree. Otherwise they are discarded. 2378 * 2379 * -- DF_PARSEDTD: add the @DTD of the document into the DOM tree 2380 * as well and validate the document, if a DTD was found. 2381 * Otherwise just parse and do not validate. 2382 * 2383 * DF_PARSEDTD is required for external entities to work 2384 * also. 2385 * 2386 * -- DF_FAIL_IF_NO_DTD: fail if no @DTD was found. Useful 2387 * if you want to enforce validation. @@todo 2388 * 2389 * -- DF_DROP_WHITESPACE: discard all @whitespace for those 2390 * elements that can only have element content. Whitespace 2391 * will be preserved only for elements that can have 2392 * mixed content. -- If this flag is not set, all whitespace 2393 * is preserved. 2394 * 2338 2395 * The following callbacks can be specified (any of these 2339 2396 * can be NULL): … … 2371 2428 * the int at index 0x94 to 0x00f6. 2372 2429 * 2373 * pvCallbackUser is a user parameter which is simply stored 2374 * in the XMLDOM struct which is returned. Since the XMLDOM 2375 * is passed to all the callbacks, you can access that pointer 2376 * from them. 2377 * 2378 * flParserFlags is any combination of the following: 2379 * 2380 * -- DF_PARSECOMMENTS: XML @comments are to be returned in 2381 * the DOM tree. Otherwise they are discarded. 2382 * 2383 * -- DF_PARSEDTD: add the @DTD of the document into the DOM tree 2384 * as well and validate the document, if a DTD was found. 2385 * Otherwise just parse and do not validate. 2386 * 2387 * DF_PARSEDTD is required for external entities to work 2388 * also. 2389 * 2390 * -- DF_FAIL_IF_NO_DTD: fail if no @DTD was found. Useful 2391 * if you want to enforce validation. @@todo 2392 * 2393 * -- DF_DROP_WHITESPACE: discard all @whitespace for those 2394 * elements that can only have element content. Whitespace 2395 * will be preserved only for elements that can have 2396 * mixed content. -- If this flag is not set, all whitespace 2397 * is preserved. 2430 * -- pvCallbackUser is a user parameter which is simply stored 2431 * in the XMLDOM struct which is returned. Since the XMLDOM 2432 * is passed to all the callbacks, you can access that pointer 2433 * from them. 2398 2434 * 2399 2435 *@@added V0.9.9 (2001-02-14) [umoeller] … … 2402 2438 2403 2439 APIRET xmlCreateDOM(ULONG flParserFlags, // in: DF_* parser flags 2440 const STATICSYSTEMID *paSystemIds, // in: array of STATICSYSTEMID's or NULL 2441 ULONG cSystemIds, // in: array item count 2404 2442 PFNGETCPDATA pfnGetCPData, // in: codepage callback or NULL 2405 2443 PFNEXTERNALHANDLER pfnExternalHandler, // in: external entity callback or NULL … … 2422 2460 pDom->pfnExternalHandler = pfnExternalHandler; 2423 2461 pDom->pvCallbackUser = pvCallbackUser; 2462 2463 // these added with V0.9.20 (2002-07-06) [umoeller] 2464 pDom->paSystemIds = paSystemIds; 2465 pDom->cSystemIds = cSystemIds; 2424 2466 2425 2467 lstInit(&pDom->llElementStack, … … 2470 2512 CommentHandler); 2471 2513 2472 if (pfnExternalHandler) 2514 if ( (pfnExternalHandler) 2515 || (cSystemIds) // V0.9.20 (2002-07-06) [umoeller] 2516 ) 2473 2517 XML_SetExternalEntityRefHandler(pDom->pParser, 2474 2518 ExternalEntityRefHandler); -
trunk/src/helpers/xstring.c
r154 r187 34 34 * iterative appends, you can pre-allocate memory to 35 35 * avoid excessive reallocations. 36 * 37 * These functions are also used internally by the 38 * WarpIN BSString class (and related classes). 36 39 * 37 40 * Usage: … … 139 142 { 140 143 memset(pxstr, 0, sizeof(XSTRING)); 144 141 145 if (ulPreAllocate) 142 146 { … … 186 190 { 187 191 memset(pxstr, 0, sizeof(XSTRING)); 192 188 193 if (ulPreAllocate) 189 194 { … … 362 367 if (pxstr->psz) 363 368 free(pxstr->psz); 369 364 370 memset(pxstr, 0, sizeof(XSTRING)); 365 371 } … … 441 447 // else: we have enough memory 442 448 443 return (pxstr->cbAllocated);449 return pxstr->cbAllocated; 444 450 } 445 451 … … 485 491 xstrInit(pxstr, ulPreAllocate); 486 492 487 return (pxstr);493 return pxstr; 488 494 } 489 495 … … 542 548 { 543 549 if (!pxstr) 544 return (0); // V0.9.9 (2001-02-14) [umoeller]550 return 0; // V0.9.9 (2001-02-14) [umoeller] 545 551 546 552 xstrClear(pxstr); … … 556 562 // else null string: cbAllocated and ulLength are 0 already 557 563 558 return (pxstr->ulLength);564 return pxstr->ulLength; 559 565 } 560 566 … … 570 576 PSZ pszNew) // in: heap PSZ to use 571 577 { 572 return (xstrset2(pxstr, pszNew, 0));578 return xstrset2(pxstr, pszNew, 0); 573 579 } 574 580 … … 621 627 622 628 ULONG xstrcpy(PXSTRING pxstr, // in/out: string 623 PCSZ pcszSource, // in: source, can be NULL629 PCSZ pcszSource, // in: source, can be NULL 624 630 ULONG ulSourceLength) // in: length of pcszSource or 0 625 631 { 626 632 if (!pxstr) 627 return (0); // V0.9.9 (2001-02-14) [umoeller]633 return 0; // V0.9.9 (2001-02-14) [umoeller] 628 634 629 635 if (pcszSource) … … 647 653 pcszSource, 648 654 ulSourceLength); 649 *(pxstr->psz + ulSourceLength)= '\0';655 pxstr->psz[ulSourceLength] = '\0'; 650 656 // V0.9.9 (2001-02-16) [umoeller] 651 657 // we must do this or otherwise we require pcszSource … … 670 676 pxstr->ulLength = ulSourceLength; 671 677 672 return (pxstr->ulLength);678 return pxstr->ulLength; 673 679 } 674 680 … … 684 690 { 685 691 if (!pcstrSource) 686 return (0);687 688 return (xstrcpy(pxstr, pcstrSource->psz, pcstrSource->ulLength));692 return 0; 693 694 return xstrcpy(pxstr, pcstrSource->psz, pcstrSource->ulLength); 689 695 } 690 696 … … 758 764 ulSourceLength); 759 765 760 *(pxstr->psz + pxstr->ulLength + ulSourceLength)= '\0';766 pxstr->psz[pxstr->ulLength + ulSourceLength] = '\0'; 761 767 // V0.9.9 (2001-02-16) [umoeller] 762 768 // we must do this or otherwise we require pcszSource … … 774 780 } 775 781 776 return (ulrc);782 return ulrc; 777 783 } 778 784 … … 816 822 if ((pxstr) && (c)) 817 823 { 818 // ULONG ulSourceLength = 1;819 824 // 1) memory management 820 825 xstrReserve(pxstr, … … 833 838 } // end if ((pxstr) && (c)) 834 839 835 return (ulrc);840 return ulrc; 836 841 } 837 842 … … 847 852 { 848 853 if (!pcstrSource) 849 return (0);850 851 return (xstrcat(pxstr,852 853 pcstrSource->ulLength));854 return 0; 855 856 return xstrcat(pxstr, 857 pcstrSource->psz, 858 pcstrSource->ulLength); 854 859 } 855 860 … … 1023 1028 } // end checks 1024 1029 1025 return (ulrc);1030 return ulrc; 1026 1031 } 1027 1032 … … 1094 1099 } 1095 1100 1096 return (pReturn);1101 return pReturn; 1097 1102 } 1098 1103 … … 1210 1215 } // end if ((pxstr) && (pstrSearch) && (pstrReplace)) 1211 1216 1212 return (ulrc);1217 return ulrc; 1213 1218 } 1214 1219 … … 1246 1251 xstrInitSet(&xstrReplace, (PSZ)pcszReplace); 1247 1252 1248 return (xstrFindReplace(pxstr, pulOfs, &xstrFind, &xstrReplace, ShiftTable, &fRepeat));1253 return xstrFindReplace(pxstr, pulOfs, &xstrFind, &xstrReplace, ShiftTable, &fRepeat); 1249 1254 } 1250 1255 … … 1325 1330 */ 1326 1331 1327 ULONG xstrEncode(PXSTRING pxstr, 1332 ULONG xstrEncode(PXSTRING pxstr, // in/out: string to convert 1328 1333 PCSZ pcszEncode) // in: characters to encode (e.g. "%,();=") 1329 1334 { … … 1383 1388 } 1384 1389 1385 return (ulrc);1390 return ulrc; 1386 1391 } 1387 1392 … … 1464 1469 } 1465 1470 1466 return (ulrc);1471 return ulrc; 1467 1472 } 1468 1473 … … 1476 1481 ULONG xstrDecode(PXSTRING pxstr) 1477 1482 { 1478 return (xstrDecode2(pxstr, '%'));1483 return xstrDecode2(pxstr, '%'); 1479 1484 } 1480 1485 … … 1683 1688 printf("New string is: \"%s\" (%d/%d/%d)\n", str.psz, str.ulLength, str.cbAllocated, str.ulDelta); 1684 1689 1685 return (0);1690 return 0; 1686 1691 } */ 1687 1692
Note:
See TracChangeset
for help on using the changeset viewer.