Changeset 33
- Timestamp:
- Feb 7, 2001, 7:30:59 PM (25 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/helpers/prfh.h
r22 r33 39 39 /* common error codes used by the prfh* functions */ 40 40 41 #define PRFERR_DATASIZE 10001 // couldn't query data size for key42 #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 list45 #define PRFERR_KEYSLIST 10006 // couldn't query keys list46 #define PRFERR_ABORTED 10007 // aborted by user47 #define PRFERR_QUERY 10007 // PrfQueryProfile failed41 #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 48 48 #define PRFERR_INVALID_FILE_NAME 10008 // profile names don't contain .INI 49 #define PRFERR_INVALID_KEY 10009 50 #define PRFERR_KEY_EXISTS 10010 49 51 50 52 PSZ prfhQueryKeysForApp(HINI hIni, … … 116 118 PSZ pszErrorKey); 117 119 120 ULONG prfhRenameKey(HINI hini, 121 const char *pcszOldApp, 122 const char *pcszOldKey, 123 const char *pcszNewApp, 124 const char *pcszNewKey); 125 118 126 BOOL prfhSetUserProfile(HAB hab, 119 127 const char *pcszUserProfile); -
trunk/include/helpers/threads.h
r18 r33 70 70 typedef THREADFUNC *PTHREADFUNC; 71 71 72 BOOLthrCreate(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); 77 77 78 78 ULONG thrRunSync(HAB hab, -
trunk/include/helpers/tree.h
r14 r33 107 107 // -- -1: t1 < t2 108 108 // -- +1: t1 > t2 109 typedef int (FNTREE_COMPARE_IDS) (unsigned long id1, unsigned long id2);110 109 typedef int (FNTREE_COMPARE_NODES) (TREE *t1, TREE *t2); 111 110 typedef int (FNTREE_COMPARE_DATA) (TREE *t1, void *pData); … … 122 121 int treeInsertID(TREE **root, 123 122 TREE *tree, 124 FNTREE_COMPARE_IDS *comp,125 123 BOOL fAllowDuplicates); 126 124 … … 132 130 int treeDelete(TREE **root, 133 131 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); */141 132 142 133 void* treeFindEQNode(TREE **root, … … 157 148 158 149 void* treeFindEQID(TREE **root, 159 unsigned long idFind, 160 FNTREE_COMPARE_IDS *comp); 150 unsigned long idFind); 161 151 void* treeFindLTID(TREE **root, 162 unsigned long idFind, 163 FNTREE_COMPARE_IDS *comp); 152 unsigned long idFind); 164 153 void* treeFindLEID(TREE **root, 165 unsigned long idFind, 166 FNTREE_COMPARE_IDS *comp); 154 unsigned long idFind); 167 155 void* treeFindGTID(TREE **root, 168 unsigned long idFind, 169 FNTREE_COMPARE_IDS *comp); 156 unsigned long idFind); 170 157 void* treeFindGEID(TREE **root, 171 unsigned long idFind, 172 FNTREE_COMPARE_IDS *comp); 158 unsigned long idFind); 173 159 174 160 void* treeFindEQData(TREE **root, -
trunk/src/helpers/dosh.c
r23 r33 1828 1828 * 1829 1829 *@@added V0.9.7 (2000-12-02) [umoeller] 1830 *@@changed V0.9.9 (2000-02-06) [umoeller]: removed disable; this broke the WarpCenter 1830 1831 */ 1831 1832 … … 1838 1839 else 1839 1840 { 1840 if (pPerfSys->fInitialized)1841 /* if (pPerfSys->fInitialized) 1841 1842 pPerfSys->pDosPerfSysCall(CMD_KI_DISABLE, 1842 0, 0, 0); 1843 0, 0, 0); */ 1843 1844 1844 1845 if (pPerfSys->paCPUUtils) -
trunk/src/helpers/prfh.c
r22 r33 304 304 305 305 ULONG prfhCopyKey(HINI hiniSource, // in: source profile (can be HINI_USER or HINI_SYSTEM) 306 const char *pcszSourceApp, // in: source application307 const char *pcszKey, // in: source/target key308 HINI hiniTarget, // in: target profile (can be HINI_USER or HINI_SYSTEM)309 const char *pcszTargetApp) // in: target app306 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 310 310 { 311 311 ULONG ulSizeOfData = 0, … … 391 391 * 392 392 * Returns: 393 * 393 394 * -- 0: no error 395 * 394 396 * -- PRFERR_KEYSLIST: couldn't query keys for pszSourceApp 397 * 395 398 * -- PRFERR_DATASIZE: couldn't query data size for key 399 * 396 400 * -- PRFERR_MEMORY: couldn't allocate memory 401 * 397 402 * -- PRFERR_READ: couldn't read data from source (PrfQueryProfileData error) 403 * 398 404 * -- PRFERR_WRITE: couldn't write data to target (PrfWriteProfileData error) 399 405 * … … 445 451 446 452 /* 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 473 ULONG 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 /* 447 532 *@@ prfhSetUserProfile: 448 533 * calls PrfReset to change the current user -
trunk/src/helpers/threads.c
r22 r33 182 182 * to the caller. 183 183 * 184 * This now (V0.9.9) returns the TID of the new thread or 185 * null on errors. 186 * 184 187 *@@changed V0.9.0 [umoeller]: default stack size raised for Watcom (thanks, Rdiger Ihle) 185 188 *@@changed V0.9.0 [umoeller]: _beginthread is now only called after all variables have been set (thanks, Rdiger Ihle) … … 190 193 *@@changed V0.9.5 (2000-08-26) [umoeller]: now using PTHREADINFO 191 194 *@@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 198 ULONG 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] 202 206 203 207 // (2000-12-18) [lafaix] TRANSIENT … … 206 210 if (pti == NULL) 207 211 pti = (PTHREADINFO) malloc(sizeof(THREADINFO)); 208 else209 return (rc);210 212 } 211 213 … … 223 225 pti->ulData = ulData; 224 226 225 rc = TRUE;226 227 227 if (flFlags & THRF_WAIT) 228 228 // "Wait" flag set: create an event semaphore which … … 233 233 FALSE) // not posted (reset) 234 234 != 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) 240 244 { 241 245 pti->tid = _beginthread( // moved, V0.9.0 (hint: Rdiger Ihle) … … 244 248 3*96000, // plenty of stack 245 249 pti); // parameter passed to thread 246 rc = (pti->tid != 0);247 248 if ( rc)250 ulrc = pti->tid; 251 252 if (ulrc) 249 253 if (flFlags & THRF_WAIT) 250 254 { … … 257 261 } 258 262 259 return ( rc);263 return (ulrc); 260 264 } 261 265 -
trunk/src/helpers/tree.c
r21 r33 17 17 * tree sorting/comparison. This implementation is released 18 18 * 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. 19 62 * 20 63 * <B>Using binary trees</B> … … 31 74 * for a sample. 32 75 * 33 * Each TREE node does not only contain data, but also an34 * "id" field. The order of nodes in the tree is determined35 * by calling a node comparison function provided by the caller36 * (which you must write). This takes two "id" values and must37 * return:38 *39 + 0: id1 == id240 + -1: id1 < id241 + +1: id1 > id242 *43 76 * Initialize the root of the tree with treeInit(). Then 44 77 * add nodes to the tree with treeInsertID() and remove nodes … … 48 81 * root with TREE_NULL. 49 82 * 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 * 50 108 * Compared to linked lists (as implemented by linklist.c), 51 109 * trees allow for much faster searching. 52 110 * 53 * Assuming a linked list contains N items, then searching the54 * li st for an item will take an average of N/2 comparisons111 * Assuming a linked list contains N items, then searching a 112 * linked list for an item will take an average of N/2 comparisons 55 113 * and even N comparisons if the item cannot be found (unless 56 114 * you keep the list sorted, but linklist.c doesn't do this). … … 72 130 * nodes because the tree is always sorted. 73 131 * 74 * -- You must always supply a comparison function to allow the75 * 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. 76 134 * 77 135 * -- As opposed to a LISTNODE, the TREE structure (which … … 134 192 135 193 /* 194 * fnCompareIDs: 195 * 196 *added V0.9.9 (2000-02-06) [umoeller] 197 */ 198 199 int 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 /* 136 209 *@@ treeInsertID: 137 210 * inserts a node into an existing tree. … … 169 242 + treeInsertID(&TreeRoot, 170 243 + (TREE*)pTreeItem, 171 + fnCompare, // your comparison function172 244 + FALSE); 173 245 * … … 179 251 * returned if a tree item with the specified ID already 180 252 * exists. 253 * 254 *@@changed V0.9.9 (2000-02-06) [umoeller]: removed comparison func 181 255 */ 182 256 183 257 int treeInsertID(TREE **root, // in: root of tree 184 258 TREE *tree, // in: new tree node 185 FNTREE_COMPARE_IDS *comp, // in: comparison function186 259 BOOL fAllowDuplicates) // in: whether duplicates with the same ID are allowed 187 260 { … … 198 271 { 199 272 parent = current; 200 last_comp = comp(tree->id, current->id);273 last_comp = fnCompareIDs(tree->id, current->id); 201 274 switch (last_comp) 202 275 { … … 211 284 } 212 285 213 // set up new node214 ((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; 218 291 219 292 // insert node in tree … … 268 341 } 269 342 270 // set up new node271 ((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; 275 348 276 349 // insert node in tree … … 464 537 return TREE_INVALID_NODE; 465 538 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) 468 541 ) 469 542 // descendent has a TREE_NULL node as a child … … 472 545 { 473 546 // find tree successor with a TREE_NULL node as a child 474 descendent = ((TREE *)tree)->right;547 descendent = ((TREE*)tree)->right; 475 548 while (descendent->left != TREE_NULL) 476 549 descendent = descendent->left; … … 499 572 500 573 if (descendent != (TREE *) tree) 501 {574 { 502 575 // Conceptually what we are doing here is moving the data from 503 576 // descendent to tree. In fact we do this by linking descendent 504 577 // 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; 509 582 510 583 if (descendent->parent) 511 {584 { 512 585 if (tree == descendent->parent->left) 513 586 descendent->parent->left = descendent; 514 587 else 515 588 descendent->parent->right = descendent; 516 }589 } 517 590 else 518 591 *root = descendent; … … 618 691 *@@ treeFindEQID: 619 692 * finds a node with ID exactly matching that provided. 620 * To find a tree node, your comparison function must621 * compare the tree node IDs.622 693 */ 623 694 624 695 void* treeFindEQID(TREE **root, 625 unsigned long id, 626 FNTREE_COMPARE_IDS *comp) 696 unsigned long id) 627 697 { 628 698 TREE … … 632 702 found = NULL; 633 703 while (current != TREE_NULL) 634 switch ( comp(current->id, id))704 switch (fnCompareIDs(current->id, id)) 635 705 { 636 706 case -1: current = current->right; break; … … 651 721 652 722 void* treeFindGEID(TREE **root, 653 unsigned long idFind, 654 FNTREE_COMPARE_IDS *comp) 723 unsigned long idFind) 655 724 { 656 725 TREE … … 660 729 found = NULL; 661 730 while (current != TREE_NULL) 662 switch ( comp(current->id, idFind))731 switch (fnCompareIDs(current->id, idFind)) 663 732 { 664 733 case -1: current = current->right; break; … … 873 942 { 874 943 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); 877 946 } 878 947 else if (method == 2) 879 948 { 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); 882 951 process(tree, pUser); 883 952 } 884 953 else 885 954 { 886 treeTraverse (((TREE *)tree)->left, process, pUser, method);955 treeTraverse (((TREE*)tree)->left, process, pUser, method); 887 956 process(tree, pUser); 888 treeTraverse (((TREE *)tree)->right, process, pUser, method);957 treeTraverse (((TREE*)tree)->right, process, pUser, method); 889 958 } 890 959 }
Note:
See TracChangeset
for help on using the changeset viewer.