Changeset 187


Ignore:
Timestamp:
Jul 8, 2002, 6:53:23 PM (23 years ago)
Author:
umoeller
Message:

Misc updates.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/xml.h

    r186 r187  
    638638
    639639    /*
     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    /*
    640671     *@@ XMLDOM:
    641672     *      DOM instance returned by xmlCreateDOM.
     
    681712        PFNEXTERNALHANDLER pfnExternalHandler;
    682713        PVOID           pvCallbackUser;
     714        const STATICSYSTEMID *paSystemIds;
     715        ULONG           cSystemIds;
    683716
    684717        XML_Parser      pParser;
     
    702735
    703736    APIRET xmlCreateDOM(ULONG flParserFlags,
     737                        const STATICSYSTEMID *paSystemIds,
     738                        ULONG cSystemIds,
    704739                        PFNGETCPDATA pfnGetCPData,
    705740                        PFNEXTERNALHANDLER pfnExternalHandler,
  • trunk/src/helpers/encodings.c

    r186 r187  
    22/*
    33 *@@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.
    58 *
    69 *      See encCreateCodec for an introduction.
  • trunk/src/helpers/xml.c

    r186 r187  
    19021902 *
    19031903 *@@added V0.9.14 (2001-08-09) [umoeller]
     1904 *@@changed V0.9.20 (2002-07-06) [umoeller]: added automatic doctype support
    19041905 */
    19051906
     
    19151916    int i = 0;          // return error per default
    19161917
    1917     APIRET  arc = NO_ERROR;
    1918 
    19191918    // store the previous parser because
    19201919    // all the callbacks use the parser pointer
     
    19221921    pDom->pParser = NULL;
    19231922
    1924     if (    (pDom->pfnExternalHandler)
     1923    if (    (    (pDom->pfnExternalHandler)
     1924              || (pDom->cSystemIds)      // V0.9.20 (2002-07-06) [umoeller]
     1925            )
    19251926            // create sub-parser and replace the one
    19261927            // in the DOM with it
     
    19301931       )
    19311932    {
    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
    19461972            else
    19471973            {
    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
    19501984                {
    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);
    19541995                }
    1955                 pDom->pcszErrorDescription = xmlDescribeError(arc);
    1956                 pDom->ulErrorLine = XML_GetCurrentLineNumber(pDom->pParser);
    1957                 pDom->ulErrorColumn = XML_GetCurrentColumnNumber(pDom->pParser);
    19581996            }
    19591997        }
    1960 
    1961         i = 1;      // success
    19621998    }
    19631999    else
    19642000        xmlSetError(pDom,
    1965                     (!arc) ? ERROR_DOM_INVALID_EXTERNAL_HANDLER : arc,
     2001                    ERROR_DOM_INVALID_EXTERNAL_HANDLER,
    19662002                    NULL,
    19672003                    FALSE);
     
    23362372 *      not all @expat features are supported yet.
    23372373 *
     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 *
    23382395 *      The following callbacks can be specified (any of these
    23392396 *      can be NULL):
     
    23712428 *              the int at index 0x94 to 0x00f6.
    23722429 *
    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.
    23982434 *
    23992435 *@@added V0.9.9 (2001-02-14) [umoeller]
     
    24022438
    24032439APIRET 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
    24042442                    PFNGETCPDATA pfnGetCPData,      // in: codepage callback or NULL
    24052443                    PFNEXTERNALHANDLER pfnExternalHandler, // in: external entity callback or NULL
     
    24222460        pDom->pfnExternalHandler = pfnExternalHandler;
    24232461        pDom->pvCallbackUser = pvCallbackUser;
     2462
     2463        // these added with V0.9.20 (2002-07-06) [umoeller]
     2464        pDom->paSystemIds = paSystemIds;
     2465        pDom->cSystemIds = cSystemIds;
    24242466
    24252467        lstInit(&pDom->llElementStack,
     
    24702512                                          CommentHandler);
    24712513
    2472                 if (pfnExternalHandler)
     2514                if (    (pfnExternalHandler)
     2515                     || (cSystemIds)     // V0.9.20 (2002-07-06) [umoeller]
     2516                   )
    24732517                    XML_SetExternalEntityRefHandler(pDom->pParser,
    24742518                                                    ExternalEntityRefHandler);
  • trunk/src/helpers/xstring.c

    r154 r187  
    3434 *         iterative appends, you can pre-allocate memory to
    3535 *         avoid excessive reallocations.
     36 *
     37 *      These functions are also used internally by the
     38 *      WarpIN BSString class (and related classes).
    3639 *
    3740 *      Usage:
     
    139142{
    140143    memset(pxstr, 0, sizeof(XSTRING));
     144
    141145    if (ulPreAllocate)
    142146    {
     
    186190{
    187191    memset(pxstr, 0, sizeof(XSTRING));
     192
    188193    if (ulPreAllocate)
    189194    {
     
    362367    if (pxstr->psz)
    363368        free(pxstr->psz);
     369
    364370    memset(pxstr, 0, sizeof(XSTRING));
    365371}
     
    441447    // else: we have enough memory
    442448
    443     return (pxstr->cbAllocated);
     449    return pxstr->cbAllocated;
    444450}
    445451
     
    485491        xstrInit(pxstr, ulPreAllocate);
    486492
    487     return (pxstr);
     493    return pxstr;
    488494}
    489495
     
    542548{
    543549    if (!pxstr)
    544         return (0);         // V0.9.9 (2001-02-14) [umoeller]
     550        return 0;         // V0.9.9 (2001-02-14) [umoeller]
    545551
    546552    xstrClear(pxstr);
     
    556562    // else null string: cbAllocated and ulLength are 0 already
    557563
    558     return (pxstr->ulLength);
     564    return pxstr->ulLength;
    559565}
    560566
     
    570576              PSZ pszNew)                   // in: heap PSZ to use
    571577{
    572     return (xstrset2(pxstr, pszNew, 0));
     578    return xstrset2(pxstr, pszNew, 0);
    573579}
    574580
     
    621627
    622628ULONG xstrcpy(PXSTRING pxstr,               // in/out: string
    623               PCSZ pcszSource,       // in: source, can be NULL
     629              PCSZ pcszSource,              // in: source, can be NULL
    624630              ULONG ulSourceLength)         // in: length of pcszSource or 0
    625631{
    626632    if (!pxstr)
    627         return (0);         // V0.9.9 (2001-02-14) [umoeller]
     633        return 0;         // V0.9.9 (2001-02-14) [umoeller]
    628634
    629635    if (pcszSource)
     
    647653                   pcszSource,
    648654                   ulSourceLength);
    649             *(pxstr->psz + ulSourceLength) = '\0';
     655            pxstr->psz[ulSourceLength] = '\0';
    650656                    // V0.9.9 (2001-02-16) [umoeller]
    651657                    // we must do this or otherwise we require pcszSource
     
    670676    pxstr->ulLength = ulSourceLength;
    671677
    672     return (pxstr->ulLength);
     678    return pxstr->ulLength;
    673679}
    674680
     
    684690{
    685691    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);
    689695}
    690696
     
    758764                       ulSourceLength);
    759765
    760                 *(pxstr->psz + pxstr->ulLength + ulSourceLength) = '\0';
     766                pxstr->psz[pxstr->ulLength + ulSourceLength] = '\0';
    761767                        // V0.9.9 (2001-02-16) [umoeller]
    762768                        // we must do this or otherwise we require pcszSource
     
    774780    }
    775781
    776     return (ulrc);
     782    return ulrc;
    777783}
    778784
     
    816822    if ((pxstr) && (c))
    817823    {
    818         // ULONG   ulSourceLength = 1;
    819824        // 1) memory management
    820825        xstrReserve(pxstr,
     
    833838    } // end if ((pxstr) && (c))
    834839
    835     return (ulrc);
     840    return ulrc;
    836841}
    837842
     
    847852{
    848853    if (!pcstrSource)
    849         return (0);
    850 
    851     return (xstrcat(pxstr,
    852                     pcstrSource->psz,
    853                     pcstrSource->ulLength));
     854        return 0;
     855
     856    return xstrcat(pxstr,
     857                   pcstrSource->psz,
     858                   pcstrSource->ulLength);
    854859}
    855860
     
    10231028    } // end checks
    10241029
    1025     return (ulrc);
     1030    return ulrc;
    10261031}
    10271032
     
    10941099    }
    10951100
    1096     return (pReturn);
     1101    return pReturn;
    10971102}
    10981103
     
    12101215    } // end if ((pxstr) && (pstrSearch) && (pstrReplace))
    12111216
    1212     return (ulrc);
     1217    return ulrc;
    12131218}
    12141219
     
    12461251    xstrInitSet(&xstrReplace, (PSZ)pcszReplace);
    12471252
    1248     return (xstrFindReplace(pxstr, pulOfs, &xstrFind, &xstrReplace, ShiftTable, &fRepeat));
     1253    return xstrFindReplace(pxstr, pulOfs, &xstrFind, &xstrReplace, ShiftTable, &fRepeat);
    12491254}
    12501255
     
    13251330 */
    13261331
    1327 ULONG xstrEncode(PXSTRING pxstr,            // in/out: string to convert
     1332ULONG xstrEncode(PXSTRING pxstr,     // in/out: string to convert
    13281333                 PCSZ pcszEncode)    // in: characters to encode (e.g. "%,();=")
    13291334{
     
    13831388    }
    13841389
    1385     return (ulrc);
     1390    return ulrc;
    13861391}
    13871392
     
    14641469    }
    14651470
    1466     return (ulrc);
     1471    return ulrc;
    14671472}
    14681473
     
    14761481ULONG xstrDecode(PXSTRING pxstr)
    14771482{
    1478     return (xstrDecode2(pxstr, '%'));
     1483    return xstrDecode2(pxstr, '%');
    14791484}
    14801485
     
    16831688    printf("New string is: \"%s\" (%d/%d/%d)\n", str.psz, str.ulLength, str.cbAllocated, str.ulDelta);
    16841689
    1685     return (0);
     1690    return 0;
    16861691} */
    16871692
Note: See TracChangeset for help on using the changeset viewer.