Changeset 9058 for trunk/tools


Ignore:
Timestamp:
Aug 20, 2002, 8:16:20 PM (23 years ago)
Author:
bird
Message:

Removed superdep. Special chars.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/fastdep/fastdep.c

    r8083 r9058  
    1 /* $Id: fastdep.c,v 1.36 2002-03-14 13:31:10 bird Exp $
     1/* $Id: fastdep.c,v 1.37 2002-08-20 18:16:20 bird Exp $
    22 *
    33 * Fast dependents. (Fast = Quick and Dirty!)
     
    55 * Copyright (c) 1999-2002 knut st. osmundsen (bird@anduin.net)
    66 *
    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
    108 *
    119 */
     
    134132    BOOL            fCacheSearchDirs;   /* cache entire search dirs. */
    135133    const char *    pszExcludeFiles;    /* List of excluded files. */
    136     const char *    pszSuperDependency; /* Name for super dependency rule. */
    137134    BOOL            fForceScan;         /* Force scan of all files. */
    138135} OPTIONS, *POPTIONS;
     
    246243static BOOL  depWriteFile(const char *pszFilename, BOOL fWriteUpdatedOnly);
    247244static 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);
     245static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, const char *pszTS, BOOL fConvertName);
     246static BOOL  depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic, BOOL fConvertName);
     247static int   depConvertName(char *pszName, int cchName, BOOL fFromMake);
    250248static void  depMarkNotFound(void *pvRule);
    251249static BOOL  depCheckCyclic(PDEPRULE pdepRule, const char *pszDep);
     
    359357    TRUE,            /* fCacheSearchDirs */
    360358    szExcludeFiles,  /* pszExcludeFiles */
    361     NULL,            /* pszSuperDependency */
    362359    FALSE            /* fForceScan */
    363360};
    364 
    365361
    366362
     
    693689                    break;
    694690
    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                         else
    702                         {
    703                             argi++;
    704                             if (argi < argc)
    705                                 /* take next parameter */
    706                                 options.pszSuperDependency = argv[argi];
    707                             else
    708                                 /* take default */
    709                                 options.pszSuperDependency = "alltargets";
    710                         }
    711                     }
    712                     break;
    713 
    714691                case 'h':
    715692                case 'H':
     
    883860{
    884861    printf(
    885         "FastDep v0.42 (build %d)\n"
     862        "FastDep v0.43 (build %d)\n"
    886863        "Dependency scanner. Creates a makefile readable depend file.\n"
    887864        " - was quick and dirty, now it's just quick -\n"
     
    917894        "                   -obr-: No object rule, rule for source filename is generated.\n"
    918895        "   -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"
    924896        "   -r[ ]<rsrcext>  Resource binary extention.            Default: res\n"
    925897        "   -x[ ]<f1[;f2]>  Files to exclude. Only exact filenames.\n"
     
    10301002    {
    10311003        if (options.fNoObjectPath)
    1032             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS);
     1004            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS, FALSE);
    10331005        else
    10341006            pvRule = depAddRule(options.fObjectDir ?
     
    10361008                                    filePathSlash(pszFilename, szBuffer),
    10371009                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    1038                                 options.pszObjectExt,
    1039                                 pszTS);
     1010                                options.pszObjectExt, pszTS, FALSE);
    10401011
    10411012        if (options.fSrcWhenObj && pvRule)
     
    10431014                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
    10441015                            fileName(pszFilename, szBuffer) : pszNormFilename,
    1045                          options.fCheckCyclic);
     1016                         options.fCheckCyclic,
     1017                         FALSE);
    10461018    }
    10471019    else
    10481020        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);
    10501022
    10511023    /* duplicate rule? */
     
    11671139                        {   /* #include <sys/stats.h> makes trouble, check for '/' and '\'. */
    11681140                            if (!strchr(szFullname, '/') && !strchr(szFullname, '\\'))
    1169                                 depAddDepend(pvRule, szFullname, options.fCheckCyclic);
     1141                                depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE);
    11701142                            else
    11711143                                fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n",
     
    11731145                        }
    11741146                        else
    1175                             depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
     1147                            depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE);
    11761148                    }
    11771149                    else
     
    13251297    {
    13261298        if (options.fNoObjectPath)
    1327             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS);
     1299            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS, FALSE);
    13281300        else
    13291301            pvRule = depAddRule(options.fObjectDir ?
     
    13311303                                    filePathSlash(pszFilename, szBuffer),
    13321304                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    1333                                 options.pszObjectExt,
    1334                                 pszTS);
     1305                                options.pszObjectExt, pszTS, FALSE);
    13351306
    13361307        if (options.fSrcWhenObj && pvRule)
     
    13381309                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
    13391310                            fileName(pszFilename, szBuffer) : pszNormFilename,
    1340                          options.fCheckCyclic);
     1311                         options.fCheckCyclic, FALSE);
    13411312    }
    13421313    else
    13431314        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);
    13451316
    13461317    /* duplicate rule? */
     
    14181389                {   /* include sys/stats.inc makes trouble, check for '/' and '\'. */
    14191390                    if (!strchr(szFullname, '/') && !strchr(szFullname, '\\'))
    1420                         depAddDepend(pvRule, szFullname, options.fCheckCyclic);
     1391                        depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE);
    14211392                    else
    14221393                        fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n",
     
    14241395                }
    14251396                else
    1426                     depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
     1397                    depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE);
    14271398            }
    14281399            else
     
    14691440    {
    14701441        if (options.fNoObjectPath)
    1471             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, pszTS);
     1442            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, pszTS, FALSE);
    14721443        else
    14731444            pvRule = depAddRule(options.fObjectDir ?
     
    14751446                                    filePathSlash(pszFilename, szBuffer),
    14761447                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    1477                                 options.pszRsrcExt,
    1478                                 pszTS);
     1448                                options.pszRsrcExt, pszTS, FALSE);
    14791449
    14801450        if (options.fSrcWhenObj && pvRule)
     
    14821452                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
    14831453                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
    1484                          options.fCheckCyclic);
     1454                         options.fCheckCyclic,
     1455                         FALSE);
    14851456    }
    14861457    else
    14871458        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);
    14901460
    14911461    /* duplicate rule? */
     
    15921562                {   /* #include <sys/stats.h> makes trouble, check for '/' and '\'. */
    15931563                    if (!strchr(szFullname, '/') && !strchr(szFullname, '\\'))
    1594                         depAddDepend(pvRule, szFullname, options.fCheckCyclic);
     1564                        depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE);
    15951565                    else
    15961566                        fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n",
     
    15981568                }
    15991569                else
    1600                     depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
     1570                    depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE);
    16011571            }
    16021572            else
     
    16431613    {
    16441614        if (options.fNoObjectPath)
    1645             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, pszTS);
     1615            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, pszTS, FALSE);
    16461616        else
    16471617            pvRule = depAddRule(options.fObjectDir ?
     
    16491619                                    filePathSlash(pszFilename, szBuffer),
    16501620                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    1651                                 options.pszRsrcExt,
    1652                                 pszTS);
     1621                                options.pszRsrcExt, pszTS, FALSE);
    16531622
    16541623        if (options.fSrcWhenObj && pvRule)
     
    16561625                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
    16571626                            fileName(pszFilename, szBuffer) : pszNormFilename,
    1658                          options.fCheckCyclic);
     1627                         options.fCheckCyclic,
     1628                         FALSE);
    16591629    }
    16601630    else
    16611631        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);
    16631633
    16641634    /* duplicate rule? */
     
    17761746                        {   /* #include <sys/stats.h> makes trouble, check for '/' and '\'. */
    17771747                            if (!strchr(szFullname, '/') && !strchr(szFullname, '\\'))
    1778                                 depAddDepend(pvRule, szFullname, options.fCheckCyclic);
     1748                                depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE);
    17791749                            else
    17801750                                fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n",
     
    17821752                        }
    17831753                        else
    1784                             depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
     1754                            depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE);
    17851755                    }
    17861756                    else
     
    19001870            /* Add filename to the dependencies. */
    19011871            if (i1)
    1902                 depAddDepend(pvRule, pszFile, options.fCheckCyclic);
     1872                depAddDepend(pvRule, pszFile, options.fCheckCyclic, FALSE);
    19031873            else
    19041874            {
     
    19151885                    {   /* #include <sys/stats.h> makes trouble, check for '/' and '\'. */
    19161886                        if (!strchr(pszFile, '/') && !strchr(pszFile, '\\'))
    1917                             depAddDepend(pvRule, pszFile, options.fCheckCyclic);
     1887                            depAddDepend(pvRule, pszFile, options.fCheckCyclic, FALSE);
    19181888                        else
    19191889                            fprintf(stderr, "%s(%d): warning include '%s' is ignored.\n",
     
    19211891                    }
    19221892                    else
    1923                         depAddDepend(pvRule, szFullname, options.fCheckCyclic);
     1893                        depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE);
    19241894                }
    19251895                else
     
    20051975    {
    20061976        if (options.fNoObjectPath)
    2007             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS);
     1977            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS, FALSE);
    20081978        else
    20091979            pvRule = depAddRule(options.fObjectDir ?
     
    20111981                                    filePathSlash(pszFilename, szBuffer),
    20121982                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    2013                                 options.pszObjectExt,
    2014                                 pszTS);
     1983                                options.pszObjectExt, pszTS, FALSE);
    20151984
    20161985        if (options.fSrcWhenObj && pvRule)
     
    20181987                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename)
    20191988                            ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
    2020                          options.fCheckCyclic);
     1989                         options.fCheckCyclic,
     1990                         FALSE);
    20211991    }
    20221992    else
    20231993        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);
    20251995
    20261996    /* duplicate rule? */
     
    21332103            {
    21342104                if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer))
    2135                     depAddDepend(pvRule, szFullname, options.fCheckCyclic);
     2105                    depAddDepend(pvRule, szFullname, options.fCheckCyclic, FALSE);
    21362106                else
    2137                     depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
     2107                    depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE);
    21382108            }
    21392109            else
     
    21812151    {
    21822152        if (options.fNoObjectPath)
    2183             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS);
     2153            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, pszTS, FALSE);
    21842154        else
    21852155            pvRule = depAddRule(options.fObjectDir ?
     
    21872157                                    filePathSlash(pszFilename, szBuffer),
    21882158                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    2189                                 options.pszObjectExt,
    2190                                 pszTS);
     2159                                options.pszObjectExt, pszTS, FALSE);
    21912160
    21922161        if (options.fSrcWhenObj && pvRule)
     
    21942163                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename)
    21952164                            ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
    2196                          options.fCheckCyclic);
     2165                         options.fCheckCyclic,
     2166                         FALSE);
    21972167    }
    21982168    else */
    21992169        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);
    22012171
    22022172    /* duplicate rule? */
     
    22742244            {
    22752245                if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer))
    2276                     depAddDepend(pvRule, fileName(szFullname, szBuffer), options.fCheckCyclic);
     2246                    depAddDepend(pvRule, fileName(szFullname, szBuffer), options.fCheckCyclic, FALSE);
    22772247                else
    2278                     depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
     2248                    depAddDepend(pvRule, szBuffer, options.fCheckCyclic, FALSE);
    22792249            }
    22802250            else
     
    22892259    textbufferDestroy(pvFile);
    22902260
     2261    fHeader = fHeader;
    22912262    return 0;
    22922263}
    2293 
    2294 
    22952264
    22962265
     
    26292598    return TRUE;
    26302599}
    2631 
    26322600
    26332601
     
    28802848
    28812849
    2882 
    28832850/**
    28842851 * Checks if the given filename may exist within any of the given paths.
     
    30202987    return cb;
    30212988}
    3022 
    30232989
    30242990
     
    33703336
    33713337                        psz[i] = '\0';
    3372                         pvRule = depAddRule(trimQuotes(trimR(psz)), NULL, NULL, szTS);
     3338                        pvRule = depAddRule(trimQuotes(trimR(psz)), NULL, NULL, szTS, TRUE);
    33733339                        if (pvRule)
    33743340                            ((PDEPRULE)pvRule)->fUpdated = fAppend;
     
    34003366                psz = trimQuotes(trim(psz));
    34013367                if (*psz != '\0')
    3402                     depAddDepend(pvRule, psz, options.fCheckCyclic);
     3368                    depAddDepend(pvRule, psz, options.fCheckCyclic, TRUE);
    34033369            }
    34043370        }
     
    34253391        AVLENUMDATA EnumData;
    34263392        PDEPRULE    pdep;
    3427         char        szBuffer[32678];
     3393        static char szBuffer[0x10000];
    34283394        int         iBuffer = 0;
    34293395        int         cch;
     
    34443410              phFile);
    34453411
    3446 
    3447         /* @@@PH 2001-03-01
    3448          * If option is selected to generate a parent
    3449          * "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 
    34933412        /* normal dependency output */
    34943413        pdep = (PDEPRULE)(void*)AVLBeginEnumTree((PPAVLNODECORE)(void*)&pdepTree, &EnumData, TRUE);
     
    35023421                /* Write rule. Flush the buffer first if necessary. */
    35033422                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))
    35053424                {
    35063425                    fwrite(szBuffer, iBuffer, 1, phFile);
     
    35153434                if (fQuoted) szBuffer[iBuffer++] = '"';
    35163435                strcpy(szBuffer + iBuffer, pdep->pszRule);
    3517                 iBuffer += cch;
     3436                iBuffer += depConvertName(szBuffer + iBuffer, sizeof(szBuffer) - iBuffer, FALSE);
    35183437                if (fQuoted) szBuffer[iBuffer++] = '"';
    35193438                strcpy(szBuffer + iBuffer++, ":");
     
    35283447                        fQuoted = strpbrk(*ppsz, " \t") != NULL; /* TODO/BUGBUG/FIXME: are there more special chars to look out for?? */
    35293448                        cch = strlen(*ppsz);
    3530                         if (iBuffer + cch + fQuoted * 2 + 20 >= sizeof(szBuffer))
     3449                        if (iBuffer + cch*2 + fQuoted * 2 + 20 >= sizeof(szBuffer))
    35313450                        {
    35323451                            fwrite(szBuffer, iBuffer, 1, phFile);
     
    35373456                        if (fQuoted) szBuffer[iBuffer++] = '"';
    35383457                        strcpy(szBuffer + iBuffer, *ppsz);
    3539                         iBuffer += cch;
     3458                        iBuffer += depConvertName(szBuffer + iBuffer, sizeof(szBuffer) - iBuffer, FALSE);
    35403459                        if (fQuoted) szBuffer[iBuffer++] = '"';
    35413460
     
    36103529 * @param     pszExt        Extention (without '.')
    36113530 *                          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 */
     3533void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, const char *pszTS, BOOL fConvertName)
    36143534{
    36153535    char     szRule[CCHMAXPATH*2];
     
    36313551        cch += strlen(szRule + cch);
    36323552    }
    3633 
     3553    if (fConvertName)
     3554        cch = depConvertName(szRule, sizeof(szRule), TRUE);
    36343555
    36353556    /*
     
    36863607
    36873608
    3688 
    36893609/**
    36903610 * Adds a dependant to a rule.
     
    36943614 * @param     pszDep        Pointer to dependant name
    36953615 * @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 */
     3618BOOL  depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic, BOOL fConvertName)
     3619{
     3620    PDEPRULE    pdep = (PDEPRULE)pvRule;
     3621    int         cchDep;
    37003622
    37013623    if (pszDep[0] == '\0')
     
    37273649
    37283650    /* 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)
    37303653    {
    37313654        fprintf(stderr, "error: out of memory, (line=%d)\n", __LINE__);
     
    37343657    strcpy(pdep->papszDep[pdep->cDeps], pszDep);
    37353658
     3659    /* convert ^# and other stuff */
     3660    if (fConvertName)
     3661        depConvertName(pdep->papszDep[pdep->cDeps], cchDep, TRUE);
     3662
    37363663    /* terminate array and increment dep count */
    37373664    pdep->papszDep[++pdep->cDeps] = NULL;
     
    37393666    /* successful! */
    37403667    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 */
     3680int 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;
    37413744}
    37423745
Note: See TracChangeset for help on using the changeset viewer.