Ignore:
Timestamp:
Aug 11, 2002, 7:07:59 PM (23 years ago)
Author:
umoeller
Message:

Major work on textview control and dialogs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/textv_html.c

    r167 r201  
    114114    CHAR    cSaved;
    115115
    116     PXHTMLDATA pxhtml;      // ptr to XHTMLDATA passed to txvConvertFromHTML
     116    PSZ     *ppszTitle;     // out: title (ptr can be NULL)
     117                            // V0.9.20 (2002-08-10) [umoeller]
    117118
    118119    // formatting flags while going through the text
     
    133134
    134135    // anchors count
    135     USHORT  usAnchorIndex;  // start with 1
     136    // USHORT  usAnchorIndex;  // start with 1      removed V0.9.20 (2002-08-10) [umoeller]
    136137
    137138    // list maintenance
     
    421422    *pSource = pct->cSaved;
    422423
    423     pSource = strchr(pct->pSource, '>');
    424     if (pSource)
     424    if (pSource = strchr(pct->pSource, '>'))
    425425    {
    426         PSZ pNextOpen = strchr(pSource, '<');
    427         if (pNextOpen)
     426        PSZ pNextOpen;
     427        if (pNextOpen = strchr(pSource, '<'))
    428428        {
    429429            // extract title
    430             pct->pxhtml->pszTitle = strhSubstr(pSource + 1, pNextOpen);
     430            if (pct->ppszTitle)
     431                *(pct->ppszTitle) = strhSubstr(pSource + 1, pNextOpen);
     432                        // adjusted V0.9.20 (2002-08-10) [umoeller]
    431433
    432434            if (strnicmp(pNextOpen + 1, "/TITLE", 6) == 0)
     
    434436                // closing /TITLE tag found:
    435437                // search on after that
    436                 pct->pNewSource = strchr(pNextOpen, '>');
    437                 if (pct->pNewSource)
     438                if (pct->pNewSource = strchr(pNextOpen, '>'))
    438439                    pct->pNewSource++;
    439440            }
     
    806807{
    807808    CHAR    szAnchor[10];
     809    PSZ     pHREF = NULL;
    808810
    809811    pct->fInLink = FALSE;
    810812
    811     if ((pct->pszAttributes) && (pct->pxhtml))     // points into main source buffer
     813    if (pct->pszAttributes)
    812814    {
    813815        // we have attributes:
    814         PSZ pszClosingTag = strchr(pct->pszAttributes, '>');
    815         if (pszClosingTag)
     816        PSZ pszClosingTag;
     817        if (pszClosingTag = strchr(pct->pszAttributes, '>'))
    816818        {
    817819            ULONG ulOfs = 0;
     
    822824             */
    823825
    824             PSZ pHREF = strhGetTextAttr(pct->pszAttributes, "HREF", &ulOfs),
    825                 pNAME = 0;
     826            PSZ pNAME = 0;
    826827
    827828            // replace '>' with null char to mark end of search
    828829            *pszClosingTag = 0;
    829830
    830             if (pHREF)
    831             {
     831            if (pHREF = strhGetTextAttr(pct->pszAttributes, "HREF", &ulOfs))
    832832                // OK, we got a link target:
    833                 // create a link item and append it to the output list
    834                 PXHTMLLINK pNewLink = (PXHTMLLINK)malloc(sizeof(XHTMLLINK));
    835                 memset(pNewLink, 0, sizeof(XHTMLLINK));
    836 
    837833                pct->fInLink = TRUE;
    838 
    839                 // this starts with anchor 1
    840                 pNewLink->usLinkIndex = ++pct->usAnchorIndex;
    841                 pNewLink->pszTargetFile = pHREF;
    842834                            // do not free
    843                 lstAppendItem(&pct->pxhtml->llLinks, pNewLink);
    844             }
    845835
    846836            /*
     
    849839             */
    850840
    851             pNAME = strhGetTextAttr(pct->pszAttributes, "NAME", &ulOfs);
    852             if (pNAME)
     841            if (pNAME = strhGetTextAttr(pct->pszAttributes, "NAME", &ulOfs))
    853842            {
    854843                AppendString(pct,
     
    860849                free(pNAME);
    861850            }
     851
    862852            // restore '>'
    863853            *pszClosingTag = '>';
     
    865855    }
    866856
    867     if (pct->fInLink)
     857    if (pHREF)
    868858    {
    869         sprintf(szAnchor, "%04hX", pct->usAnchorIndex);
    870859        AppendString(pct,
    871                      TXVESC_LINK);
     860                     TXVESC_LINK_BEGIN);
    872861        AppendString(pct,
    873                      szAnchor);
     862                     pHREF);
     863        // must be terminated with 0xFF
     864        AppendChar(pct, 0xFF);
     865
     866        free(pHREF);
    874867    }
    875868}
     
    880873    {
    881874        AppendString(pct,
    882                      TXVESC_LINK "####");
     875                     TXVESC_LINK_END);
    883876        pct->fInLink = FALSE;
    884877    }
     
    20512044 *
    20522045 *@@added V0.9.3 (2000-05-06) [umoeller]
     2046 *@@changed V0.9.20 (2002-08-10) [umoeller]: changed prototype
    20532047 */
    20542048
    2055 BOOL txvConvertFromHTML(char **ppszText,
    2056                         PVOID pxhtml,           // out: various config data (PXHTMLDATA)
     2049BOOL txvConvertFromHTML(PSZ *ppszText,          // in/out: text (gets reallocated)
     2050                        PSZ *ppszTitle,         // out: if != NULL, receives malloc'd buffer with HTML title
    20572051                        PULONG pulProgress,     // out: progress (ptr can be NULL)
    20582052                        PBOOL pfCancel)         // in: cancel flag (ptr can be NULL)
     
    20622056    ULONG   cbSource = strlen(*ppszText);
    20632057
    2064     XHTMLDATA xhtmlTemp = {0};
    2065     BOOL fUsingTemp = FALSE;
    20662058    COPYTARGET  ct = {0};
    20672059
    20682060    lstInit(&ct.llLists,
    20692061            TRUE);      // free items
     2062
     2063    ct.ppszTitle = ppszTitle;       // V0.9.20 (2002-08-10) [umoeller]
     2064                // can be NULL
    20702065
    20712066    ct.pSource = *ppszText;
    20722067    // skip leading spaces
    20732068    ct.fSkipNextSpace = TRUE;
    2074     ct.pxhtml = (PXHTMLDATA)pxhtml;
    2075     if (ct.pxhtml == NULL)  // not specified:
    2076     {
    2077         ct.pxhtml = &xhtmlTemp;
    2078         fUsingTemp = TRUE;
    2079     }
    2080 
    2081     lstInit(&ct.pxhtml->llLinks, TRUE);       // auto-free
    20822069
    20832070    // step 2:
     
    22292216    lstClear(&ct.llLists);
    22302217
    2231     if (fUsingTemp)
    2232     {
    2233         if (xhtmlTemp.pszTitle)
    2234             free(xhtmlTemp.pszTitle);
    2235         lstClear(&xhtmlTemp.llLinks);
    2236                 // ### better really clear this... there are PSZ's inside
    2237     }
    2238 
    22392218    return brc;
    22402219}
Note: See TracChangeset for help on using the changeset viewer.