Changeset 3180


Ignore:
Timestamp:
Mar 21, 2000, 2:16:18 PM (25 years ago)
Author:
bird
Message:

Corrected and optimized the searching of the exclude list.
Corrected RCINCLUDE filename extraction.
Updated version number.

File:
1 edited

Legend:

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

    r3169 r3180  
    1 /* $Id: fastdep.c,v 1.16 2000-03-19 16:23:55 bird Exp $
     1/* $Id: fastdep.c,v 1.17 2000-03-21 13:16:18 bird Exp $
    22 *
    33 * Fast dependents. (Fast = Quick and Dirty!)
     
    172172/* pathlist operations */
    173173static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer, POPTIONS pOptions);
     174static BOOL  pathlistFindFile2(const char *pszPathList, const char *pszFilename, POPTIONS pOptions);
    174175
    175176/* word operations */
     
    670671{
    671672    printf(
    672         "FastDep v0.2\n"
    673         "Quick and dirty dependency scanner. Creates a makefile readable depend file.\n"
     673        "FastDep v0.3\n"
     674        "Dependency scanner. Creates a makefile readable depend file.\n"
     675        " - was quick and dirty, now it's just quick -\n"
    674676        "\n"
    675677        "Syntax: FastDep [-a<[+]|->] [-ca] [-cy<[+]|->] [-d <outputfn>]\n"
    676678        "                [-e <excludepath>] [-eall<[+]|->] [-i <include>] [-n<[+]|->]\n"
    677679        "                [-o <objdir>] [-obr<[+]|->]  <files>\n"
     680        "    or\n"
     681        "        FastDep [options] @<parameterfile>\n"
    678682        "\n"
    679683        "   -a<[+]|->       Append to the output file. Default: Overwrite.\n"
     
    685689        "   -e excludepath  Exclude paths. If a filename is found in any\n"
    686690        "                   of these paths only the filename is used, not\n"
    687         "                   the path+filename (which is default) (don't work?).\n"
     691        "                   the path+filename (which is default).\n"
    688692        "   -eall<[+]|->    Include and source filenames, paths or no paths.\n"
    689693        "                   -eall+: No path are added to the filename.\n"
     
    814818        if (pOptions->fSrcWhenObj && pvRule)
    815819            depAddDepend(pvRule,
    816                          pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
     820                         pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszFilename, pOptions) ?
     821                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
    817822                         pOptions->fCheckCyclic);
    818823    }
    819824    else
    820         pvRule = depAddRule(pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL);
     825        pvRule = depAddRule(pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszFilename, pOptions) ?
     826                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL);
    821827
    822828    /* duplicate rule? */
     
    920926                    if (psz != NULL)
    921927                    {
    922                         char    szBuffer2[CCHMAXPATH];
    923                         if (pOptions->fExcludeAll ||
    924                             pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2, pOptions) != NULL
    925                             )
     928                        if (pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))
    926929                            depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);
    927930                        else
     
    10801083        if (pOptions->fSrcWhenObj && pvRule)
    10811084            depAddDepend(pvRule,
    1082                          pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
     1085                         pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszFilename, pOptions) ?
     1086                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
    10831087                         pOptions->fCheckCyclic);
    10841088    }
    10851089    else
    1086         pvRule = depAddRule(pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL);
     1090        pvRule = depAddRule(pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszFilename, pOptions) ?
     1091                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL);
    10871092
    10881093    /* duplicate rule? */
     
    11461151            if (psz != NULL)
    11471152            {
    1148                 char szBuffer2[CCHMAXPATH];
    1149                 if (pOptions->fExcludeAll ||
    1150                     pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2, pOptions) != NULL
    1151                     )
     1153                if (pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))
    11521154                    depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);
    11531155                else
     
    11991201        if (pOptions->fSrcWhenObj && pvRule)
    12001202            depAddDepend(pvRule,
    1201                          pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
     1203                         pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszFilename, pOptions) ?
     1204                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
    12021205                         pOptions->fCheckCyclic);
    12031206    }
    12041207    else
    1205         pvRule = depAddRule(pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL);
     1208        pvRule = depAddRule(pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszFilename, pOptions) ?
     1209                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL);
    12061210
    12071211    /* duplicate rule? */
     
    12191223        int cbLen;
    12201224        int i = 0;
     1225        int i1;
    12211226        iLine++;
    12221227
     
    12271232
    12281233        /* is this an include? */
    1229         if (   strncmp(&szBuffer[i], "#include", 8) == 0
    1230             || strncmp(&szBuffer[i], "RCINCLUDE", 9) == 0
    1231             || strncmp(&szBuffer[i], "DLGINCLUDE", 10) == 0
     1234        if (   (i1 = strncmp(&szBuffer[i], "#include", 8)) == 0
     1235            ||       strncmp(&szBuffer[i], "RCINCLUDE", 9) == 0
     1236            || (i1 = strncmp(&szBuffer[i], "DLGINCLUDE", 10)) == 0
    12321237            )
    12331238        {
     
    12371242            int  j;
    12381243
    1239             /* extract info between "" or <> */
    1240             while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<')))
    1241                 i++;
    1242             i++; /* skip '"' or '<' */
    1243 
    1244             /* if invalid statement then continue with the next line! */
    1245             if (!f) continue;
    1246 
    1247             /* find end */
    1248             j = f = 0;
    1249             while (i + j < cbLen &&  j < CCHMAXPATH &&
    1250                    !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>')))
    1251                 j++;
    1252 
    1253             /* if invalid statement then continue with the next line! */
    1254             if (!f) continue;
     1244            if (i1 == 0)
     1245            {   /*
     1246                 * #include <file.h>,  #include "file.h" or DLGINCLUDE 1 "file.h"
     1247                 *
     1248                 * extract info between "" or <>
     1249                 */
     1250                while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<')))
     1251                    i++;
     1252                i++; /* skip '"' or '<' */
     1253
     1254                /* if invalid statement then continue with the next line! */
     1255                if (!f) continue;
     1256
     1257                /* find end */
     1258                j = f = 0;
     1259                while (i + j < cbLen &&  j < CCHMAXPATH &&
     1260                       !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>')))
     1261                    j++;
     1262
     1263                /* if invalid statement then continue with the next line! */
     1264                if (!f) continue;
     1265            }
     1266            else
     1267            {   /* RCINCLUDE filename.dlg
     1268                 * Extract filename.
     1269                 */
     1270
     1271                /* skip to filename.dlg start - if eol will continue to loop. */
     1272                i += 9;
     1273                while (szBuffer[i] == ' ' || szBuffer[i] == '\t')
     1274                    i++;
     1275                if (szBuffer[i] == '\0')
     1276                    continue;
     1277
     1278                /* search to end of filename. */
     1279                j = i+1;
     1280                while (szBuffer[i+j] != ' ' && szBuffer[i+j] != '\t' && szBuffer[i+j] != '\0')
     1281                    j++;
     1282            }
    12551283
    12561284            /* copy filename */
     
    12671295            if (psz != NULL)
    12681296            {
    1269                 char szBuffer2[CCHMAXPATH];
    1270                 if (pOptions->fExcludeAll ||
    1271                     pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2, pOptions) != NULL
    1272                     )
     1297                if (pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))
    12731298                    depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);
    12741299                else
     
    13201345        if (pOptions->fSrcWhenObj && pvRule)
    13211346            depAddDepend(pvRule,
    1322                          pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
     1347                         pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszFilename, pOptions) ?
     1348                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
    13231349                         pOptions->fCheckCyclic);
    13241350    }
    13251351    else
    1326         pvRule = depAddRule(pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL);
     1352        pvRule = depAddRule(pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszFilename, pOptions) ?
     1353                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), NULL, NULL);
    13271354
    13281355    /* duplicate rule? */
     
    14181445            if (psz != NULL)
    14191446            {
    1420                 char szBuffer2[CCHMAXPATH];
    1421                 if (pOptions->fExcludeAll ||
    1422                     pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2, pOptions) != NULL
    1423                     )
     1447                if (pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))
    14241448                    depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);
    14251449                else
     
    15981622    else
    15991623    {
    1600         strncpy(pszBuffer, pszFilename, psz - pszFilename - 1);
    1601         pszBuffer[psz - pszFilename - 1] = '\0';
     1624        strncpy(pszBuffer, pszFilename, psz - pszFilename);
     1625        pszBuffer[psz - pszFilename] = '\0';
    16021626    }
    16031627
     
    18851909 * @status    completely implemented.
    18861910 * @author    knut st. osmundsen
    1887  * @remark    need substantial optimizations. 95% of execution is spend here.
    18881911 */
    18891912static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer, POPTIONS pOptions)
     
    19141937                strcpy(&pszBuffer[pszNext - psz], "\\");
    19151938            strcat(pszBuffer, pszFilename);
    1916             //strlwr(pszBuffer); /* to speed up AVL tree search we'll lowercase all names. */
    19171939            fileNormalize(pszBuffer);
    19181940
     
    19651987
    19661988
     1989
     1990/**
     1991 * Checks if the given filename may exist within any of the given paths.
     1992 * This check only matches the filename path agianst the paths in the pathlist.
     1993 * @returns   TRUE: if exists.
     1994 *            FALSE: don't exist.
     1995 * @param     pszPathList  Path list to search for filename.
     1996 * @parma     pszFilename  Filename to find.
     1997 * @param     pOptions     Pointer to options struct.
     1998 * @status    completely implemented.
     1999 * @author    knut st. osmundsen
     2000 */
     2001static BOOL pathlistFindFile2(const char *pszPathList, const char *pszFilename, POPTIONS pOptions)
     2002{
     2003    const char *psz = pszPathList;
     2004    const char *pszNext = NULL;
     2005    char        szBuffer[CCHMAXPATH];
     2006    char        szBuffer2[CCHMAXPATH];
     2007    char       *pszPathToFind = &szBuffer2[0];
     2008
     2009    /*
     2010     * Input checking
     2011     */
     2012    if (pszPathList == NULL)
     2013        return FALSE;
     2014
     2015    /*
     2016     * Normalize the filename and get it's path.
     2017     */
     2018    fileNormalize2(pszFilename, szBuffer);
     2019    filePath(pszFilename, pszPathToFind);
     2020
     2021
     2022    /*
     2023     * Loop thru the path list.
     2024     */
     2025    while (*psz != '\0')
     2026    {
     2027        /* find end of this path */
     2028        pszNext = strchr(psz, ';');
     2029        if (pszNext == NULL)
     2030            pszNext = psz + strlen(psz);
     2031
     2032        if (pszNext - psz > 0)
     2033        {
     2034            char *  pszPath = &szBuffer[0];
     2035
     2036            /*
     2037             * Extract and normalize the path
     2038             */
     2039            strncpy(pszPath, psz, pszNext - psz);
     2040            pszPath[pszNext - psz] = '\0';
     2041            if (pszPath[pszNext - psz - 1] == '\\' && pszPath[pszNext - psz - 1] == '/')
     2042                pszPath[pszNext - psz - 1] = '\0';
     2043            fileNormalize(pszPath);
     2044
     2045            /*
     2046             * Check if it matches the path of the filename
     2047             */
     2048            if (strcmp(pszPath, pszPathToFind) == 0)
     2049                return TRUE;
     2050        }
     2051
     2052        /*
     2053         * Next part of the path list.
     2054         */
     2055        if (*pszNext != ';')
     2056            break;
     2057        psz = pszNext + 1;
     2058    }
     2059
     2060    pOptions = pOptions;
     2061    return FALSE;
     2062}
     2063
     2064
    19672065/**
    19682066 * Finds the first char after word.
     
    20812179 * @returns   Pointer to file memoryblock. NULL on error.
    20822180 * @param     pszFilename  Pointer to filename string.
     2181 * @remark    This function is the one using most of the execution
     2182 *            time (DosRead + DosOpen) - about 70% of the execution time!
    20832183 */
    20842184static void *textbufferCreate(const char *pszFilename)
Note: See TracChangeset for help on using the changeset viewer.