Changeset 6866 for trunk/tools


Ignore:
Timestamp:
Sep 30, 2001, 2:22:05 AM (24 years ago)
Author:
bird
Message:

Corrected quoted include behaviour. Made it cleanup deleted files. Some buffers was increased.

File:
1 edited

Legend:

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

    r6632 r6866  
    1 /* $Id: fastdep.c,v 1.30 2001-09-04 13:48:29 bird Exp $
     1/* $Id: fastdep.c,v 1.31 2001-09-30 00:22:05 bird Exp $
    22 *
    33 * Fast dependents. (Fast = Quick and Dirty!)
     
    163163    int             cDeps;              /* Entries in the dependant array. */
    164164    char **         papszDep;           /* Pointer to an array of pointers to dependants. */
    165     BOOL            fUpdated;           /* If we have updated this entry during current run. */
     165    BOOL            fUpdated;           /* If we have updated this entry during the run. */
    166166    char            szTS[TS_SIZE];      /* Time stamp. */
    167167} DEPRULE, *PDEPRULE;
     
    234234
    235235/* depend workers */
    236 static BOOL  depReadFile(const char *pszFilename);
    237 static BOOL  depWriteFile(const char *pszFilename);
     236static BOOL  depReadFile(const char *pszFilename, BOOL fAppend);
     237static BOOL  depWriteFile(const char *pszFilename, BOOL fWriteUpdatedOnly);
    238238static void  depRemoveAll(void);
    239239static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, const char *pszTS);
     
    462462                    if (pdepTree != NULL && pszOld != pszDepFile)
    463463                    {
    464                         if (!depWriteFile(pszOld))
     464                        if (!depWriteFile(pszOld, !options.fAppend))
    465465                            fprintf(stderr, "error: failed to write (flush) dependencies.\n");
    466466                        depRemoveAll();
     
    779779             */
    780780            if (pdepTree == NULL && (options.fAppend || !options.fForceScan))
    781                 depReadFile(pszDepFile);
     781                depReadFile(pszDepFile, options.fAppend);
    782782
    783783            /*
     
    849849
    850850    /* Write the depend file! */
    851     if (!depWriteFile(pszDepFile))
     851    if (!depWriteFile(pszDepFile, !options.fAppend))
    852852        fprintf(stderr, "error: failed to write dependencies file!\n");
    853853    #if 0
     
    10021002                                         */
    10031003    } achIfStack[256];
    1004 
     1004    char    szSrcDir[CCHMAXPATH];
     1005    filePath(pszNormFilename, szSrcDir);/* determin source code directory. */
    10051006
    10061007    /**********************************/
     
    11051106                if (achIfStack[iIfStack].fIncluded)
    11061107                {
    1107                     char szFullname[CCHMAXPATH];
    1108                     char *psz;
    1109                     BOOL f = FALSE;
    1110                     int  j;
     1108                    char    szFullname[CCHMAXPATH];
     1109                    char *  psz;
     1110                    BOOL    f = FALSE;
     1111                    int     j;
     1112                    BOOL    fQuote;
    11111113
    11121114                    /* extract info between "" or <> */
    11131115                    while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<')))
    11141116                        i++;
     1117                    fQuote = szBuffer[i] == '"';
    11151118                    i++; /* skip '"' or '<' */
    11161119
     
    11331136
    11341137                    /* find include file! */
    1135                     psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer);
     1138                    psz = fQuote ? pathlistFindFile(szSrcDir, szFullname, szBuffer) : NULL;
     1139                    if (psz == NULL)
     1140                        psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer);
    11361141                    if (psz == NULL)
    11371142                        psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer);
     
    24462451    char            szDir[CCHMAXPATH];
    24472452    int             cchDir;
    2448     char            achBuffer[16384];
     2453    char            achBuffer[32768];
    24492454    PFILEFINDBUF3   pfindbuf3 = (PFILEFINDBUF3)(void*)&achBuffer[0];
    24502455    HDIR            hDir = HDIR_CREATE;
     
    30323037 * This will update the date in the option struct.
    30333038 */
    3034 BOOL  depReadFile(const char *pszFilename)
     3039BOOL  depReadFile(const char *pszFilename, BOOL fAppend)
    30353040{
    30363041    void *      pvFile;
     
    31163121                        psz[i] = '\0';
    31173122                        pvRule = depAddRule(trimQuotes(trimR(psz)), NULL, NULL, szTS);
    3118                         ((PDEPRULE)pvRule)->fUpdated = FALSE;
     3123                        ((PDEPRULE)pvRule)->fUpdated = fAppend;
    31193124                        psz += i + 1;
    31203125                        cch -= i + 1;
     
    31583163 *
    31593164 * @returns   Success indicator.
    3160  * @params    pszFilename  Pointer to name of the output file.
    3161  */
    3162 BOOL  depWriteFile(const char *pszFilename)
     3165 * @param     pszFilename           Pointer to name of the output file.
     3166 * @param     fWriteUpdatedOnly     If set we'll only write updated rules.
     3167 */
     3168BOOL  depWriteFile(const char *pszFilename, BOOL fWriteUpdatedOnly)
    31633169{
    31643170    FILE *phFile;
     
    31683174        AVLENUMDATA EnumData;
    31693175        PDEPRULE    pdep;
    3170         char        szBuffer[4096];
     3176        char        szBuffer[32678];
    31713177        int         iBuffer = 0;
    31723178        int         cch;
     
    32013207            while (pdep != NULL)
    32023208            {
    3203                 char *psz = pdep->pszRule;
    3204 
    3205                 /* flush buffer? */
    3206                 if (iBuffer + strlen(psz) + 20 >= sizeof(szBuffer))
     3209                if (!fWriteUpdatedOnly || pdep->fUpdated)
     3210                {
     3211                    char *psz = pdep->pszRule;
     3212
     3213                    /* flush buffer? */
     3214                    if (iBuffer + strlen(psz) + 20 >= sizeof(szBuffer))
     3215                    {
     3216                        fwrite(szBuffer, iBuffer, 1, phFile);
     3217                        iBuffer = 0;
     3218                    }
     3219
     3220                    /* write rule title as dependant */
     3221                    iBuffer += sprintf(szBuffer + iBuffer,
     3222                                       " \\\n    %s",psz);
     3223                }
     3224
     3225                /* next rule */
     3226                pdep = (PDEPRULE)(void*)AVLGetNextNode(&EnumData);
     3227            }
     3228
     3229            /* Add two new lines. Flush buffer first if necessary. */
     3230            if (iBuffer + CBNEWLINE*2 >= sizeof(szBuffer))
     3231            {
     3232                fwrite(szBuffer, iBuffer, 1, phFile);
     3233                iBuffer = 0;
     3234            }
     3235
     3236            /* add 2 linefeeds */
     3237            strcpy(szBuffer + iBuffer, "\n\n");
     3238            iBuffer += CBNEWLINE*2;
     3239        }
     3240
     3241
     3242        /* normal dependency output */
     3243        pdep = (PDEPRULE)(void*)AVLBeginEnumTree((PPAVLNODECORE)(void*)&pdepTree, &EnumData, TRUE);
     3244        while (pdep != NULL)
     3245        {
     3246            if (!fWriteUpdatedOnly || pdep->fUpdated)
     3247            {
     3248                int cchTS = strlen(pdep->szTS);
     3249                int fQuoted = strpbrk(pdep->pszRule, " \t") != NULL; /* TODO/BUGBUG/FIXME: are there more special chars to look out for?? */
     3250
     3251                /* Write rule. Flush the buffer first if necessary. */
     3252                cch = strlen(pdep->pszRule);
     3253                if (iBuffer + cch + fQuoted * 2 + cchTS + 9 >= sizeof(szBuffer))
    32073254                {
    32083255                    fwrite(szBuffer, iBuffer, 1, phFile);
     
    32103257                }
    32113258
    3212                 /* write rule title as dependant */
    3213                 iBuffer += sprintf(szBuffer + iBuffer,
    3214                                    " \\\n    %s",psz);
    3215 
    3216                 /* next rule */
    3217                 pdep = (PDEPRULE)(void*)AVLGetNextNode(&EnumData);
    3218             }
    3219 
    3220             /* Add two new lines. Flush buffer first if necessary. */
    3221             if (iBuffer + CBNEWLINE*2 >= sizeof(szBuffer))
    3222             {
    3223                 fwrite(szBuffer, iBuffer, 1, phFile);
    3224                 iBuffer = 0;
    3225             }
    3226 
    3227             /* add 2 linefeeds */
    3228             strcpy(szBuffer + iBuffer, "\n\n");
    3229             iBuffer += CBNEWLINE*2;
    3230         }
    3231 
    3232 
    3233         /* normal dependency output */
    3234         pdep = (PDEPRULE)(void*)AVLBeginEnumTree((PPAVLNODECORE)(void*)&pdepTree, &EnumData, TRUE);
    3235         while (pdep != NULL)
    3236         {
    3237             int cchTS = strlen(pdep->szTS);
    3238             int fQuoted = strpbrk(pdep->pszRule, " \t") != NULL; /* TODO/BUGBUG/FIXME: are there more special chars to look out for?? */
    3239 
    3240             /* Write rule. Flush the buffer first if necessary. */
    3241             cch = strlen(pdep->pszRule);
    3242             if (iBuffer + cch + fQuoted * 2 + cchTS + 9 >= sizeof(szBuffer))
    3243             {
    3244                 fwrite(szBuffer, iBuffer, 1, phFile);
    3245                 iBuffer = 0;
    3246             }
    3247 
    3248             memcpy(szBuffer + iBuffer, "# ", 2);
    3249             memcpy(szBuffer + iBuffer + 2, pdep->szTS, cchTS);
    3250             iBuffer += cchTS + 2;
    3251             szBuffer[iBuffer++] = '\n';
    3252 
    3253             if (fQuoted) szBuffer[iBuffer++] = '"';
    3254             strcpy(szBuffer + iBuffer, pdep->pszRule);
    3255             iBuffer += cch;
    3256             if (fQuoted) szBuffer[iBuffer++] = '"';
    3257             strcpy(szBuffer + iBuffer++, ":");
    3258 
    3259             /* write rule dependants. */
    3260             if (pdep->papszDep != NULL)
    3261             {
    3262                 char **ppsz = pdep->papszDep;
    3263                 while (*ppsz != NULL)
     3259                memcpy(szBuffer + iBuffer, "# ", 2);
     3260                memcpy(szBuffer + iBuffer + 2, pdep->szTS, cchTS);
     3261                iBuffer += cchTS + 2;
     3262                szBuffer[iBuffer++] = '\n';
     3263
     3264                if (fQuoted) szBuffer[iBuffer++] = '"';
     3265                strcpy(szBuffer + iBuffer, pdep->pszRule);
     3266                iBuffer += cch;
     3267                if (fQuoted) szBuffer[iBuffer++] = '"';
     3268                strcpy(szBuffer + iBuffer++, ":");
     3269
     3270                /* write rule dependants. */
     3271                if (pdep->papszDep != NULL)
    32643272                {
    3265                     /* flush buffer? */
    3266                     fQuoted = strpbrk(*ppsz, " \t") != NULL; /* TODO/BUGBUG/FIXME: are there more special chars to look out for?? */
    3267                     cch = strlen(*ppsz);
    3268                     if (iBuffer + cch + fQuoted * 2 + 20 >= sizeof(szBuffer))
     3273                    char **ppsz = pdep->papszDep;
     3274                    while (*ppsz != NULL)
    32693275                    {
    3270                         fwrite(szBuffer, iBuffer, 1, phFile);
    3271                         iBuffer = 0;
     3276                        /* flush buffer? */
     3277                        fQuoted = strpbrk(*ppsz, " \t") != NULL; /* TODO/BUGBUG/FIXME: are there more special chars to look out for?? */
     3278                        cch = strlen(*ppsz);
     3279                        if (iBuffer + cch + fQuoted * 2 + 20 >= sizeof(szBuffer))
     3280                        {
     3281                            fwrite(szBuffer, iBuffer, 1, phFile);
     3282                            iBuffer = 0;
     3283                        }
     3284                        strcpy(szBuffer + iBuffer, " \\\n    ");
     3285                        iBuffer += 7;
     3286                        if (fQuoted) szBuffer[iBuffer++] = '"';
     3287                        strcpy(szBuffer + iBuffer, *ppsz);
     3288                        iBuffer += cch;
     3289                        if (fQuoted) szBuffer[iBuffer++] = '"';
     3290
     3291                        /* next dependant */
     3292                        ppsz++;
    32723293                    }
    3273                     strcpy(szBuffer + iBuffer, " \\\n    ");
    3274                     iBuffer += 7;
    3275                     if (fQuoted) szBuffer[iBuffer++] = '"';
    3276                     strcpy(szBuffer + iBuffer, *ppsz);
    3277                     iBuffer += cch;
    3278                     if (fQuoted) szBuffer[iBuffer++] = '"';
    3279 
    3280                     /* next dependant */
    3281                     ppsz++;
    32823294                }
    3283             }
    3284 
    3285             /* Add two new lines. Flush buffer first if necessary. */
    3286             if (iBuffer + CBNEWLINE*2 >= sizeof(szBuffer))
    3287             {
    3288                 fwrite(szBuffer, iBuffer, 1, phFile);
    3289                 iBuffer = 0;
    3290             }
    3291 
    3292             /* add 2 linefeeds */
    3293             strcpy(szBuffer + iBuffer, "\n\n");
    3294             iBuffer += CBNEWLINE*2;
     3295
     3296                /* Add two new lines. Flush buffer first if necessary. */
     3297                if (iBuffer + CBNEWLINE*2 >= sizeof(szBuffer))
     3298                {
     3299                    fwrite(szBuffer, iBuffer, 1, phFile);
     3300                    iBuffer = 0;
     3301                }
     3302
     3303                /* add 2 linefeeds */
     3304                strcpy(szBuffer + iBuffer, "\n\n");
     3305                iBuffer += CBNEWLINE*2;
     3306            }
    32953307
    32963308            /* next rule */
Note: See TracChangeset for help on using the changeset viewer.