Changeset 9070 for trunk/tools


Ignore:
Timestamp:
Aug 21, 2002, 3:51:56 AM (23 years ago)
Author:
bird
Message:

Bugfixing. Optimized checking of cyclic dependencies.

File:
1 edited

Legend:

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

    r9069 r9070  
    1 /* $Id: fastdep.c,v 1.38 2002-08-20 22:29:43 bird Exp $
     1/* $Id: fastdep.c,v 1.39 2002-08-21 01:51:56 bird Exp $
    22 *
    33 * Fast dependents. (Fast = Quick and Dirty!)
     
    245245static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, const char *pszTS, BOOL fConvertName);
    246246static BOOL  depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic, BOOL fConvertName);
    247 static int   depConvertName(char *pszName, int cchName, BOOL fFromMake);
     247static int   depNameToReal(char *pszName);
     248static int   depNameToMake(char *pszName, int cchName, const char *pszSrc);
    248249static void  depMarkNotFound(void *pvRule);
    249250static BOOL  depCheckCyclic(PDEPRULE pdepRule, const char *pszDep);
     
    860861{
    861862    printf(
    862         "FastDep v0.44 (build %d)\n"
     863        "FastDep v0.45 (build %d)\n"
    863864        "Dependency scanner. Creates a makefile readable depend file.\n"
    864865        " - was quick and dirty, now it's just quick -\n"
     
    34213422                /* Write rule. Flush the buffer first if necessary. */
    34223423                cch = strlen(pdep->pszRule);
    3423                 if (iBuffer + cch*2 + fQuoted * 2 + cchTS + 9 >= sizeof(szBuffer))
     3424                if (iBuffer + cch*3 + fQuoted * 2 + cchTS + 9 >= sizeof(szBuffer))
    34243425                {
    34253426                    fwrite(szBuffer, iBuffer, 1, phFile);
     
    34333434
    34343435                if (fQuoted) szBuffer[iBuffer++] = '"';
    3435                 strcpy(szBuffer + iBuffer, pdep->pszRule);
    3436                 iBuffer += depConvertName(szBuffer + iBuffer, sizeof(szBuffer) - iBuffer, FALSE);
     3436                iBuffer += depNameToMake(szBuffer + iBuffer, sizeof(szBuffer) - iBuffer, pdep->pszRule);
    34373437                if (fQuoted) szBuffer[iBuffer++] = '"';
    34383438                strcpy(szBuffer + iBuffer++, ":");
     
    34473447                        fQuoted = strpbrk(*ppsz, " \t") != NULL; /* TODO/BUGBUG/FIXME: are there more special chars to look out for?? */
    34483448                        cch = strlen(*ppsz);
    3449                         if (iBuffer + cch*2 + fQuoted * 2 + 20 >= sizeof(szBuffer))
     3449                        if (iBuffer + cch*3 + fQuoted * 2 + 20 >= sizeof(szBuffer))
    34503450                        {
    34513451                            fwrite(szBuffer, iBuffer, 1, phFile);
     
    34553455                        iBuffer += 7;
    34563456                        if (fQuoted) szBuffer[iBuffer++] = '"';
    3457                         strcpy(szBuffer + iBuffer, *ppsz);
    3458                         iBuffer += depConvertName(szBuffer + iBuffer, sizeof(szBuffer) - iBuffer, FALSE);
     3457                        iBuffer += depNameToMake(szBuffer + iBuffer, sizeof(szBuffer) - iBuffer, *ppsz);
    34593458                        if (fQuoted) szBuffer[iBuffer++] = '"';
    34603459
     
    35523551    }
    35533552    if (fConvertName)
    3554         cch = depConvertName(szRule, sizeof(szRule), TRUE);
     3553        cch = depNameToReal(szRule);
    35553554
    35563555    /*
     
    36593658    /* convert ^# and other stuff */
    36603659    if (fConvertName)
    3661         depConvertName(pdep->papszDep[pdep->cDeps], cchDep, TRUE);
     3660        depNameToReal(pdep->papszDep[pdep->cDeps]);
    36623661
    36633662    /* terminate array and increment dep count */
     
    36703669
    36713670/**
    3672  * Converts to and from makefile filenames.
     3671 * Converts from makefile filename to real filename.
    36733672 * @returns New name length.
    3674  *          -1 on error.
    3675  * @param   pszName     Double pointer to the string.
     3673 * @param   pszName     Pointer to the string to make real.
     3674 */
     3675int depNameToReal(char *pszName)
     3676{
     3677    int cchNewName = strlen(pszName);
     3678    int iDisplacement = 0;
     3679
     3680    /*
     3681     * Look for '^' and '$$'.
     3682     */
     3683    while (*pszName)
     3684    {
     3685        if (    *pszName == '^'
     3686            ||  (*pszName == '$' && pszName[1] == '$'))
     3687        {
     3688            iDisplacement--;
     3689            pszName++;
     3690            cchNewName--;
     3691        }
     3692        if (iDisplacement)
     3693            pszName[iDisplacement] = *pszName;
     3694        pszName++;
     3695    }
     3696    pszName[iDisplacement] = '\0';
     3697
     3698    return cchNewName;
     3699}
     3700
     3701
     3702/**
     3703 * Converts from real filename to makefile filename.
     3704 * @returns New name length.
     3705 * @param   pszName     Output name buffer.
    36763706 * @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)
     3707 * @param   pszSrc      Input name.
     3708 */
     3709int   depNameToMake(char *pszName, int cchName, const char *pszSrc)
     3710{
     3711    char *pszNameOrg = pszName;
     3712
     3713    /*
     3714     * Convert real name to makefile name.
     3715     */
     3716    while (*pszSrc)
     3717    {
     3718        if (    *pszSrc == '#'
     3719            ||  *pszSrc == '!'
     3720            ||  (*pszSrc == '$' && pszSrc[1] != '(')
     3721            ||  *pszSrc == '@'
     3722            ||  *pszSrc == '-'
     3723            ||  *pszSrc == '^'
     3724           /* ||  *pszSrc == '('
     3725            ||  *pszSrc == ')'
     3726            ||  *pszSrc == '{'
     3727            ||  *pszSrc == '}'*/)
    36983728        {
    3699             if (    *pszName == '^'
    3700                 ||  (*pszName == '$' && pszName[1] == '$'))
    3701             {
    3702                 iDisplacement--;
    3703                 pszName++;
    3704                 cchNewName--;
    3705             }
    3706             if (iDisplacement)
    3707                 pszName[iDisplacement] = *pszName;
    3708             pszName++;
     3729            if (!cchName--)
     3730            {
     3731                fprintf(stderr, "error: buffer too small, (line=%d)\n", __LINE__);
     3732                return pszName - pszNameOrg + strlen(pszName);
     3733            }
     3734            *pszName++ = '^';
    37093735        }
    3710         pszName[iDisplacement] = '\0';
    3711     }
    3712     else
    3713     {
    3714         /*
    3715          * Convert real name to makefile name.
    3716          */
    3717         while (*pszName)
     3736        if (!cchName--)
    37183737        {
    3719             if (    *pszName == '#'
    3720                 ||  *pszName == '!'
    3721                 ||  (*pszName == '$' && pszName[1] != '(')
    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++;
     3738            fprintf(stderr, "error: buffer too small, (line=%d)\n", __LINE__);
     3739            return pszName - pszNameOrg + strlen(pszName);
    37413740        }
    3742     }
    3743     return cchNewName;
    3744 }
     3741        *pszName++ = *pszSrc++;
     3742    }
     3743    *pszName = '\0';
     3744
     3745    return pszName - pszNameOrg;
     3746}
     3747
    37453748
    37463749
     
    37573760
    37583761/**
    3759  * Checks if adding this dependent will create a cylic dependency.
     3762 * Checks if adding this dependent will create a cyclic dependency.
    37603763 * @returns   TRUE: Cyclic.
    37613764 *            FALSE: Non-cylic.
     
    37653768BOOL depCheckCyclic(PDEPRULE pdepRule, const char *pszDep)
    37663769{
     3770#define DEPTH_FIRST 1
     3771#ifdef DEPTH_FIRST
    37673772    #define DEPTH 32
    3768     char *   pszRule = pdepRule->pszRule;
    3769     char **  appsz[DEPTH];
     3773#else
     3774    #define DEPTH 128
     3775#endif
     3776    #define HISTORY 256
     3777    char *  pszRule = pdepRule->pszRule;
     3778    char ** appsz[DEPTH];
     3779#if HISTORY
     3780    char *  apszHistory[HISTORY];
     3781    int     iHistory;
     3782    int     j;
     3783#endif
    37703784    PDEPRULE pdep;
    3771     int      i;
     3785    int     i;
    37723786
    37733787    /* self check */
     
    37803794        return FALSE; /* no rule, or no dependents, not cyclic */
    37813795
    3782     i = 0;
     3796    i = 1;
    37833797    appsz[0] = pdep->papszDep;
    3784     while (i >= 0)
    3785     {
    3786         register char **  ppsz = appsz[i];
     3798#ifdef HISTORY
     3799    iHistory = 1;
     3800    apszHistory[0] = pdep->pszRule;
     3801#endif
     3802    while (i > 0)
     3803    {
     3804        /* pop off element */
     3805        register char **  ppsz = appsz[--i];
    37873806
    37883807        while (*ppsz != NULL)
     
    37983817                if (i >= DEPTH)
    37993818                {
    3800                     fprintf(stderr, "error: too deap chain (%d). pszRule=%s  pszDep=%s\n",
     3819                    fprintf(stderr, "error: too deep chain (%d). pszRule=%s  pszDep=%s\n",
    38013820                            i, pszRule, pszDep);
    38023821                    return FALSE;
    38033822                }
    3804                 appsz[i++] = ppsz; /* save next */
    3805                 ppsz = pdep->papszDep; /* start processing new node */
     3823#ifdef HISTORY
     3824                /*
     3825                 * Check if in history, if so we'll skip it.
     3826                 */
     3827                for (j = 0;  j < iHistory; j++)
     3828                    if (!strcmp(apszHistory[j], pdep->pszRule))
     3829                        break;
     3830                if (j != iHistory)
     3831                    continue;
     3832
     3833                /*
     3834                 * Push into history - might concider make this binary sorted one day.
     3835                 */
     3836                if (iHistory < HISTORY)
     3837                    apszHistory[iHistory++] = pdep->pszRule;
     3838#endif
     3839                /*
     3840                 * Push on to the stack.
     3841                 */
     3842                #ifdef DEPTH_FIRST
     3843                /* dept first */
     3844                appsz[i++] = ppsz;      /* save current posistion */
     3845                ppsz = pdep->papszDep;  /* process new node */
     3846                #else
     3847                /* complete current node first. */
     3848                appsz[i++] = pdep->papszDep;
     3849                #endif
    38063850            }
    38073851        }
    3808 
    3809         /* pop stack */
    3810         i--;
    38113852    }
    38123853
Note: See TracChangeset for help on using the changeset viewer.