Changeset 3134 for trunk/tools
- Timestamp:
- Mar 17, 2000, 5:26:32 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/fastdep/fastdep.c
r3133 r3134 1 /* $Id: fastdep.c,v 1.1 1 2000-03-16 23:53:34bird Exp $1 /* $Id: fastdep.c,v 1.12 2000-03-17 04:26:32 bird Exp $ 2 2 * 3 3 * Fast dependents. (Fast = Quick and Dirty!) … … 23 23 #include <string.h> 24 24 #include <stdlib.h> 25 #include <direct.h> 25 26 26 27 #include "avl.h" … … 86 87 const char * pszObjectExt; 87 88 const char * pszObjectDir; 88 BOOL fObjectDir; /* replace object directory? */89 BOOL fObjectDir; /* replace object directory? */ 89 90 const char * pszRsrcExt; 90 91 BOOL fObjRule; … … 92 93 BOOL fSrcWhenObj; 93 94 BOOL fAppend; /* append to the output file, not overwrite it. */ 95 BOOL fCheckCyclic; /* allways check for cylic dependency before inserting an dependent. */ 96 BOOL fCacheSearchDirs; /* cache entire search dirs. */ 94 97 } OPTIONS, *POPTIONS; 95 98 … … 122 125 typedef struct _DepRule 123 126 { 127 AVLNODECORE avlCore; 124 128 char * pszRule; /* Pointer to rule name */ 125 129 int cDeps; /* Entries in the dependant array. */ 126 130 char ** papszDep; /* Pointer to an array of pointers to dependants. */ 127 struct _DepRule *pNext; /* Pointer to the next rule */128 131 } DEPRULE, *PDEPRULE; 129 132 … … 153 156 /* file operations */ 154 157 static char *fileNormalize(char *pszFilename); 158 static char *fileNormalize2(const char *pszFilename, char *pszBuffer); 155 159 char *filePath(const char *pszFilename, char *pszBuffer); 156 160 static char *filePathSlash(const char *pszFilename, char *pszBuffer); … … 167 171 168 172 /* pathlist operations */ 169 static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer );173 static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer, POPTIONS pOptions); 170 174 171 175 /* word operations */ … … 189 193 190 194 /* depend workers */ 191 static BOOL depReadFile(const char *pszFilename );195 static BOOL depReadFile(const char *pszFilename, POPTIONS pOptions); 192 196 static BOOL depWriteFile(const char *pszFilename); 193 197 static void depRemoveAll(void); 194 198 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt); 195 static BOOL depAddDepend(void *pvRule, const char *pszDep );199 static BOOL depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic); 196 200 #if 0 /* not used */ 197 201 static BOOL depCleanFile(const char *pszFilename); 198 202 #endif 203 static BOOL depCheckCyclic(PDEPRULE pdepRule, const char *pszDep); 199 204 200 205 … … 205 210 * Pointer to the list of dependencies. 206 211 */ 207 static PDEPRULE pdepList = NULL; 208 static BOOL fCacheSearchDirs = FALSE; 212 static PDEPRULE pdepTree = NULL; 209 213 210 214 … … 215 219 static unsigned cfcNodes = 0; 216 220 static PFCACHEENTRY pfcDirTree = NULL; 221 222 223 /* 224 * Current directory stuff 225 */ 226 static char szCurDir[CCHMAXPATH]; 227 static int aiSlashes[CCHMAXPATH]; 228 static int cSlashes; 217 229 218 230 … … 279 291 int rc = 0; 280 292 int argi = 1; 293 int i; 281 294 const char *pszDepFile = pszDefaultDepFile; 282 295 … … 299 312 FALSE, /* fNoObjectPath */ 300 313 TRUE, /* fSrcWhenObj */ 301 FALSE /* fAppend */ 314 FALSE, /* fAppend */ 315 TRUE, /* fCheckCyclic */ 316 TRUE /* fCacheSearchDirs */ 302 317 }; 303 318 … … 310 325 } 311 326 327 /* 328 * Initiate current directory stuff 329 */ 330 if (_getcwd(szCurDir, sizeof(szCurDir)) == NULL) 331 { 332 fprintf(stderr, "fatal error: failed to get current directory\n"); 333 return -88; 334 } 335 strlwr(szCurDir); 336 for (i = 0, cSlashes; szCurDir[i] != '\0'; i++) 337 { 338 if (szCurDir[i] == '/') 339 szCurDir[i] = '\\'; 340 if (szCurDir[i] == '\\') 341 aiSlashes[cSlashes++] = i; 342 } 343 if (szCurDir[i-1] != '\\') 344 { 345 aiSlashes[cSlashes] = i; 346 szCurDir[i++] = '\\'; 347 szCurDir[i] = '\0'; 348 } 349 350 /* 351 * parse arguments 352 */ 312 353 while (argi < argc) 313 354 { … … 340 381 341 382 /* if dependencies are generated we'll flush them to the old filename */ 342 if (pdep List!= NULL && pszOld != pszDepFile)383 if (pdepTree != NULL && pszOld != pszDepFile) 343 384 { 344 385 if (!depWriteFile(pszOld)) … … 348 389 break; 349 390 } 391 392 case 'C': /* forced directory cache 'ca' or cylic check 'cy'*/ 393 case 'c': 394 if (argv[argi][2] == 'a' || argv[argi][2] == 'A') 395 options.fCacheSearchDirs = TRUE; 396 else if ((argv[argi][2] == 'y' || argv[argi][2] == 'Y')) 397 options.fCheckCyclic = argv[argi][3] != '-'; 398 break; 350 399 351 400 case 'E': /* list of paths. If a file is found in one of these directories the */ … … 470 519 * before starting adding new dependencies. 471 520 */ 472 if (pdep List== NULL && options.fAppend)473 depReadFile(pszDepFile );521 if (pdepTree == NULL && options.fAppend) 522 depReadFile(pszDepFile, &options); 474 523 475 524 /* … … 479 528 FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_ARCHIVED, 480 529 pfindbuf3, sizeof(achBuffer), &cFiles, FIL_STANDARD); 481 if (! fCacheSearchDirs)482 fCacheSearchDirs = cFiles > 25;530 if (!options.fCacheSearchDirs) 531 options.fCacheSearchDirs = cFiles > 25; 483 532 while (ulRc == NO_ERROR) 484 533 { … … 539 588 { 540 589 printf( 541 "FastDep v0. 1\n"542 "Quick and dirty depend antscanner. Creates a makefile readable depend file.\n"590 "FastDep v0.2\n" 591 "Quick and dirty dependency scanner. Creates a makefile readable depend file.\n" 543 592 "\n" 544 "Syntax: FastDep [-a<[+]|->] [-d <outputfn>] [-e <excludepath>] [-eall<[+]|->]\n" 545 " [-i <include>] [-n<[+]|->] [-o <objdir>] [-obr<[+]|->] <files>\n" 593 "Syntax: FastDep [-a<[+]|->] [-ca] [-cy<[+]|->] [-d <outputfn>]\n" 594 " [-e <excludepath>] [-eall<[+]|->] [-i <include>] [-n<[+]|->]\n" 595 " [-o <objdir>] [-obr<[+]|->] <files>\n" 546 596 "\n" 547 597 " -a<[+]|-> Append to the output file. Default: Overwrite.\n" 598 " -ca Force search directory caching.\n" 599 " Default: cache if more that 25 files are to be searched.\n" 600 " (more than 25 in the first file expression.)\n" 601 " -cy<[+]|-> Check for cylic dependencies. Default: -cy-\n" 548 602 " -d <outputfn> Output filename. Default: %s\n" 549 603 " -e excludepath Exclude paths. If a filename is found in any\n" … … 565 619 " -r[ ]<rsrcext> Resource binary extention. Default: res\n" 566 620 " <files> Files to scan. Wildchars are allowed.\n" 567 "\n", 621 "\n" 622 " copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)\n", 568 623 pszDefaultDepFile 569 624 ); … … 676 731 677 732 if (pOptions->fSrcWhenObj && pvRule) 678 depAddDepend(pvRule, pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename); 733 depAddDepend(pvRule, 734 pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), 735 pOptions->fCheckCyclic); 679 736 } 680 737 else 681 pvRule = depAddRule(p szFilename, NULL, NULL);738 pvRule = depAddRule(pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL); 682 739 683 740 /* duplicate rule? */ … … 773 830 774 831 /* find include file! */ 775 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer );832 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer, pOptions); 776 833 if (psz == NULL) 777 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer );834 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer, pOptions); 778 835 779 836 /* did we find the include? */ … … 782 839 char szBuffer2[CCHMAXPATH]; 783 840 if (pOptions->fExcludeAll || 784 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2 ) != NULL841 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2, pOptions) != NULL 785 842 ) 786 depAddDepend(pvRule, szFullname );843 depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic); 787 844 else 788 depAddDepend(pvRule, szBuffer );845 depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic); 789 846 } 790 847 else … … 939 996 940 997 if (pOptions->fSrcWhenObj && pvRule) 941 depAddDepend(pvRule, pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename); 998 depAddDepend(pvRule, 999 pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), 1000 pOptions->fCheckCyclic); 942 1001 } 943 1002 else 944 pvRule = depAddRule(p szFilename, NULL, NULL);1003 pvRule = depAddRule(pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL); 945 1004 946 1005 /* duplicate rule? */ … … 996 1055 997 1056 /* find include file! */ 998 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer );1057 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer, pOptions); 999 1058 if (psz == NULL) 1000 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer );1059 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer, pOptions); 1001 1060 1002 1061 /* Did we find the include? */ … … 1005 1064 char szBuffer2[CCHMAXPATH]; 1006 1065 if (pOptions->fExcludeAll || 1007 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2 ) != NULL1066 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2, pOptions) != NULL 1008 1067 ) 1009 depAddDepend(pvRule, szFullname );1068 depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic); 1010 1069 else 1011 depAddDepend(pvRule, szBuffer );1070 depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic); 1012 1071 } 1013 1072 else … … 1055 1114 1056 1115 if (pOptions->fSrcWhenObj && pvRule) 1057 depAddDepend(pvRule, pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename); 1116 depAddDepend(pvRule, 1117 pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), 1118 pOptions->fCheckCyclic); 1058 1119 } 1059 1120 else 1060 pvRule = depAddRule(p szFilename, NULL, NULL);1121 pvRule = depAddRule(pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL); 1061 1122 1062 1123 /* duplicate rule? */ … … 1114 1175 1115 1176 /* find include file! */ 1116 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer );1177 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer, pOptions); 1117 1178 if (psz == NULL) 1118 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer );1179 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer, pOptions); 1119 1180 1120 1181 /* did we find the include? */ … … 1123 1184 char szBuffer2[CCHMAXPATH]; 1124 1185 if (pOptions->fExcludeAll || 1125 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2 ) != NULL1186 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2, pOptions) != NULL 1126 1187 ) 1127 depAddDepend(pvRule, szFullname );1188 depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic); 1128 1189 else 1129 depAddDepend(pvRule, szBuffer );1190 depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic); 1130 1191 } 1131 1192 else … … 1173 1234 1174 1235 if (pOptions->fSrcWhenObj && pvRule) 1175 depAddDepend(pvRule, pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename); 1236 depAddDepend(pvRule, 1237 pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), 1238 pOptions->fCheckCyclic); 1176 1239 } 1177 1240 else 1178 pvRule = depAddRule(p szFilename, NULL, NULL);1241 pvRule = depAddRule(pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL); 1179 1242 1180 1243 /* duplicate rule? */ … … 1264 1327 1265 1328 /* find include file! */ 1266 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer );1329 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer, pOptions); 1267 1330 1268 1331 /* did we find the include? */ … … 1271 1334 char szBuffer2[CCHMAXPATH]; 1272 1335 if (pOptions->fExcludeAll || 1273 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2 ) != NULL1336 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2, pOptions) != NULL 1274 1337 ) 1275 depAddDepend(pvRule, szFullname );1338 depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic); 1276 1339 else 1277 depAddDepend(pvRule, szBuffer );1340 depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic); 1278 1341 } 1279 1342 else … … 1322 1385 1323 1386 /** 1324 * Normalizes the path slashes for the filename. 1387 * Normalizes the path slashes for the filename. It will partially expand paths too. 1325 1388 * @returns pszFilename 1326 * @param pszFilename Pointer to filename string. 1389 * @param pszFilename Pointer to filename string. Not empty string! 1390 * Much space to play with. 1327 1391 */ 1328 1392 char *fileNormalize(char *pszFilename) … … 1330 1394 char *psz = pszFilename; 1331 1395 1396 /* correct slashes */ 1332 1397 while ((pszFilename = strchr(pszFilename, '//')) != NULL) 1333 1398 *pszFilename++ = '\\'; 1334 1399 1400 /* expand path? */ 1401 pszFilename = psz; 1402 if (pszFilename[1] != ':') 1403 { /* relative path */ 1404 int iSlash; 1405 char szFile[CCHMAXPATH]; 1406 char * psz = szFile; 1407 1408 strcpy(szFile, pszFilename); 1409 iSlash = *psz == '\\' ? 0 : cSlashes; 1410 while (*psz != '\0') 1411 { 1412 if (*psz == '.' && psz[1] == '.' && psz[2] == '\\') 1413 { /* up one directory */ 1414 if (iSlash > 0) 1415 iSlash--; 1416 psz += 3; 1417 } 1418 else if (*psz == '.' && psz[1] == '\\') 1419 { /* no change */ 1420 psz += 2; 1421 } 1422 else 1423 { /* completed expantion! */ 1424 strncpy(pszFilename, szCurDir, aiSlashes[iSlash]+1); 1425 strcpy(pszFilename + aiSlashes[iSlash]+1, psz); 1426 break; 1427 } 1428 } 1429 } 1430 /* else: assume full path */ 1431 1335 1432 return psz; 1336 1433 } 1434 1435 1436 /** 1437 * Normalizes the path slashes for the filename. It will partially expand paths too. 1438 * @returns pszFilename 1439 * @param pszFilename Pointer to filename string. Not empty string! 1440 * Much space to play with. 1441 * @param pszBuffer Pointer to output buffer. 1442 */ 1443 char *fileNormalize2(const char *pszFilename, char *pszBuffer) 1444 { 1445 char *psz = pszBuffer; 1446 1447 /* expand path? */ 1448 if (pszFilename[1] != ':') 1449 { /* relative path */ 1450 int iSlash; 1451 1452 iSlash = *pszFilename == '\\' || *pszFilename == '/' ? 0 : cSlashes; 1453 while (*pszFilename != '\0') 1454 { 1455 if (*pszFilename == '.' && pszFilename[1] == '.' && (pszFilename[2] == '\\' || pszFilename[1] == '/')) 1456 { /* up one directory */ 1457 if (iSlash > 0) 1458 iSlash--; 1459 pszFilename += 3; 1460 } 1461 else if (*pszFilename == '.' && (pszFilename[1] == '\\' || pszFilename[1] == '/')) 1462 { /* no change */ 1463 pszFilename += 2; 1464 } 1465 else 1466 { /* completed expantion! */ 1467 strncpy(pszBuffer, szCurDir, aiSlashes[iSlash]+1); 1468 strcpy(pszBuffer + aiSlashes[iSlash]+1, pszFilename); 1469 break; 1470 } 1471 } 1472 } 1473 /* else: assume full path */ 1474 1475 /* correct slashes */ 1476 while ((pszBuffer = strchr(pszBuffer, '//')) != NULL) 1477 *pszBuffer++ = '\\'; 1478 1479 return psz; 1480 } 1481 1337 1482 1338 1483 /** … … 1593 1738 else 1594 1739 cfcNodes++; 1595 _heap_check();1596 1740 } 1597 1741 … … 1641 1785 * @parma pszFilename Filename to find. 1642 1786 * @parma pszBuffer Ouput Buffer. 1787 * @param pOptions Pointer to options struct. 1643 1788 * @status completely implemented. 1644 1789 * @author knut st. osmundsen 1645 1790 * @remark need substantial optimizations. 95% of execution is spend here. 1646 1791 */ 1647 static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer )1792 static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer, POPTIONS pOptions) 1648 1793 { 1649 1794 const char *psz = pszPathList; … … 1665 1810 { 1666 1811 APIRET rc; 1667 char szFile[CCHMAXPATH];1668 1812 1669 1813 /* make search statment */ 1670 strncpy( szFile, psz, pszNext - psz);1671 szFile[pszNext - psz] = '\0';1672 if ( szFile[pszNext - psz - 1] != '\\' && szFile[pszNext - psz - 1] != '/')1673 strcpy(& szFile[pszNext - psz], "\\");1674 strcat( szFile, pszFilename);1675 strlwr( szFile); /* to speed up AVL tree search we'll lowercase all names. */1676 fileNormalize( szFile);1814 strncpy(pszBuffer, psz, pszNext - psz); 1815 pszBuffer[pszNext - psz] = '\0'; 1816 if (pszBuffer[pszNext - psz - 1] != '\\' && pszBuffer[pszNext - psz - 1] != '/') 1817 strcpy(&pszBuffer[pszNext - psz], "\\"); 1818 strcat(pszBuffer, pszFilename); 1819 strlwr(pszBuffer); /* to speed up AVL tree search we'll lowercase all names. */ 1820 fileNormalize(pszBuffer); 1677 1821 1678 1822 /* … … 1680 1824 * Search cache first 1681 1825 */ 1682 if (!filecacheFind( szFile))1826 if (!filecacheFind(pszBuffer)) 1683 1827 { 1684 1828 char szDir[CCHMAXPATH]; 1685 1829 1686 filePathSlash(szFile, szDir); 1687 if (filecacheIsDirCached(szDir)) 1688 rc = ERROR_FILE_NOT_FOUND; 1689 else 1830 filePathSlash(pszBuffer, szDir); 1831 if (!filecacheIsDirCached(szDir)) 1690 1832 { 1691 1833 /* … … 1693 1835 * add the directory to the cache and search it. 1694 1836 */ 1695 if (fCacheSearchDirs && filecacheAddDir(szDir)) 1696 rc = filecacheFind(szFile) ? NO_ERROR : ERROR_FILE_NOT_FOUND; 1837 if (pOptions->fCacheSearchDirs && filecacheAddDir(szDir)) 1838 { 1839 if (filecacheFind(pszBuffer)) 1840 return pszBuffer; 1841 } 1697 1842 else 1698 1843 { … … 1700 1845 1701 1846 /* ask the OS */ 1702 rc = DosQueryPathInfo( szFile, FIL_STANDARD, &fsts3, sizeof(fsts3));1847 rc = DosQueryPathInfo(pszBuffer, FIL_STANDARD, &fsts3, sizeof(fsts3)); 1703 1848 if (rc == NO_ERROR) 1704 1849 { /* add file to cache. */ 1705 filecacheAddFile(szFile); 1850 filecacheAddFile(pszBuffer); 1851 return pszBuffer; 1706 1852 } 1707 1853 } … … 1709 1855 } 1710 1856 else 1711 rc = NO_ERROR; 1712 1713 /* did we find it? */ 1714 if (rc == NO_ERROR) 1715 { 1716 strncpy(pszBuffer, psz, pszNext - psz); 1717 pszBuffer[pszNext - psz] = '\0'; 1718 if (pszBuffer[pszNext - psz - 1] != '\\' && pszBuffer[pszNext - psz - 1] != '/') 1719 strcpy(&pszBuffer[pszNext - psz], "\\"); 1720 strcat(pszBuffer, pszFilename); 1721 break; 1722 } 1857 return pszBuffer; 1723 1858 } 1724 1859 … … 1729 1864 } 1730 1865 1731 return *pszBuffer == '\0' ? NULL : pszBuffer;1866 return NULL; 1732 1867 } 1733 1868 … … 1971 2106 * Appends a depend file to the internal file. 1972 2107 */ 1973 static BOOL depReadFile(const char *pszFilename )2108 static BOOL depReadFile(const char *pszFilename, POPTIONS pOptions) 1974 2109 { 1975 2110 void *pvFile; … … 2059 2194 psz = trim(psz); 2060 2195 if (*psz != '\0') 2061 depAddDepend(pvRule, psz );2196 depAddDepend(pvRule, psz, pOptions->fCheckCyclic); 2062 2197 } 2063 2198 } … … 2081 2216 if (phFile != NULL) 2082 2217 { 2083 char szBuffer[4096]; 2084 int iBuffer = 0; 2085 int cch; 2086 PDEPRULE pdep = pdepList; 2087 2218 AVLENUMDATA EnumData; 2219 PDEPRULE pdep; 2220 char szBuffer[4096]; 2221 int iBuffer = 0; 2222 int cch; 2223 2224 pdep = (PDEPRULE)(void*)AVLBeginEnumTree((PPAVLNODECORE)(void*)&pdepTree, &EnumData, TRUE); 2088 2225 while (pdep != NULL) 2089 2226 { … … 2128 2265 2129 2266 /* next rule */ 2130 pdep = pdep->pNext;2267 pdep = (PDEPRULE)(void*)AVLGetNextNode(&EnumData); 2131 2268 } 2132 2269 … … 2143 2280 2144 2281 /** 2145 * Removes all entries in the list of dependencies. (pdepList)2282 * Removes all nodes in the tree of dependencies. (pdepTree) 2146 2283 */ 2147 2284 static void depRemoveAll(void) 2148 2285 { 2149 while (pdepList != NULL)2150 {2151 register PDEPRULE pdepToBeFree = pdepList; 2152 /* next */2153 pdepList = pdepToBeFree->pNext;2154 2286 AVLENUMDATA EnumData; 2287 PDEPRULE pdep; 2288 2289 pdep = (PDEPRULE)(void*)AVLBeginEnumTree((PPAVLNODECORE)(void*)&pdepTree, &EnumData, TRUE); 2290 while (pdep != NULL) 2291 { 2155 2292 /* free this */ 2156 if (pdep ToBeFree->papszDep != NULL)2293 if (pdep->papszDep != NULL) 2157 2294 { 2158 char ** ppsz = pdep ToBeFree->papszDep;2295 char ** ppsz = pdep->papszDep; 2159 2296 while (*ppsz != NULL) 2160 2297 free(*ppsz++); 2161 free(pdep ToBeFree->papszDep);2298 free(pdep->papszDep); 2162 2299 } 2163 free(pdepToBeFree); 2164 } 2300 free(pdep); 2301 2302 /* next */ 2303 pdep = (PDEPRULE)(void*)AVLGetNextNode(&EnumData); 2304 } 2305 pdepTree = NULL; 2165 2306 } 2166 2307 … … 2179 2320 { 2180 2321 char szRule[CCHMAXPATH*2]; 2181 PDEPRULE pdepPrev = NULL;2182 PDEPRULE pdep = pdepList;2183 2322 PDEPRULE pNew; 2184 2323 int cch; … … 2199 2338 } 2200 2339 2201 /* find location */2202 while (pdep != NULL && stricmp(pdep->pszRule, szRule) < 0)2203 {2204 pdepPrev = pdep;2205 pdep = pdep->pNext;2206 }2207 2208 /* check if matching rule name */2209 if (pdep != NULL && stricmp(pdep->pszRule, szRule) == 0)2210 return NULL;2211 2340 2212 2341 /* … … 2216 2345 pNew = malloc(sizeof(DEPRULE) + cch + 1); 2217 2346 if (pNew == NULL) 2347 { 2348 fprintf(stderr, "error: out of memory. (line=%d)\n", __LINE__); 2218 2349 return NULL; 2350 } 2219 2351 pNew->pszRule = (char*)(void*)(pNew + 1); 2220 2352 strcpy(pNew->pszRule, szRule); 2221 2353 pNew->cDeps = 0; 2222 2354 pNew->papszDep = NULL; 2223 2224 /* link in module (before pdep) */ 2225 pNew->pNext = pdep;2226 if ( pdepPrev == NULL)2227 pdepList = pNew;2228 else2229 pdepPrev->pNext = pNew;2230 2231 _heap_check(); 2355 pNew->avlCore.Key = pNew->pszRule; 2356 2357 /* Insert rule */ 2358 if (!AVLInsert((PPAVLNODECORE)(void*)&pdepTree, &pNew->avlCore)) 2359 { /* rule existed - return NULL */ 2360 free(pNew); 2361 return NULL; 2362 } 2363 2232 2364 return pNew; 2233 2365 } … … 2237 2369 /** 2238 2370 * Adds a dependant to a rule. 2239 * @returns Successindicator. 2240 * @param pvRule Rule handle. 2241 * @param pszDep Pointer to dependant name 2242 */ 2243 static BOOL depAddDepend(void *pvRule, const char *pszDep) 2371 * @returns Successindicator. TRUE = success. 2372 * FALSE = cyclic or out of memory. 2373 * @param pvRule Rule handle. 2374 * @param pszDep Pointer to dependant name 2375 * @param fCheckCyclic When set we'll check that we're not creating an cyclic dependency. 2376 */ 2377 static BOOL depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic) 2244 2378 { 2245 2379 PDEPRULE pdep = (PDEPRULE)pvRule; 2380 2381 if (fCheckCyclic && depCheckCyclic(pdep, pszDep)) 2382 { 2383 fprintf(stderr, "warning: Cylic dependancy caused us to ignore '%s' in rule '%s'.\n", 2384 pszDep, pdep->pszRule); 2385 return FALSE; 2386 } 2246 2387 2247 2388 /* allocate more array space */ … … 2252 2393 { 2253 2394 pdep->cDeps = 0; 2395 fprintf(stderr, "error: out of memory, (line=%d)\n", __LINE__); 2254 2396 return FALSE; 2255 2397 } … … 2258 2400 /* allocate string space and copy pszDep */ 2259 2401 if ((pdep->papszDep[pdep->cDeps] = malloc(strlen(pszDep) + 1)) == NULL) 2402 { 2403 fprintf(stderr, "error: out of memory, (line=%d)\n", __LINE__); 2260 2404 return FALSE; 2405 } 2261 2406 strcpy(pdep->papszDep[pdep->cDeps], pszDep); 2262 2407 … … 2265 2410 2266 2411 /* successful! */ 2267 _heap_check();2268 2412 return TRUE; 2269 2413 } 2270 2414 2415 2416 /** 2417 * Checks if adding this dependent will create a cylic dependency. 2418 * @returns TRUE: Cyclic. 2419 * FALSE: Non-cylic. 2420 * @param pdepRule Rule pszDep is to be inserted in. 2421 * @param pszDep Depend name. 2422 */ 2423 static BOOL depCheckCyclic(PDEPRULE pdepRule, const char *pszDep) 2424 { 2425 #define DEPTH 32 2426 char * pszRule = pdepRule->pszRule; 2427 char ** appsz[DEPTH]; 2428 PDEPRULE pdep; 2429 int i; 2430 2431 /* find rule for the dep. */ 2432 if ((pdep = (PDEPRULE)(void*)AVLGet((PPAVLNODECORE)(void*)&pdepTree, pszDep)) == NULL 2433 || pdep->papszDep == NULL) 2434 return FALSE; /* no rule, or no dependents, not cyclic */ 2435 2436 i = 0; 2437 appsz[0] = pdep->papszDep; 2438 while (i >= 0) 2439 { 2440 register char ** ppsz = appsz[i]; 2441 2442 while (*ppsz != NULL) 2443 { 2444 /* check if equal to the main rule */ 2445 if (strcmp(pszRule, *ppsz) == 0) 2446 return TRUE; 2447 2448 /* push onto stack (ppsz is incremented in this test!) */ 2449 if ((pdep = (PDEPRULE)(void*)AVLGet((PPAVLNODECORE)(void*)&pdepTree, *ppsz++)) != NULL 2450 && pdep->papszDep != NULL) 2451 { 2452 appsz[i++] = ppsz; /* save next */ 2453 ppsz = pdep->papszDep; /* start processing new node */ 2454 } 2455 } 2456 2457 /* pop stack */ 2458 i--; 2459 } 2460 2461 return FALSE; 2462 } 2271 2463 2272 2464 … … 2275 2467 */ 2276 2468 #include <os2.h> 2277 2278 2279 2469 #ifdef OLEMANN 2470 #include "olemann.h" 2471 #endif 2472 2473 2474
Note:
See TracChangeset
for help on using the changeset viewer.