Changeset 71


Ignore:
Timestamp:
May 22, 2001, 7:18:41 PM (24 years ago)
Author:
umoeller
Message:

misc updates

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/expat/expat.h

    r39 r71  
    101101                    // one of:
    102102                    // -- XML_CQUANT_NONE   --> all fields below are NULL
    103                     // -- XML_CQUANT_OPT,
    104                     // -- XML_CQUANT_REP,
    105                     // -- XML_CQUANT_PLUS
     103                    // -- XML_CQUANT_OPT,   question mark
     104                    // -- XML_CQUANT_REP,   asterisk
     105                    // -- XML_CQUANT_PLUS   plus sign
    106106
    107107    const XML_Char              *name;
     
    626626#define ERROR_XML_FIRST         40000   // first error code used
    627627
    628 typedef enum _XMLERROR
    629 {
    630     ERROR_EXPAT_NONE = 0,
    631     // ERROR_EXPAT_NONE,            // removed to adhere with APIRET V0.9.9 (2001-02-14) [umoeller]
    632     ERROR_EXPAT_NO_MEMORY = ERROR_XML_FIRST,
    633     ERROR_EXPAT_SYNTAX,
    634     ERROR_EXPAT_NO_ELEMENTS,
    635     ERROR_EXPAT_INVALID_TOKEN,
    636     ERROR_EXPAT_UNCLOSED_TOKEN,
    637     ERROR_EXPAT_PARTIAL_CHAR,
    638     ERROR_EXPAT_TAG_MISMATCH,
    639     ERROR_EXPAT_DUPLICATE_ATTRIBUTE,
    640     ERROR_EXPAT_JUNK_AFTER_DOC_ELEMENT,
    641     ERROR_EXPAT_PARAM_ENTITY_REF,
    642     ERROR_EXPAT_UNDEFINED_ENTITY,
    643     ERROR_EXPAT_RECURSIVE_ENTITY_REF,
    644     ERROR_EXPAT_ASYNC_ENTITY,
    645     ERROR_EXPAT_BAD_CHAR_REF,
    646     ERROR_EXPAT_BINARY_ENTITY_REF,
    647     ERROR_EXPAT_ATTRIBUTE_EXTERNAL_ENTITY_REF,
    648     ERROR_EXPAT_MISPLACED_XML_PI,
    649     ERROR_EXPAT_UNKNOWN_ENCODING,
    650     ERROR_EXPAT_INCORRECT_ENCODING,
    651     ERROR_EXPAT_UNCLOSED_CDATA_SECTION,
    652     ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING,
    653     ERROR_EXPAT_NOT_STANDALONE,
    654     ERROR_EXPAT_UNEXPECTED_STATE,
    655 
    656     ERROR_EXPAT_AFTER_LAST      // added V0.9.9 (2001-02-14) [umoeller];
    657                                 // xml.h builds on this
    658 } XMLERROR;
     628typedef unsigned long XMLERROR;     // V0.9.12 (2001-05-20) [umoeller]
     629
     630#define ERROR_EXPAT_NONE                0
     631#define ERROR_EXPAT_NO_MEMORY           (ERROR_XML_FIRST)
     632#define ERROR_EXPAT_SYNTAX              (ERROR_XML_FIRST + 1)
     633#define ERROR_EXPAT_NO_ELEMENTS         (ERROR_XML_FIRST + 2)
     634#define ERROR_EXPAT_INVALID_TOKEN       (ERROR_XML_FIRST + 3)
     635#define ERROR_EXPAT_UNCLOSED_TOKEN      (ERROR_XML_FIRST + 4)
     636#define ERROR_EXPAT_PARTIAL_CHAR        (ERROR_XML_FIRST + 5)
     637#define ERROR_EXPAT_TAG_MISMATCH        (ERROR_XML_FIRST + 6)
     638#define ERROR_EXPAT_DUPLICATE_ATTRIBUTE (ERROR_XML_FIRST + 7)
     639#define ERROR_EXPAT_JUNK_AFTER_DOC_ELEMENT (ERROR_XML_FIRST + 8)
     640#define ERROR_EXPAT_PARAM_ENTITY_REF    (ERROR_XML_FIRST + 10)
     641#define ERROR_EXPAT_UNDEFINED_ENTITY    (ERROR_XML_FIRST + 11)
     642#define ERROR_EXPAT_RECURSIVE_ENTITY_REF (ERROR_XML_FIRST + 12)
     643#define ERROR_EXPAT_ASYNC_ENTITY        (ERROR_XML_FIRST + 13)
     644#define ERROR_EXPAT_BAD_CHAR_REF        (ERROR_XML_FIRST + 14)
     645#define ERROR_EXPAT_BINARY_ENTITY_REF   (ERROR_XML_FIRST + 15)
     646#define ERROR_EXPAT_ATTRIBUTE_EXTERNAL_ENTITY_REF (ERROR_XML_FIRST + 16)
     647#define ERROR_EXPAT_MISPLACED_XML_PI    (ERROR_XML_FIRST + 17)
     648#define ERROR_EXPAT_UNKNOWN_ENCODING    (ERROR_XML_FIRST + 18)
     649#define ERROR_EXPAT_INCORRECT_ENCODING  (ERROR_XML_FIRST + 19)
     650#define ERROR_EXPAT_UNCLOSED_CDATA_SECTION (ERROR_XML_FIRST + 20)
     651#define ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING (ERROR_XML_FIRST + 21)
     652#define ERROR_EXPAT_NOT_STANDALONE      (ERROR_XML_FIRST + 22)
     653#define ERROR_EXPAT_UNEXPECTED_STATE    (ERROR_XML_FIRST + 23)
    659654
    660655/* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
  • trunk/include/helpers/linklist.h

    r53 r71  
    140140    typedef LSTINIT *PLSTINIT;
    141141
    142     #ifdef __XWPMEMDEBUG__ // setup.h, helpers\memdebug.c
     142    #ifdef __DEBUG_MALLOC_ENABLED__ // setup.h, helpers\memdebug.c
    143143        PLINKLIST XWPENTRY lstCreateDebug(BOOL fItemsFreeable,
    144144                                          const char *file,
     
    194194    typedef LSTINDEXFROMITEM *PLSTINDEXFROMITEM;
    195195
    196     #ifdef __XWPMEMDEBUG__ // setup.h, helpers\memdebug.c
     196    #ifdef __DEBUG_MALLOC_ENABLED__ // setup.h, helpers\memdebug.c
    197197        PLISTNODE XWPENTRY lstAppendItemDebug(PLINKLIST pList,
    198198                                              void* pNewItemData,
  • trunk/include/helpers/memdebug.h

    r14 r71  
    138138            #endif
    139139
     140            #define __DEBUG_MALLOC_ENABLED__
     141
    140142        #endif
    141143    #endif
  • trunk/include/helpers/prfh.h

    r68 r71  
    5252                               PSZ *ppszKeys);
    5353
    54     #ifdef __XWPMEMDEBUG__ // setup.h, helpers\memdebug.c
     54    #ifdef __DEBUG_MALLOC_ENABLED__ // setup.h, helpers\memdebug.c
    5555        PSZ prfhQueryProfileDataDebug(HINI hIni,
    5656                                      const char *pcszApp,
  • trunk/include/helpers/winh.h

    r69 r71  
    543543                                   BOOL fSelectTarget);
    544544
     545    ULONG XWPENTRY winhLboxFindItemFromHandle(HWND hwndListBox,
     546                                              ULONG ulHandle);
     547
    545548    /* ******************************************************************
    546549     *
  • trunk/include/helpers/xml.h

    r64 r71  
    4343     ********************************************************************/
    4444
    45     typedef enum _DOMERROR
    46     {
    47         // validity errors:
     45    // ERROR_XML_FIRST is defined in expat\expat.h;
     46    // the range up to ERROR_XML_FIRST + 24 is used
     47    // by expat
     48
    4849// START MATCHING ERROR MESSAGES (xmlDescribeError)
    49         ERROR_DOM_UNDECLARED_ELEMENT = ERROR_EXPAT_AFTER_LAST,
     50            // validity errors:
     51    #define ERROR_DOM_UNDECLARED_ELEMENT    (ERROR_XML_FIRST + 24)
    5052                // invalidity: element is undeclared
    51         ERROR_DOM_ROOT_ELEMENT_MISNAMED,
    52         ERROR_DOM_INVALID_ROOT_ELEMENT,
    53         ERROR_DOM_INVALID_SUBELEMENT,
     53    #define ERROR_DOM_ROOT_ELEMENT_MISNAMED (ERROR_XML_FIRST + 25)
     54    #define ERROR_DOM_INVALID_ROOT_ELEMENT (ERROR_XML_FIRST + 26)
     55    #define ERROR_DOM_INVALID_SUBELEMENT (ERROR_XML_FIRST + 27)
    5456                // subelement may not appear in its parent element
    55         ERROR_DOM_DUPLICATE_ELEMENT_DECL,
     57    #define ERROR_DOM_DUPLICATE_ELEMENT_DECL (ERROR_XML_FIRST + 28)
    5658                // more than one declaration for an element type
    57         ERROR_DOM_DUPLICATE_ATTRIBUTE_DECL,
     59    #define ERROR_DOM_DUPLICATE_ATTRIBUTE_DECL (ERROR_XML_FIRST + 29)
    5860                // more than one declaration for an attribute type
    59         ERROR_DOM_UNDECLARED_ATTRIBUTE,
    60         ERROR_ELEMENT_CANNOT_HAVE_CONTENT,
     61    #define ERROR_DOM_UNDECLARED_ATTRIBUTE (ERROR_XML_FIRST + 30)
     62    #define ERROR_ELEMENT_CANNOT_HAVE_CONTENT (ERROR_XML_FIRST + 31)
    6163                // element was declared "empty" and contains text anyway,
    6264                // or was declared "children" and contains something other
    6365                // than whitespace
    64         ERROR_DOM_INVALID_ATTRIB_VALUE,
    65         ERROR_DOM_REQUIRED_ATTRIBUTE_MISSING,
    66         ERROR_DOM_SUBELEMENT_IN_EMPTY_ELEMENT,
     66    #define ERROR_DOM_INVALID_ATTRIB_VALUE (ERROR_XML_FIRST + 32)
     67    #define ERROR_DOM_REQUIRED_ATTRIBUTE_MISSING (ERROR_XML_FIRST + 33)
     68    #define ERROR_DOM_SUBELEMENT_IN_EMPTY_ELEMENT (ERROR_XML_FIRST + 34)
    6769// END MATCHING ERROR MESSAGES (xmlDescribeError)
    6870
    6971        // error categories:
    70         ERROR_DOM_PARSING,
    71         ERROR_DOM_VALIDITY,
     72    #define ERROR_DOM_PARSING (ERROR_XML_FIRST + 35)
     73    #define ERROR_DOM_VALIDITY (ERROR_XML_FIRST + 36)
    7274
    7375        // additional DOM errors
    74         ERROR_DOM_NODETYPE_NOT_SUPPORTED,
     76    #define ERROR_DOM_NODETYPE_NOT_SUPPORTED (ERROR_XML_FIRST + 37)
    7577                // invalid node type in xmlCreateDomNode
    76         ERROR_DOM_NO_DOCUMENT,
     78    #define ERROR_DOM_NO_DOCUMENT (ERROR_XML_FIRST + 38)
    7779                // cannot find document node
    78         ERROR_DOM_NO_ELEMENT,
    79         ERROR_DOM_DUPLICATE_DOCTYPE,
    80         ERROR_DOM_DOCTYPE_ROOT_NAMES_MISMATCH,
     80    #define ERROR_DOM_NO_ELEMENT (ERROR_XML_FIRST + 39)
     81    #define ERROR_DOM_DUPLICATE_DOCTYPE (ERROR_XML_FIRST + 40)
     82    #define ERROR_DOM_DOCTYPE_ROOT_NAMES_MISMATCH (ERROR_XML_FIRST + 41)
    8183                // DOCTYPE is given and root element name does not match doctype name
    82         ERROR_DOM_INTEGRITY,
    83         ERROR_DOM_DUPLICATE_ATTRIBUTE,
     84    #define ERROR_DOM_INTEGRITY (ERROR_XML_FIRST + 42)
     85    #define ERROR_DOM_DUPLICATE_ATTRIBUTE (ERROR_XML_FIRST + 43)
    8486
    8587        // @@@todo these
    86         ERROR_DOM_VALIDATE_INVALID_ELEMENT,
    87         ERROR_DOM_ELEMENT_DECL_OUTSIDE_DOCTYPE,
    88         ERROR_DOM_ATTLIST_DECL_OUTSIDE_DOCTYPE
    89     } DOMERROR;
     88    #define ERROR_DOM_VALIDATE_INVALID_ELEMENT (ERROR_XML_FIRST + 44)
     89    #define ERROR_DOM_ELEMENT_DECL_OUTSIDE_DOCTYPE (ERROR_XML_FIRST + 45)
     90    #define ERROR_DOM_ATTLIST_DECL_OUTSIDE_DOCTYPE (ERROR_XML_FIRST + 46)
    9091
    9192    const char* xmlDescribeError(int code);
     
    130131    /*
    131132     *@@ NODEBASE:
    132      *      "content model" node. With the DOM content models,
    133      *      this represents an entry in a DTD or XML schema.
     133     *      root class of all nodes used in the
     134     *      DOM tree.
     135     *
     136     *      The first item is a TREE to make this insertable
     137     *      into string maps via the functions in tree.c.
     138     *
     139     *      A NODEBASE is also the first member of a DOMNODE
     140     *      so this is effectively a simulation of inheritance
     141     *      in plain C... DOMNODE inherits from NODEBASE,
     142     *      and some other types inherit from DOMNODE.
     143     *
     144     *      This contains the node name, which is also used
     145     *      by the DOMNODE's (e.g. for element names).
     146     *      However, only DOMNODE defines the node value
     147     *      string.
    134148     *
    135149     *@@added V0.9.9 (2001-02-14) [umoeller]
     
    138152    typedef struct _NODEBASE
    139153    {
    140         TREE            Tree;
    141 
    142         NODEBASETYPE    ulNodeType;
     154        TREE            Tree;           // tree.c
     155
     156        NODEBASETYPE    ulNodeType;     // class type; this is precious,
     157                                        // all xml* functions make assumptions
     158                                        // from this value
    143159
    144160        XSTRING         strNodeName;
     
    189205     *      Overview of member fields usage:
    190206     +
    191      +      ulNodeType    | strNodeName | strNodeValue | llChildren | llAttributes
     207     +      ulNodeType    | strNodeName | strNodeValue | llChildren | AttributesMap
     208     +      (NODEBASE)    | (NODEBASE)  | (DOMNODE)    | (DOMNODE)  | (DOMNODE)
    192209     +      =======================================================================
    193210     +                    |             |              |            |
     
    409426                    // one of:
    410427                    // -- XML_CQUANT_NONE   --> all fields below are NULL
    411                     // -- XML_CQUANT_OPT,
    412                     // -- XML_CQUANT_REP,
    413                     // -- XML_CQUANT_PLUS
     428                    // -- XML_CQUANT_OPT,   question mark
     429                    // -- XML_CQUANT_REP,   asterisk
     430                    // -- XML_CQUANT_PLUS   plus sign
    414431
    415432        struct _CMELEMENTPARTICLE *pParentParticle;     // or NULL if this is in the
     
    596613    /* ******************************************************************
    597614     *
    598      *   DOM APIs
     615     *   DOM parser APIs
    599616     *
    600617     ********************************************************************/
     
    690707                                   const char *pcszAttribName);
    691708
     709    /* ******************************************************************
     710     *
     711     *   DOM build
     712     *
     713     ********************************************************************/
     714
     715    APIRET xmlCreateDocument(const char *pcszRootElementName,
     716                             PDOMDOCUMENTNODE *ppDocument,
     717                             PDOMNODE *ppRootElement);
     718
     719    APIRET xmlWriteDocument(PDOMDOCUMENTNODE pDocument,
     720                            const char *pcszEncoding,
     721                            const char *pcszDoctype,
     722                            PXSTRING pxstr);
    692723#endif
    693724
  • trunk/src/helpers/configsys.c

    r63 r71  
    159159 *      for analyzing CONFIG.SYS settings.
    160160 *
     161 *      Remarks:
     162 *
     163 *      --  With pcszKey, you can either specify a CONFIG.SYS
     164 *          key WITH an equals sign (e.g. search for "LIBPATH=")
     165 *          or the key name only (e.g. "SET SHELL").
     166 *
     167 *          Only in the latter case, this function makes sure
     168 *          that the search key is complete; e.g. it will not
     169 *          find "SET SHELLHANDLESINC=" then.
     170 *
     171 *      --  If the line found starts with leading spaces,
     172 *          *ppStartOfLine will still receive the start of
     173 *          the line.
     174 *          For example, if you're searching for "SET PATH"
     175 *          and the PATH line is
     176 *
     177 +              "   SET PATH=C:\os2"
     178 *
     179 *          the first space in the line is written into
     180 *          *ppStartOfLine.
     181 *
    161182 *@@changed V0.9.0 [umoeller]: fixed bug in that this would also return something if only the first chars matched
    162183 *@@changed V0.9.0 [umoeller]: fixed bug which could cause character before pszSearchIn to be examined
     
    164185 *@@changed V0.9.7 (2001-01-15) [umoeller]: now checking for tabs too
    165186 *@@changed V0.9.11 (2001-04-25) [umoeller]: this never found lines which had leading spaces, fixed
     187 *@@changed V0.9.12 (2001-05-22) [umoeller]: added checks for key termination (SET SHELLHANDLESINC)
    166188 */
    167189
     
    177199    ULONG       ulKeyLength = strlen(pcszKey);
    178200
     201    BOOL        fSearchKeyContainsEquals = (strchr(pcszKey, '=') != 0);
     202
    179203    do
    180204    {
    181         p = strhistr(p, pcszKey);
    182 
    183         if (    (p)
    184              && (p >= pcszSearchIn)
    185            )
     205        // find the key
     206        // (on first loop, p is start of buffer;
     207        // on subsequent loops, p is somewhere in bufer,
     208        // if we've found the key somewhere else)
     209        if (p = strhistr(p, pcszKey))
    186210        {
    187211            // make sure the key is at the beginning of a line
     
    207231                // OK, we're at the start of a line:
    208232
    209                 // return address of key
    210                 pReturn = (PSZ)p;
    211                 // return start of line
    212                 if (ppStartOfLine)
    213                     *ppStartOfLine = (PSZ)pStartOfLine;
    214 
    215                 // test for all upper case?
    216                 if (pfIsAllUpperCase)
     233                // check the character AFTER the
     234                // key if it's a space or '=';
     235                // without this check, we'd find
     236                // SET SHELL= if caller is really
     237                // looking for SET SHELLHANDLESINC=,
     238                // but only do this check if the caller
     239                // doesn't have '=' in the search string
     240                // already
     241                // V0.9.12 (2001-05-22) [umoeller]
     242                CHAR c = *(p + ulKeyLength);
     243                if (    (fSearchKeyContainsEquals)
     244                     || (c == ' ')
     245                     || (c == '=')
     246                     || (c == '\n')
     247                     || (c == '\r')
     248                     || (c == '\t')
     249                   )
    217250                {
    218                     ULONG   ul = 0;
    219                     *pfIsAllUpperCase = TRUE;
    220 
    221                     for (ul = 0;
    222                          ul < ulKeyLength;
    223                          ul++)
     251                    // return address of key
     252                    pReturn = (PSZ)p;
     253                    // return start of line
     254                    if (ppStartOfLine)
     255                        *ppStartOfLine = (PSZ)pStartOfLine;
     256
     257                    // test for all upper case?
     258                    if (pfIsAllUpperCase)
    224259                    {
    225                         if (islower(*(p + ul)))
     260                        ULONG   ul = 0;
     261                        *pfIsAllUpperCase = TRUE;
     262
     263                        for (ul = 0;
     264                             ul < ulKeyLength;
     265                             ul++)
    226266                        {
    227                             *pfIsAllUpperCase = FALSE;
    228                             break; // for
     267                            if (islower(*(p + ul)))
     268                            {
     269                                *pfIsAllUpperCase = FALSE;
     270                                break; // for
     271                            }
    229272                        }
    230273                    }
    231                 }
    232 
    233                 break; // do
     274
     275                    break; // do
     276                } // else search next key
    234277            } // else search next key
    235278
    236             p++; // search on after this key
     279            p += ulKeyLength; // search on after this key
     280                    // now skipping ulKeyLength V0.9.12 (2001-05-22) [umoeller]
    237281        }
    238282        else
     
    475519 *
    476520 *      If the manipulation succeeded, NO_ERROR is returned
    477  *      and *ppszChanged receives a new string describing
     521 *      and pstrChanged receives a new string describing
    478522 *      what was changed. This can be:
    479523 *
     
    502546 *
    503547 *      -- This assumes that the line breaks are represented
    504  *         by \r\n items ONLY.
     548 *         by \n ONLY. If *ppszContents has \r\n line breaks,
     549 *         they must be converted to pure \n first.
    505550 */
    506551
     
    611656                                    &pStartOfLineWithKeyFound,
    612657                                    &fIsAllUpperCase);
     658                // returns beginning of line
    613659
    614660            if (!pKeyFound)
  • trunk/src/helpers/dosh2.c

    r69 r71  
    499499 *
    500500 *@@added V0.9.4 (2000-07-19) [umoeller]
     501 *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
    501502 */
    502503
     
    544545                ppszThis++;
    545546            }
     547
     548            free(pszSearch);        // was missing V0.9.12 (2001-05-21) [umoeller]
    546549        }
    547550    }
     
    571574 *@@added V0.9.4 (2000-07-19) [umoeller]
    572575 *@@changed V0.9.7 (2000-12-17) [umoeller]: added fAddFirst
     576 *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
    573577 */
    574578
     
    625629                else
    626630                {
     631                    if (pEnv->papszVars)
     632                        free(pEnv->papszVars);      // was missing V0.9.12 (2001-05-21) [umoeller]
     633
    627634                    pEnv->papszVars = papszNew;
    628635                    pEnv->cVars++;
  • trunk/src/helpers/linklist.c

    r53 r71  
    235235}
    236236
    237 #ifdef __XWPMEMDEBUG__
     237#ifdef __DEBUG_MALLOC_ENABLED__
    238238
    239239/*
     
    263263}
    264264
    265 #else
     265#endif      // __DEBUG_MALLOC_ENABLED__
    266266
    267267/*
     
    286286 */
    287287
    288 PLINKLIST lstCreate(BOOL fItemsFreeable)    // in: invoke free() on the data
     288PLINKLIST (lstCreate)(BOOL fItemsFreeable)    // in: invoke free() on the data
    289289                                            // item pointers upon destruction?
    290290{
     
    294294    return (pNewList);
    295295}
    296 
    297 #endif      // __XWPMEMDEBUG__
    298296
    299297/*
     
    543541}
    544542
    545 #ifdef __XWPMEMDEBUG__
     543#ifdef __DEBUG_MALLOC_ENABLED__
    546544
    547545/*
     
    603601}
    604602
    605 #else
     603#endif // __DEBUG_MALLOC_ENABLED__
    606604
    607605/*
     
    615613 */
    616614
    617 PLISTNODE lstAppendItem(PLINKLIST pList,
     615PLISTNODE (lstAppendItem)(PLINKLIST pList,
    618616                        void* pNewItemData)     // in: data to store in list node
    619617{
     
    656654    return (pNewNode);
    657655}
    658 
    659 #endif // __XWPMEMDEBUG__
    660656
    661657/*
  • trunk/src/helpers/memdebug.c

    r21 r71  
    456456 *
    457457 *@@added V0.9.6 (2000-11-12) [umoeller]
     458 *@@changed V0.9.12 (2001-05-21) [umoeller]: this reported errors on realloc(0), which is a valid call, fixed
    458459 */
    459460
     
    466467    void *prc = NULL;
    467468    BOOL fFound = FALSE;
     469
     470    if (!p)
     471        // p == NULL: this is valid, use malloc() instead
     472        // V0.9.12 (2001-05-21) [umoeller]
     473        return (memdMalloc(stSize, pcszSourceFile, ulLine, pcszFunction));
    468474
    469475    if (memdLock())
  • trunk/src/helpers/memdebug_win.c

    r13 r71  
    479479        case WM_CREATE:
    480480        {
    481             TRY_LOUD(excpt1, NULL)
     481            TRY_LOUD(excpt1)
    482482            {
    483483                // PCREATESTRUCT pcs = (PCREATESTRUCT)mp2;
  • trunk/src/helpers/prfh.c

    r68 r71  
    122122}
    123123
    124 #ifdef __XWPMEMDEBUG__ // setup.h, helpers\memdebug.c
     124#ifdef __DEBUG_MALLOC_ENABLED__ // setup.h, helpers\memdebug.c
    125125
    126126/*
  • trunk/src/helpers/winh.c

    r69 r71  
    14921492
    14931493/*
     1494 *@@ winhLboxFindItemFromHandle:
     1495 *      finds the list box item with the specified
     1496 *      handle.
     1497 *
     1498 *      Of course this only makes sense if each item
     1499 *      has a unique handle indeed.
     1500 *
     1501 *      Returns the index of the item found or -1.
     1502 *
     1503 *@@added V0.9.12 (2001-05-18) [umoeller]
     1504 */
     1505
     1506ULONG winhLboxFindItemFromHandle(HWND hwndListBox,
     1507                                 ULONG ulHandle)
     1508{
     1509    LONG cItems = WinQueryLboxCount(hwndListBox);
     1510    if (cItems)
     1511    {
     1512        ULONG ul;
     1513        for (ul = 0;
     1514             ul < cItems;
     1515             ul++)
     1516        {
     1517            if (ulHandle == winhQueryLboxItemHandle(hwndListBox,
     1518                                                    ul))
     1519                return (ul);
     1520        }
     1521    }
     1522
     1523    return (-1);
     1524}
     1525
     1526/*
    14941527 *@@category: Helpers\PM helpers\Scroll bar helpers
    14951528 */
     
    35663599 *
    35673600 *@@added V0.9.3 (2000-04-29) [umoeller]
     3601 *@@changed V0.9.12 (2001-05-21) [umoeller]: this failed if INI data had root dir, fixed
    35683602 */
    35693603
     
    35803614{
    35813615    FILEDLG fd;
     3616    FILESTATUS3 fs3;
     3617
    35823618    memset(&fd, 0, sizeof(FILEDLG));
    35833619    fd.cbSize = sizeof(FILEDLG);
     
    35893625        fd.fl |= FDS_OPEN_DIALOG;
    35903626
    3591     // default: copy pszFile
    3592     strcpy(fd.szFullFile, pszFile);
    3593 
    3594     if ( (hini) && (flFlags & WINH_FOD_INILOADDIR) )
    3595     {
    3596         // overwrite with initial directory for FOD from OS2.INI
    3597         if (PrfQueryProfileString(hini,
    3598                                   (PSZ)pcszApplication,
    3599                                   (PSZ)pcszKey,
    3600                                   "",      // default string V0.9.9 (2001-02-10) [umoeller]
    3601                                   fd.szFullFile,
    3602                                   sizeof(fd.szFullFile)-10)
    3603                     >= 2)
    3604         {
    3605             // found: append "\*"
    3606             strcat(fd.szFullFile, "\\");
    3607             strcat(fd.szFullFile, pszFile);
    3608         }
    3609     }
     3627    if (    (hini)
     3628         && (flFlags & WINH_FOD_INILOADDIR)
     3629         && (PrfQueryProfileString(hini,
     3630                                   (PSZ)pcszApplication,
     3631                                   (PSZ)pcszKey,
     3632                                   "",      // default string V0.9.9 (2001-02-10) [umoeller]
     3633                                   fd.szFullFile,
     3634                                   sizeof(fd.szFullFile)-10)
     3635                     > 2)
     3636         // added these checks V0.9.12 (2001-05-21) [umoeller]
     3637         && (!DosQueryPathInfo(fd.szFullFile,
     3638                               FIL_STANDARD,
     3639                               &fs3,
     3640                               sizeof(fs3)))
     3641         && (fs3.attrFile & FILE_DIRECTORY)
     3642       )
     3643    {
     3644        // found: append "\*"
     3645        strcat(fd.szFullFile, "\\");
     3646        strcat(fd.szFullFile, pszFile);
     3647    }
     3648    else
     3649        // default: copy pszFile
     3650        strcpy(fd.szFullFile, pszFile);
     3651        // fixed V0.9.12 (2001-05-21) [umoeller]
    36103652
    36113653    if (    WinFileDlg(HWND_DESKTOP,    // parent
  • trunk/src/helpers/xml.c

    r65 r71  
    77 *      layers:
    88 *
    9  *      --  The bottom layer is implemented by @expat, which I have
    10  *          ported and hacked to the xwphelpers.
     9 *      --  The bottom layer is implemented by the @expat parser,
     10 *          which I have ported and hacked to the xwphelpers.
    1111 *
    1212 *          See xmlparse.c for an introduction.
     
    1616 *          which is vaguely modelled after the Document Object Model
    1717 *          (DOM) standardized by the W3C. That's this file.
     18 *
     19 *          This top layer allows you to do two things VERY EASILY:
     20 *
     21 *          1)  Parse an XML document (which uses expat internally)
     22 *              and build a DOM tree from that. See xmlCreateDOM.
     23 *
     24 *          2)  Create a DOM tree in memory and write an XML
     25 *              document from that. See xmlCreateDocument.
    1826 *
    1927 *      <B>XML</B>
     
    4351 *      Most notably, there are the following differences:
    4452 *
     53 *      --  External entities don't work yet. As a result, DOCTYPE's
     54 *          only make sense if the entire DTD is in the same document
     55 *          (internal subset).
     56 *
    4557 *      --  Not all node types are implemented. See _DOMNODE for
    4658 *          the supported types.
    4759 *
    48  *      --  Only a small subset of the standardized methods is implemented,
     60 *      --  Only a subset of the standardized methods is implemented,
    4961 *          and they are called differently to adhere to the xwphelpers
    5062 *          conventions.
     
    349361 *      associated with its members.
    350362 *
    351  *      NOTE: If you call this for derived types, call
    352  *      this LAST, after you have cleared additional
    353  *      members. After calling this, pNode is no longer
    354  *      valid.
     363 *      After calling this, pNode is no longer valid.
     364 *
     365 *      If you invoke this on a DOCUMENT node, the
     366 *      entire DOM tree will get deleted recursively.
    355367 *
    356368 *@@added V0.9.9 (2001-02-16) [umoeller]
     
    383395                {
    384396                    // call delete recursively
     397                    PDOMNODE pNext = (PDOMNODE)treeNext((TREE*)pAttrib);
    385398                    xmlDeleteNode((PNODEBASE)pAttrib);
    386399                            // this will remove pAttrib from pNode's attrib
    387                             // tree and rebalance the tree; treeNext will
    388                             // still work #### noooooo
    389                     pAttrib = (PDOMNODE)treeNext((TREE*)pAttrib);
     400                            // tree and rebalance the tree
     401                    pAttrib = pNext;
    390402                }
    391403            break; }
     
    395407            case DOMNODE_PROCESSING_INSTRUCTION:
    396408            case DOMNODE_COMMENT:
     409                pDomNode = (PDOMNODE)pNode;
     410            break;
     411
    397412            case DOMNODE_DOCUMENT:
     413                if (((PDOMDOCUMENTNODE)pNode)->pDocType)
     414                    xmlDeleteNode((PNODEBASE)((PDOMDOCUMENTNODE)pNode)->pDocType);
    398415                pDomNode = (PDOMNODE)pNode;
    399416            break;
     
    441458                                pParticle = (PCMELEMENTPARTICLE)pDelNode->pItemData;
    442459                        xmlDeleteNode((PNODEBASE)pParticle);
    443                         //  treeDelete(pp->         ###
     460                        //  treeDelete(pp->         // @@todo
    444461                        pDelNode = pDelNode->pNext;
    445462                    }
     
    962979 *      _XMLCONTENT content model (which is the @expat structure).
    963980 *      This recurses, if necessary.
     981 *
     982 *      NOTE: As opposed to the other "create" functions,
     983 *      this does not take a parent node as input. If this
     984 *      returns NO_ERROR, it is the caller's responsibility
     985 *      to add the produced node to the document's DOCTYPE node.
    964986 *
    965987 *@@added V0.9.9 (2001-02-16) [umoeller]
     
    21202142/* ******************************************************************
    21212143 *
    2122  *   DOM root APIs
     2144 *   DOM parser APIs
    21232145 *
    21242146 ********************************************************************/
     
    21582180 +                         TRUE); // if last, this will clean up the parser
    21592181 *
    2160  *      3) Process the data in the DOM tree. When done,
    2161  *         call xmlFreeDOM, which will free all memory.
     2182 *      3) Process the data in the DOM tree.
     2183 *
     2184 *         Look at the DOMNODE definition to see how you
     2185 *         can traverse the data. Essentially, everything
     2186 *         is based on linked lists and string maps.
     2187 *
     2188 *         A few helper functions have been added for
     2189 *         quick lookup. See xmlGetRootElement,
     2190 *         xmlGetFirstChild, xmlGetLastChild, xmlGetFirstText,
     2191 *         xmlGetElementsByTagName, xmlGetAttribute.
     2192 *
     2193 *      4) When done, call xmlFreeDOM, which will free all memory.
    21622194 *
    21632195 *@@added V0.9.9 (2001-02-14) [umoeller]
     
    21832215        // create the document node
    21842216        arc = xmlCreateDomNode(NULL, // no parent
    2185                             DOMNODE_DOCUMENT,
    2186                             NULL,
    2187                             0,
    2188                             &pDocument);
     2217                               DOMNODE_DOCUMENT,
     2218                               NULL,
     2219                               0,
     2220                               &pDocument);
    21892221
    21902222        if (arc == NO_ERROR)
     
    22632295/*
    22642296 *@@ xmlParse:
    2265  *      parses another piece of XML data.
     2297 *      parses another chunk of XML data.
    22662298 *
    22672299 *      If (fIsLast == TRUE), the internal @expat parser
     
    23752407            pDom->pParser = NULL;
    23762408        }
     2409
     2410        xmlDeleteNode((PNODEBASE)pDom->pDocumentNode);
    23772411
    23782412        free(pDom);
     
    26452679    return (NULL);
    26462680}
     2681
     2682/* ******************************************************************
     2683 *
     2684 *   DOM build
     2685 *
     2686 ********************************************************************/
     2687
     2688/*
     2689 *@@ xmlCreateDocument:
     2690 *      creates a new XML document.
     2691 *
     2692 *      This is the first step in creating a DOM
     2693 *      tree in memory.
     2694 *
     2695 *      This function creates a DOCUMENT node
     2696 *      (which is returned) and a root ELEMENT node
     2697 *      within the document. For convenience, the
     2698 *      root ELEMENT node is returned as well.
     2699 *
     2700 *      This does not create a DOCTYPE node in
     2701 *      the document.
     2702 *
     2703 *      After this, you can add sub-elements and
     2704 *      attributes to the root element using
     2705 *      xmlCreateElementNode and xmlCreateAttributeNode.
     2706 *
     2707 *      Use xmlDeleteNode on the DOCUMENT node
     2708 *      to delete the entire DOM tree.
     2709 *
     2710 *@@added V0.9.12 (2001-05-21) [umoeller]
     2711 */
     2712
     2713APIRET xmlCreateDocument(const char *pcszRootElementName,   // in: root element name
     2714                         PDOMDOCUMENTNODE *ppDocument,      // out: DOCUMENT node
     2715                         PDOMNODE *ppRootElement)           // out: root ELEMENT node within DOCUMENT
     2716{
     2717    APIRET arc = NO_ERROR;
     2718    PDOMDOCUMENTNODE pDocument = NULL;
     2719    PDOMNODE pRootElement = NULL;
     2720
     2721    if ( (!pcszRootElementName) || (!ppDocument) || (!ppRootElement) )
     2722        arc = ERROR_INVALID_PARAMETER;
     2723    else
     2724        // create the document node
     2725        if (!(arc = xmlCreateDomNode(NULL, // no parent
     2726                                     DOMNODE_DOCUMENT,
     2727                                     NULL,
     2728                                     0,
     2729                                     (PDOMNODE*)&pDocument)))
     2730            if (!(arc = xmlCreateDomNode((PDOMNODE)pDocument,     // parent
     2731                                         DOMNODE_ELEMENT,
     2732                                         pcszRootElementName,
     2733                                         0,
     2734                                         &pRootElement)))
     2735            {
     2736                *ppDocument = pDocument;
     2737                *ppRootElement = pRootElement;
     2738            }
     2739
     2740    return (arc);
     2741}
     2742
     2743/*
     2744 *@@ WriteNodes:
     2745 *      internal helper for writing out the nodes.
     2746 *
     2747 *@@added V0.9.12 (2001-05-21) [umoeller]
     2748 */
     2749
     2750VOID WriteNodes(PXSTRING pxstr,
     2751                PDOMNODE pDomNode)       // in: node whose children are to be written (initially DOCUMENT)
     2752{
     2753    PLISTNODE pListNode;
     2754
     2755    BOOL fMixedContent = (xmlGetFirstText(pDomNode) != NULL);
     2756
     2757    for (pListNode = lstQueryFirstNode(&pDomNode->llChildren);
     2758         (pListNode);
     2759         pListNode = pListNode->pNext)
     2760    {
     2761        PDOMNODE pChildNode = (PDOMNODE)pListNode->pItemData;
     2762
     2763        switch (pChildNode->NodeBase.ulNodeType)
     2764        {
     2765            case DOMNODE_ELEMENT:
     2766            {
     2767                PDOMNODE pAttribNode;
     2768                // write out opening ELEMENT tag
     2769                // add a line break if this does NOT have mixed
     2770                // content
     2771                if (!fMixedContent)
     2772                    xstrcatc(pxstr, '\n');
     2773
     2774                xstrcatc(pxstr, '<');
     2775                xstrcats(pxstr, &pChildNode->NodeBase.strNodeName);
     2776
     2777                // go through attributes
     2778                for (pAttribNode = (PDOMNODE)treeFirst(pChildNode->AttributesMap);
     2779                     (pAttribNode);
     2780                     pAttribNode = (PDOMNODE)treeNext((TREE*)pAttribNode))
     2781                {
     2782                    xstrcat(pxstr, "\n    ", 0);
     2783                    xstrcats(pxstr, &pAttribNode->NodeBase.strNodeName);
     2784                    xstrcat(pxstr, "=\"", 0);
     2785                    xstrcats(pxstr, pAttribNode->pstrNodeValue);
     2786                    xstrcatc(pxstr, '\"');
     2787                }
     2788
     2789                // now check... do we have child nodes?
     2790                if (lstCountItems(&pChildNode->llChildren))
     2791                {
     2792                    // yes:
     2793                    xstrcatc(pxstr, '>');
     2794
     2795                    // recurse into this child element
     2796                    WriteNodes(pxstr, pChildNode);
     2797
     2798                    if (!fMixedContent)
     2799                        xstrcatc(pxstr, '\n');
     2800
     2801                    // write closing tag
     2802                    xstrcat(pxstr, "</", 0);
     2803                    xstrcats(pxstr, &pChildNode->NodeBase.strNodeName);
     2804                    xstrcatc(pxstr, '>');
     2805                }
     2806                else
     2807                {
     2808                    // no child nodes:
     2809                    // mark this tag as "empty"
     2810                    xstrcat(pxstr, "/>", 0);
     2811                }
     2812            }
     2813            break;
     2814
     2815            case DOMNODE_TEXT:
     2816            case DOMNODE_COMMENT:
     2817                // that's simple
     2818                xstrcats(pxstr, pChildNode->pstrNodeValue);
     2819            break;
     2820
     2821            case DOMNODE_DOCUMENT_TYPE:
     2822                // @@todo
     2823            break;
     2824
     2825        }
     2826    }
     2827}
     2828
     2829/*
     2830 *@@ xmlWriteDocument:
     2831 *      creates a complete XML document in the specified
     2832 *      string buffer from the specified DOMDOCUMENTNODE.
     2833 *
     2834 *      This creates a full XML document, starting with
     2835 *      the <?xml...?> header, the DTD (if present),
     2836 *      and the elements and attributes.
     2837 *
     2838 *      The input XSTRING must be initialized. Its
     2839 *      contents will be overwritten, if any exists.
     2840 *
     2841 *      Sooo... to write a full XML document to disk,
     2842 *      do the following:
     2843 *
     2844 *      1)  Call xmlCreateDocument to have an empty
     2845 *          document with a root element created.
     2846 *
     2847 *      2)  Add elements, subelements, and attributes
     2848 *          using xmlCreateElementNode and
     2849 *          xmlCreateAttributeNode.
     2850 *
     2851 *      3)  Call xmlWriteDocument to have the XML
     2852 *          document written into an XSTRING.
     2853 *
     2854 *      4)  Write the XSTRING to disk, e.g. using
     2855 *          fwrite().
     2856 *
     2857 *          Note: You can also use doshWriteTextFile,
     2858 *          but you should then first convert the
     2859 *          line format using xstrConvertLineFormat.
     2860 *
     2861 *      Example:
     2862 *
     2863 +          APIRET arc = NO_ERROR;
     2864 +          PDOMDOCUMENTNODE pDocument = NULL;
     2865 +          PDOMNODE pRootElement = NULL;
     2866 +
     2867 +          // create a DOM
     2868 +          if (!(arc = xmlCreateDocument("MYROOTNODE",
     2869 +                                        &pDocument,
     2870 +                                        &pRootElement)))
     2871 +          {
     2872 +              // add subelements to the root element
     2873 +              PDOMNODE pSubelement;
     2874 +              if (!(arc = xmlCreateElementNode(pRootElement,
     2875 +                                               "MYSUBELEMENT",
     2876 +                                               &pSubelement)))
     2877 +              {
     2878 +                  // add an attribute
     2879 +                  PDOMNODE pAttribute;
     2880 +                  if (!(arc = xmlCreateAttributeNode(pSubElement,
     2881 +                                                     "MYATTRIB",
     2882 +                                                     "VALUE",
     2883 +                                                     &pAttribute)))
     2884 +                  {
     2885 +                      // alright, turn this into a string
     2886 +                      XSTRING str;
     2887 +                      xstrInit(&str, 1000);
     2888 +                      if (!(arc = xmlWriteDocument(pDocument,
     2889 +                                                   "ISO-8859-1",
     2890 +                                                   NULL,      // or DOCTYPE
     2891 +                                                   &str)))
     2892 +                      {
     2893 +                          FILE *file = fopen("myfile.xml", "w");
     2894 +                          fwrite(str.psz,
     2895 +                                 1,
     2896 +                                 str.ulLength,
     2897 +                                 file);
     2898 +                          fclose(file);
     2899 +                      }
     2900 +                  }
     2901 +              }
     2902 +
     2903 +              // this kills the entire tree
     2904 +              xmlDeleteNode((PNODEBASE)pDocument);
     2905 +
     2906 +          }
     2907 +
     2908 *
     2909 *      A note about whitespace handling. Presently, this
     2910 *      adds line breaks after the opening tag of an
     2911 *      element if the element has element content only.
     2912 *      However, if the element has mixed content, this
     2913 *      line break is NOT automatically added because
     2914 *      white space may then be significant.
     2915 *
     2916 *@@added V0.9.12 (2001-05-21) [umoeller]
     2917 */
     2918
     2919APIRET xmlWriteDocument(PDOMDOCUMENTNODE pDocument,     // in: document node
     2920                        const char *pcszEncoding,       // in: encoding string (e.g. "ISO-8859-1")
     2921                        const char *pcszDoctype,        // in: entire DOCTYPE statement or NULL
     2922                        PXSTRING pxstr)                 // out: document
     2923{
     2924    APIRET arc = NO_ERROR;
     2925
     2926    if ( (!pDocument) || (!pcszEncoding) || (!pxstr) )
     2927        arc = ERROR_INVALID_PARAMETER;
     2928    else
     2929    {
     2930        // <?xml version="1.0" encoding="ISO-8859-1"?>
     2931        xstrcpy(pxstr, "<?xml version=\"1.0\" encoding=\"", 0);
     2932        xstrcat(pxstr, pcszEncoding, 0);
     2933        xstrcat(pxstr, "\"?>\n", 0);
     2934
     2935        // write entire DOCTYPE statement
     2936        if (pcszDoctype)
     2937        {
     2938            xstrcatc(pxstr, '\n');
     2939            xstrcat(pxstr, pcszDoctype, 0);
     2940            xstrcatc(pxstr, '\n');
     2941        }
     2942
     2943        // write out children
     2944        WriteNodes(pxstr, (PDOMNODE)pDocument);
     2945
     2946        xstrcatc(pxstr, '\n');
     2947    }
     2948
     2949    return (arc);
     2950}
     2951
     2952
  • trunk/src/helpers/xmlparse.c

    r39 r71  
    873873        XML_Memory_Handling_Suite *mtemp;
    874874
    875         parser = malloc(sizeof(Parser));
     875        parser = (malloc)(sizeof(Parser));
    876876        mtemp = &(((Parser*)parser)->m_mem);
     877
    877878        mtemp->malloc_fcn = malloc;
    878879        mtemp->realloc_fcn = realloc;
  • trunk/src/helpers/xstring.c

    r65 r71  
    285285 *@@added V0.9.7 (2001-01-07) [umoeller]
    286286 *@@changed V0.9.9 (2001-03-09) [umoeller]: now using ulDelta
     287 *@@changed V0.9.12 (2001-05-21) [umoeller]: now reporting error on realloc fail
    287288 */
    288289
     
    318319        // this gives the C runtime a chance to expand the
    319320        // existing block
    320         pxstr->psz = (PSZ)realloc(pxstr->psz, cbAllocate);
     321        if (pxstr->psz = (PSZ)realloc(pxstr->psz, cbAllocate))
    321322                    // if pxstr->psz is NULL, realloc behaves like malloc
    322         pxstr->cbAllocated = cbAllocate;
     323            pxstr->cbAllocated = cbAllocate;
    323324                // ulLength is unchanged
     325        else
     326            // error: V0.9.12 (2001-05-21) [umoeller]
     327            pxstr->cbAllocated = 0;
    324328    }
    325329    // else: we have enough memory
     
    448452 *@@changed V0.9.9 (2001-02-16) [umoeller]: now supporting non-zero-terminated pcszSource
    449453 *@@changed V0.9.9 (2001-03-09) [umoeller]: now using xstrReserve
     454 *@@changed V0.9.12 (2001-05-21) [umoeller]: added xstrReserve error checking
    450455 */
    451456
     
    470475    {
    471476        // we do have a source string:
    472         xstrReserve(pxstr,
    473                     // required memory:
    474                     ulSourceLength + 1);
    475 
    476         memcpy(pxstr->psz,
    477                pcszSource,
    478                ulSourceLength);
    479         *(pxstr->psz + ulSourceLength) = '\0';
    480                 // V0.9.9 (2001-02-16) [umoeller]
    481                 // we must do this or otherwise we require pcszSource
    482                 // to be zero-terminated... not a good idea
     477        if (xstrReserve(pxstr,
     478                        // required memory:
     479                        ulSourceLength + 1))
     480        {
     481            memcpy(pxstr->psz,
     482                   pcszSource,
     483                   ulSourceLength);
     484            *(pxstr->psz + ulSourceLength) = '\0';
     485                    // V0.9.9 (2001-02-16) [umoeller]
     486                    // we must do this or otherwise we require pcszSource
     487                    // to be zero-terminated... not a good idea
     488        }
     489        else
     490            pxstr->ulLength = 0;        // error V0.9.12 (2001-05-21) [umoeller]
    483491    }
    484492    else
Note: See TracChangeset for help on using the changeset viewer.