Changeset 5921 for trunk/tools


Ignore:
Timestamp:
Jun 7, 2001, 2:35:42 AM (24 years ago)
Author:
bird
Message:

Synced with lates chagnes from OS2Tools. Optimizations like only scan files back 1 month compared to existing .depend file.

Location:
trunk/tools/fastdep
Files:
3 edited

Legend:

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

    r4653 r5921  
    1 /* $Id: avl.c,v 1.3 2000-11-21 04:35:36 bird Exp $
     1/* $Id: avl.c,v 1.4 2001-06-07 00:35:41 bird Exp $
    22 *
    33 * AVL-Tree (lookalike) implementation.
     
    186186        assert(AVLStack.cEntries < AVL_MAX_HEIGHT);
    187187        AVLStack.aEntries[AVLStack.cEntries++] = ppDeleteNode;
     188        #ifndef AVL_CMP
    188189        if (AVL_E(pDeleteNode->Key, Key))
    189190            break;
     
    193194        else
    194195            ppDeleteNode = &pDeleteNode->pRight;
     196        #else
     197        {
     198        int register iDiff;
     199        if ((iDiff = AVL_CMP(pDeleteNode->Key, Key)) == 0)
     200            break;
     201
     202        if (iDiff > 0)
     203            ppDeleteNode = &pDeleteNode->pLeft;
     204        else
     205            ppDeleteNode = &pDeleteNode->pRight;
     206        }
     207        #endif
    195208    }
    196209
     
    245258PAVLNODECORE AVLGet(PPAVLNODECORE ppTree, AVLKEY Key)
    246259{
    247     register PAVLNODECORE  pNode = *ppTree;
     260    #ifndef AVL_CMP
     261    register PAVLNODECORE   pNode = *ppTree;
    248262
    249263    while (pNode != NULL && AVL_NE(pNode->Key, Key))
     
    255269    }
    256270
     271    #else
     272
     273    register int            iDiff;
     274    register PAVLNODECORE   pNode = *ppTree;
     275
     276    while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0)
     277    {
     278        if (iDiff > 0)
     279            pNode = pNode->pLeft;
     280        else
     281            pNode = pNode->pRight;
     282    }
     283
     284    #endif
     285
    257286    return pNode;
    258287}
    259 
    260288
    261289
     
    273301PAVLNODECORE    AVLGetWithParent(PPAVLNODECORE ppTree, PPAVLNODECORE ppParent, AVLKEY Key)
    274302{
    275     register PAVLNODECORE  pNode = *ppTree;
    276     register PAVLNODECORE  pParent = NULL;
     303    #ifndef AVL_CMP
     304
     305    register PAVLNODECORE   pNode = *ppTree;
     306    register PAVLNODECORE   pParent = NULL;
    277307
    278308    while (pNode != NULL && AVL_NE(pNode->Key, Key))
     
    284314            pNode = pNode->pRight;
    285315    }
     316
     317    #else
     318
     319    register PAVLNODECORE   pNode = *ppTree;
     320    register PAVLNODECORE   pParent = NULL;
     321    register int            iDiff;
     322
     323    while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0)
     324    {
     325        pParent = pNode;
     326        if (iDiff > 0)
     327            pNode = pNode->pLeft;
     328        else
     329            pNode = pNode->pRight;
     330    }
     331
     332    #endif
    286333
    287334    *ppParent = pParent;
     
    314361    PPAVLNODECORE   ppNode = ppTree;
    315362    PAVLNODECORE    pNode;
     363    #ifdef AVL_CMP
     364    int     iDiff;
     365    #endif
    316366
    317367    AVLStack.cEntries = 0;
    318368
     369    #ifndef AVL_CMP
    319370    while ((pNode = *ppNode) != NULL && AVL_NE(pNode->Key, Key))
     371    #else
     372    while ((pNode = *ppNode) != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0)
     373    #endif
    320374    {
    321375        assert(AVLStack.cEntries < AVL_MAX_HEIGHT);
    322376        AVLStack.aEntries[AVLStack.cEntries++] = ppNode;
     377        #ifndef AVL_CMP
    323378        if (AVL_G(pNode->Key, Key))
     379        #else
     380        if (iDiff > 0)
     381        #endif
    324382            ppNode = &pNode->pLeft;
    325383        else
     
    349407        {
    350408            pCurNode = *AVLStack.aEntries[AVLStack.cEntries];
     409            #ifndef AVL_CMP
    351410            if (AVL_L(pCurNode->Key, Key) && (*ppLeft == NULL || AVL_G(pCurNode->Key, (*ppLeft)->Key)))
    352411                *ppLeft = pCurNode;
    353412            else if (AVL_G(pCurNode->Key, Key) && (*ppRight == NULL || AVL_L(pCurNode->Key, (*ppRight)->Key)))
    354413                *ppRight = pCurNode;
     414            #else
     415            if ((iDiff = AVL_CMP(pCurNode->Key, Key)) < 0 && (*ppLeft == NULL || AVL_G(pCurNode->Key, (*ppLeft)->Key)))
     416                *ppLeft = pCurNode;
     417            else if (iDiff > 0 && (*ppRight == NULL || AVL_L(pCurNode->Key, (*ppRight)->Key)))
     418                *ppRight = pCurNode;
     419            #endif
    355420        }
    356421    }
     
    583648PAVLNODECORE    AVLGetBestFit(PPAVLNODECORE ppTree, AVLKEY Key, int fAbove)
    584649{
     650    #ifdef AVL_CMP
     651    register int            iDiff;
     652    #endif
    585653    register PAVLNODECORE   pNode = *ppTree;
    586654    PAVLNODECORE            pNodeLast = NULL;
     
    588656    if (fAbove)
    589657    {   /* pNode->Key >= Key */
     658        #ifndef AVL_CMP
    590659        while (pNode != NULL && AVL_NE(pNode->Key, Key))
    591         {
     660        #else
     661        while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0)
     662        #endif
     663        {
     664            #ifndef AVL_CMP
    592665            if (AVL_G(pNode->Key, Key))
     666            #else
     667            if (iDiff > 0)
     668            #endif
    593669            {
    594670                pNodeLast = pNode;
     
    601677    else
    602678    {   /* pNode->Key <= Key */
     679        #ifndef AVL_CMP
    603680        while (pNode != NULL && AVL_NE(pNode->Key, Key))
    604         {
     681        #else
     682        while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0)
     683        #endif
     684        {
     685            #ifndef AVL_CMP
    605686            if (AVL_L(pNode->Key, Key))
     687            #else
     688            if (iDiff < 0)
     689            #endif
    606690            {
    607691                pNodeLast = pNode;
  • trunk/tools/fastdep/avl.h

    r3132 r5921  
    1 /* $Id: avl.h,v 1.2 2000-03-16 23:51:25 bird Exp $
     1/* $Id: avl.h,v 1.3 2001-06-07 00:35:42 bird Exp $
    22 *
    33 * AVL-Tree (lookalike) declaration.
     
    3838#define AVL_E(key1, key2)  (strcmp(key1, key2) == 0)
    3939#define AVL_NE(key1, key2) (strcmp(key1, key2) != 0)
    40 
     40#define AVL_CMP(key1, key2) strcmp(key1, key2)
    4141
    4242/**
  • trunk/tools/fastdep/fastdep.c

    r5317 r5921  
    1 /* $Id: fastdep.c,v 1.26 2001-03-14 20:17:52 bird Exp $
     1/* $Id: fastdep.c,v 1.27 2001-06-07 00:35:42 bird Exp $
    22 *
    33 * Fast dependents. (Fast = Quick and Dirty!)
     
    2121 * If you're compiling this under a UNICODE system this may perhaps change,
    2222 * but I doubd that fastdep will work at all under a UNICODE system. ;-)
    23  */                       
     23 */
    2424#if defined(UNICODE) && !defined(__WIN32OS2__)
    2525#define CBNEWLINE     (2)
     
    4343#include <stdlib.h>
    4444#include <direct.h>
     45#include <assert.h>
    4546
    4647#include "avl.h"
     
    119120    BOOL            fCacheSearchDirs;   /* cache entire search dirs. */
    120121    const char *    pszExcludeFiles;    /* List of excluded files. */
    121     const char *    pszSuperDependency; /* name for super dependency */
     122    const char *    pszSuperDependency; /* Name for super dependency rule. */
     123    BOOL            fForceScan;         /* Force scan of all files. */
     124    FDATE           fDepDate;           /* The date which files are to be search from. */
    122125} OPTIONS, *POPTIONS;
    123126
     
    127130 */
    128131typedef int ( _FNLANG)  (const char *pszFilename, const char *pszNormFilename,
    129                          void *pvFile, BOOL fHeader, POPTIONS pOptions);
     132                         FDATE FileDate, BOOL fHeader);
    130133typedef _FNLANG    *PFNLANG;
    131134
     
    150153typedef struct _DepRule
    151154{
    152     AVLNODECORE      avlCore;
    153     char *           pszRule;          /* Pointer to rule name */
    154     int              cDeps;            /* Entries in the dependant array. */
    155     char **          papszDep;         /* Pointer to an array of pointers to dependants. */
     155    AVLNODECORE     avlCore;
     156    char *          pszRule;            /* Pointer to rule name */
     157    int             cDeps;              /* Entries in the dependant array. */
     158    char **         papszDep;           /* Pointer to an array of pointers to dependants. */
     159    BOOL            fUpdated;           /* If we have updated this entry during current run. */
    156160} DEPRULE, *PDEPRULE;
    157161
     
    168172*******************************************************************************/
    169173static void syntax(void);
    170 static int makeDependent(const char *pszFilename, POPTIONS pOptions);
    171 
    172 int langC_CPP(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);
    173 int langAsm(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);
    174 int langRC(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);
    175 int langCOBOL(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);
     174static int makeDependent(const char *pszFilename, FDATE FileDate);
     175
     176static int langC_CPP(const char *pszFilename, const char *pszNormFilename, FDATE FileDate, BOOL fHeader);
     177static int langAsm(  const char *pszFilename, const char *pszNormFilename, FDATE FileDate, BOOL fHeader);
     178static int langRC(   const char *pszFilename, const char *pszNormFilename, FDATE FileDate, BOOL fHeader);
     179static int langCOBOL(const char *pszFilename, const char *pszNormFilename, FDATE FileDate, BOOL fHeader);
    176180
    177181
     
    196200
    197201/* pathlist operations */
    198 static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer, POPTIONS pOptions);
    199 static BOOL  pathlistFindFile2(const char *pszPathList, const char *pszFilename, POPTIONS pOptions);
     202static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer);
     203static BOOL  pathlistFindFile2(const char *pszPathList, const char *pszFilename);
    200204
    201205/* word operations */
     
    212216INLINE char *trimR(char *psz);
    213217
     218/* preprocessors */
     219static char *PreProcessLine(char *pszOut, const char *pszIn);
     220
    214221/* textbuffer */
    215222static void *textbufferCreate(const char *pszFilename);
     
    219226
    220227/* depend workers */
    221 static BOOL  depReadFile(const char *pszFilename, POPTIONS pOptions);
    222 static BOOL  depWriteFile(const char *pszFilename, POPTIONS pOptions);
     228static BOOL  depReadFile(const char *pszFilename);
     229static BOOL  depWriteFile(const char *pszFilename);
    223230static void  depRemoveAll(void);
    224 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt);
     231static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, FDATE FileDate);
    225232static BOOL  depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic);
    226 #if 0  /* not used */
    227 static BOOL  depCleanFile(const char *pszFilename);
    228 #endif
    229233static BOOL  depCheckCyclic(PDEPRULE pdepRule, const char *pszDep);
    230234
     
    303307    }
    304308};
     309
     310
     311static char szObjectDir[CCHMAXPATH];
     312static char szObjectExt[64] = "obj";
     313static char szRsrcExt[64]   = "res";
     314static char szInclude[32768] = ";";
     315static char szExclude[32768] = ";";
     316static char szExcludeFiles[65536] = "";
     317
     318OPTIONS options =
     319{
     320    szInclude,       /* pszInclude */
     321    szExclude,       /* pszExclude */
     322    FALSE,           /* fExcludeAll */
     323    szObjectExt,     /* pszObjectExt */
     324    szObjectDir,     /* pszObjectDir */
     325    FALSE,           /* fObjectDir */
     326    szRsrcExt,       /* pszRsrcExt */
     327    TRUE,            /* fObjRule */
     328    FALSE,           /* fNoObjectPath */
     329    TRUE,            /* fSrcWhenObj */
     330    FALSE,           /* fAppend */
     331    TRUE,            /* fCheckCyclic */
     332    TRUE,            /* fCacheSearchDirs */
     333    szExcludeFiles,  /* pszExcludeFiles */
     334    NULL,            /* pszSuperDependency */
     335    FALSE,           /* fForceScan */
     336    {1,1,1}          /* fDepDate */
     337};
     338
    305339
    306340
     
    329363    const char *pszDepFile = pszDefaultDepFile;
    330364    char        achBuffer[4096];
    331 
    332     static char szObjectDir[CCHMAXPATH];
    333     static char szObjectExt[64] = "obj";
    334     static char szRsrcExt[64]   = "res";
    335     static char szInclude[32768] = ";";
    336     static char szExclude[32768] = ";";
    337     static char szExcludeFiles[65536] = "";
    338 
    339     OPTIONS options =
    340     {
    341         szInclude,       /* pszInclude */
    342         szExclude,       /* pszExclude */
    343         FALSE,           /* fExcludeAll */
    344         szObjectExt,     /* pszObjectExt */
    345         szObjectDir,     /* pszObjectDir */
    346         FALSE,           /* fObjectDir */
    347         szRsrcExt,       /* pszRsrcExt */
    348         TRUE,            /* fObjRule */
    349         FALSE,           /* fNoObjectPath */
    350         TRUE,            /* fSrcWhenObj */
    351         FALSE,           /* fAppend */
    352         TRUE,            /* fCheckCyclic */
    353         TRUE,            /* fCacheSearchDirs */
    354         szExcludeFiles,  /* pszExcludeFiles */
    355         NULL             /* pszSuperDependency */
    356     };
    357365
    358366    szObjectDir[0] = '\0';
     
    438446                    if (pdepTree != NULL && pszOld != pszDepFile)
    439447                    {
    440                         if (!depWriteFile(pszOld, &options))
     448                        if (!depWriteFile(pszOld))
    441449                            fprintf(stderr, "error: failed to write (flush) dependencies.\n");
    442450                        depRemoveAll();
     
    501509                    break;
    502510
     511                case 'f':
     512                case 'F': /* force scan of all files. */
     513                    options.fForceScan = argv[argi][2] != '-';
     514                    break;
     515
    503516                case 'I': /* optional include path. This has precedence over the INCLUDE environment variable. */
    504517                case 'i':
     
    745758
    746759            /*
    747              * If append option is specified we'll have to read the existing dep file
    748              * before starting adding new dependencies.
     760             * If append option is or if the forcescan option isn't is
     761             * we'll have to read the existing dep file before starting
     762             * adding new dependencies.
    749763             */
    750             if (pdepTree == NULL && options.fAppend)
    751                 depReadFile(pszDepFile, &options);
     764            if (pdepTree == NULL && (options.fAppend || !options.fForceScan))
     765                depReadFile(pszDepFile);
    752766
    753767            /*
     
    802816                     * Analyse the file.
    803817                     */
    804                     rc -= makeDependent(&szSource[0], &options);
     818                    rc -= makeDependent(&szSource[0], pfindbuf3->fdateLastWrite);
    805819                }
    806820
     
    817831
    818832    /* Write the depend file! */
    819     if (!depWriteFile(pszDepFile, &options))
     833    if (!depWriteFile(pszDepFile))
    820834        fprintf(stderr, "error: failed to write dependencies file!\n");
    821835    #if 0
     
    832846 * @author    knut st. osmundsen
    833847 */
    834 static void syntax(void)
     848void syntax(void)
    835849{
    836850    printf(
    837         "FastDep v0.32\n"
     851        "FastDep v0.40\n"
    838852        "Dependency scanner. Creates a makefile readable depend file.\n"
    839853        " - was quick and dirty, now it's just quick -\n"
    840854        "\n"
    841         "Syntax: FastDep [-a<[+]|->] [-ca] [-cy<[+]|->] [-d <outputfn>]\n"
    842         "                [-e <excludepath>] [-eall<[+]|->] [-i <include>] [-n<[+]|->]\n"
    843         "                [-o <objdir>] [-obr<[+]|->] [-x <f1[;f2]>] [-r <rsrcext>]\n"
    844         "                <files> [more options [more files [...]]]\n"
     855        "Syntax: FastDep [options] <files> [more options [more files [...]]]\n"
    845856        "    or\n"
    846857        "        FastDep [options] @<parameterfile>\n"
    847858        "\n"
    848         "   -a<[+]|->       Append to the output file. Default: Overwrite.\n"
     859        "Options:\n"
     860        "   -a<[+]|->       Append to the output file.            Default: Overwrite.\n"
    849861        "   -ca             Force search directory caching.\n"
    850862        "                   Default: cache if more that 25 files are to be searched.\n"
    851863        "                            (more than 25 in the first file expression.)\n"
    852         "   -cy<[+]|->      Check for cylic dependencies. Default: -cy-\n"
    853         "   -d <outputfn>   Output filename. Default: %s\n"
     864        "   -cy<[+]|->      Check for cylic dependencies.         Default: -cy-\n"
     865        "   -d <outputfn>   Output filename.                      Default: %s\n"
    854866        "   -e excludepath  Exclude paths. If a filename is found in any\n"
    855867        "                   of these paths only the filename is used, not\n"
     
    860872        "                           was found in.\n"
    861873        "                   Default: eall-\n"
     874        "   -f<[+]|->       Force scanning of all files. If disabled we'll only scan\n"
     875        "                   files which are younger or up to one month older than the\n"
     876        "                   dependancy file (if it exists).       Default: disabled\n"
    862877        "   -i <include>    Additional include paths. INCLUDE is searched after this.\n"
    863878        "   -n<[+]|->       No path for object files in the rules.\n"
     
    867882        "   -obr<[+]|->     -obr+: Object rule.\n"
    868883        "                   -obr-: No object rule, rule for source filename is generated.\n"
    869         "   -obj[ ]<objext> Object extention.           Default: obj\n"
     884        "   -obj[ ]<objext> Object extention.                     Default: obj\n"
    870885        "   -s[ ][name]     Insert super-dependency on top of tree.\n"
    871886        "                   If not specified name defaults to 'alltargets'.\n"
    872887        "                   Default: disabled\n"
    873         "   -r[ ]<rsrcext>  Resource binary extention.  Default: res\n"
     888        "   -r[ ]<rsrcext>  Resource binary extention.            Default: res\n"
    874889        "   -x[ ]<f1[;f2]>  Files to exclude. Only exact filenames.\n"
    875890        "   <files>         Files to scan. Wildchars are allowed.\n"
     
    886901 * and written to file later.
    887902 * @returns
    888  * @param     pszFilename  Pointer to source filename. Correct case is assumed!
    889  * @param     pOptions     Pointer to options struct.
    890  * @status    completely implemented.
    891  * @author    knut st. osmundsen
    892  */
    893 static int makeDependent(const char *pszFilename, POPTIONS pOptions)
     903 * @param   pszFilename     Pointer to source filename. Correct case is assumed!
     904 * @param   FileDate        File date.
     905 * @status  completely implemented.
     906 * @author  knut st. osmundsen
     907 */
     908int makeDependent(const char *pszFilename, FDATE FileDate)
    894909{
    895910    int    rc = -1;
    896     void * pvFile;
    897 
    898     pvFile = textbufferCreate(pszFilename);
    899     if (pvFile != NULL)
    900     {
    901         char            szExt[CCHMAXPATH];
    902         PCONFIGENTRY    pCfg = &aConfig[0];
    903         BOOL            fHeader;
    904 
    905         /*
    906          * Find which filetype this is...
    907          */
    908         fileExt(pszFilename, szExt);
    909         while (pCfg->papszExts != NULL)
     911
     912    char            szExt[CCHMAXPATH];
     913    PCONFIGENTRY    pCfg = &aConfig[0];
     914    BOOL            fHeader;
     915
     916    /*
     917     * Find which filetype this is...
     918     */
     919    fileExt(pszFilename, szExt);
     920    while (pCfg->papszExts != NULL)
     921    {
     922        const char **ppsz = pCfg->papszExts;
     923        while (*ppsz != NULL && stricmp(*ppsz, szExt) != 0)
     924            ppsz++;
     925        if (*ppsz != NULL)
    910926        {
    911             const char **ppsz = pCfg->papszExts;
    912             while (*ppsz != NULL && stricmp(*ppsz, szExt) != 0)
    913                 ppsz++;
    914             if (*ppsz != NULL)
    915             {
    916                 fHeader = &pCfg->papszExts[pCfg->iFirstHdr] <= ppsz;
    917                 break;
    918             }
    919             pCfg++;
     927            fHeader = &pCfg->papszExts[pCfg->iFirstHdr] <= ppsz;
     928            break;
    920929        }
    921 
    922         /* Found? */
    923         if (pCfg->papszExts != NULL)
    924         {
    925             char szNormFile[CCHMAXPATH];
    926             fileNormalize2(pszFilename, szNormFile);
    927             rc = (*pCfg->pfn)(pszFilename, &szNormFile[0],  pvFile, fHeader, pOptions);
    928         }
    929         else
    930         {
    931             if (*fileName(pszFilename, szExt) != '.') /* these are 'hidden' files, like .cvsignore, let's ignore them. */
    932                 fprintf(stderr, "warning: '%s' has an unknown file type.\n", pszFilename);
    933             rc = 0;
    934         }
    935 
    936         textbufferDestroy(pvFile);
     930        pCfg++;
     931    }
     932
     933    /* Found? */
     934    if (pCfg->papszExts != NULL)
     935    {
     936        char szNormFile[CCHMAXPATH];
     937        fileNormalize2(pszFilename, szNormFile);
     938        rc = (*pCfg->pfn)(pszFilename, &szNormFile[0], FileDate, fHeader);
    937939    }
    938940    else
    939         fprintf(stderr, "failed to open '%s'\n", pszFilename);
     941    {
     942        if (*fileName(pszFilename, szExt) != '.') /* these are 'hidden' files, like .cvsignore, let's ignore them. */
     943            fprintf(stderr, "warning: '%s' has an unknown file type.\n", pszFilename);
     944        rc = 0;
     945    }
     946
    940947
    941948    return rc;
     
    946953 * Generates depend info on this C or C++ file, these are stored internally
    947954 * and written to file later.
    948  * @returns   0 on success.
    949  *            !0 on error.
    950  * @param     pszFilename      Pointer to source filename. Correct case is assumed!
    951  * @param     pszNormFilename  Pointer to normalized source filename.
    952  * @param     pvFile           Pointer to file textbuffer.
    953  * @param     pOptions         Pointer to options struct.
    954  * @status    completely implemented.
    955  * @author    knut st. osmundsen
    956  */
    957 int langC_CPP(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions)
    958 {
     955 * @returns 0 on success.
     956 *          !0 on error.
     957 * @param   pszFilename         Pointer to source filename. Correct case is assumed!
     958 * @param   pszNormFilename     Pointer to normalized source filename.
     959 * @parma   FileDate            Date of the source file.
     960 * @parma   fHeader             True if header file is being scanned.
     961 * @status  completely implemented.
     962 * @author  knut st. osmundsen
     963 */
     964int langC_CPP(const char *pszFilename, const char *pszNormFilename,
     965              FDATE FileDate, BOOL fHeader)
     966{
     967    void *  pvFile;                     /* Text buffer pointer. */
    959968    void *  pvRule;                     /* Handle to the current rule. */
    960969    char    szBuffer[4096];             /* Max line length is 4096... should not be a problem. */
     
    980989    /* Add the depend rule            */
    981990    /**********************************/
    982     if (pOptions->fObjRule && !fHeader)
    983     {
    984         if (pOptions->fNoObjectPath)
    985             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszObjectExt);
     991    if (options.fObjRule && !fHeader)
     992    {
     993        if (options.fNoObjectPath)
     994            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, FileDate);
    986995        else
    987             pvRule = depAddRule(pOptions->fObjectDir ?
    988                                     pOptions->pszObjectDir :
     996            pvRule = depAddRule(options.fObjectDir ?
     997                                    options.pszObjectDir :
    989998                                    filePathSlash(pszFilename, szBuffer),
    990999                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    991                                 pOptions->pszObjectExt);
    992 
    993         if (pOptions->fSrcWhenObj && pvRule)
     1000                                options.pszObjectExt,
     1001                                FileDate);
     1002
     1003        if (options.fSrcWhenObj && pvRule)
    9941004            depAddDepend(pvRule,
    995                          pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?
     1005                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
    9961006                            fileName(pszFilename, szBuffer) : pszNormFilename,
    997                          pOptions->fCheckCyclic);
     1007                         options.fCheckCyclic);
    9981008    }
    9991009    else
    1000         pvRule = depAddRule(pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?
    1001                             fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL);
     1010        pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
     1011                            fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, FileDate);
    10021012
    10031013    /* duplicate rule? */
    10041014    if (pvRule == NULL)
    10051015        return 0;
     1016
     1017
     1018    /********************/
     1019    /* Make file buffer */
     1020    /********************/
     1021    pvFile = textbufferCreate(pszFilename);
     1022    if (!pvFile)
     1023    {
     1024        fprintf(stderr, "failed to open '%s'\n", pszFilename);
     1025        return -1;
     1026    }
    10061027
    10071028
     
    10941115
    10951116                    /* find include file! */
    1096                     psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer, pOptions);
     1117                    psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer);
    10971118                    if (psz == NULL)
    1098                         psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer, pOptions);
     1119                        psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer);
    10991120
    11001121                    /* did we find the include? */
    11011122                    if (psz != NULL)
    11021123                    {
    1103                         if (pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))
    1104                             depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);
     1124                        if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer))
     1125                            depAddDepend(pvRule, szFullname, options.fCheckCyclic);
    11051126                        else
    1106                             depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic);
     1127                            depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
    11071128                    }
    11081129                    else
     
    12191240    } /*while*/
    12201241
     1242    textbufferDestroy(pvFile);
     1243
    12211244    return 0;
    12221245}
     
    12261249 * Generates depend info on this file, these are stored internally
    12271250 * and written to file later.
    1228  * @returns   0 on success.
    1229  *            !0 on error.
    1230  * @param     pszFilename      Pointer to source filename. Correct case is assumed!
    1231  * @param     pszNormFilename  Pointer to normalized source filename.
    1232  * @param     pvFile           Pointer to file textbuffer.
    1233  * @param     pOptions         Pointer to options struct.
    1234  * @status    completely implemented.
    1235  * @author    knut st. osmundsen
    1236  */
    1237 int langAsm(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions)
    1238 {
     1251 * @returns 0 on success.
     1252 *          !0 on error.
     1253 * @param   pszFilename         Pointer to source filename. Correct case is assumed!
     1254 * @param   pszNormFilename     Pointer to normalized source filename.
     1255 * @parma   FileDate            Date of the source file.
     1256 * @parma   fHeader             True if header file is being scanned.
     1257 * @status  completely implemented.
     1258 * @author  knut st. osmundsen
     1259 */
     1260int langAsm(const char *pszFilename, const char *pszNormFilename,
     1261            FDATE FileDate, BOOL fHeader)
     1262{
     1263    void *  pvFile;                     /* Text buffer pointer. */
    12391264    void *  pvRule;                     /* Handle to the current rule. */
    12401265    char    szBuffer[4096];             /* Temporary buffer (max line lenght size...) */
     
    12461271    /* Add the depend rule            */
    12471272    /**********************************/
    1248     if (pOptions->fObjRule && !fHeader)
    1249     {
    1250         if (pOptions->fNoObjectPath)
    1251             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszObjectExt);
     1273    if (options.fObjRule && !fHeader)
     1274    {
     1275        if (options.fNoObjectPath)
     1276            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, FileDate);
    12521277        else
    1253             pvRule = depAddRule(pOptions->fObjectDir ?
    1254                                     pOptions->pszObjectDir :
     1278            pvRule = depAddRule(options.fObjectDir ?
     1279                                    options.pszObjectDir :
    12551280                                    filePathSlash(pszFilename, szBuffer),
    12561281                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    1257                                 pOptions->pszObjectExt);
    1258 
    1259         if (pOptions->fSrcWhenObj && pvRule)
     1282                                options.pszObjectExt,
     1283                                FileDate);
     1284
     1285        if (options.fSrcWhenObj && pvRule)
    12601286            depAddDepend(pvRule,
    1261                          pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?
     1287                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
    12621288                            fileName(pszFilename, szBuffer) : pszNormFilename,
    1263                          pOptions->fCheckCyclic);
     1289                         options.fCheckCyclic);
    12641290    }
    12651291    else
    1266         pvRule = depAddRule(pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?
    1267                             fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL);
     1292        pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
     1293                            fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, FileDate);
    12681294
    12691295    /* duplicate rule? */
    12701296    if (pvRule == NULL)
    12711297        return 0;
     1298
     1299
     1300    /********************/
     1301    /* Make file buffer */
     1302    /********************/
     1303    pvFile = textbufferCreate(pszFilename);
     1304    if (!pvFile)
     1305    {
     1306        fprintf(stderr, "failed to open '%s'\n", pszFilename);
     1307        return -1;
     1308    }
    12721309
    12731310
     
    13201357
    13211358            /* find include file! */
    1322             psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer, pOptions);
     1359            psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer);
    13231360            if (psz == NULL)
    1324                 psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer, pOptions);
     1361                psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer);
    13251362
    13261363            /* Did we find the include? */
    13271364            if (psz != NULL)
    13281365            {
    1329                 if (pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))
    1330                     depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);
     1366                if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer))
     1367                    depAddDepend(pvRule, szFullname, options.fCheckCyclic);
    13311368                else
    1332                     depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic);
     1369                    depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
    13331370            }
    13341371            else
     
    13371374        }
    13381375    } /*while*/
     1376
     1377    textbufferDestroy(pvFile);
    13391378
    13401379    return 0;
     
    13491388 * @param     pszFilename      Pointer to source filename. Correct case is assumed!
    13501389 * @param     pszNormFilename  Pointer to normalized source filename.
    1351  * @param     pvFile           Pointer to file textbuffer.
    1352  * @param     pOptions         Pointer to options struct.
     1390 * @parma   FileDate            Date of the source file.
     1391 * @parma   fHeader             True if header file is being scanned.
    13531392 * @status    completely implemented.
    13541393 * @author    knut st. osmundsen
    13551394 */
    1356 int langRC(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions)
    1357 {
     1395#if 0
     1396int langRC(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader)
     1397{
     1398    void *  pvFile;                     /* Text buffer pointer. */
    13581399    void *  pvRule;                     /* Handle to the current rule. */
    13591400    char    szBuffer[4096];             /* Temporary buffer (max line lenght size...) */
     
    13651406    /* Add the depend rule            */
    13661407    /**********************************/
    1367     if (pOptions->fObjRule && !fHeader)
    1368     {
    1369         if (pOptions->fNoObjectPath)
    1370             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszRsrcExt);
     1408    if (options.fObjRule && !fHeader)
     1409    {
     1410        if (options.fNoObjectPath)
     1411            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, FileDate);
    13711412        else
    1372             pvRule = depAddRule(pOptions->fObjectDir ?
    1373                                     pOptions->pszObjectDir :
     1413            pvRule = depAddRule(options.fObjectDir ?
     1414                                    options.pszObjectDir :
    13741415                                    filePathSlash(pszFilename, szBuffer),
    13751416                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    1376                                 pOptions->pszRsrcExt);
    1377 
    1378         if (pOptions->fSrcWhenObj && pvRule)
     1417                                options.pszRsrcExt,
     1418                                FileDate);
     1419
     1420        if (options.fSrcWhenObj && pvRule)
    13791421            depAddDepend(pvRule,
    1380                          pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?
     1422                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
    13811423                            fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
    1382                          pOptions->fCheckCyclic);
     1424                         options.fCheckCyclic);
    13831425    }
    13841426    else
    1385         pvRule = depAddRule(pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?
    1386                             fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL);
     1427        pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
     1428                            fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL,
     1429                            FileDate);
    13871430
    13881431    /* duplicate rule? */
    13891432    if (pvRule == NULL)
    13901433        return 0;
     1434
     1435
     1436    /********************/
     1437    /* Make file buffer */
     1438    /********************/
     1439    pvFile = textbufferCreate(pszFilename);
     1440    if (!pvFile)
     1441    {
     1442        fprintf(stderr, "failed to open '%s'\n", pszFilename);
     1443        return -1;
     1444    }
    13911445
    13921446
     
    14111465        i1 = 1;
    14121466        if (   strncmp(&szBuffer[i], "#include", 8) == 0
    1413             || (i1 = strncmp(&szBuffer[i], "RCINCLUDE", 9)) == 0
    1414             || strncmp(&szBuffer[i], "DLGINCLUDE", 10) == 0
     1467            || (i1 = strnicmp(&szBuffer[i], "RCINCLUDE", 9)) == 0
     1468            || strnicmp(&szBuffer[i], "DLGINCLUDE", 10) == 0
    14151469            )
    14161470        {
     
    14681522
    14691523            /* find include file! */
    1470             psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer, pOptions);
     1524            psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer);
    14711525            if (psz == NULL)
    1472                 psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer, pOptions);
     1526                psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer);
    14731527
    14741528            /* did we find the include? */
    14751529            if (psz != NULL)
    14761530            {
    1477                 if (pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))
    1478                     depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);
     1531                if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer))
     1532                    depAddDepend(pvRule, szFullname, options.fCheckCyclic);
    14791533                else
    1480                     depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic);
     1534                    depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
    14811535            }
    14821536            else
    14831537                fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
    14841538                        pszFilename, iLine, szFullname);
     1539        }     } /*while*/
     1540
     1541    textbufferDestroy(pvFile);
     1542    return 0;
     1543}
     1544#else
     1545int langRC(const char *pszFilename, const char *pszNormFilename,
     1546           FDATE FileDate, BOOL fHeader)
     1547{
     1548    void *  pvFile;                     /* Text buffer pointer. */
     1549    void *  pvRule;                     /* Handle to the current rule. */
     1550    char    szBuffer[4096];             /* Max line length is 4096... should not be a problem. */
     1551    int     iLine;                      /* Linenumber. */
     1552    void *  pv = NULL;                  /* An index used by textbufferGetNextLine. */
     1553    BOOL    fComment;                   /* TRUE when within a multiline comment. */
     1554                                        /* FALSE when not within a multiline comment. */
     1555    int     iIfStack;                   /* StackPointer. */
     1556    struct  IfStackEntry
     1557    {
     1558        int fIncluded : 1;              /* TRUE:  include this code;
     1559                                         * FALSE: excluded */
     1560        int fIf : 1;                    /* TRUE:  #if part of the expression.
     1561                                         * FALSE: #else part of the expression. */
     1562        int fSupported : 1;             /* TRUE:  supported if/else statement
     1563                                         * FALSE: unsupported all else[<something>] are ignored
     1564                                         *        All code is included.
     1565                                         */
     1566    } achIfStack[256];
     1567
     1568
     1569    /**********************************/
     1570    /* Add the depend rule            */
     1571    /**********************************/
     1572    if (options.fObjRule && !fHeader)
     1573    {
     1574        if (options.fNoObjectPath)
     1575            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, FileDate);
     1576        else
     1577            pvRule = depAddRule(options.fObjectDir ?
     1578                                    options.pszObjectDir :
     1579                                    filePathSlash(pszFilename, szBuffer),
     1580                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
     1581                                options.pszRsrcExt,
     1582                                FileDate);
     1583
     1584        if (options.fSrcWhenObj && pvRule)
     1585            depAddDepend(pvRule,
     1586                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
     1587                            fileName(pszFilename, szBuffer) : pszNormFilename,
     1588                         options.fCheckCyclic);
     1589    }
     1590    else
     1591        pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
     1592                            fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, FileDate);
     1593
     1594    /* duplicate rule? */
     1595    if (pvRule == NULL)
     1596        return 0;
     1597
     1598
     1599    /********************/
     1600    /* Make file buffer */
     1601    /********************/
     1602    pvFile = textbufferCreate(pszFilename);
     1603    if (!pvFile)
     1604    {
     1605        fprintf(stderr, "failed to open '%s'\n", pszFilename);
     1606        return -1;
     1607    }
     1608
     1609
     1610    /*******************/
     1611    /* find dependants */
     1612    /*******************/
     1613    /* Initiate the IF-stack, comment state and line number. */
     1614    iIfStack = 0;
     1615    achIfStack[iIfStack].fIf = TRUE;
     1616    achIfStack[iIfStack].fIncluded = TRUE;
     1617    achIfStack[iIfStack].fSupported = TRUE;
     1618    fComment = FALSE;
     1619    iLine = 0;
     1620    while (textbufferGetNextLine(pvFile, &pv, szBuffer, sizeof(szBuffer)) != NULL) /* line loop */
     1621    {
     1622        register char * pszC;
     1623        char            szFullname[CCHMAXPATH];
     1624        int             cbLen;
     1625        int             i1 = 1;
     1626        int             i = 0;
     1627        iLine++;
     1628
     1629        /* skip blank chars */
     1630        cbLen = strlen(szBuffer);
     1631        while (i + 2 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t'))
     1632            i++;
     1633
     1634        /* preprocessor statement? */
     1635        if (!fComment && szBuffer[i] == '#')
     1636        {
     1637            /*
     1638             * Preprocessor checks
     1639             * We known that we have a preprocessor statment (starting with an '#' * at szBuffer[i]).
     1640             * Depending on the word afterwards we'll take some different actions.
     1641             * So we'll start of by extracting that word and make a string swich on it.
     1642             * Note that there might be some blanks between the hash and the word.
     1643             */
     1644            int     cchWord;
     1645            char *  pszEndWord;
     1646            char *  pszArgument;
     1647            i++;                /* skip hash ('#') */
     1648            while (szBuffer[i] == '\t' || szBuffer[i] == ' ') /* skip blanks */
     1649                i++;
     1650            pszArgument = pszEndWord = findEndOfWord(&szBuffer[i]);
     1651            cchWord = pszEndWord - &szBuffer[i];
     1652
     1653            /*
     1654             * Find the argument by skipping the blanks.
     1655             */
     1656            while (*pszArgument == '\t' || *pszArgument == ' ') /* skip blanks */
     1657                pszArgument++;
     1658
     1659            /*
     1660             * string switch.
     1661             */
     1662            if (strncmp(&szBuffer[i], "include", cchWord) == 0)
     1663            {
     1664                /*
     1665                 * #include
     1666                 *
     1667                 * Are we in a state where this file is to be included?
     1668                 */
     1669                if (achIfStack[iIfStack].fIncluded)
     1670                {
     1671                    char *psz;
     1672                    BOOL f = FALSE;
     1673                    int  j;
     1674
     1675                    /* extract info between "" or <> */
     1676                    while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<')))
     1677                        i++;
     1678                    i++; /* skip '"' or '<' */
     1679
     1680                    /* if invalid statement then continue with the next line! */
     1681                    if (!f) continue;
     1682
     1683                    /* find end */
     1684                    j = f = 0;
     1685                    while (i + j < cbLen &&  j < CCHMAXPATH &&
     1686                           !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>')))
     1687                        j++;
     1688
     1689                    /* if invalid statement then continue with the next line! */
     1690                    if (!f) continue;
     1691
     1692                    /* copy filename */
     1693                    strncpy(szFullname, &szBuffer[i], j);
     1694                    szFullname[j] = '\0'; /* ensure terminatition. */
     1695                    strlwr(szFullname);
     1696
     1697                    /* find include file! */
     1698                    psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer);
     1699                    if (psz == NULL)
     1700                        psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer);
     1701
     1702                    /* did we find the include? */
     1703                    if (psz != NULL)
     1704                    {
     1705                        if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer))
     1706                            depAddDepend(pvRule, szFullname, options.fCheckCyclic);
     1707                        else
     1708                            depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
     1709                    }
     1710                    else
     1711                        fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
     1712                                pszFilename, iLine, szFullname);
     1713                }
     1714            }
     1715            else
     1716                /*
     1717                 * #if
     1718                 */
     1719                if (strncmp(&szBuffer[i], "if", cchWord) == 0)
     1720            {   /* #if 0 and #if <1-9> are supported */
     1721                pszEndWord = findEndOfWord(pszArgument);
     1722                iIfStack++;
     1723                if ((pszEndWord - pszArgument) == 1
     1724                    && *pszArgument >= '0' && *pszArgument <= '9')
     1725                {
     1726                    if (*pszArgument != '0')
     1727                        achIfStack[iIfStack].fIncluded =  TRUE;
     1728                    else
     1729                        achIfStack[iIfStack].fIncluded =  FALSE;
     1730                }
     1731                else
     1732                    achIfStack[iIfStack].fSupported = FALSE;
     1733                achIfStack[iIfStack].fIncluded = TRUE;
     1734                achIfStack[iIfStack].fIf = TRUE;
     1735            }
     1736            else
     1737                /*
     1738                 * #else
     1739                 */
     1740                if (strncmp(&szBuffer[i], "else", cchWord) == 0)
     1741            {
     1742                if (achIfStack[iIfStack].fSupported)
     1743                {
     1744                    if (achIfStack[iIfStack].fIncluded) /* ARG!! this'll prevent warning */
     1745                        achIfStack[iIfStack].fIncluded = FALSE;
     1746                    else
     1747                        achIfStack[iIfStack].fIncluded = TRUE;
     1748                }
     1749                achIfStack[iIfStack].fIf = FALSE;
     1750            }
     1751            else
     1752                /*
     1753                 * #endif
     1754                 */
     1755                if (strncmp(&szBuffer[i], "endif", cchWord) == 0)
     1756            {   /* Pop the if-stack. */
     1757                if (iIfStack > 0)
     1758                    iIfStack--;
     1759                else
     1760                    fprintf(stderr, "%s(%d): If-Stack underflow!\n", pszFilename, iLine);
     1761            }
     1762            /*
     1763             * general if<something> and elseif<something> implementations
     1764             */
     1765            else
     1766                if (strncmp(&szBuffer[i], "elseif", 6) == 0)
     1767            {
     1768                achIfStack[iIfStack].fSupported = FALSE;
     1769                achIfStack[iIfStack].fIncluded = TRUE;
     1770            }
     1771            else
     1772                if (strncmp(&szBuffer[i], "if", 2) == 0)
     1773            {
     1774                iIfStack++;
     1775                achIfStack[iIfStack].fIf = TRUE;
     1776                achIfStack[iIfStack].fSupported = FALSE;
     1777                achIfStack[iIfStack].fIncluded = TRUE;
     1778            }
     1779            /* The rest of them aren't implemented yet.
     1780            else if (strncmp(&szBuffer[i], "if") == 0)
     1781            {
     1782            }
     1783            */
     1784        } else
     1785            /*
     1786             * Check for resource compiler directives.
     1787             */
     1788            if (    !fComment
     1789                &&  !strchr(&szBuffer[i], ',')
     1790                &&  (   !strnicmp(&szBuffer[i], "ICON", 4)
     1791                     || !strnicmp(&szBuffer[i], "FONT", 4)
     1792                     || !strnicmp(&szBuffer[i], "BITMAP", 6)
     1793                     || !strnicmp(&szBuffer[i], "POINTER", 7)
     1794                     || !strnicmp(&szBuffer[i], "RESOURCE", 8)
     1795                     || !(i1 = strnicmp(&szBuffer[i], "RCINCLUDE", 9))
     1796                   /*|| !strnicmp(&szBuffer[i], "DLGINCLUDE", 10) - only used by the dlgeditor */
     1797                     || !strnicmp(&szBuffer[i], "DEFAULTICON", 11)
     1798                     )
     1799                )
     1800        {
     1801            /*
     1802             * RESOURCE 123 1 ["]filename.ext["]
     1803             */
     1804            char    szLine[1024];
     1805            char *  pszFilename;
     1806            char    chQuote = ' ';
     1807
     1808            PreProcessLine(szLine, &szBuffer[i]);
     1809
     1810            pszFilename = &szLine[strlen(szLine)-1];
     1811            if (*pszFilename == '\"' || *pszFilename == '\'')
     1812            {
     1813                chQuote = *pszFilename;
     1814                *pszFilename-- = '\0';
     1815            }
     1816            while (*pszFilename != chQuote)
     1817                pszFilename--;
     1818            *pszFilename++ = '\0'; /* We now have extracted the filename - pszFilename. */
     1819            strlwr(pszFilename);
     1820
     1821            /* Add filename to the dependencies. */
     1822            if (i1)
     1823                depAddDepend(pvRule, pszFilename, options.fCheckCyclic);
     1824            else
     1825            {
     1826                char *psz;
     1827                /* find include file! */
     1828                psz = pathlistFindFile(options.pszInclude, pszFilename, szFullname);
     1829                if (psz == NULL)
     1830                    psz = pathlistFindFile(pszIncludeEnv, pszFilename, szFullname);
     1831
     1832                /* did we find the include? */
     1833                if (psz != NULL)
     1834                {
     1835                    if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szFullname))
     1836                        depAddDepend(pvRule, pszFilename, options.fCheckCyclic);
     1837                    else
     1838                        depAddDepend(pvRule, szFullname, options.fCheckCyclic);
     1839                }
     1840                else
     1841                    fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",
     1842                            pszFilename, iLine, pszFilename);
     1843            }
     1844        }
     1845
     1846
     1847        /*
     1848         * Comment checks.
     1849         *  -Start at first non-blank.
     1850         *  -Loop thru the line since we might have more than one
     1851         *   comment statement on a single line.
     1852         */
     1853        pszC = &szBuffer[i];
     1854        while (pszC != NULL && *pszC != '\0')
     1855        {
     1856            if (fComment)
     1857                pszC = strstr(pszC, "*/");  /* look for end comment mark. */
     1858            else
     1859            {
     1860                char *pszLC;
     1861                pszLC= strstr(pszC, "//");  /* look for single line comment mark. */
     1862                pszC = strstr(pszC, "/*");  /* look for start comment mark */
     1863                if (pszLC && pszLC < pszC)  /* if there is an single line comment mark before the */
     1864                    break;                  /* muliline comment mark we'll ignore the multiline mark. */
     1865            }
     1866
     1867            /* Comment mark found? */
     1868            if (pszC != NULL)
     1869            {
     1870                fComment = !fComment;
     1871                pszC += 2;          /* skip comment mark */
     1872
     1873                /* debug */
     1874                /*
     1875                if (fComment)
     1876                    fprintf(stderr, "starts at line %d\n", iLine);
     1877                else
     1878                    fprintf(stderr, "ends   at line %d\n", iLine);
     1879                    */
     1880            }
    14851881        }
    14861882    } /*while*/
    14871883
     1884    textbufferDestroy(pvFile);
     1885
    14881886    return 0;
    14891887}
     1888#endif
    14901889
    14911890
     
    14931892 * Generates depend info on this COBOL file, these are stored internally
    14941893 * and written to file later.
    1495  * @returns   0 on success.
    1496  *            !0 on error.
    1497  * @param     pszFilename      Pointer to source filename. Correct case is assumed!
    1498  * @param     pszNormFilename  Pointer to normalized source filename.
    1499  * @param     pvFile           Pointer to file textbuffer.
    1500  * @param     pOptions         Pointer to options struct.
    1501  * @status    completely implemented.
    1502  * @author    knut st. osmundsen
    1503  */
    1504 int langCOBOL(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions)
    1505 {
     1894 * @returns 0 on success.
     1895 *          !0 on error.
     1896 * @param   pszFilename         Pointer to source filename. Correct case is assumed!
     1897 * @param   pszNormFilename     Pointer to normalized source filename.
     1898 * @parma   FileDate            Date of the source file.
     1899 * @parma   fHeader             True if header file is being scanned.
     1900 * @status  completely implemented.
     1901 * @author  knut st. osmundsen
     1902 */
     1903int langCOBOL(const char *pszFilename, const char *pszNormFilename,
     1904              FDATE FileDate, BOOL fHeader)
     1905{
     1906    void *  pvFile;                     /* Text buffer pointer. */
    15061907    void *  pvRule;                     /* Handle to the current rule. */
    15071908    char    szBuffer[4096];             /* Temporary buffer (max line lenght size...) */
     
    15131914    /* Add the depend rule            */
    15141915    /**********************************/
    1515     if (pOptions->fObjRule && !fHeader)
    1516     {
    1517         if (pOptions->fNoObjectPath)
    1518             pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszObjectExt);
     1916    if (options.fObjRule && !fHeader)
     1917    {
     1918        if (options.fNoObjectPath)
     1919            pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, FileDate);
    15191920        else
    1520             pvRule = depAddRule(pOptions->fObjectDir ?
    1521                                     pOptions->pszObjectDir :
     1921            pvRule = depAddRule(options.fObjectDir ?
     1922                                    options.pszObjectDir :
    15221923                                    filePathSlash(pszFilename, szBuffer),
    15231924                                fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH),
    1524                                 pOptions->pszObjectExt);
    1525 
    1526         if (pOptions->fSrcWhenObj && pvRule)
     1925                                options.pszObjectExt,
     1926                                FileDate);
     1927
     1928        if (options.fSrcWhenObj && pvRule)
    15271929            depAddDepend(pvRule,
    1528                          pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?
    1529                             fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
    1530                          pOptions->fCheckCyclic);
     1930                         options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename)
     1931                            ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),
     1932                         options.fCheckCyclic);
    15311933    }
    15321934    else
    1533         pvRule = depAddRule(pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?
    1534                             fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL);
     1935        pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ?
     1936                            fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, FileDate);
    15351937
    15361938    /* duplicate rule? */
    15371939    if (pvRule == NULL)
    15381940        return 0;
     1941
     1942
     1943    /********************/
     1944    /* Make file buffer */
     1945    /********************/
     1946    pvFile = textbufferCreate(pszFilename);
     1947    if (!pvFile)
     1948    {
     1949        fprintf(stderr, "failed to open '%s'\n", pszFilename);
     1950        return -1;
     1951    }
    15391952
    15401953
     
    16212034
    16222035            /* find include file! */
    1623             psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer, pOptions);
     2036            psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer);
    16242037
    16252038            /* did we find the include? */
    16262039            if (psz != NULL)
    16272040            {
    1628                 if (pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))
    1629                     depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);
     2041                if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer))
     2042                    depAddDepend(pvRule, szFullname, options.fCheckCyclic);
    16302043                else
    1631                     depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic);
     2044                    depAddDepend(pvRule, szBuffer, options.fCheckCyclic);
    16322045            }
    16332046            else
     
    16362049        }
    16372050    } /*while*/
     2051
     2052    textbufferDestroy(pvFile);
    16382053
    16392054    return 0;
     
    16512066 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    16522067 */
    1653 static int strnicmpwords(const char *pszS1, const char *pszS2, int cch)
     2068int strnicmpwords(const char *pszS1, const char *pszS2, int cch)
    16542069{
    16552070    do
     
    18212236 * @author    knut st. osmundsen
    18222237 */
    1823 static char *filePathSlash(const char *pszFilename, char *pszBuffer)
     2238char *filePathSlash(const char *pszFilename, char *pszBuffer)
    18242239{
    18252240    char *psz = strrchr(pszFilename, '\\');
     
    18492264 * @author    knut st. osmundsen
    18502265 */
    1851 static char *filePathSlash2(const char *pszFilename, char *pszBuffer)
     2266char *filePathSlash2(const char *pszFilename, char *pszBuffer)
    18522267{
    18532268    char *psz = strrchr(pszFilename, '\\');
     
    19522367 * @param     pszFilename   Name of the file which is to be added. (with path!)
    19532368 */
    1954 static BOOL filecacheAddFile(const char *pszFilename)
     2369BOOL filecacheAddFile(const char *pszFilename)
    19552370{
    19562371    PFCACHEENTRY pfcNew;
     
    19822397 * @param     pszDir   Name of the path which is to be added. (with slash!)
    19832398 */
    1984 static BOOL filecacheAddDir(const char *pszDir)
     2399BOOL filecacheAddDir(const char *pszDir)
    19852400{
    19862401    PFCACHEENTRY    pfcNew;
     
    20872502 * @parma     pszFilename  Filename to find.
    20882503 * @parma     pszBuffer    Ouput Buffer.
    2089  * @param     pOptions     Pointer to options struct.
    20902504 * @status    completely implemented.
    20912505 * @author    knut st. osmundsen
    20922506 */
    2093 static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer, POPTIONS pOptions)
     2507char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer)
    20942508{
    20952509    const char *psz = pszPathList;
     
    21352549                     * add the directory to the cache and search it.
    21362550                     */
    2137                     if (pOptions->fCacheSearchDirs && filecacheAddDir(szDir))
     2551                    if (options.fCacheSearchDirs && filecacheAddDir(szDir))
    21382552                    {
    21392553                        if (filecacheFind(pszBuffer))
     
    21762590 * @param     pszPathList  Path list to search for filename.
    21772591 * @parma     pszFilename  Filename to find. The filename should be normalized!
    2178  * @param     pOptions     Pointer to options struct.
    21792592 * @status    completely implemented.
    21802593 * @author    knut st. osmundsen
    21812594 */
    2182 static BOOL pathlistFindFile2(const char *pszPathList, const char *pszFilename, POPTIONS pOptions)
     2595BOOL pathlistFindFile2(const char *pszPathList, const char *pszFilename)
    21832596{
    21842597    const char *psz = pszPathList;
     
    22382651    }
    22392652
    2240     pOptions = pOptions;
    22412653    return FALSE;
    22422654}
     
    22492661 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    22502662 */
    2251 static char *findEndOfWord(char *psz)
     2663char *findEndOfWord(char *psz)
    22522664{
    22532665
     
    22732685 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    22742686 */
    2275 static char *findStartOfWord(const char *psz, const char *pszStart)
     2687char *findStartOfWord(const char *psz, const char *pszStart)
    22762688{
    22772689    const char *pszR = psz;
     
    22942706 * @param     phFile  File handle.
    22952707 */
    2296 static signed long fsize(FILE *phFile)
     2708signed long fsize(FILE *phFile)
    22972709{
    22982710    int ipos;
     
    23562768
    23572769/**
     2770 * C/C++ preprocess a single line. Assumes that we're not starting
     2771 * with at comment.
     2772 * @returns Pointer to output buffer.
     2773 * @param   pszOut  Ouput (preprocessed) string.
     2774 * @param   pszIn   Input string.
     2775 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     2776 */
     2777char *PreProcessLine(char *pszOut, const char *pszIn)
     2778{
     2779    char *  psz = pszOut;
     2780    BOOL    fComment = FALSE;
     2781    BOOL    fQuote = FALSE;
     2782
     2783    /*
     2784     * Loop thru the string.
     2785     */
     2786    while (*pszIn != '\0')
     2787    {
     2788        if (fQuote)
     2789        {
     2790            *psz++ = *pszIn;
     2791            if (*pszIn == '\\')
     2792            {
     2793                *psz++ = *++pszIn;
     2794                pszIn++;
     2795            }
     2796            else if (*pszIn++ == '"')
     2797                fQuote = FALSE;
     2798        }
     2799        else if (fComment)
     2800        {
     2801            if (*pszIn == '*' && pszIn[1] == '/')
     2802            {
     2803                fComment = FALSE;
     2804                pszIn += 2;
     2805            }
     2806            else
     2807                pszIn++;
     2808        }
     2809        else
     2810        {
     2811            if (   (*pszIn == '/' && pszIn[1] == '/')
     2812                ||  *pszIn == '\0')
     2813            {   /* End of line. */
     2814                break;
     2815            }
     2816
     2817            if (*pszIn == '/' && pszIn[1] == '*')
     2818            {   /* Start comment */
     2819                fComment = TRUE;
     2820                pszIn += 2;
     2821            }
     2822            else
     2823                *psz++ = *pszIn++;
     2824        }
     2825    }
     2826
     2827    /*
     2828     * Trim right.
     2829     */
     2830    psz--;
     2831    while (psz >= pszOut && *psz == ' ' && *psz == '\t')
     2832        psz--;
     2833    psz[1] = '\0';
     2834
     2835    return pszOut;
     2836}
     2837
     2838
     2839/**
    23582840 * Creates a memory buffer for a text file.
    23592841 * @returns   Pointer to file memoryblock. NULL on error.
     
    23622844 *            time (DosRead + DosOpen) - about 70% of the execution time!
    23632845 */
    2364 static void *textbufferCreate(const char *pszFilename)
     2846void *textbufferCreate(const char *pszFilename)
    23652847{
    23662848    void *pvFile = NULL;
     
    23962878 * @param     pvBuffer   Buffer handle.
    23972879 */
    2398 static void textbufferDestroy(void *pvBuffer)
     2880void textbufferDestroy(void *pvBuffer)
    23992881{
    24002882    free(pvBuffer);
     
    24092891 *                      NULL is passed in to get the first line.
    24102892 */
    2411 static char *textbufferNextLine(void *pvBuffer, register char *psz)
     2893char *textbufferNextLine(void *pvBuffer, register char *psz)
    24122894{
    24132895    register char ch;
     
    24432925 * @remark    '\n' and '\r' are removed!
    24442926 */
    2445 static char *textbufferGetNextLine(void *pvBuffer, void **ppv, char *pszLineBuffer, int cchLineBuffer)
     2927char *textbufferGetNextLine(void *pvBuffer, void **ppv, char *pszLineBuffer, int cchLineBuffer)
    24462928{
    24472929    char *          pszLine = pszLineBuffer;
     
    24822964/**
    24832965 * Appends a depend file to the internal file.
    2484  */
    2485 static BOOL  depReadFile(const char *pszFilename, POPTIONS pOptions)
    2486 {
    2487     void *pvFile;
    2488     char *pszNext;
    2489     BOOL  fMoreDeps = FALSE;
    2490     void *pvRule = NULL;
     2966 * This will update the date in the option struct.
     2967 */
     2968BOOL  depReadFile(const char *pszFilename)
     2969{
     2970    FILESTATUS3 fst3;
     2971    void *      pvFile;
     2972    char *      pszNext;
     2973    BOOL        fMoreDeps = FALSE;
     2974    void *      pvRule = NULL;
     2975
    24912976
    24922977    /* read depend file */
     
    24942979    if (pvFile == NULL)
    24952980        return FALSE;
     2981
     2982    /* get the filedate and subtract one month from it. */
     2983    if (!DosQueryPathInfo(pszFilename, FIL_STANDARD, &fst3, sizeof(fst3)))
     2984    {
     2985        if (fst3.fdateLastWrite.month <= 1)
     2986        {
     2987            if (fst3.fdateLastWrite.year != 0)
     2988            {
     2989                fst3.fdateLastWrite.month = 12;
     2990                fst3.fdateLastWrite.year--;
     2991            }
     2992        }
     2993        else
     2994            fst3.fdateLastWrite.month--;
     2995        options.fDepDate = fst3.fdateLastWrite;
     2996    }
    24962997
    24972998    /* parse the original depend file */
     
    25423043                    )
    25433044                {
     3045                    static FDATE FileDate = {0,0,0};
    25443046                    psz[i] = '\0';
    2545                     pvRule = depAddRule(trimR(psz), NULL, NULL);
     3047                    pvRule = depAddRule(trimR(psz), NULL, NULL, FileDate);
     3048                    ((PDEPRULE)pvRule)->fUpdated = FALSE;
    25463049                    psz += i + 1;
    25473050                    cch -= i + 1;
     
    25693072                psz = trim(psz);
    25703073                if (*psz != '\0')
    2571                     depAddDepend(pvRule, psz, pOptions->fCheckCyclic);
     3074                    depAddDepend(pvRule, psz, options.fCheckCyclic);
    25723075            }
    25733076        }
     
    25853088 * @params    pszFilename  Pointer to name of the output file.
    25863089 */
    2587 static BOOL  depWriteFile(const char *pszFilename, POPTIONS options)
     3090BOOL  depWriteFile(const char *pszFilename)
    25883091{
    25893092    FILE *phFile;
     
    26013104         * "super" dependency, enter this scope.
    26023105         */
    2603         if (options->pszSuperDependency != NULL)
     3106        if (options.pszSuperDependency != NULL)
    26043107        {
    26053108            iBuffer = sprintf(szBuffer,
    26063109                              "%s:",
    2607                               options->pszSuperDependency);
     3110                              options.pszSuperDependency);
    26083111
    26093112            pdep = (PDEPRULE)(void*)AVLBeginEnumTree((PPAVLNODECORE)(void*)&pdepTree, &EnumData, TRUE);
     
    27043207 * Removes all nodes in the tree of dependencies. (pdepTree)
    27053208 */
    2706 static void  depRemoveAll(void)
     3209void  depRemoveAll(void)
    27073210{
    27083211    AVLENUMDATA EnumData;
     
    27393242 *                          NULL if pszRulePath or pszRulePath and pszName contains the entire rule.
    27403243 */
    2741 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt)
     3244void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, FDATE FileDate)
    27423245{
    27433246    char     szRule[CCHMAXPATH*2];
     
    27763279    pNew->papszDep = NULL;
    27773280    pNew->avlCore.Key = pNew->pszRule;
    2778 
    2779     /* Insert rule */
     3281    pNew->fUpdated = TRUE;
     3282
     3283    /* Insert the rule */
    27803284    if (!AVLInsert((PPAVLNODECORE)(void*)&pdepTree, &pNew->avlCore))
    2781     {   /* rule existed - return NULL */
     3285    {   /*
     3286         * The rule existed.
     3287         * If it's allready touched (updated) during this session
     3288         *   there is nothing to be done.
     3289         * If not force scan and it's newer than depfile-1month then
     3290         *   we'll use the information we've got.
     3291         * Reuse the node in the tree.
     3292         */
     3293        PDEPRULE    pOld = (PDEPRULE)(void*)AVLGet((PPAVLNODECORE)(void*)&pdepTree, pNew->avlCore.Key);
     3294        assert(pOld);
    27823295        free(pNew);
    2783         return NULL;
     3296        if (pOld->fUpdated)
     3297            return NULL;
     3298
     3299        pOld->fUpdated = TRUE;
     3300        if (!options.fForceScan && *(PUSHORT)(void*)&FileDate < *(PUSHORT)(void*)&options.fDepDate)
     3301            return NULL;
     3302
     3303        if (pOld->papszDep)
     3304        {
     3305            free(pOld->papszDep);
     3306            pOld->papszDep = NULL;
     3307        }
     3308        pOld->cDeps = 0;
     3309
     3310        return pOld;
    27843311    }
    27853312
     
    27973324 * @param     fCheckCyclic  When set we'll check that we're not creating an cyclic dependency.
    27983325 */
    2799 static BOOL  depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic)
     3326BOOL  depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic)
    28003327{
    28013328    PDEPRULE pdep = (PDEPRULE)pvRule;
     
    28433370 * @param     pszDep    Depend name.
    28443371 */
    2845 static BOOL depCheckCyclic(PDEPRULE pdepRule, const char *pszDep)
     3372BOOL depCheckCyclic(PDEPRULE pdepRule, const char *pszDep)
    28463373{
    28473374    #define DEPTH 32
     
    29003427 * Testing purpose.
    29013428 */
     3429
    29023430#if !defined(OS2FAKE)
    29033431#include <os2.h>
     
    29063434#include "olemann.h"
    29073435#endif
    2908 
    2909 
    2910 
    2911 
Note: See TracChangeset for help on using the changeset viewer.