Changeset 3129


Ignore:
Timestamp:
Mar 16, 2000, 10:10:11 PM (25 years ago)
Author:
bird
Message:

Speed optimizations. Using an AVL tree to cache the files which we have found,
we'll check this tree before we issue a DosQueryPathInfo. The function
pathlistFindFile is still the slowest function...

Location:
trunk/tools/fastdep
Files:
2 added
2 edited

Legend:

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

    r3123 r3129  
    1 /* $Id: fastdep.c,v 1.8 2000-03-16 15:27:08 bird Exp $
     1/* $Id: fastdep.c,v 1.9 2000-03-16 21:10:11 bird Exp $
    22 *
    33 * Fast dependents. (Fast = Quick and Dirty!)
     
    2323#include <string.h>
    2424#include <stdlib.h>
     25
     26#include "avl.h"
     27
     28#ifndef INLINE
     29#   if defined(__IBMC__)
     30#       define INLINE _Inline
     31#   elif defined(__IBMCPP__)
     32#       define INLINE inline
     33#   else
     34#       error "unknown compiler - inline keyword unknown!"
     35#   endif
     36#endif
    2537
    2638/*
     
    8698 * Language specific analysis functions type.
    8799 */
    88 typedef int ( _FNLANG)  (const char *pszFilename, FILE *phFile,
     100typedef int ( _FNLANG)  (const char *pszFilename, void *pvFile,
    89101                         BOOL fHeader, POPTIONS pOptions);
    90102typedef _FNLANG    *PFNLANG;
     
    117129
    118130
     131/**
     132 * Filename cache entry.
     133 */
     134#define FCACHEENTRY     AVLNODECORE
     135#define PFCACHEENTRY    PAVLNODECORE
     136
     137
    119138/*******************************************************************************
    120139*   Internal Functions                                                         *
     
    123142static int makeDependent(const char *pszFilename, POPTIONS pOptions);
    124143
    125 int langC_CPP(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions);
    126 int langAsm(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions);
    127 int langRC(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions);
    128 int langCOBOL(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions);
     144int langC_CPP(const char *pszFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);
     145int langAsm(const char *pszFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);
     146int langRC(const char *pszFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);
     147int langCOBOL(const char *pszFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);
    129148
    130149
     
    139158char *fileExt(const char *pszFilename, char *pszBuffer);
    140159
     160/* filecache operations */
     161static BOOL filecacheAdd(const char *pszFilename);
     162static BOOL filecacheFind(const char *pszFilename);
     163
    141164/* pathlist operations */
    142 char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer);
     165static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer);
    143166
    144167/* word operations */
     
    152175
    153176/* text helpers */
    154 static char *trim(char *psz);
    155 static char *trimR(char *psz);
     177INLINE char *trim(char *psz);
     178INLINE char *trimR(char *psz);
    156179
    157180/* textbuffer */
     
    159182static void  textbufferDestroy(void *pvBuffer);
    160183static char *textbufferNextLine(void *pvBuffer, char *psz);
     184static char *textbufferGetNextLine(void *pvBuffer, void **ppv, char *pszLineBuffer, int cchLineBuffer);
    161185
    162186/* depend workers */
     
    166190static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt);
    167191static BOOL  depAddDepend(void *pvRule, const char *pszDep);
    168 
     192#if 0  /* not used */
    169193static BOOL  depCleanFile(const char *pszFilename);
     194#endif
    170195
    171196
     
    173198*   Global Variables                                                           *
    174199*******************************************************************************/
     200/*
     201 * Pointer to the list of dependencies.
     202 */
    175203static PDEPRULE pdepList = NULL;
    176204
     205/*
     206 * Filecache - tree starts here.
     207 */
     208static PFCACHEENTRY pfcTree = NULL;
     209static unsigned     cfcNodes = 0;
     210
     211
     212/*
     213 * Configuration stuff.
     214 */
    177215static const char pszDefaultDepFile[] = ".depend";
    178216static const char *apszExtC_CPP[] = {"c", "sqc", "cpp", "h", "hpp", NULL};
     
    422460
    423461            /*
     462             * If append option is specified we'll have to read the existing dep file
     463             * before starting adding new dependencies.
     464             */
     465            if (pdepList == NULL && options.fAppend)
     466                depReadFile(pszDepFile);
     467
     468            /*
    424469             * Search for the files specified.
    425470             */
     
    461506    if (!depWriteFile(pszDepFile))
    462507        fprintf(stderr, "error: failed to write dependencies file!\n");
     508    #if 0
     509    printf("cfcNodes=%d\n", cfcNodes);
     510    #endif
    463511
    464512    return rc;
     
    518566{
    519567    int    rc = -1;
    520     FILE  *phFile;
    521 
    522     phFile = fopen(pszFilename, "r");
    523     if (phFile != NULL)
     568    void * pvFile;
     569
     570    pvFile = textbufferCreate(pszFilename);
     571    if (pvFile != NULL)
    524572    {
    525573        char            szExt[CCHMAXPATH];
     
    546594        /* Found? */
    547595        if (pCfg->papszExts != NULL)
    548             rc = (*pCfg->pfn)(pszFilename, phFile, fHeader, pOptions);
     596            rc = (*pCfg->pfn)(pszFilename, pvFile, fHeader, pOptions);
    549597        else
    550598        {
     
    554602        }
    555603
    556         fclose(phFile);
     604        textbufferDestroy(pvFile);
    557605    }
    558606    else
     
    569617 *            !0 on error.
    570618 * @param     pszFilename  Pointer to source filename.
    571  * @param     phFile       Pointer to source file handle.
     619 * @param     pvFile       Pointer to file textbuffer.
    572620 * @param     pOptions     Pointer to options struct.
    573621 * @status    completely implemented.
    574622 * @author    knut st. osmundsen
    575623 */
    576 int langC_CPP(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions)
     624int langC_CPP(const char *pszFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions)
    577625{
    578626    void *  pvRule;                     /* Handle to the current rule. */
     627    char    szBuffer[4096];             /* Max line length is 4096... should not be a problem. */
    579628    int     iLine;                      /* Linenumber. */
    580     char    szBuffer[4096];             /* Max line length is 4096... should not be a problem. */
     629    void *  pv = NULL;                  /* An index used by textbufferGetNextLine. */
    581630    BOOL    fComment;                   /* TRUE when within a multiline comment. */
    582631                                        /* FALSE when not within a multiline comment. */
     
    630679    fComment = FALSE;
    631680    iLine = 0;
    632     while (!feof(phFile)) /* line loop */
    633     {
    634         if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL)
     681    while (textbufferGetNextLine(pvFile, &pv, szBuffer, sizeof(szBuffer)) != NULL) /* line loop */
     682    {
     683        /* search for #include */
     684        register char *pszC;
     685        int cbLen;
     686        int i = 0;
     687        iLine++;
     688
     689        /* skip blank chars */
     690        cbLen = strlen(szBuffer);
     691        while (i + 2 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
     692            i++;
     693
     694        /* preprocessor statement? */
     695        if (!fComment && szBuffer[i] == '#')
    635696        {
    636             /* search for #include */
    637             register char *pszC;
    638             int cbLen;
    639             int i = 0;
    640             iLine++;
    641 
    642             /* skip blank chars */
    643             cbLen = strlen(szBuffer);
    644             while (i + 2 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
     697            /*
     698             * Preprocessor checks
     699             * We known that we have a preprocessor statment (starting with an '#' * at szBuffer[i]).
     700             * Depending on the word afterwards we'll take some different actions.
     701             * So we'll start of by extracting that word and make a string swich on it.
     702             * Note that there might be some blanks between the hash and the word.
     703             */
     704            int     cchWord;
     705            char *  pszEndWord;
     706            char *  pszArgument;
     707            i++;                /* skip hash ('#') */
     708            while (szBuffer[i] == '\t' || szBuffer[i] == ' ') /* skip blanks */
    645709                i++;
    646 
    647             /* preprocessor statement? */
    648             if (!fComment && szBuffer[i] == '#')
     710            pszArgument = pszEndWord = findEndOfWord(&szBuffer[i]);
     711            cchWord = pszEndWord - &szBuffer[i];
     712
     713            /*
     714             * Find the argument by skipping the blanks.
     715             */
     716            while (*pszArgument == '\t' || *pszArgument == ' ') /* skip blanks */
     717                pszArgument++;
     718
     719            /*
     720             * string switch.
     721             */
     722            if (strncmp(&szBuffer[i], "include", cchWord) == 0)
    649723            {
    650724                /*
    651                  * Preprocessor checks
    652                  * We known that we have a preprocessor statment (starting with an '#' * at szBuffer[i]).
    653                  * Depending on the word afterwards we'll take some different actions.
    654                  * So we'll start of by extracting that word and make a string swich on it.
    655                  * Note that there might be some blanks between the hash and the word.
     725                 * #include
     726                 *
     727                 * Are we in a state where this file is to be included?
    656728                 */
    657                 int     cchWord;
    658                 char *  pszEndWord;
    659                 char *  pszArgument;
    660                 i++;                /* skip hash ('#') */
    661                 while (szBuffer[i] == '\t' || szBuffer[i] == ' ') /* skip blanks */
    662                     i++;
    663                 pszArgument = pszEndWord = findEndOfWord(&szBuffer[i]);
    664                 cchWord = pszEndWord - &szBuffer[i];
    665 
     729                if (achIfStack[iIfStack].fIncluded)
     730                {
     731                    char szFullname[CCHMAXPATH];
     732                    char *psz;
     733                    BOOL f = FALSE;
     734                    int  j;
     735
     736                    /* extract info between "" or <> */
     737                    while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<')))
     738                        i++;
     739                    i++; /* skip '"' or '<' */
     740
     741                    /* if invalid statement then continue with the next line! */
     742                    if (!f) continue;
     743
     744                    /* find end */
     745                    j = f = 0;
     746                    while (i + j < cbLen &&  j < CCHMAXPATH &&
     747                           !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>')))
     748                        j++;
     749
     750                    /* if invalid statement then continue with the next line! */
     751                    if (!f) continue;
     752
     753                    /* copy filename */
     754                    strncpy(szFullname, &szBuffer[i], j);
     755                    szFullname[j] = '\0'; /* ensure terminatition. */
     756
     757                    /* find include file! */
     758                    psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer);
     759                    if (psz == NULL)
     760                        psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer);
     761
     762                    /* did we find the include? */
     763                    if (psz != NULL)
     764                    {
     765                        char    szBuffer2[CCHMAXPATH];
     766                        if (pOptions->fExcludeAll ||
     767                            pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL
     768                            )
     769                            depAddDepend(pvRule, szFullname);
     770                        else
     771                            depAddDepend(pvRule, szBuffer);
     772                    }
     773                    else
     774                        fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
     775                                pszFilename, iLine, szFullname);
     776                }
     777            }
     778            else
    666779                /*
    667                  * Find the argument by skipping the blanks.
     780                 * #if
    668781                 */
    669                 while (*pszArgument == '\t' || *pszArgument == ' ') /* skip blanks */
    670                     pszArgument++;
    671 
    672                 /*
    673                  * string switch.
    674                  */
    675                 if (strncmp(&szBuffer[i], "include", cchWord) == 0)
     782                if (strncmp(&szBuffer[i], "if", cchWord) == 0)
     783            {   /* #if 0 and #if <1-9> are supported */
     784                pszEndWord = findEndOfWord(pszArgument);
     785                iIfStack++;
     786                if ((pszEndWord - pszArgument) == 1
     787                    && *pszArgument >= '0' && *pszArgument <= '9')
    676788                {
    677                     /*
    678                      * #include
    679                      *
    680                      * Are we in a state where this file is to be included?
    681                      */
    682                     if (achIfStack[iIfStack].fIncluded)
    683                     {
    684                         char szFullname[CCHMAXPATH];
    685                         char *psz;
    686                         BOOL f = FALSE;
    687                         int  j;
    688 
    689                         /* extract info between "" or <> */
    690                         while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<')))
    691                             i++;
    692                         i++; /* skip '"' or '<' */
    693 
    694                         /* if invalid statement then continue with the next line! */
    695                         if (!f) continue;
    696 
    697                         /* find end */
    698                         j = f = 0;
    699                         while (i + j < cbLen &&  j < CCHMAXPATH &&
    700                                !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>')))
    701                             j++;
    702 
    703                         /* if invalid statement then continue with the next line! */
    704                         if (!f) continue;
    705 
    706                         /* copy filename */
    707                         strncpy(szFullname, &szBuffer[i], j);
    708                         szFullname[j] = '\0'; /* ensure terminatition. */
    709 
    710                         /* find include file! */
    711                         psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer);
    712                         if (psz == NULL)
    713                             psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer);
    714 
    715                         /* did we find the include? */
    716                         if (psz != NULL)
    717                         {
    718                             char    szBuffer2[CCHMAXPATH];
    719                             if (pOptions->fExcludeAll ||
    720                                 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL
    721                                 )
    722                                 depAddDepend(pvRule, szFullname);
    723                             else
    724                                 depAddDepend(pvRule, szBuffer);
    725                         }
    726                         else
    727                             fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
    728                                     pszFilename, iLine, szFullname);
    729                     }
     789                    if (*pszArgument != '0')
     790                        achIfStack[iIfStack].fIncluded =  TRUE;
     791                    else
     792                        achIfStack[iIfStack].fIncluded =  FALSE;
    730793                }
    731794                else
    732                     /*
    733                      * #if
    734                      */
    735                     if (strncmp(&szBuffer[i], "if", cchWord) == 0)
    736                 {   /* #if 0 and #if <1-9> are supported */
    737                     pszEndWord = findEndOfWord(pszArgument);
    738                     iIfStack++;
    739                     if ((pszEndWord - pszArgument) == 1
    740                         && *pszArgument >= '0' && *pszArgument <= '9')
    741                     {
    742                         if (*pszArgument != '0')
    743                             achIfStack[iIfStack].fIncluded =  TRUE;
    744                         else
    745                             achIfStack[iIfStack].fIncluded =  FALSE;
    746                     }
     795                    achIfStack[iIfStack].fSupported = FALSE;
     796                achIfStack[iIfStack].fIncluded = TRUE;
     797                achIfStack[iIfStack].fIf = TRUE;
     798            }
     799            else
     800                /*
     801                 * #else
     802                 */
     803                if (strncmp(&szBuffer[i], "else", cchWord) == 0)
     804            {
     805                if (achIfStack[iIfStack].fSupported)
     806                {
     807                    if (achIfStack[iIfStack].fIncluded) /* ARG!! this'll prevent warning */
     808                        achIfStack[iIfStack].fIncluded = FALSE;
    747809                    else
    748                         achIfStack[iIfStack].fSupported = FALSE;
    749                     achIfStack[iIfStack].fIncluded = TRUE;
    750                     achIfStack[iIfStack].fIf = TRUE;
     810                        achIfStack[iIfStack].fIncluded = TRUE;
    751811                }
     812                achIfStack[iIfStack].fIf = FALSE;
     813            }
     814            else
     815                /*
     816                 * #endif
     817                 */
     818                if (strncmp(&szBuffer[i], "endif", cchWord) == 0)
     819            {   /* Pop the if-stack. */
     820                if (iIfStack > 0)
     821                    iIfStack--;
    752822                else
    753                     /*
    754                      * #else
    755                      */
    756                     if (strncmp(&szBuffer[i], "else", cchWord) == 0)
    757                 {
    758                     if (achIfStack[iIfStack].fSupported)
    759                     {
    760                         if (achIfStack[iIfStack].fIncluded) /* ARG!! this'll prevent warning */
    761                             achIfStack[iIfStack].fIncluded = FALSE;
    762                         else
    763                             achIfStack[iIfStack].fIncluded = TRUE;
    764                     }
    765                     achIfStack[iIfStack].fIf = FALSE;
    766                 }
     823                    fprintf(stderr, "%s(%d): If-Stack underflow!\n", pszFilename, iLine);
     824            }
     825            /*
     826             * general if<something> and elseif<something> implementations
     827             */
     828            else
     829                if (strncmp(&szBuffer[i], "elseif", 6) == 0)
     830            {
     831                achIfStack[iIfStack].fSupported = FALSE;
     832                achIfStack[iIfStack].fIncluded = TRUE;
     833            }
     834            else
     835                if (strncmp(&szBuffer[i], "if", 2) == 0)
     836            {
     837                iIfStack++;
     838                achIfStack[iIfStack].fIf = TRUE;
     839                achIfStack[iIfStack].fSupported = FALSE;
     840                achIfStack[iIfStack].fIncluded = TRUE;
     841            }
     842            /* The rest of them aren't implemented yet.
     843            else if (strncmp(&szBuffer[i], "if") == 0)
     844            {
     845            }
     846            */
     847        }
     848
     849        /*
     850         * Comment checks.
     851         *  -Start at first non-blank.
     852         *  -Loop thru the line since we might have more than one
     853         *   comment statement on a single line.
     854         */
     855        pszC = &szBuffer[i];
     856        while (pszC != NULL && *pszC != '\0')
     857        {
     858            if (fComment)
     859                pszC = strstr(pszC, "*/");  /* look for end comment mark. */
     860            else
     861            {
     862                char *pszLC;
     863                pszLC= strstr(pszC, "//");  /* look for single line comment mark. */
     864                pszC = strstr(pszC, "/*");  /* look for start comment mark */
     865                if (pszLC && pszLC < pszC)  /* if there is an single line comment mark before the */
     866                    break;                  /* muliline comment mark we'll ignore the multiline mark. */
     867            }
     868
     869            /* Comment mark found? */
     870            if (pszC != NULL)
     871            {
     872                fComment = !fComment;
     873                pszC += 2;          /* skip comment mark */
     874
     875                /* debug */
     876                /*
     877                if (fComment)
     878                    fprintf(stderr, "starts at line %d\n", iLine);
    767879                else
    768                     /*
    769                      * #endif
    770                      */
    771                     if (strncmp(&szBuffer[i], "endif", cchWord) == 0)
    772                 {   /* Pop the if-stack. */
    773                     if (iIfStack > 0)
    774                         iIfStack--;
    775                     else
    776                         fprintf(stderr, "%s(%d): If-Stack underflow!\n", pszFilename, iLine);
    777                 }
    778                 /*
    779                  * general if<something> and elseif<something> implementations
    780                  */
    781                 else
    782                     if (strncmp(&szBuffer[i], "elseif", 6) == 0)
    783                 {
    784                     achIfStack[iIfStack].fSupported = FALSE;
    785                     achIfStack[iIfStack].fIncluded = TRUE;
    786                 }
    787                 else
    788                     if (strncmp(&szBuffer[i], "if", 2) == 0)
    789                 {
    790                     iIfStack++;
    791                     achIfStack[iIfStack].fIf = TRUE;
    792                     achIfStack[iIfStack].fSupported = FALSE;
    793                     achIfStack[iIfStack].fIncluded = TRUE;
    794                 }
    795                 /* The rest of them aren't implemented yet.
    796                 else if (strncmp(&szBuffer[i], "if") == 0)
    797                 {
    798                 }
    799                 */
    800             }
    801 
    802             /*
    803              * Comment checks.
    804              *  -Start at first non-blank.
    805              *  -Loop thru the line since we might have more than one
    806              *   comment statement on a single line.
    807              */
    808             pszC = &szBuffer[i];
    809             while (pszC != NULL && *pszC != '\0')
    810             {
    811                 if (fComment)
    812                     pszC = strstr(pszC, "*/");  /* look for end comment mark. */
    813                 else
    814                 {
    815                     char *pszLC;
    816                     pszLC= strstr(pszC, "//");  /* look for single line comment mark. */
    817                     pszC = strstr(pszC, "/*");  /* look for start comment mark */
    818                     if (pszLC && pszLC < pszC)  /* if there is an single line comment mark before the */
    819                         break;                  /* muliline comment mark we'll ignore the multiline mark. */
    820                 }
    821 
    822                 /* Comment mark found? */
    823                 if (pszC != NULL)
    824                 {
    825                     fComment = !fComment;
    826                     pszC += 2;          /* skip comment mark */
    827 
    828                     /* debug */
    829                     /*
    830                     if (fComment)
    831                         fprintf(stderr, "starts at line %d\n", iLine);
    832                     else
    833                         fprintf(stderr, "ends   at line %d\n", iLine);
    834                         */
    835                 }
     880                    fprintf(stderr, "ends   at line %d\n", iLine);
     881                    */
    836882            }
    837883        }
    838         else
    839             break;
    840884    } /*while*/
    841885
     
    850894 *            !0 on error.
    851895 * @param     pszFilename  Pointer to source filename.
    852  * @param     phFile       Pointer to source file handle.
     896 * @param     pvFile       Pointer to file textbuffer.
    853897 * @param     pOptions     Pointer to options struct.
    854898 * @status    completely implemented.
    855899 * @author    knut st. osmundsen
    856900 */
    857 int langAsm(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions)
     901int langAsm(const char *pszFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions)
    858902{
    859903    void *  pvRule;                     /* Handle to the current rule. */
    860904    char    szBuffer[4096];             /* Temporary buffer (max line lenght size...) */
    861905    int     iLine;                      /* current line number */
     906    void *  pv = NULL;                  /* An index used by textbufferGetNextLine. */
    862907
    863908
     
    891936    /*******************/
    892937    iLine = 0;
    893     while (!feof(phFile)) /* line loop */
    894     {
    895         if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL)
     938    while (textbufferGetNextLine(pvFile, &pv, szBuffer, sizeof(szBuffer)) != NULL) /* line loop */
     939    {
     940        /* search for include */
     941        int cbLen;
     942        int i = 0;
     943        iLine++;
     944
     945        /* skip blank chars */
     946        cbLen = strlen(szBuffer);
     947        while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
     948            i++;
     949
     950        /* is this an include? */
     951        if (strnicmp(&szBuffer[i], "include", 7) == 0
     952            && (szBuffer[i + 7] == '\t' || szBuffer[i + 7] == ' ')
     953            )
    896954        {
    897             /* search for include */
    898             int cbLen;
    899             int i = 0;
    900             iLine++;
    901 
    902             /* skip blank chars */
    903             cbLen = strlen(szBuffer);
    904             while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
     955            char szFullname[CCHMAXPATH];
     956            char *psz;
     957            int  j;
     958
     959            /* skip to first no blank char  */
     960            i += 7;
     961            while (i < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
    905962                i++;
    906963
    907             /* is this an include? */
    908             if (strnicmp(&szBuffer[i], "include", 7) == 0
    909                 && (szBuffer[i + 7] == '\t' || szBuffer[i + 7] == ' ')
    910                 )
    911             {
    912                 char szFullname[CCHMAXPATH];
    913                 char *psz;
    914                 int  j;
    915 
    916                 /* skip to first no blank char  */
    917                 i += 7;
    918                 while (i < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
    919                     i++;
    920 
    921                 /* comment check - if comment found, no filename was given. continue. */
    922                 if (szBuffer[i] == ';') continue;
    923 
    924                 /* find end */
    925                 j = 0;
    926                 while (i + j < cbLen
    927                        &&  j < CCHMAXPATH
    928                        && szBuffer[i+j] != ' '  && szBuffer[i+j] != '\t' && szBuffer[i+j] != '\n'
    929                        && szBuffer[i+j] != '\0' && szBuffer[i+j] != ';'  && szBuffer[i+j] != '\r'
    930                        )
    931                     j++;
    932 
    933                 /* copy filename */
    934                 strncpy(szFullname, &szBuffer[i], j);
    935                 szFullname[j] = '\0'; /* ensure terminatition. */
    936 
    937                 /* find include file! */
    938                 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer);
    939                 if (psz == NULL)
    940                     psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer);
    941 
    942                 /* Did we find the include? */
    943                 if (psz != NULL)
    944                 {
    945                     char szBuffer2[CCHMAXPATH];
    946                     if (pOptions->fExcludeAll ||
    947                         pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL
    948                         )
    949                         depAddDepend(pvRule, szFullname);
    950                     else
    951                         depAddDepend(pvRule, szBuffer);
    952                 }
     964            /* comment check - if comment found, no filename was given. continue. */
     965            if (szBuffer[i] == ';') continue;
     966
     967            /* find end */
     968            j = 0;
     969            while (i + j < cbLen
     970                   &&  j < CCHMAXPATH
     971                   && szBuffer[i+j] != ' '  && szBuffer[i+j] != '\t' && szBuffer[i+j] != '\n'
     972                   && szBuffer[i+j] != '\0' && szBuffer[i+j] != ';'  && szBuffer[i+j] != '\r'
     973                   )
     974                j++;
     975
     976            /* copy filename */
     977            strncpy(szFullname, &szBuffer[i], j);
     978            szFullname[j] = '\0'; /* ensure terminatition. */
     979
     980            /* find include file! */
     981            psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer);
     982            if (psz == NULL)
     983                psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer);
     984
     985            /* Did we find the include? */
     986            if (psz != NULL)
     987            {
     988                char szBuffer2[CCHMAXPATH];
     989                if (pOptions->fExcludeAll ||
     990                    pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL
     991                    )
     992                    depAddDepend(pvRule, szFullname);
    953993                else
    954                     fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
    955                             pszFilename, iLine, szFullname);
    956             }
     994                    depAddDepend(pvRule, szBuffer);
     995            }
     996            else
     997                fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
     998                        pszFilename, iLine, szFullname);
    957999        }
    958         else
    959             break;
    9601000    } /*while*/
    9611001
     
    9701010 *            !0 on error.
    9711011 * @param     pszFilename  Pointer to source filename.
    972  * @param     phFile       Pointer to source file handle.
     1012 * @param     pvFile       Pointer to file textbuffer.
    9731013 * @param     pOptions     Pointer to options struct.
    9741014 * @status    completely implemented.
    9751015 * @author    knut st. osmundsen
    9761016 */
    977 int langRC(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions)
     1017int langRC(const char *pszFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions)
    9781018{
    9791019    void *  pvRule;                     /* Handle to the current rule. */
    9801020    char    szBuffer[4096];             /* Temporary buffer (max line lenght size...) */
    9811021    int     iLine;                      /* current line number */
     1022    void *  pv = NULL;                  /* An index used by textbufferGetNextLine. */
    9821023
    9831024
     
    10111052    /*******************/
    10121053    iLine = 0;
    1013     while (!feof(phFile)) /* line loop */
    1014     {
    1015         if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL)
     1054    while (textbufferGetNextLine(pvFile, &pv, szBuffer, sizeof(szBuffer)) != NULL) /* line loop */
     1055    {
     1056        /* search for #include */
     1057        int cbLen;
     1058        int i = 0;
     1059        iLine++;
     1060
     1061        /* skip blank chars */
     1062        cbLen = strlen(szBuffer);
     1063        while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
     1064            i++;
     1065
     1066        /* is this an include? */
     1067        if (   strncmp(&szBuffer[i], "#include", 8) == 0
     1068            || strncmp(&szBuffer[i], "RCINCLUDE", 9) == 0
     1069            || strncmp(&szBuffer[i], "DLGINCLUDE", 10) == 0
     1070            )
    10161071        {
    1017             /* search for #include */
    1018             int cbLen;
    1019             int i = 0;
    1020             iLine++;
    1021 
    1022             /* skip blank chars */
    1023             cbLen = strlen(szBuffer);
    1024             while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
     1072            char szFullname[CCHMAXPATH];
     1073            char *psz;
     1074            BOOL f = FALSE;
     1075            int  j;
     1076
     1077            /* extract info between "" or <> */
     1078            while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<')))
    10251079                i++;
    1026 
    1027             /* is this an include? */
    1028             if (   strncmp(&szBuffer[i], "#include", 8) == 0
    1029                 || strncmp(&szBuffer[i], "RCINCLUDE", 9) == 0
    1030                 || strncmp(&szBuffer[i], "DLGINCLUDE", 10) == 0
    1031                 )
    1032             {
    1033                 char szFullname[CCHMAXPATH];
    1034                 char *psz;
    1035                 BOOL f = FALSE;
    1036                 int  j;
    1037 
    1038                 /* extract info between "" or <> */
    1039                 while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<')))
    1040                     i++;
    1041                 i++; /* skip '"' or '<' */
    1042 
    1043                 /* if invalid statement then continue with the next line! */
    1044                 if (!f) continue;
    1045 
    1046                 /* find end */
    1047                 j = f = 0;
    1048                 while (i + j < cbLen &&  j < CCHMAXPATH &&
    1049                        !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>')))
    1050                     j++;
    1051 
    1052                 /* if invalid statement then continue with the next line! */
    1053                 if (!f) continue;
    1054 
    1055                 /* copy filename */
    1056                 strncpy(szFullname, &szBuffer[i], j);
    1057                 szFullname[j] = '\0'; /* ensure terminatition. */
    1058 
    1059                 /* find include file! */
    1060                 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer);
    1061                 if (psz == NULL)
    1062                     psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer);
    1063 
    1064                 /* did we find the include? */
    1065                 if (psz != NULL)
    1066                 {
    1067                     char szBuffer2[CCHMAXPATH];
    1068                     if (pOptions->fExcludeAll ||
    1069                         pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL
    1070                         )
    1071                         depAddDepend(pvRule, szFullname);
    1072                     else
    1073                         depAddDepend(pvRule, szBuffer);
    1074                 }
     1080            i++; /* skip '"' or '<' */
     1081
     1082            /* if invalid statement then continue with the next line! */
     1083            if (!f) continue;
     1084
     1085            /* find end */
     1086            j = f = 0;
     1087            while (i + j < cbLen &&  j < CCHMAXPATH &&
     1088                   !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>')))
     1089                j++;
     1090
     1091            /* if invalid statement then continue with the next line! */
     1092            if (!f) continue;
     1093
     1094            /* copy filename */
     1095            strncpy(szFullname, &szBuffer[i], j);
     1096            szFullname[j] = '\0'; /* ensure terminatition. */
     1097
     1098            /* find include file! */
     1099            psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer);
     1100            if (psz == NULL)
     1101                psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer);
     1102
     1103            /* did we find the include? */
     1104            if (psz != NULL)
     1105            {
     1106                char szBuffer2[CCHMAXPATH];
     1107                if (pOptions->fExcludeAll ||
     1108                    pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL
     1109                    )
     1110                    depAddDepend(pvRule, szFullname);
    10751111                else
    1076                     fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
    1077                             pszFilename, iLine, szFullname);
    1078             }
     1112                    depAddDepend(pvRule, szBuffer);
     1113            }
     1114            else
     1115                fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
     1116                        pszFilename, iLine, szFullname);
    10791117        }
    1080         else
    1081             break;
    10821118    } /*while*/
    10831119
     
    10921128 *            !0 on error.
    10931129 * @param     pszFilename  Pointer to source filename.
    1094  * @param     phFile       Pointer to source file handle.
     1130 * @param     pvFile       Pointer to file textbuffer.
    10951131 * @param     pOptions     Pointer to options struct.
    10961132 * @status    completely implemented.
    10971133 * @author    knut st. osmundsen
    10981134 */
    1099 int langCOBOL(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions)
     1135int langCOBOL(const char *pszFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions)
    11001136{
    11011137    void *  pvRule;                     /* Handle to the current rule. */
    11021138    char    szBuffer[4096];             /* Temporary buffer (max line lenght size...) */
    11031139    int     iLine;                      /* current line number */
     1140    void *  pv = NULL;                  /* An index used by textbufferGetNextLine. */
    11041141
    11051142
     
    11331170    /*******************/
    11341171    iLine = 0;
    1135     while (!feof(phFile)) /* line loop */
    1136     {
    1137         if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL)
     1172    while (textbufferGetNextLine(pvFile, &pv, szBuffer, sizeof(szBuffer)) != NULL) /* line loop */
     1173    {
     1174        /* search for #include */
     1175        int cbLen;
     1176        int i = 0;
     1177        int i1, i2;
     1178        iLine++;
     1179
     1180        /* check for comment mark (column 7) */
     1181        if (szBuffer[6] == '*')
     1182            continue;
     1183
     1184        /* skip blank chars */
     1185        cbLen = strlen(szBuffer);
     1186        while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
     1187            i++;
     1188
     1189        /* is this an include? */
     1190        if (   (i1 = strnicmp(&szBuffer[i], "COPY", 4)) == 0
     1191            || (i2 = strnicmpwords(&szBuffer[i], "EXEC SQL INCLUDE", 16)) == 0
     1192            )
    11381193        {
    1139             /* search for #include */
    1140             int cbLen;
    1141             int i = 0;
    1142             int i1, i2;
    1143             iLine++;
    1144 
    1145             /* check for comment mark (column 7) */
    1146             if (szBuffer[6] == '*')
     1194            char szFullname[CCHMAXPATH];
     1195            char *psz;
     1196            int  j;
     1197
     1198            /* skip statement */
     1199            i += 4;
     1200            if (i1 != 0)
     1201            {
     1202                int y = 2; /* skip two words */
     1203                do
     1204                {
     1205                    /* skip blanks */
     1206                    while (szBuffer[i] == ' ' || szBuffer[i] == '\t')
     1207                        i++;
     1208                    /* skip word */
     1209                    while (szBuffer[i] != ' ' && szBuffer[i] != '\t'
     1210                           && szBuffer[i] != '\0' && szBuffer[i] != '\n')
     1211                        i++;
     1212                    y--;
     1213                } while (y > 0);
     1214            }
     1215
     1216            /* check for blank */
     1217            if (szBuffer[i] != ' ' && szBuffer[i] != '\t') /* no copybook specified... */
    11471218                continue;
    11481219
    1149             /* skip blank chars */
    1150             cbLen = strlen(szBuffer);
    1151             while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
     1220            /* skip blanks */
     1221            while (szBuffer[i] == ' ' || szBuffer[i] == '\t')
    11521222                i++;
    11531223
    1154             /* is this an include? */
    1155             if (   (i1 = strnicmp(&szBuffer[i], "COPY", 4)) == 0
    1156                 || (i2 = strnicmpwords(&szBuffer[i], "EXEC SQL INCLUDE", 16)) == 0
    1157                 )
    1158             {
    1159                 char szFullname[CCHMAXPATH];
    1160                 char *psz;
    1161                 int  j;
    1162 
    1163                 /* skip statement */
    1164                 i += 4;
    1165                 if (i1 != 0)
    1166                 {
    1167                     int y = 2; /* skip two words */
    1168                     do
    1169                     {
    1170                         /* skip blanks */
    1171                         while (szBuffer[i] == ' ' || szBuffer[i] == '\t')
    1172                             i++;
    1173                         /* skip word */
    1174                         while (szBuffer[i] != ' ' && szBuffer[i] != '\t'
    1175                                && szBuffer[i] != '\0' && szBuffer[i] != '\n')
    1176                             i++;
    1177                         y--;
    1178                     } while (y > 0);
    1179                 }
    1180 
    1181                 /* check for blank */
    1182                 if (szBuffer[i] != ' ' && szBuffer[i] != '\t') /* no copybook specified... */
    1183                     continue;
    1184 
    1185                 /* skip blanks */
    1186                 while (szBuffer[i] == ' ' || szBuffer[i] == '\t')
    1187                     i++;
    1188 
    1189                 /* if invalid statement then continue with the next line! */
    1190                 if (szBuffer[i] == '\0' || szBuffer[i] == '\n')
    1191                     continue;
    1192 
    1193                 /* find end */
    1194                 j = 0;
    1195                 while (i + j < cbLen && j < CCHMAXPATH
    1196                        && szBuffer[i+j] != '.'
    1197                        && szBuffer[i+j] != ' '  && szBuffer[i+j] != '\t'
    1198                        && szBuffer[i+j] != '\0' && szBuffer[i+j] != '\n'
    1199                        )
    1200                     j++;
    1201 
    1202                 /* if invalid statement then continue with the next line! */
    1203                 if (szBuffer[i+j] != '.' && szBuffer[i+j] != ' ' && szBuffer[i] != '\t')
    1204                     continue;
    1205 
    1206                 /* copy filename */
    1207                 strncpy(szFullname, &szBuffer[i], j);
    1208                 szFullname[j] = '\0'; /* ensure terminatition. */
    1209 
    1210                 /* add extention .cpy - hardcoded for the moment. */
    1211                 strcat(szFullname, ".cpy");
    1212 
    1213                 /* find include file! */
    1214                 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer);
    1215 
    1216                 /* did we find the include? */
    1217                 if (psz != NULL)
    1218                 {
    1219                     char szBuffer2[CCHMAXPATH];
    1220                     if (pOptions->fExcludeAll ||
    1221                         pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL
    1222                         )
    1223                         depAddDepend(pvRule, szFullname);
    1224                     else
    1225                         depAddDepend(pvRule, szBuffer);
    1226                 }
     1224            /* if invalid statement then continue with the next line! */
     1225            if (szBuffer[i] == '\0' || szBuffer[i] == '\n')
     1226                continue;
     1227
     1228            /* find end */
     1229            j = 0;
     1230            while (i + j < cbLen && j < CCHMAXPATH
     1231                   && szBuffer[i+j] != '.'
     1232                   && szBuffer[i+j] != ' '  && szBuffer[i+j] != '\t'
     1233                   && szBuffer[i+j] != '\0' && szBuffer[i+j] != '\n'
     1234                   )
     1235                j++;
     1236
     1237            /* if invalid statement then continue with the next line! */
     1238            if (szBuffer[i+j] != '.' && szBuffer[i+j] != ' ' && szBuffer[i] != '\t')
     1239                continue;
     1240
     1241            /* copy filename */
     1242            strncpy(szFullname, &szBuffer[i], j);
     1243            szFullname[j] = '\0'; /* ensure terminatition. */
     1244
     1245            /* add extention .cpy - hardcoded for the moment. */
     1246            strcat(szFullname, ".cpy");
     1247
     1248            /* find include file! */
     1249            psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer);
     1250
     1251            /* did we find the include? */
     1252            if (psz != NULL)
     1253            {
     1254                char szBuffer2[CCHMAXPATH];
     1255                if (pOptions->fExcludeAll ||
     1256                    pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL
     1257                    )
     1258                    depAddDepend(pvRule, szFullname);
    12271259                else
    1228                     fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
    1229                             pszFilename, iLine, szFullname);
    1230             }
     1260                    depAddDepend(pvRule, szBuffer);
     1261            }
     1262            else
     1263                fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
     1264                        pszFilename, iLine, szFullname);
    12311265        }
    1232         else
    1233             break;
    12341266    } /*while*/
    12351267
     
    14021434
    14031435
     1436/**
     1437 * Adds a file to the cache.
     1438 * @returns   Success indicator.
     1439 * @param     pszFilename   Name of the file which is to be added. (with path!)
     1440 */
     1441static BOOL filecacheAdd(const char *pszFilename)
     1442{
     1443    PFCACHEENTRY pfcNew;
     1444
     1445    /* allocate new block and fill in data */
     1446    pfcNew = malloc(sizeof(FCACHEENTRY) + strlen(pszFilename) + 1);
     1447    if (pfcNew == NULL)
     1448    {
     1449        fprintf(stderr, "error: out of memory! (line=%d)\n", __LINE__);
     1450        return FALSE;
     1451    }
     1452    pfcNew->Key = (char*)(void*)pfcNew + sizeof(FCACHEENTRY);
     1453    strcpy((char*)(unsigned)pfcNew->Key, pszFilename);
     1454    if (!AVLInsert(&pfcTree, pfcNew))
     1455    {
     1456        free(pfcNew);
     1457        return TRUE;
     1458    }
     1459
     1460    cfcNodes++;
     1461
     1462    return TRUE;
     1463}
     1464
     1465
     1466
     1467/**
     1468 * Checks if pszFile is exists in the cache.
     1469 * @return    TRUE if found. FALSE if not found.
     1470 * @param     pszFilename   Name of the file to be found. (with path!)
     1471 */
     1472static BOOL filecacheFind(const char *pszFilename)
     1473{
     1474    return AVLGet(&pfcTree, (AVLKEY)pszFilename) != NULL;
     1475}
     1476
    14041477
    14051478
     
    14141487 * @status    completely implemented.
    14151488 * @author    knut st. osmundsen
    1416  */
    1417 char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer)
     1489 * @remark    need substantial optimizations. 95% of execution is spend here.
     1490 */
     1491static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer)
    14181492{
    14191493    const char *psz = pszPathList;
     
    14341508        if (pszNext - psz > 0)
    14351509        {
    1436             HDIR            hDir = HDIR_CREATE;
    1437             ULONG           cFiles = 1UL;
    1438             FILEFINDBUF3    FileFindBuf;
    14391510            APIRET          rc;
    14401511            char            szFile[CCHMAXPATH];
     
    14471518            strcat(szFile, pszFilename);
    14481519
    1449             /* search for file */
    1450             rc = DosFindFirst(szFile, &hDir, FILE_NORMAL, &FileFindBuf, sizeof(FileFindBuf),
    1451                               &cFiles, FIL_STANDARD);
    1452             DosFindClose(hDir);
     1520            /*
     1521             * Search for the file in this directory.
     1522             *   Search cache first
     1523             */
     1524            if (!filecacheFind(szFile))
     1525            {
     1526                FILESTATUS3 fsts3;
     1527
     1528                /* ask the OS */
     1529                rc = DosQueryPathInfo(szFile, FIL_STANDARD, &fsts3, sizeof(fsts3));
     1530                if (rc == NO_ERROR)
     1531                {   /* add file to cache. */
     1532                    filecacheAdd(szFile);
     1533                }
     1534            }
     1535            else
     1536                rc = NO_ERROR;
     1537
     1538            /* did we find it? */
    14531539            if (rc == NO_ERROR)
    14541540            {
     
    15491635 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    15501636 */
    1551 static char *trim(char *psz)
     1637INLINE char *trim(char *psz)
    15521638{
    15531639    int i;
     
    15711657 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    15721658 */
    1573 static char *trimR(char *psz)
     1659INLINE char *trimR(char *psz)
    15741660{
    15751661    int i;
     
    15981684    {
    15991685        signed long cbFile = fsize(phFile);
    1600         if (cbFile != -1)
     1686        if (cbFile > 0)
    16011687        {
    16021688            pvFile = malloc(cbFile + 1);
     
    16101696                }
    16111697            }
     1698            else
     1699                fprintf(stderr, "warning/error: failed to open file %s\n", pszFilename);
    16121700        }
    16131701        fclose(phFile);
     
    16541742
    16551743    return psz;
     1744}
     1745
     1746
     1747/**
     1748 * Gets the next line from an textbuffer.
     1749 * (fgets for textbuffer)
     1750 * @returns   Pointer to pszOutBuffer. NULL when end of file.
     1751 * @param     pvBuffer  Buffer handle.
     1752 * @param     ppv       Pointer to a buffer index pointer. (holds the current buffer index)
     1753 *                      Pointer to a null pointer is passed in to get the first line.
     1754 * @param     pszLineBuffer  Output line buffer. (!= NULL)
     1755 * @param     cchLineBuffer  Size of the output line buffer. (> 0)
     1756 * @remark    '\n' and '\r' are removed!
     1757 */
     1758static char *textbufferGetNextLine(void *pvBuffer, void **ppv, char *pszLineBuffer, int cchLineBuffer)
     1759{
     1760    char *          pszLine = pszLineBuffer;
     1761    char *          psz = *(char**)(void*)ppv;
     1762    register char   ch;
     1763
     1764    /* first line? */
     1765    if (psz == NULL)
     1766        psz = pvBuffer;
     1767
     1768    /* Copy to end of the line or end of the linebuffer. */
     1769    ch = *psz;
     1770    cchLineBuffer--; /* reserve space for '\0' */
     1771    while (cchLineBuffer > 0 && ch != '\0' && ch != '\n' && ch != '\r')
     1772    {
     1773        *pszLine++ = ch;
     1774        ch = *++psz;
     1775    }
     1776    *pszLine = '\0';
     1777
     1778    /* skip line end */
     1779    if (ch == '\n')
     1780        ch = *++psz;
     1781    if (ch == '\r')
     1782        psz++;
     1783
     1784    /* check if position has changed - if unchanged it's the end of file! */
     1785    if (*ppv == (void*)psz)
     1786        pszLineBuffer = NULL;
     1787
     1788    /* store current position */
     1789    *ppv = (void*)psz;
     1790
     1791    return pszLineBuffer;
    16561792}
    16571793
     
    17721908        char     szBuffer[4096];
    17731909        int      iBuffer = 0;
     1910        int      cch;
    17741911        PDEPRULE pdep = pdepList;
    17751912
     
    17771914        {
    17781915            /* Write rule. Flush the buffer first if necessary. */
    1779             if (iBuffer + 2 >= sizeof(szBuffer))
     1916            cch = strlen(pdep->pszRule);
     1917            if (iBuffer + cch + 2 >= sizeof(szBuffer))
    17801918            {
    17811919                fwrite(szBuffer, iBuffer, 1, phFile);
    17821920                iBuffer = 0;
    17831921            }
    1784             iBuffer += sprintf(szBuffer + iBuffer, "%s:", pdep->pszRule);
     1922            strcpy(szBuffer + iBuffer, pdep->pszRule);
     1923            iBuffer += cch;
     1924            strcpy(szBuffer + iBuffer++, ":");
    17851925
    17861926            /* write rule dependants. */
     
    19142054        pdepPrev->pNext = pNew;
    19152055
     2056    _heap_check();
    19162057    return pNew;
    19172058}
     
    19302071
    19312072    /* allocate more array space */
    1932     if (pdep->cDeps == 0 || ((pdep->cDeps + 2) % 32) == 0)
    1933     {
    1934         pdep->papszDep = realloc(pdep->papszDep, sizeof(char*) * (pdep->cDeps + 32));
     2073    if (((pdep->cDeps) % 48) == 0)
     2074    {
     2075        pdep->papszDep = realloc(pdep->papszDep, sizeof(char*) * (pdep->cDeps + 50));
    19352076        if (pdep->papszDep == NULL)
    19362077        {
     
    19492090
    19502091    /* successful! */
     2092    _heap_check();
    19512093    return TRUE;
    19522094}
    19532095
    1954 
    1955 
    1956 /**
    1957  * Removes double dependencies.
    1958  * @returns   Success indicator.
    1959  * @param     pszFilename  Depend filename.
    1960  */
    1961 static BOOL depCleanFile(const char *pszFilename)
    1962 {
    1963     if (depReadFile(pszFilename))
    1964         return depWriteFile(pszFilename);
    1965     return FALSE;
    1966 }
    19672096
    19682097
     
    19722101#include <os2.h>
    19732102
     2103
     2104
  • TabularUnified trunk/tools/fastdep/makefile

    r3091 r3129  
    1 # $Id: makefile,v 1.3 2000-03-11 18:07:48 bird Exp $
     1# $Id: makefile,v 1.4 2000-03-16 21:10:10 bird Exp $
    22
    33#
     
    1515# Addjust common definitions
    1616!ifdef DEBUG
    17 CFLAGS   = $(CFLAGS)  -Ge+ -Tx+ -I$(PDWIN32_INCLUDE) -I..\common  \
    18            -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -O+
     17CFLAGS   = $(CFLAGS)  -Ge+ -Tx+ -I..\common \
     18           -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -O+ -Tm-
     19#          -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -Gh+
    1920LDFLAGS  = $(LDFLAGS) -Ge+ -Fe$@ /B"/MAP:full"
    2021!else
    21 CFLAGS   = $(CFLAGS)  -Ge+ -Tx+ -I$(PDWIN32_INCLUDE) -I..\common      \
     22CFLAGS   = $(CFLAGS)  -Ge+ -Tx+ -I..\common      \
    2223           -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext-
    2324LDFLAGS  = $(LDFLAGS) -Ge+ -Fe$@ /B"/MAP:full"
     
    2930
    3031
    31 fastdep.exe: fastdep.obj
    32    $(LD) $(LDFLAGS) $** $(RTLLIB) os2386.lib
     32fastdep.exe: fastdep.obj avl.obj
     33    $(LD) $(LDFLAGS) $** $(RTLLIB) os2386.lib
     34#   $(LD) $(LDFLAGS) $** CPPOPA3.OBJ $(RTLLIB) os2386.lib
    3335
    3436..\bin\fastdep.exe: fastdep.exe
    3537   $(CP) $** $@
    3638
     39
    3740dep: # dummy rule
    3841
     42
    3943clean:
    40    -@$(RM) *.obj
    41    -@$(RM) *.exe
    42    -@$(RM) *.map
    43    -@$(RM) *.pch
    44    -@$(RM) *.log
     44   -@$(RM) *.obj *.exe *.map *.pch *.log ..\bin\fastdep.exe
Note: See TracChangeset for help on using the changeset viewer.