Changeset 3132 for trunk/tools
- Timestamp:
- Mar 17, 2000, 12:51:26 AM (26 years ago)
- Location:
- trunk/tools/fastdep
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/fastdep/avl.h
r3129 r3132 1 /* $Id: avl.h,v 1. 1 2000-03-16 21:10:10bird Exp $1 /* $Id: avl.h,v 1.2 2000-03-16 23:51:25 bird Exp $ 2 2 * 3 3 * AVL-Tree (lookalike) declaration. … … 8 8 * one type of trees within one program (module). 9 9 * 10 * TREETYPE: Case Insensitive Strings (Key is pointer).10 * TREETYPE: Case Sensitive Strings (Key is pointer). 11 11 * 12 12 * … … 32 32 * AVL Compare macros 33 33 */ 34 #define AVL_L(key1, key2) (str icmp(key1, key2) < 0)35 #define AVL_LE(key1, key2) (str icmp(key1, key2) <= 0)36 #define AVL_G(key1, key2) (str icmp(key1, key2) > 0)37 #define AVL_GE(key1, key2) (str icmp(key1, key2) >= 0)38 #define AVL_E(key1, key2) (str icmp(key1, key2) == 0)39 #define AVL_NE(key1, key2) (str icmp(key1, key2) != 0)34 #define AVL_L(key1, key2) (strcmp(key1, key2) < 0) 35 #define AVL_LE(key1, key2) (strcmp(key1, key2) <= 0) 36 #define AVL_G(key1, key2) (strcmp(key1, key2) > 0) 37 #define AVL_GE(key1, key2) (strcmp(key1, key2) >= 0) 38 #define AVL_E(key1, key2) (strcmp(key1, key2) == 0) 39 #define AVL_NE(key1, key2) (strcmp(key1, key2) != 0) 40 40 41 41 -
trunk/tools/fastdep/fastdep.c
r3129 r3132 1 /* $Id: fastdep.c,v 1. 9 2000-03-16 21:10:11bird Exp $1 /* $Id: fastdep.c,v 1.10 2000-03-16 23:51:26 bird Exp $ 2 2 * 3 3 * Fast dependents. (Fast = Quick and Dirty!) … … 152 152 153 153 /* file operations */ 154 char *filePath(const char *pszFilename, char *pszBuffer); 155 char *filePathSlash(const char *pszFilename, char *pszBuffer); 156 char *fileName(const char *pszFilename, char *pszBuffer); 157 char *fileNameNoExt(const char *pszFilename, char *pszBuffer); 158 char *fileExt(const char *pszFilename, char *pszBuffer); 154 static char *fileNormalize(char *pszFilename); 155 char *filePath(const char *pszFilename, char *pszBuffer); 156 static char *filePathSlash(const char *pszFilename, char *pszBuffer); 157 static char *filePathSlash2(const char *pszFilename, char *pszBuffer); 158 static char *fileName(const char *pszFilename, char *pszBuffer); 159 static char *fileNameNoExt(const char *pszFilename, char *pszBuffer); 160 static char *fileExt(const char *pszFilename, char *pszBuffer); 159 161 160 162 /* filecache operations */ 161 static BOOL filecacheAdd(const char *pszFilename); 163 static BOOL filecacheAddFile(const char *pszFilename); 164 static BOOL filecacheAddDir(const char *pszDir); 162 165 static BOOL filecacheFind(const char *pszFilename); 166 static BOOL filecacheIsDirCached(const char *pszDir); 163 167 164 168 /* pathlist operations */ … … 202 206 */ 203 207 static PDEPRULE pdepList = NULL; 208 static BOOL fCacheSearchDirs = FALSE; 209 204 210 205 211 /* … … 208 214 static PFCACHEENTRY pfcTree = NULL; 209 215 static unsigned cfcNodes = 0; 216 static PFCACHEENTRY pfcDirTree = NULL; 210 217 211 218 … … 452 459 else 453 460 { /* not a parameter! */ 454 ULONG ulRc;455 FILEFINDBUF3 filebuf;456 HDIR hDir = HDIR_CREATE;457 ULONG ulFound = 1;458 459 memset(&filebuf, 0, sizeof(filebuf));461 ULONG ulRc; 462 char achBuffer[4096]; 463 PFILEFINDBUF3 pfindbuf3 = (PFILEFINDBUF3)(void*)&achBuffer[0]; 464 HDIR hDir = HDIR_CREATE; 465 ULONG cFiles = ~0UL; 466 int i; 460 467 461 468 /* … … 471 478 ulRc = DosFindFirst(argv[argi], &hDir, 472 479 FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_ARCHIVED, 473 &filebuf, sizeof(FILEFINDBUF3), &ulFound, FIL_STANDARD); 480 pfindbuf3, sizeof(achBuffer), &cFiles, FIL_STANDARD); 481 if (!fCacheSearchDirs) 482 fCacheSearchDirs = cFiles > 25; 474 483 while (ulRc == NO_ERROR) 475 484 { 476 char *psz; 477 char szSource[CCHMAXPATH]; 478 479 /* 480 * Make full path. 481 */ 482 if ((psz = strrchr(argv[argi], '\\')) || (psz = strrchr(argv[argi], '/'))) 485 for (i = 0; 486 i < cFiles; 487 i++, pfindbuf3 = (PFILEFINDBUF3)((int)pfindbuf3 + pfindbuf3->oNextEntryOffset) 488 ) 483 489 { 484 strncpy(szSource, argv[argi], psz - argv[argi] + 1); 485 szSource[psz - argv[argi] + 1] = '\0'; 490 char *psz; 491 char szSource[CCHMAXPATH]; 492 493 /* 494 * Make full path. 495 */ 496 if ((psz = strrchr(argv[argi], '\\')) || (psz = strrchr(argv[argi], '/'))) 497 { 498 strncpy(szSource, argv[argi], psz - argv[argi] + 1); 499 szSource[psz - argv[argi] + 1] = '\0'; 500 } 501 else 502 szSource[0] = '\0'; 503 strcat(szSource, pfindbuf3->achName); 504 505 /* 506 * Analyse the file. 507 */ 508 rc -= makeDependent(&szSource[0], &options); 486 509 } 487 else488 szSource[0] = '\0';489 strcat(szSource, filebuf.achName);490 491 /*492 * Analyse the file.493 */494 rc -= makeDependent(&szSource[0], &options);495 510 496 511 /* next file */ 497 ulRc = DosFindNext(hDir, &filebuf, sizeof(filebuf), &ulFound); 512 cFiles = ~0UL; 513 pfindbuf3 = (PFILEFINDBUF3)(void*)&achBuffer[0]; 514 ulRc = DosFindNext(hDir, pfindbuf3, sizeof(achBuffer), &cFiles); 498 515 } 499 516 DosFindClose(hDir); … … 1303 1320 } 1304 1321 1322 1323 /** 1324 * Normalizes the path slashes for the filename. 1325 * @returns pszFilename 1326 * @param pszFilename Pointer to filename string. 1327 */ 1328 char *fileNormalize(char *pszFilename) 1329 { 1330 char *psz = pszFilename; 1331 1332 while ((pszFilename = strchr(pszFilename, '//')) != NULL) 1333 *pszFilename++ = '\\'; 1334 1335 return psz; 1336 } 1337 1305 1338 /** 1306 1339 * Copies the path part (excluding the slash) into pszBuffer and returns … … 1341 1374 * @author knut st. osmundsen 1342 1375 */ 1343 char *filePathSlash(const char *pszFilename, char *pszBuffer)1376 static char *filePathSlash(const char *pszFilename, char *pszBuffer) 1344 1377 { 1345 1378 char *psz = strrchr(pszFilename, '\\'); … … 1353 1386 strncpy(pszBuffer, pszFilename, psz - pszFilename + 1); 1354 1387 pszBuffer[psz - pszFilename + 1] = '\0'; 1388 } 1389 1390 return pszBuffer; 1391 } 1392 1393 1394 /** 1395 * Copies the path part including the slash into pszBuffer and returns 1396 * a pointer to the buffer. If no path is found "" is returned. 1397 * The path is normalized to only use '\\'. 1398 * @returns Pointer to pszBuffer with path. 1399 * @param pszFilename Pointer to readonly filename. 1400 * @param pszBuffer Pointer to output Buffer. 1401 * @status completely implemented. 1402 * @author knut st. osmundsen 1403 */ 1404 static char *filePathSlash2(const char *pszFilename, char *pszBuffer) 1405 { 1406 char *psz = strrchr(pszFilename, '\\'); 1407 if (psz == NULL) 1408 psz = strrchr(pszFilename, '/'); 1409 1410 if (psz == NULL) 1411 *pszBuffer = '\0'; 1412 else 1413 { 1414 strncpy(pszBuffer, pszFilename, psz - pszFilename + 1); 1415 pszBuffer[psz - pszFilename + 1] = '\0'; 1416 1417 /* normalize all '/' to '\\' */ 1418 psz = pszBuffer; 1419 while ((psz = strchr(psz, '/')) != NULL) 1420 *psz++ = '\\'; 1355 1421 } 1356 1422 … … 1439 1505 * @param pszFilename Name of the file which is to be added. (with path!) 1440 1506 */ 1441 static BOOL filecacheAdd (const char *pszFilename)1507 static BOOL filecacheAddFile(const char *pszFilename) 1442 1508 { 1443 1509 PFCACHEENTRY pfcNew; … … 1457 1523 return TRUE; 1458 1524 } 1459 1460 1525 cfcNodes++; 1461 1526 … … 1466 1531 1467 1532 /** 1468 * Checks if pszFile is exists in the cache. 1533 * Adds a file to the cache. 1534 * @returns Success indicator. 1535 * @param pszDir Name of the path which is to be added. (with slash!) 1536 */ 1537 static BOOL filecacheAddDir(const char *pszDir) 1538 { 1539 PFCACHEENTRY pfcNew; 1540 APIRET rc; 1541 char szDir[CCHMAXPATH]; 1542 int cchDir; 1543 char achBuffer[16384]; 1544 PFILEFINDBUF3 pfindbuf3 = (PFILEFINDBUF3)(void*)&achBuffer[0]; 1545 HDIR hDir = HDIR_CREATE; 1546 ULONG cFiles = 0xFFFFFFF; 1547 int i; 1548 1549 /* Make path */ 1550 filePathSlash2(pszDir, szDir); 1551 strlwr(szDir); /* Convert name to lower case to allow faster searchs! */ 1552 cchDir = strlen(szDir); 1553 1554 1555 /* Add directory to pfcDirTree. */ 1556 pfcNew = malloc(sizeof(FCACHEENTRY) + cchDir + 1); 1557 if (pfcNew == NULL) 1558 { 1559 fprintf(stderr, "error: out of memory! (line=%d)\n", __LINE__); 1560 DosFindClose(hDir); 1561 return FALSE; 1562 } 1563 pfcNew->Key = (char*)(void*)pfcNew + sizeof(FCACHEENTRY); 1564 strcpy((char*)(unsigned)pfcNew->Key, szDir); 1565 AVLInsert(&pfcDirTree, pfcNew); 1566 1567 1568 /* Start to search directory - all files */ 1569 strcat(szDir + cchDir, "*"); 1570 rc = DosFindFirst(szDir, &hDir, FILE_NORMAL, 1571 pfindbuf3, sizeof(achBuffer), 1572 &cFiles, FIL_STANDARD); 1573 while (rc == NO_ERROR) 1574 { 1575 for (i = 0; 1576 i < cFiles; 1577 i++, pfindbuf3 = (PFILEFINDBUF3)((int)pfindbuf3 + pfindbuf3->oNextEntryOffset) 1578 ) 1579 { 1580 pfcNew = malloc(sizeof(FCACHEENTRY) + cchDir + pfindbuf3->cchName + 1); 1581 if (pfcNew == NULL) 1582 { 1583 fprintf(stderr, "error: out of memory! (line=%d)\n", __LINE__); 1584 DosFindClose(hDir); 1585 return FALSE; 1586 } 1587 pfcNew->Key = (char*)(void*)pfcNew + sizeof(FCACHEENTRY); 1588 strcpy((char*)(unsigned)pfcNew->Key, szDir); 1589 strcpy((char*)(unsigned)pfcNew->Key + cchDir, pfindbuf3->achName); 1590 strlwr((char*)(unsigned)pfcNew->Key + cchDir); /* Convert name to lower case to allow faster searchs! */ 1591 if (!AVLInsert(&pfcTree, pfcNew)) 1592 free(pfcNew); 1593 else 1594 cfcNodes++; 1595 _heap_check(); 1596 } 1597 1598 /* next */ 1599 cFiles = 0xFFFFFFF; 1600 pfindbuf3 = (PFILEFINDBUF3)(void*)&achBuffer[0]; 1601 rc = DosFindNext(hDir, pfindbuf3, sizeof(achBuffer), &cFiles); 1602 } 1603 1604 DosFindClose(hDir); 1605 1606 return TRUE; 1607 } 1608 1609 1610 /** 1611 * Checks if pszFilename is exists in the cache. 1469 1612 * @return TRUE if found. FALSE if not found. 1470 1613 * @param pszFilename Name of the file to be found. (with path!) 1614 * This is in lower case! 1471 1615 */ 1472 1616 static BOOL filecacheFind(const char *pszFilename) 1473 1617 { 1474 1618 return AVLGet(&pfcTree, (AVLKEY)pszFilename) != NULL; 1619 } 1620 1621 1622 /** 1623 * Checks if pszFilename is exists in the cache. 1624 * @return TRUE if found. FALSE if not found. 1625 * @param pszFilename Name of the file to be found. (with path!) 1626 * This is in lower case! 1627 */ 1628 static BOOL filecacheIsDirCached(const char *pszDir) 1629 { 1630 return AVLGet(&pfcDirTree, (AVLKEY)pszDir) != NULL; 1475 1631 } 1476 1632 … … 1517 1673 strcpy(&szFile[pszNext - psz], "\\"); 1518 1674 strcat(szFile, pszFilename); 1675 strlwr(szFile); /* to speed up AVL tree search we'll lowercase all names. */ 1676 fileNormalize(szFile); 1519 1677 1520 1678 /* … … 1524 1682 if (!filecacheFind(szFile)) 1525 1683 { 1526 FILESTATUS3 fsts3; 1527 1528 /* ask the OS */ 1529 rc = DosQueryPathInfo(szFile, FIL_STANDARD, &fsts3, sizeof(fsts3)); 1530 if (rc == NO_ERROR) 1531 { /* add file to cache. */ 1532 filecacheAdd(szFile); 1684 char szDir[CCHMAXPATH]; 1685 1686 filePathSlash(szFile, szDir); 1687 if (filecacheIsDirCached(szDir)) 1688 rc = ERROR_FILE_NOT_FOUND; 1689 else 1690 { 1691 /* 1692 * If caching of entire dirs are enabled, we'll 1693 * add the directory to the cache and search it. 1694 */ 1695 if (fCacheSearchDirs && filecacheAddDir(szDir)) 1696 rc = filecacheFind(szFile) ? NO_ERROR : ERROR_FILE_NOT_FOUND; 1697 else 1698 { 1699 FILESTATUS3 fsts3; 1700 1701 /* ask the OS */ 1702 rc = DosQueryPathInfo(szFile, FIL_STANDARD, &fsts3, sizeof(fsts3)); 1703 if (rc == NO_ERROR) 1704 { /* add file to cache. */ 1705 filecacheAddFile(szFile); 1706 } 1707 } 1533 1708 } 1534 1709 } -
trunk/tools/fastdep/makefile
r3129 r3132 1 # $Id: makefile,v 1. 4 2000-03-16 21:10:10bird Exp $1 # $Id: makefile,v 1.5 2000-03-16 23:51:26 bird Exp $ 2 2 3 3 # … … 17 17 CFLAGS = $(CFLAGS) -Ge+ -Tx+ -I..\common \ 18 18 -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -O+ -Tm- 19 # -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -Gh+ 19 # -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -Gh+ -Tm- #-O+ 20 20 LDFLAGS = $(LDFLAGS) -Ge+ -Fe$@ /B"/MAP:full" 21 21 !else … … 32 32 fastdep.exe: fastdep.obj avl.obj 33 33 $(LD) $(LDFLAGS) $** $(RTLLIB) os2386.lib 34 # $(LD) $(LDFLAGS) $** CPPOPA3.OBJ $(RTLLIB) os2386.lib34 # $(LD) $(LDFLAGS) $** CPPOPA3.OBJ $(RTLLIB) _DOSCALL.LIB os2386.lib 35 35 36 36 ..\bin\fastdep.exe: fastdep.exe
Note:
See TracChangeset
for help on using the changeset viewer.