Changeset 9058 for trunk/tools
- Timestamp:
- Aug 20, 2002, 8:16:20 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/fastdep/fastdep.c
r8083 r9058 1 /* $Id: fastdep.c,v 1.3 6 2002-03-14 13:31:10 bird Exp $1 /* $Id: fastdep.c,v 1.37 2002-08-20 18:16:20 bird Exp $ 2 2 * 3 3 * Fast dependents. (Fast = Quick and Dirty!) … … 5 5 * Copyright (c) 1999-2002 knut st. osmundsen (bird@anduin.net) 6 6 * 7 * PH 2001-03-01 added optional support for a super-dependency 8 * 9 * Project Odin Software License can be found in LICENSE.TXT 7 * GPL 10 8 * 11 9 */ … … 134 132 BOOL fCacheSearchDirs; /* cache entire search dirs. */ 135 133 const char * pszExcludeFiles; /* List of excluded files. */ 136 const char * pszSuperDependency; /* Name for super dependency rule. */137 134 BOOL fForceScan; /* Force scan of all files. */ 138 135 } OPTIONS, *POPTIONS; … … 246 243 static BOOL depWriteFile(const char *pszFilename, BOOL fWriteUpdatedOnly); 247 244 static void depRemoveAll(void); 248 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, const char *pszTS); 249 static BOOL depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic); 245 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, const char *pszTS, BOOL fConvertName); 246 static BOOL depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic, BOOL fConvertName); 247 static int depConvertName(char *pszName, int cchName, BOOL fFromMake); 250 248 static void depMarkNotFound(void *pvRule); 251 249 static BOOL depCheckCyclic(PDEPRULE pdepRule, const char *pszDep); … … 359 357 TRUE, /* fCacheSearchDirs */ 360 358 szExcludeFiles, /* pszExcludeFiles */ 361 NULL, /* pszSuperDependency */362 359 FALSE /* fForceScan */ 363 360 }; 364 365 361 366 362 … … 693 689 break; 694 690 695 case 's': /* insert super-dependency on top of tree */696 case 'S': /* -s <name for super-dependency>" */697 {698 if (strlen(argv[argi]) > 2)699 /* syntax was /s:name */700 options.pszSuperDependency = &argv[argi][2];701 else702 {703 argi++;704 if (argi < argc)705 /* take next parameter */706 options.pszSuperDependency = argv[argi];707 else708 /* take default */709 options.pszSuperDependency = "alltargets";710 }711 }712 break;713 714 691 case 'h': 715 692 case 'H': … … 883 860 { 884 861 printf( 885 "FastDep v0.4 2(build %d)\n"862 "FastDep v0.43 (build %d)\n" 886 863 "Dependency scanner. Creates a makefile readable depend file.\n" 887 864 " - was quick and dirty, now it's just quick -\n" … … 917 894 " -obr-: No object rule, rule for source filename is generated.\n" 918 895 " -obj[ ]<objext> Object extention. Default: obj\n" 919 " -s[ ][name] Insert super-dependency on top of tree.\n"920 " If not specified name defaults to 'alltargets'.\n"921 " You can specify a '=' at the end and a macro will\n"922 " be created instead of a rule.\n"923 " Default: disabled\n"924 896 " -r[ ]<rsrcext> Resource binary extention. Default: res\n" 925 897 " -x[ ]<f1[;f2]> Files to exclude. Only exact filenames.\n" … … 1030 1002 { 1031 1003 if (options.fNoObjectPath) 1032 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS );1004 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS, FALSE); 1033 1005 else 1034 1006 pvRule = depAddRule(options.fObjectDir ? … … 1036 1008 filePathSlash(pszFilename, szBuffer), 1037 1009 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1038 options.pszObjectExt, 1039 pszTS); 1010 options.pszObjectExt, pszTS, FALSE); 1040 1011 1041 1012 if (options.fSrcWhenObj && pvRule) … … 1043 1014 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1044 1015 fileName(pszFilename, szBuffer) : pszNormFilename, 1045 options.fCheckCyclic); 1016 options.fCheckCyclic, 1017 FALSE); 1046 1018 } 1047 1019 else 1048 1020 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1049 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS );1021 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS, FALSE); 1050 1022 1051 1023 /* duplicate rule? */ … … 1167 1139 { /* #include <sys/stats.h> makes trouble, check for '/' and '\'. */ 1168 1140 if (!strchr(szFullname, '/') && !strchr(szFullname, '\\')) 1169 depAddDepend(pvRule, szFullname, options.fCheckCyclic );1141 depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE); 1170 1142 else 1171 1143 fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n", … … 1173 1145 } 1174 1146 else 1175 depAddDepend(pvRule, szBuffer, options.fCheckCyclic );1147 depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE); 1176 1148 } 1177 1149 else … … 1325 1297 { 1326 1298 if (options.fNoObjectPath) 1327 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS );1299 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS, FALSE); 1328 1300 else 1329 1301 pvRule = depAddRule(options.fObjectDir ? … … 1331 1303 filePathSlash(pszFilename, szBuffer), 1332 1304 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1333 options.pszObjectExt, 1334 pszTS); 1305 options.pszObjectExt, pszTS, FALSE); 1335 1306 1336 1307 if (options.fSrcWhenObj && pvRule) … … 1338 1309 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1339 1310 fileName(pszFilename, szBuffer) : pszNormFilename, 1340 options.fCheckCyclic );1311 options.fCheckCyclic, FALSE); 1341 1312 } 1342 1313 else 1343 1314 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1344 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS );1315 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS, FALSE); 1345 1316 1346 1317 /* duplicate rule? */ … … 1418 1389 { /* include sys/stats.inc makes trouble, check for '/' and '\'. */ 1419 1390 if (!strchr(szFullname, '/') && !strchr(szFullname, '\\')) 1420 depAddDepend(pvRule, szFullname, options.fCheckCyclic );1391 depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE); 1421 1392 else 1422 1393 fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n", … … 1424 1395 } 1425 1396 else 1426 depAddDepend(pvRule, szBuffer, options.fCheckCyclic );1397 depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE); 1427 1398 } 1428 1399 else … … 1469 1440 { 1470 1441 if (options.fNoObjectPath) 1471 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, pszTS );1442 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, pszTS, FALSE); 1472 1443 else 1473 1444 pvRule = depAddRule(options.fObjectDir ? … … 1475 1446 filePathSlash(pszFilename, szBuffer), 1476 1447 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1477 options.pszRsrcExt, 1478 pszTS); 1448 options.pszRsrcExt, pszTS, FALSE); 1479 1449 1480 1450 if (options.fSrcWhenObj && pvRule) … … 1482 1452 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1483 1453 fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), 1484 options.fCheckCyclic); 1454 options.fCheckCyclic, 1455 FALSE); 1485 1456 } 1486 1457 else 1487 1458 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1488 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, 1489 pszTS); 1459 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS, FALSE); 1490 1460 1491 1461 /* duplicate rule? */ … … 1592 1562 { /* #include <sys/stats.h> makes trouble, check for '/' and '\'. */ 1593 1563 if (!strchr(szFullname, '/') && !strchr(szFullname, '\\')) 1594 depAddDepend(pvRule, szFullname, options.fCheckCyclic );1564 depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE); 1595 1565 else 1596 1566 fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n", … … 1598 1568 } 1599 1569 else 1600 depAddDepend(pvRule, szBuffer, options.fCheckCyclic );1570 depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE); 1601 1571 } 1602 1572 else … … 1643 1613 { 1644 1614 if (options.fNoObjectPath) 1645 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, pszTS );1615 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, pszTS, FALSE); 1646 1616 else 1647 1617 pvRule = depAddRule(options.fObjectDir ? … … 1649 1619 filePathSlash(pszFilename, szBuffer), 1650 1620 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1651 options.pszRsrcExt, 1652 pszTS); 1621 options.pszRsrcExt, pszTS, FALSE); 1653 1622 1654 1623 if (options.fSrcWhenObj && pvRule) … … 1656 1625 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1657 1626 fileName(pszFilename, szBuffer) : pszNormFilename, 1658 options.fCheckCyclic); 1627 options.fCheckCyclic, 1628 FALSE); 1659 1629 } 1660 1630 else 1661 1631 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1662 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS );1632 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS, FALSE); 1663 1633 1664 1634 /* duplicate rule? */ … … 1776 1746 { /* #include <sys/stats.h> makes trouble, check for '/' and '\'. */ 1777 1747 if (!strchr(szFullname, '/') && !strchr(szFullname, '\\')) 1778 depAddDepend(pvRule, szFullname, options.fCheckCyclic );1748 depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE); 1779 1749 else 1780 1750 fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n", … … 1782 1752 } 1783 1753 else 1784 depAddDepend(pvRule, szBuffer, options.fCheckCyclic );1754 depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE); 1785 1755 } 1786 1756 else … … 1900 1870 /* Add filename to the dependencies. */ 1901 1871 if (i1) 1902 depAddDepend(pvRule, pszFile, options.fCheckCyclic );1872 depAddDepend(pvRule, pszFile, options.fCheckCyclic, FALSE); 1903 1873 else 1904 1874 { … … 1915 1885 { /* #include <sys/stats.h> makes trouble, check for '/' and '\'. */ 1916 1886 if (!strchr(pszFile, '/') && !strchr(pszFile, '\\')) 1917 depAddDepend(pvRule, pszFile, options.fCheckCyclic );1887 depAddDepend(pvRule, pszFile, options.fCheckCyclic, FALSE); 1918 1888 else 1919 1889 fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n", … … 1921 1891 } 1922 1892 else 1923 depAddDepend(pvRule, szFullname, options.fCheckCyclic );1893 depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE); 1924 1894 } 1925 1895 else … … 2005 1975 { 2006 1976 if (options.fNoObjectPath) 2007 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS );1977 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS, FALSE); 2008 1978 else 2009 1979 pvRule = depAddRule(options.fObjectDir ? … … 2011 1981 filePathSlash(pszFilename, szBuffer), 2012 1982 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 2013 options.pszObjectExt, 2014 pszTS); 1983 options.pszObjectExt, pszTS, FALSE); 2015 1984 2016 1985 if (options.fSrcWhenObj && pvRule) … … 2018 1987 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) 2019 1988 ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), 2020 options.fCheckCyclic); 1989 options.fCheckCyclic, 1990 FALSE); 2021 1991 } 2022 1992 else 2023 1993 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 2024 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS );1994 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS, FALSE); 2025 1995 2026 1996 /* duplicate rule? */ … … 2133 2103 { 2134 2104 if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer)) 2135 depAddDepend(pvRule, szFullname, options.fCheckCyclic );2105 depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE); 2136 2106 else 2137 depAddDepend(pvRule, szBuffer, options.fCheckCyclic );2107 depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE); 2138 2108 } 2139 2109 else … … 2181 2151 { 2182 2152 if (options.fNoObjectPath) 2183 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS );2153 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS, FALSE); 2184 2154 else 2185 2155 pvRule = depAddRule(options.fObjectDir ? … … 2187 2157 filePathSlash(pszFilename, szBuffer), 2188 2158 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 2189 options.pszObjectExt, 2190 pszTS); 2159 options.pszObjectExt, pszTS, FALSE); 2191 2160 2192 2161 if (options.fSrcWhenObj && pvRule) … … 2194 2163 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) 2195 2164 ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), 2196 options.fCheckCyclic); 2165 options.fCheckCyclic, 2166 FALSE); 2197 2167 } 2198 2168 else */ 2199 2169 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 2200 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS );2170 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, pszTS, FALSE); 2201 2171 2202 2172 /* duplicate rule? */ … … 2274 2244 { 2275 2245 if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer)) 2276 depAddDepend(pvRule, fileName(szFullname, szBuffer), options.fCheckCyclic );2246 depAddDepend(pvRule, fileName(szFullname, szBuffer), options.fCheckCyclic, FALSE); 2277 2247 else 2278 depAddDepend(pvRule, szBuffer, options.fCheckCyclic );2248 depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE); 2279 2249 } 2280 2250 else … … 2289 2259 textbufferDestroy(pvFile); 2290 2260 2261 fHeader = fHeader; 2291 2262 return 0; 2292 2263 } 2293 2294 2295 2264 2296 2265 … … 2629 2598 return TRUE; 2630 2599 } 2631 2632 2600 2633 2601 … … 2880 2848 2881 2849 2882 2883 2850 /** 2884 2851 * Checks if the given filename may exist within any of the given paths. … … 3020 2987 return cb; 3021 2988 } 3022 3023 2989 3024 2990 … … 3370 3336 3371 3337 psz[i] = '\0'; 3372 pvRule = depAddRule(trimQuotes(trimR(psz)), NULL, NULL, szTS );3338 pvRule = depAddRule(trimQuotes(trimR(psz)), NULL, NULL, szTS, TRUE); 3373 3339 if (pvRule) 3374 3340 ((PDEPRULE)pvRule)->fUpdated = fAppend; … … 3400 3366 psz = trimQuotes(trim(psz)); 3401 3367 if (*psz != '\0') 3402 depAddDepend(pvRule, psz, options.fCheckCyclic );3368 depAddDepend(pvRule, psz, options.fCheckCyclic, TRUE); 3403 3369 } 3404 3370 } … … 3425 3391 AVLENUMDATA EnumData; 3426 3392 PDEPRULE pdep; 3427 char szBuffer[32678];3393 static char szBuffer[0x10000]; 3428 3394 int iBuffer = 0; 3429 3395 int cch; … … 3444 3410 phFile); 3445 3411 3446 3447 /* @@@PH 2001-03-013448 * If option is selected to generate a parent3449 * "super" dependency, enter this scope.3450 */3451 if (options.pszSuperDependency != NULL)3452 {3453 iBuffer = sprintf(szBuffer,3454 strrchr(options.pszSuperDependency, '=') ? "%s" : "%s:",3455 options.pszSuperDependency);3456 3457 pdep = (PDEPRULE)(void*)AVLBeginEnumTree((PPAVLNODECORE)(void*)&pdepTree, &EnumData, TRUE);3458 while (pdep != NULL)3459 {3460 if (!fWriteUpdatedOnly || pdep->fUpdated)3461 {3462 char *psz = pdep->pszRule;3463 3464 /* flush buffer? */3465 if (iBuffer + strlen(psz) + 20 >= sizeof(szBuffer))3466 {3467 fwrite(szBuffer, iBuffer, 1, phFile);3468 iBuffer = 0;3469 }3470 3471 /* write rule title as dependant */3472 iBuffer += sprintf(szBuffer + iBuffer,3473 " \\\n %s",psz);3474 }3475 3476 /* next rule */3477 pdep = (PDEPRULE)(void*)AVLGetNextNode(&EnumData);3478 }3479 3480 /* Add two new lines. Flush buffer first if necessary. */3481 if (iBuffer + CBNEWLINE*2 >= sizeof(szBuffer))3482 {3483 fwrite(szBuffer, iBuffer, 1, phFile);3484 iBuffer = 0;3485 }3486 3487 /* add 2 linefeeds */3488 strcpy(szBuffer + iBuffer, "\n\n");3489 iBuffer += CBNEWLINE*2;3490 }3491 3492 3493 3412 /* normal dependency output */ 3494 3413 pdep = (PDEPRULE)(void*)AVLBeginEnumTree((PPAVLNODECORE)(void*)&pdepTree, &EnumData, TRUE); … … 3502 3421 /* Write rule. Flush the buffer first if necessary. */ 3503 3422 cch = strlen(pdep->pszRule); 3504 if (iBuffer + cch + fQuoted * 2 + cchTS + 9 >= sizeof(szBuffer))3423 if (iBuffer + cch*2 + fQuoted * 2 + cchTS + 9 >= sizeof(szBuffer)) 3505 3424 { 3506 3425 fwrite(szBuffer, iBuffer, 1, phFile); … … 3515 3434 if (fQuoted) szBuffer[iBuffer++] = '"'; 3516 3435 strcpy(szBuffer + iBuffer, pdep->pszRule); 3517 iBuffer += cch;3436 iBuffer += depConvertName(szBuffer + iBuffer, sizeof(szBuffer) - iBuffer, FALSE); 3518 3437 if (fQuoted) szBuffer[iBuffer++] = '"'; 3519 3438 strcpy(szBuffer + iBuffer++, ":"); … … 3528 3447 fQuoted = strpbrk(*ppsz, " \t") != NULL; /* TODO/BUGBUG/FIXME: are there more special chars to look out for?? */ 3529 3448 cch = strlen(*ppsz); 3530 if (iBuffer + cch + fQuoted * 2 + 20 >= sizeof(szBuffer))3449 if (iBuffer + cch*2 + fQuoted * 2 + 20 >= sizeof(szBuffer)) 3531 3450 { 3532 3451 fwrite(szBuffer, iBuffer, 1, phFile); … … 3537 3456 if (fQuoted) szBuffer[iBuffer++] = '"'; 3538 3457 strcpy(szBuffer + iBuffer, *ppsz); 3539 iBuffer += cch;3458 iBuffer += depConvertName(szBuffer + iBuffer, sizeof(szBuffer) - iBuffer, FALSE); 3540 3459 if (fQuoted) szBuffer[iBuffer++] = '"'; 3541 3460 … … 3610 3529 * @param pszExt Extention (without '.') 3611 3530 * NULL if pszRulePath or pszRulePath and pszName contains the entire rule. 3612 */ 3613 void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, const char *pszTS) 3531 * @param fConvertName If set we'll convert from makefile name to realname. 3532 */ 3533 void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, const char *pszTS, BOOL fConvertName) 3614 3534 { 3615 3535 char szRule[CCHMAXPATH*2]; … … 3631 3551 cch += strlen(szRule + cch); 3632 3552 } 3633 3553 if (fConvertName) 3554 cch = depConvertName(szRule, sizeof(szRule), TRUE); 3634 3555 3635 3556 /* … … 3686 3607 3687 3608 3688 3689 3609 /** 3690 3610 * Adds a dependant to a rule. … … 3694 3614 * @param pszDep Pointer to dependant name 3695 3615 * @param fCheckCyclic When set we'll check that we're not creating an cyclic dependency. 3696 */ 3697 BOOL depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic) 3698 { 3699 PDEPRULE pdep = (PDEPRULE)pvRule; 3616 * @param fConvertName If set we'll convert from makefile name to realname. 3617 */ 3618 BOOL depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic, BOOL fConvertName) 3619 { 3620 PDEPRULE pdep = (PDEPRULE)pvRule; 3621 int cchDep; 3700 3622 3701 3623 if (pszDep[0] == '\0') … … 3727 3649 3728 3650 /* allocate string space and copy pszDep */ 3729 if ((pdep->papszDep[pdep->cDeps] = malloc(strlen(pszDep) + 1)) == NULL) 3651 cchDep = strlen(pszDep) + 1; 3652 if ((pdep->papszDep[pdep->cDeps] = malloc(cchDep)) == NULL) 3730 3653 { 3731 3654 fprintf(stderr, "error: out of memory, (line=%d)\n", __LINE__); … … 3734 3657 strcpy(pdep->papszDep[pdep->cDeps], pszDep); 3735 3658 3659 /* convert ^# and other stuff */ 3660 if (fConvertName) 3661 depConvertName(pdep->papszDep[pdep->cDeps], cchDep, TRUE); 3662 3736 3663 /* terminate array and increment dep count */ 3737 3664 pdep->papszDep[++pdep->cDeps] = NULL; … … 3739 3666 /* successful! */ 3740 3667 return TRUE; 3668 } 3669 3670 3671 /** 3672 * Converts to and from makefile filenames. 3673 * @returns New name length. 3674 * -1 on error. 3675 * @param pszName Double pointer to the string. 3676 * @param cchName Size of name buffer. 3677 * @param fFromMake TRUE: Convert from makefile name to real name. 3678 * FALSE: Convert from real name to makefile name. 3679 */ 3680 int depConvertName(char *pszName, int cchName, BOOL fFromMake) 3681 { 3682 int cchNewName = strlen(pszName); 3683 3684 if (cchNewName >= cchName) 3685 { 3686 fprintf(stderr, "error: buffer on input is too small, (line=%d)\n", __LINE__); 3687 return -1; 3688 } 3689 3690 if (fFromMake) 3691 { 3692 /* 3693 * Convert from makefile to real name. 3694 */ 3695 int iDisplacement = 0; 3696 3697 while (*pszName) 3698 { 3699 if ( *pszName == '^' 3700 || (*pszName == '$' && pszName[1] == '$')) 3701 { 3702 iDisplacement--; 3703 pszName++; 3704 cchNewName--; 3705 } 3706 if (iDisplacement) 3707 pszName[iDisplacement] = *pszName; 3708 pszName++; 3709 } 3710 pszName[iDisplacement] = '\0'; 3711 } 3712 else 3713 { 3714 /* 3715 * Convert real name to makefile name. 3716 */ 3717 while (*pszName) 3718 { 3719 if ( *pszName == '#' 3720 || *pszName == '!' 3721 || *pszName == '$' 3722 || *pszName == '@' 3723 || *pszName == '-' 3724 || *pszName == '^' 3725 || *pszName == '(' 3726 || *pszName == ')' 3727 || *pszName == '{' 3728 || *pszName == '}') 3729 { 3730 char * psz = pszName + strlen(pszName) + 1; 3731 if (++cchNewName >= cchName) 3732 { 3733 fprintf(stderr, "error: buffer too small, (line=%d)\n", __LINE__); 3734 return -1; 3735 } 3736 while (--psz > pszName) 3737 *psz = psz[-1]; 3738 *pszName++ = '^'; 3739 } 3740 pszName++; 3741 } 3742 } 3743 return cchNewName; 3741 3744 } 3742 3745
Note:
See TracChangeset
for help on using the changeset viewer.