Changeset 33


Ignore:
Timestamp:
Feb 7, 2001, 7:30:59 PM (25 years ago)
Author:
umoeller
Message:

misc. changes

Location:
trunk
Files:
7 edited

Legend:

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

    r22 r33  
    3939    /* common error codes used by the prfh* functions */
    4040
    41     #define PRFERR_DATASIZE 10001   // couldn't query data size for key
    42     #define PRFERR_READ     10003   // couldn't read data from source (PrfQueryProfileData error)
    43     #define PRFERR_WRITE    10004   // couldn't write data to target (PrfWriteProfileData error)
    44     #define PRFERR_APPSLIST 10005   // couldn't query apps list
    45     #define PRFERR_KEYSLIST 10006   // couldn't query keys list
    46     #define PRFERR_ABORTED  10007   // aborted by user
    47     #define PRFERR_QUERY    10007   // PrfQueryProfile failed
     41    #define PRFERR_DATASIZE     10001   // couldn't query data size for key
     42    #define PRFERR_READ         10003   // couldn't read data from source (PrfQueryProfileData error)
     43    #define PRFERR_WRITE        10004   // couldn't write data to target (PrfWriteProfileData error)
     44    #define PRFERR_APPSLIST     10005   // couldn't query apps list
     45    #define PRFERR_KEYSLIST     10006   // couldn't query keys list
     46    #define PRFERR_ABORTED      10007   // aborted by user
     47    #define PRFERR_QUERY        10007   // PrfQueryProfile failed
    4848    #define PRFERR_INVALID_FILE_NAME  10008   // profile names don't contain .INI
     49    #define PRFERR_INVALID_KEY  10009
     50    #define PRFERR_KEY_EXISTS   10010
    4951
    5052    PSZ prfhQueryKeysForApp(HINI hIni,
     
    116118                      PSZ pszErrorKey);
    117119
     120    ULONG prfhRenameKey(HINI hini,
     121                        const char *pcszOldApp,
     122                        const char *pcszOldKey,
     123                        const char *pcszNewApp,
     124                        const char *pcszNewKey);
     125
    118126    BOOL prfhSetUserProfile(HAB hab,
    119127                            const char *pcszUserProfile);
  • trunk/include/helpers/threads.h

    r18 r33  
    7070    typedef THREADFUNC *PTHREADFUNC;
    7171
    72     BOOL thrCreate(PTHREADINFO pti,
    73                    PTHREADFUNC pfn,
    74                    PBOOL pfRunning,
    75                    ULONG flFlags,
    76                    ULONG ulData);
     72    ULONG thrCreate(PTHREADINFO pti,
     73                    PTHREADFUNC pfn,
     74                    PBOOL pfRunning,
     75                    ULONG flFlags,
     76                    ULONG ulData);
    7777
    7878    ULONG thrRunSync(HAB hab,
  • trunk/include/helpers/tree.h

    r14 r33  
    107107    // --  -1: t1 < t2
    108108    // --  +1: t1 > t2
    109     typedef int (FNTREE_COMPARE_IDS) (unsigned long id1, unsigned long id2);
    110109    typedef int (FNTREE_COMPARE_NODES) (TREE *t1, TREE *t2);
    111110    typedef int (FNTREE_COMPARE_DATA) (TREE *t1, void *pData);
     
    122121    int treeInsertID(TREE **root,
    123122                     TREE *tree,
    124                      FNTREE_COMPARE_IDS *comp,
    125123                     BOOL fAllowDuplicates);
    126124
     
    132130    int treeDelete(TREE **root,
    133131                   TREE *tree);
    134 
    135     /* void *treeFindEQID  (TREE **root,
    136                        TREE *tree,
    137                        TREE_COMPARE *comp); */
    138     /* void *treeFindGEID  (TREE **root,
    139                        TREE *tree,
    140                        FNTREE_COMPARE_IDS *comp); */
    141132
    142133    void* treeFindEQNode(TREE **root,
     
    157148
    158149    void* treeFindEQID(TREE **root,
    159                        unsigned long idFind,
    160                        FNTREE_COMPARE_IDS *comp);
     150                       unsigned long idFind);
    161151    void* treeFindLTID(TREE **root,
    162                        unsigned long idFind,
    163                        FNTREE_COMPARE_IDS *comp);
     152                       unsigned long idFind);
    164153    void* treeFindLEID(TREE **root,
    165                        unsigned long idFind,
    166                        FNTREE_COMPARE_IDS *comp);
     154                       unsigned long idFind);
    167155    void* treeFindGTID(TREE **root,
    168                        unsigned long idFind,
    169                        FNTREE_COMPARE_IDS *comp);
     156                       unsigned long idFind);
    170157    void* treeFindGEID(TREE **root,
    171                        unsigned long idFind,
    172                        FNTREE_COMPARE_IDS *comp);
     158                       unsigned long idFind);
    173159
    174160    void* treeFindEQData(TREE **root,
  • trunk/src/helpers/dosh.c

    r23 r33  
    18281828 *
    18291829 *@@added V0.9.7 (2000-12-02) [umoeller]
     1830 *@@changed V0.9.9 (2000-02-06) [umoeller]: removed disable; this broke the WarpCenter
    18301831 */
    18311832
     
    18381839    else
    18391840    {
    1840         if (pPerfSys->fInitialized)
     1841        /* if (pPerfSys->fInitialized)
    18411842            pPerfSys->pDosPerfSysCall(CMD_KI_DISABLE,
    1842                                       0, 0, 0);
     1843                                      0, 0, 0); */
    18431844
    18441845        if (pPerfSys->paCPUUtils)
  • trunk/src/helpers/prfh.c

    r22 r33  
    304304
    305305ULONG prfhCopyKey(HINI hiniSource,       // in: source profile (can be HINI_USER or HINI_SYSTEM)
    306                  const char *pcszSourceApp,      // in: source application
    307                  const char *pcszKey,            // in: source/target key
    308                  HINI hiniTarget,       // in: target profile (can be HINI_USER or HINI_SYSTEM)
    309                  const char *pcszTargetApp)      // in: target app
     306                  const char *pcszSourceApp,      // in: source application
     307                  const char *pcszKey,            // in: source/target key
     308                  HINI hiniTarget,       // in: target profile (can be HINI_USER or HINI_SYSTEM)
     309                  const char *pcszTargetApp)      // in: target app
    310310{
    311311    ULONG   ulSizeOfData = 0,
     
    391391 *
    392392 *      Returns:
     393 *
    393394 *      --  0: no error
     395 *
    394396 *      --  PRFERR_KEYSLIST: couldn't query keys for pszSourceApp
     397 *
    395398 *      --  PRFERR_DATASIZE: couldn't query data size for key
     399 *
    396400 *      --  PRFERR_MEMORY: couldn't allocate memory
     401 *
    397402 *      --  PRFERR_READ: couldn't read data from source (PrfQueryProfileData error)
     403 *
    398404 *      --  PRFERR_WRITE: couldn't write data to target (PrfWriteProfileData error)
    399405 *
     
    445451
    446452/*
     453 *@@ prfhRenameKey:
     454 *      renames a key in an INI file.
     455 *
     456 *      Since there's no such thing as a PrfRename,
     457 *      what we do here is load the old data, write
     458 *      it under a new key, and delete the old data.
     459 *
     460 *      Returns:
     461 *
     462 *      --  0: no error
     463 *
     464 *      --  PRFERR_INVALID_KEY: pcszApp or pcszOldKey do not exist.
     465 *
     466 *      --  PRFERR_KEY_EXISTS: pcszNewApp/pcszNewKey is already occupied.
     467 *
     468 *      --  PRFERR_WRITE: couldn't write data to target (PrfWriteProfileData error)
     469 *
     470 *@@added V0.9.9 (2000-02-06) [umoeller]
     471 */
     472
     473ULONG prfhRenameKey(HINI hini,
     474                    const char *pcszOldApp,
     475                    const char *pcszOldKey, // in: key to rename
     476                    const char *pcszNewApp, // in: new app (if NULL, pcszOldApp is used)
     477                    const char *pcszNewKey) // in: new name for pcszOldKey
     478{
     479    ULONG ulrc = 0;
     480
     481    ULONG   cbData = 0;
     482    PSZ pszData = prfhQueryProfileData(hini,
     483                                       pcszOldApp,
     484                                       pcszOldKey,
     485                                       &cbData);
     486    if (!pszData)
     487        // not found:
     488        ulrc = PRFERR_INVALID_KEY;
     489    else
     490    {
     491        ULONG   cb;
     492
     493        if (!pcszNewApp)
     494            // is NULL:
     495            pcszNewApp = pcszOldApp;
     496
     497        // make sure target doesn't exist
     498        if (    (PrfQueryProfileSize(hini,
     499                                     (PSZ)pcszNewApp,
     500                                     (PSZ)pcszNewKey,
     501                                     &cb))
     502             && (cb)
     503           )
     504            ulrc = PRFERR_KEY_EXISTS;
     505        else
     506        {
     507            if (!PrfWriteProfileData(hini,
     508                                     (PSZ)pcszNewApp,
     509                                     (PSZ)pcszNewKey,
     510                                     pszData,
     511                                     cbData))
     512                ulrc = PRFERR_WRITE;
     513            else
     514            {
     515                // success writing:
     516                // delete old
     517                PrfWriteProfileData(hini,
     518                                    (PSZ)pcszOldApp,
     519                                    (PSZ)pcszOldKey,
     520                                    NULL,
     521                                    0);
     522            }
     523        }
     524
     525        free(pszData);
     526    }
     527
     528    return (ulrc);
     529}
     530
     531/*
    447532 *@@ prfhSetUserProfile:
    448533 *      calls PrfReset to change the current user
  • trunk/src/helpers/threads.c

    r22 r33  
    182182 *         to the caller.
    183183 *
     184 *      This now (V0.9.9) returns the TID of the new thread or
     185 *      null on errors.
     186 *
    184187 *@@changed V0.9.0 [umoeller]: default stack size raised for Watcom (thanks, Rdiger Ihle)
    185188 *@@changed V0.9.0 [umoeller]: _beginthread is now only called after all variables have been set (thanks, Rdiger Ihle)
     
    190193 *@@changed V0.9.5 (2000-08-26) [umoeller]: now using PTHREADINFO
    191194 *@@changed V0.9.7 (2000-12-18) [lafaix]: THRF_TRANSIENT support added
    192  */
    193 
    194 BOOL thrCreate(PTHREADINFO pti,     // out: THREADINFO data
    195                PTHREADFUNC pfn,     // in: _Optlink thread function
    196                PBOOL pfRunning,     // out: variable set to TRUE while thread is running;
    197                                     // ptr can be NULL
    198                ULONG flFlags,       // in: THRF_* flags
    199                ULONG ulData)        // in: user data to be stored in THREADINFO
    200 {
    201     BOOL            rc = FALSE;
     195 *@@changed V0.9.9 (2000-02-06) [umoeller]: now returning TID
     196 */
     197
     198ULONG thrCreate(PTHREADINFO pti,     // out: THREADINFO data
     199                PTHREADFUNC pfn,     // in: _Optlink thread function
     200                PBOOL pfRunning,     // out: variable set to TRUE while thread is running;
     201                                     // ptr can be NULL
     202                ULONG flFlags,       // in: THRF_* flags
     203                ULONG ulData)        // in: user data to be stored in THREADINFO
     204{
     205    ULONG ulrc = 0;     // V0.9.9 (2000-02-06) [umoeller]
    202206
    203207    // (2000-12-18) [lafaix] TRANSIENT
     
    206210        if (pti == NULL)
    207211            pti = (PTHREADINFO) malloc(sizeof(THREADINFO));
    208         else
    209             return (rc);
    210212    }
    211213
     
    223225        pti->ulData = ulData;
    224226
    225         rc = TRUE;
    226 
    227227        if (flFlags & THRF_WAIT)
    228228            // "Wait" flag set: create an event semaphore which
     
    233233                                  FALSE)    // not posted (reset)
    234234                    != NO_ERROR)
    235                 rc = FALSE;
    236 
    237         pti->fExit = FALSE;
    238 
    239         if (rc)
     235            {
     236                if (flFlags & THRF_TRANSIENT)
     237                    free(pti);
     238
     239                // stop right here
     240                pti = NULL;
     241            }
     242
     243        if (pti)
    240244        {
    241245            pti->tid = _beginthread(        // moved, V0.9.0 (hint: Rdiger Ihle)
     
    244248                                    3*96000, // plenty of stack
    245249                                    pti);   // parameter passed to thread
    246             rc = (pti->tid != 0);
    247 
    248             if (rc)
     250            ulrc = pti->tid;
     251
     252            if (ulrc)
    249253                if (flFlags & THRF_WAIT)
    250254                {
     
    257261    }
    258262
    259     return (rc);
     263    return (ulrc);
    260264}
    261265
  • trunk/src/helpers/tree.c

    r21 r33  
    1717 *      tree sorting/comparison. This implementation is released
    1818 *      under the GPL.
     19 *
     20 *      <B>Introduction</B>
     21 *
     22 *      Binary trees are different from linked lists in that items
     23 *      are not simply linked sequentially, but instead put into
     24 *      a tree-like structure.
     25 *
     26 *      For this, the functions here use the TREE structure. You can
     27 *      easily see that this has the "left" and "right" members,
     28 *      which make up the tree.
     29 *
     30 *      In addition, each tree has a "tree root" item, from which all
     31 *      other tree nodes can be reached by following the "left" and
     32 *      "right" pointers.
     33 *
     34 *      Per definition, in our trees, if you follow the "left" pointer,
     35 *      you will reach an item which is "greater than" the current node.
     36 *      Reversely, following the "right" pointer will lead you to a
     37 *      node which is "less than" the current node.
     38 *
     39 *      The implementation here has the following characteristics:
     40 *
     41 *      -- We have "binary" trees. That is, there are only "left" and
     42 *         "right" pointers.
     43 *
     44 *      -- The tree is always "balanced". The tree gets completely
     45 *         reordered when items are added/removed to ensure that
     46 *         all paths through the tree are approximately the same
     47 *         length. This avoids the "worst case" scenario that some
     48 *         paths grow terribly long while others remain short, which
     49 *         can make searching very inefficient.
     50 *
     51 *      -- The tree nodes are marked as either "red" or "black", which
     52 *         is an algorithm to allow the implementation of 2-3-4 trees
     53 *         using a binary tree only. I don't fully understand how this
     54 *         works, but essentially, "red" nodes represent a 3 or 4 node,
     55 *         while "black" nodes are plain binary nodes.
     56 *
     57 *      As much as I understand about all this, red-black balanced
     58 *      binary trees are the most efficient tree algorithm known to
     59 *      mankind. As long as you are sure that trees are more efficient
     60 *      in your situation than a linked list in the first place (see
     61 *      below for comparisons), use the functions in here.
    1962 *
    2063 *      <B>Using binary trees</B>
     
    3174 *      for a sample.
    3275 *
    33  *      Each TREE node does not only contain data, but also an
    34  *      "id" field. The order of nodes in the tree is determined
    35  *      by calling a node comparison function provided by the caller
    36  *      (which you must write). This takes two "id" values and must
    37  *      return:
    38  *
    39  +           0: id1 == id2
    40  +          -1: id1 < id2
    41  +          +1: id1 > id2
    42  *
    4376 *      Initialize the root of the tree with treeInit(). Then
    4477 *      add nodes to the tree with treeInsertID() and remove nodes
     
    4881 *      root with TREE_NULL.
    4982 *
     83 *      Most functions in here come in two flavors.
     84 *
     85 *      -- You can provide a comparison function and use the "Node"
     86 *         flavors of these functions. This is useful, for example,
     87 *         if you are storing strings. You can then write a short
     88 *         comparison function which does a strcmp() on the data
     89 *         of tree nodes.
     90 *
     91 *         The order of nodes in the tree is determined by calling a
     92 *         node comparison function provided by the caller
     93 *         (which you must write). This takes two TREE pointers and
     94 *         must return:
     95 *
     96 +           0: tree1 == tree2
     97 +          -1: tree1 < tree2
     98 +          +1: tree1 > tree2
     99 *
     100 *      -- The "ID" functions (e.g. treeInsertID) do not require
     101 *         a comparison function, but will use the "id" member of
     102 *         the TREE structure instead. If this flavor is used, an
     103 *         internal comparison function is used for comparing the
     104 *         "id" fields, which are plain ULONGs.
     105 *
     106 *      <B>Trees vs. linked lists</B>
     107 *
    50108 *      Compared to linked lists (as implemented by linklist.c),
    51109 *      trees allow for much faster searching.
    52110 *
    53  *      Assuming a linked list contains N items, then searching the
    54  *      list for an item will take an average of N/2 comparisons
     111 *      Assuming a linked list contains N items, then searching a
     112 *      linked list for an item will take an average of N/2 comparisons
    55113 *      and even N comparisons if the item cannot be found (unless
    56114 *      you keep the list sorted, but linklist.c doesn't do this).
     
    72130 *         nodes because the tree is always sorted.
    73131 *
    74  *      -- You must always supply a comparison function to allow the
    75  *         tree functions to sort the tree.
     132 *      -- If you are not using the "ID" flavors, you must supply a
     133 *         comparison function to allow the tree functions to sort the tree.
    76134 *
    77135 *      -- As opposed to a LISTNODE, the TREE structure (which
     
    134192
    135193/*
     194 * fnCompareIDs:
     195 *
     196 *added V0.9.9 (2000-02-06) [umoeller]
     197 */
     198
     199int fnCompareIDs(unsigned long id1, unsigned long id2)
     200{
     201    if (id1 < id2)
     202        return -1;
     203    if (id1 > id2)
     204        return +1;
     205    return (0);
     206}
     207
     208/*
    136209 *@@ treeInsertID:
    137210 *      inserts a node into an existing tree.
     
    169242 +          treeInsertID(&TreeRoot,
    170243 +                     (TREE*)pTreeItem,
    171  +                     fnCompare,       // your comparison function
    172244 +                     FALSE);
    173245 *
     
    179251 *          returned if a tree item with the specified ID already
    180252 *          exists.
     253 *
     254 *@@changed V0.9.9 (2000-02-06) [umoeller]: removed comparison func
    181255 */
    182256
    183257int treeInsertID(TREE **root,             // in: root of tree
    184258                 TREE *tree,              // in: new tree node
    185                  FNTREE_COMPARE_IDS *comp,      // in: comparison function
    186259                 BOOL fAllowDuplicates)   // in: whether duplicates with the same ID are allowed
    187260{
     
    198271    {
    199272        parent  = current;
    200         last_comp = comp(tree->id, current->id);
     273        last_comp = fnCompareIDs(tree->id, current->id);
    201274        switch (last_comp)
    202275        {
     
    211284    }
    212285
    213     // setup new node
    214     ((TREE *) tree)->parent = parent;
    215     ((TREE *) tree)->left   = TREE_NULL;
    216     ((TREE *) tree)->right  = TREE_NULL;
    217     ((TREE *) tree)->colour = RED;
     286    // set up new node
     287    ((TREE*)tree)->parent = parent;
     288    ((TREE*)tree)->left   = TREE_NULL;
     289    ((TREE*)tree)->right  = TREE_NULL;
     290    ((TREE*)tree)->colour = RED;
    218291
    219292    // insert node in tree
     
    268341    }
    269342
    270     // setup new node
    271     ((TREE *) tree)->parent = parent;
    272     ((TREE *) tree)->left   = TREE_NULL;
    273     ((TREE *) tree)->right  = TREE_NULL;
    274     ((TREE *) tree)->colour = RED;
     343    // set up new node
     344    ((TREE*)tree)->parent = parent;
     345    ((TREE*)tree)->left   = TREE_NULL;
     346    ((TREE*)tree)->right  = TREE_NULL;
     347    ((TREE*)tree)->colour = RED;
    275348
    276349    // insert node in tree
     
    464537        return TREE_INVALID_NODE;
    465538
    466     if (    (((TREE *) tree)->left  == TREE_NULL)
    467          || (((TREE *) tree)->right == TREE_NULL)
     539    if (    (((TREE*)tree)->left  == TREE_NULL)
     540         || (((TREE*)tree)->right == TREE_NULL)
    468541       )
    469542        // descendent has a TREE_NULL node as a child
     
    472545  {
    473546        // find tree successor with a TREE_NULL node as a child
    474         descendent = ((TREE *) tree)->right;
     547        descendent = ((TREE*)tree)->right;
    475548        while (descendent->left != TREE_NULL)
    476549            descendent = descendent->left;
     
    499572
    500573    if (descendent != (TREE *) tree)
    501   {
     574    {
    502575        // Conceptually what we are doing here is moving the data from
    503576        // descendent to tree.  In fact we do this by linking descendent
    504577        // into the structure in the place of tree.
    505         descendent->left   = ((TREE *) tree)->left;
    506         descendent->right  = ((TREE *) tree)->right;
    507         descendent->parent = ((TREE *) tree)->parent;
    508         descendent->colour = ((TREE *) tree)->colour;
     578        descendent->left   = ((TREE*)tree)->left;
     579        descendent->right  = ((TREE*)tree)->right;
     580        descendent->parent = ((TREE*)tree)->parent;
     581        descendent->colour = ((TREE*)tree)->colour;
    509582
    510583        if (descendent->parent)
    511       {
     584        {
    512585            if (tree == descendent->parent->left)
    513586                descendent->parent->left  = descendent;
    514587            else
    515588                descendent->parent->right = descendent;
    516       }
     589        }
    517590        else
    518591            *root = descendent;
     
    618691 *@@ treeFindEQID:
    619692 *      finds a node with ID exactly matching that provided.
    620  *      To find a tree node, your comparison function must
    621  *      compare the tree node IDs.
    622693 */
    623694
    624695void* treeFindEQID(TREE **root,
    625                    unsigned long id,
    626                    FNTREE_COMPARE_IDS *comp)
     696                   unsigned long id)
    627697{
    628698    TREE
     
    632702    found = NULL;
    633703    while (current != TREE_NULL)
    634         switch (comp(current->id, id))
     704        switch (fnCompareIDs(current->id, id))
    635705        {
    636706            case -1: current = current->right; break;
     
    651721
    652722void* treeFindGEID(TREE **root,
    653                    unsigned long idFind,
    654                    FNTREE_COMPARE_IDS *comp)
     723                   unsigned long idFind)
    655724{
    656725    TREE
     
    660729    found = NULL;
    661730    while (current != TREE_NULL)
    662         switch (comp(current->id, idFind))
     731        switch (fnCompareIDs(current->id, idFind))
    663732        {
    664733            case -1: current = current->right; break;
     
    873942    {
    874943        process(tree, pUser);
    875         treeTraverse (((TREE *) tree)->left,  process, pUser, method);
    876         treeTraverse (((TREE *) tree)->right, process, pUser, method);
     944        treeTraverse (((TREE*)tree)->left,  process, pUser, method);
     945        treeTraverse (((TREE*)tree)->right, process, pUser, method);
    877946    }
    878947    else if (method == 2)
    879948    {
    880         treeTraverse (((TREE *) tree)->left,  process, pUser, method);
    881         treeTraverse (((TREE *) tree)->right, process, pUser, method);
     949        treeTraverse (((TREE*)tree)->left,  process, pUser, method);
     950        treeTraverse (((TREE*)tree)->right, process, pUser, method);
    882951        process(tree, pUser);
    883952    }
    884953    else
    885954    {
    886         treeTraverse (((TREE *) tree)->left,  process, pUser, method);
     955        treeTraverse (((TREE*)tree)->left,  process, pUser, method);
    887956        process(tree, pUser);
    888         treeTraverse (((TREE *) tree)->right, process, pUser, method);
     957        treeTraverse (((TREE*)tree)->right, process, pUser, method);
    889958    }
    890959}
Note: See TracChangeset for help on using the changeset viewer.