Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes
CFileRecord Class Reference

List of all members.

Public Member Functions

 CFileRecord (const char *shortName, const char *pFullName, BOOL bSystem, BOOL bSource)
void ProcessFile ()
void PrintIncludes ()
void PrintDepend ()
void PrintDepend2 ()

Static Public Member Functions

static CString NormalizeFileName (const char *pName)
static CFileRecordFindFileRecord (const char *pName)
static CFileRecordAddFile (const char *pShortName, const char *pFullName, BOOL bSystem=FALSE, BOOL bSource=FALSE)
static void PrintDependancies ()
static void PrintDependancies2 ()
static void PrintTargets (const char *pMacroName, const char *pDelimiter)
static CString DirDefine (const char *pPath)
static void PrintSources ()
static CString SourceDirName (const char *pPath, BOOL bFileName)
static CString GetExt (const char *pPath)
static void PrintBuildRules ()
static void ProcessFiles ()

Public Attributes

CString m_shortName
CString m_pathName
CPtrArray m_includes
BOOL m_bVisited
BOOL m_bSystem
BOOL m_bSource

Static Public Attributes

static CMapStringToPtr fileMap
static CStringArray orderedFileNames
static CMapStringToPtr includeMap
static CMapStringToPtr noDependMap

Detailed Description

Definition at line 122 of file makedep.cpp.


Constructor & Destructor Documentation

CFileRecord::CFileRecord ( const char *  shortName,
const char *  pFullName,
BOOL  bSystem,
BOOL  bSource 
) [inline]

Definition at line 135 of file makedep.cpp.

                                                                                          :
                m_shortName( shortName ),
                m_pathName(),
                m_includes(),
                m_bVisited(FALSE),
                m_bSource( bSource ),
                m_bSystem(bSystem){

              m_pathName = pFullName;
              FixPathName(m_pathName);                         // all upper case for consistency
              ASSERT(FindFileRecord(m_pathName) == NULL);      // make sure it's not already in the map
        fileMap[m_pathName] = this;                     // add this to the filemap, using the appropriate name as the key
              if (bSource) {
                     orderedFileNames.Add(m_pathName);  // remember the order we saw source files in
              }
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

static CFileRecord* CFileRecord::AddFile ( const char *  pShortName,
const char *  pFullName,
BOOL  bSystem = FALSE,
BOOL  bSource = FALSE 
) [inline, static]

Definition at line 307 of file makedep.cpp.

                                      {

              char fullName[_MAX_PATH];
              BOOL bFound = FALSE;
              CString foundName;
              CString fixedShortName;
        CString s;

        // normalize the name
        fixedShortName = pShortName;
        FixPathName(fixedShortName);
        pShortName = fixedShortName;

        // if it is source, we might be getting an obj file.  If we do,
        //  convert it to a c or c++ file.
        if( bSource && (strcmp(GetExt(pShortName),".obj") == 0) ){
            char path_buffer[_MAX_PATH];
            char fname[_MAX_FNAME] = "";
            CString s;

            _splitpath( pShortName, NULL, NULL, fname, NULL );
            if( FileExists( s = CString(fname) + ".cpp") ){
                pShortName = s;
                pFullName = s;
            }
            else if( FileExists( s = CString(fname) + ".c" ) ){
                pShortName = s;
                pFullName = s;
            }
            else {
                return 0;
            }
        }

              // if pFullName was not constructed, construct it here based on the current directory
              if (!pFullName) {
                     _AfxFullPath(fullName, pShortName);
                     pFullName = fullName;
              }
              
              // first check to see if we already have this exact file
              CFileRecord *pRec = FindFileRecord(pFullName);

        // if not found and not a source file check the header list --
        // all files we've found in include directories are in the includeMap.
        // we can save gobs of time by getting it from there
        if (!pRec && !bSource)
            includeMap.Lookup(fixedShortName, (void*&)pRec);

        if (!pRec) {
            // not in one of our lists, start scrounging on disk

            // check the fullname first
            if (FileExists(pFullName)) {
                foundName = pFullName;
                bFound = TRUE;
            }
            else {
                // if still not found, search the include paths
                int i = 0;
                while( i < includeDirectories.GetSize() ){
                    if( FileExists( includeDirectories[i] + pShortName ) ){
                        foundName = includeDirectories[i] + pShortName;
                        bFound = TRUE;
                        break;
                    }
                    i++;
                }
            }
        }
        else {
            // we found it
            bFound = TRUE;
        }

              // source files are not allowed to be missing
              if (bSource && !pRec && !bFound) {
                     fprintf(stderr, "Source file: %s doesn't exist\n", pFullName);
                     mainReturn = -1;            // exit with an error, don't write out the results
              }

#ifdef _DEBUG
              if (!pRec && !bFound && !bSystem) {
                     fprintf(stderr, "Header not found: %s (%s)\n", pShortName, pFullName);
              }
#endif

              // if none of the above logic found it already in the list, 
        // must be a new file, add it to the list
        if (bFound && (pRec == NULL)) {
            pRec = new CFileRecord( pShortName, foundName, bSystem, bSource);

                     // if this one isn't a source file add it to the includeMap
                     // for performance reasons (so we can find it there next time rather
                     // than having to search the file system again)
                     if (!bSource) {
                            includeMap[pShortName] = pRec;
                     }
        }
        return pRec;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static CString CFileRecord::DirDefine ( const char *  pPath) [inline, static]

Definition at line 491 of file makedep.cpp.

                                                 {
        char path_buffer[_MAX_PATH];
        char dir[_MAX_DIR] = "";
        char dir2[_MAX_DIR] = "";
        char fname[_MAX_FNAME] = "";
        char ext[_MAX_EXT] = "";
        CString s;

        _splitpath( pPath, 0, dir, 0, ext );

        BOOL bDone = FALSE;

        while( dir && !bDone){
            // remove the trailing slash
            dir[ strlen(dir)-1] = 0;
            _splitpath( dir, 0, dir2, fname, 0 );
            if( strcmp( fname, "SRC" ) == 0 ){
                strcpy( dir, dir2 );
            }
            else {
                bDone = TRUE;
            }
        }
        s = CString(fname) + "_" + (ext+1);
        return s;
    }

Here is the caller graph for this function:

static CFileRecord* CFileRecord::FindFileRecord ( const char *  pName) [inline, static]

Definition at line 299 of file makedep.cpp.

                                                           {
              CFileRecord* pRec = NULL;
              CString name(pName);
              FixPathName(name);
              fileMap.Lookup(name, (void*&)pRec);
              return(pRec);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static CString CFileRecord::GetExt ( const char *  pPath) [inline, static]

Definition at line 556 of file makedep.cpp.

                                             {
        char ext[_MAX_EXT] = "";

        _splitpath( pPath, 0,0,0, ext );

        CString s = CString(ext);
        s.MakeLower();
        return s;
    }

Here is the caller graph for this function:

static CString CFileRecord::NormalizeFileName ( const char *  pName) [inline, static]

Definition at line 295 of file makedep.cpp.

                                                         {
        return CString(pName);
    }
static void CFileRecord::PrintBuildRules ( ) [inline, static]

Definition at line 566 of file makedep.cpp.

                                 {
        int i;
        CString dirName;
        
        CMapStringToPtr dirList;

        for( i=0; i< orderedFileNames.GetSize(); i++ ){
            dirList[ SourceDirName(orderedFileNames[i], TRUE) ]= 0;
        }

        POSITION next;
        CString name;
        void *pVal;

        next = dirList.GetStartPosition();
        while( next ){
            dirList.GetNextAssoc( next, name, pVal);
            CString dirDefine = DirDefine( name );
            CString ext = GetExt( name );
            name = SourceDirName( name, FALSE );
            CString response = dirDefine.Left(8);

            fprintf( pAltFile, 
                "\n\n\n{%s}%s{$(OUTDIR)}.obj:\n"
                "\t@rem <<$(OUTDIR)\\%s.cl\n"
                "\t$(CFILEFLAGS)\n"
                "\t$(CFLAGS_%s)\n"
                "<<KEEP\n"
                "\t$(CPP) @$(OUTDIR)\\%s.cl %%s\n",
                (const char*)name,
                (const char*)ext,
                (const char*)response,
                (const char*)dirDefine,
                (const char*)response
            );

            fprintf( pAltFile, 
                "\n\n\nBATCH_%s:\n"
                "\t@rem <<$(OUTDIR)\\%s.cl\n"
                "\t$(CFILEFLAGS)\n"
                "\t$(CFLAGS_%s)\n"
                "\t$(FILES_%s)\n"
                "<<KEEP\n"
                "\t$(TIMESTART)\n"
                "\t$(CPP) @$(OUTDIR)\\%s.cl\n"
                "\t$(TIMESTOP)\n",
                (const char*)dirDefine,
                (const char*)response,
                (const char*)dirDefine,
                (const char*)dirDefine,
                (const char*)response
            );
        }

        //
        // Loop through one more time and build the final batch build
        //  rule
        //
        fprintf( pAltFile, 
            "\n\n\nBATCH_BUILD_OBJECTS:\t\t\\\n");

        next = dirList.GetStartPosition();
        while( next ){
            dirList.GetNextAssoc( next, name, pVal);
            CString dirDefine = DirDefine( name );

            fprintf( pAltFile, 
                "\tBATCH_%s\t\t\\\n", dirDefine );
        }

        fprintf( pAltFile, 
            "\n\n");
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 260 of file makedep.cpp.

                      {
        CFileRecord *pRec;
        BOOL bFound;
        POSITION next;
        CString name;

              // clear all the m_bVisisted flags so we can use it to keep track
              // of whether we've already output this file as a dependency
        next = fileMap.GetStartPosition();
        while( next ){
            fileMap.GetNextAssoc( next, name, *(void**)&pRec );
            pRec->m_bVisited = FALSE;
        }

        char fname[_MAX_FNAME];

              if (pRec->m_pathName.GetLength() != 0) {
            if( bSimple ){
                     fprintf(pAltFile, "\n\n\n%s:\t", m_pathName );
            }
            else {
                CString csOutput;
                csOutput = m_pathName;
                FATName(csOutput);

                     _splitpath( csOutput, NULL, NULL, fname, NULL );

                     fprintf(pAltFile, "\n\n\n$(OUTDIR)\\%s.obj: %s ", fname, (const char*) csOutput );
            }
               m_bVisited = TRUE;         // mark it as done so we won't do it again
               PrintIncludes();
              }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 427 of file makedep.cpp.

                       {
        CFileRecord *pRec;
        int i;

        if( m_includes.GetSize() != 0 ){
                     fprintf(pAltFile, "\n\n\n%s: \\\n",m_pathName );
            i = 0;
            while( i < m_includes.GetSize() ){
                pRec = (CFileRecord*) m_includes[i];
                     fprintf(pAltFile, "\t\t\t%s\t\\\n",pRec->m_pathName );
                i++;
            }
        }
    }

Here is the call graph for this function:

static void CFileRecord::PrintDependancies ( ) [inline, static]

Definition at line 411 of file makedep.cpp.

                                   {
        CFileRecord *pRec;
        BOOL bFound;
        POSITION next;
        CString name;

              // use orderedFileNames to preserve order
              for (int pos = 0; pos < orderedFileNames.GetSize(); pos++) {
                     pRec = FindFileRecord(orderedFileNames[pos]);
            if(pRec && pRec->m_bSource ){
                pRec->PrintDepend();
                     }
              }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static void CFileRecord::PrintDependancies2 ( ) [inline, static]

Definition at line 442 of file makedep.cpp.

                                    {
        CFileRecord *pRec;
        BOOL bFound;
        POSITION next;
        CString name;

        next = fileMap.GetStartPosition();
        while( next ){
            fileMap.GetNextAssoc( next, name, *(void**)&pRec );
            pRec->PrintDepend2();
        }
    }

Definition at line 230 of file makedep.cpp.

                        {
        int i = 0;
        while( i < m_includes.GetSize() ){
            CFileRecord *pRec = (CFileRecord*) m_includes[i];

            //  Don't write out files that don't exist or are not in the namespace
            //      of the programs using it (netscape_AppletMozillaContext.h doesn't
            //      mix well with 16 bits).
                     // Also don't write out files that are in the noDependMap
                     void*  lookupJunk;
            if( !pRec->m_bVisited && pRec->m_pathName.GetLength() != 0 && !noDependMap.Lookup(pRec->m_pathName, lookupJunk)) {

                            // not supposed to have a file in the list that doesn't exist
                            ASSERT(FileExists(pRec->m_pathName));

                CString csOutput;
                csOutput = pRec->m_pathName;
                FATName(csOutput);

                            fprintf(pAltFile, "\\\n    %s ", (const char *) csOutput );

                            // mark this one as done so we don't do it more than once
                pRec->m_bVisited = TRUE;

                pRec->PrintIncludes();
            }
            i++;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static void CFileRecord::PrintSources ( ) [inline, static]

Definition at line 519 of file makedep.cpp.

                              {
        int i;
        CString dirName, newDirName;

        for( i=0; i< orderedFileNames.GetSize(); i++ ){
            newDirName= DirDefine( orderedFileNames[i] );
            if( newDirName != dirName ){
                fprintf( pAltFile, "\n\n\nFILES_%s= $(FILES_%s) \\", 
                        (const char*)newDirName, (const char*)newDirName );
                dirName = newDirName;
            }
            fprintf( pAltFile, "\n\t%s^", (const char*)orderedFileNames[i] );
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static void CFileRecord::PrintTargets ( const char *  pMacroName,
const char *  pDelimiter 
) [inline, static]

Definition at line 456 of file makedep.cpp.

                                                                            {
        CFileRecord *pRec;
        BOOL bFound;
        POSITION next;
        CString name;

        BOOL bNeedDelimiter = FALSE;
              fprintf(pAltFile, "%s = ", pMacroName);        

              // use orderedFileNames to preserve target order
              for (int pos = 0; pos < orderedFileNames.GetSize(); pos++) {
                     pRec = FindFileRecord(orderedFileNames[pos]);
                     ASSERT(pRec);

            if( pRec && pRec->m_bSource && pRec->m_pathName.GetLength() != 0){
                char fname[_MAX_FNAME];

                CString csOutput;
                csOutput = pRec->m_pathName;
                FATName(csOutput);

                _splitpath( csOutput, NULL, NULL, fname, NULL );

                if(bNeedDelimiter)  {
                    fprintf(pAltFile, "%s\n", pDelimiter);
                    bNeedDelimiter = FALSE;
                }

                            fprintf(pAltFile, "     $(OUTDIR)\\%s.obj   ", fname );
                bNeedDelimiter = TRUE;
            }
        }
              fprintf(pAltFile, "\n\n\n");        
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 155 of file makedep.cpp.

                      {
        FILE *f;
              CString fullName;
        BOOL bSystem;
              DWORD lineCntr = 0;
              char *a = new char[2048];
        memset(a, 0, 2048);
              char srcPath[_MAX_PATH];

              // construct the full path
              if (!_AfxFullPath(srcPath, m_pathName)) {
                     strcpy(srcPath, m_pathName);
              }

              // strip off the source filename to end up with just the path
              LPSTR pTemp = strrchr(srcPath, '\\');
              if (pTemp) {
                     *(pTemp + 1) = 0;
              }

        f = fopen(m_pathName, "r");
        if(f != NULL && f != (FILE *)-1)  {
                     setvbuf(f, NULL, _IOFBF, 32768);          // use a large file buffer
            while(fgets(a, 2047, f)) {
                            // if the string "//{{NO_DEPENDENCIES}}" is at the start of one of the 
                            // first 10 lines of a file, don't build dependencies on it or any
                            // of the files it includes
                            if (lineCntr < 10) {
                                   static char* pDependStr = "//{{NO_DEPENDENCIES}}";
                                   if (strncmp(a, pDependStr, strlen(pDependStr)) == 0) {
                                          noDependMap[m_pathName] = 0;       // add it to the noDependMap
                                          break;                                           // no need for further processing of this file
                                   }
                            }
                            ++lineCntr;
                            // have to handle a variety of legal syntaxes that we find in our source files:
                            //    #include
                            // #   include
                // #include
                            // if the first non-whitespace char is a '#', consider this line
                            pTemp = a;
                            pTemp += strspn(pTemp, " \t");                   // skip whitespace
                            if (*pTemp == '#') {
                                   ++pTemp;                                                // skip the '#'
                                   pTemp += strspn(pTemp, " \t");            // skip more whitespace
                                   if( !strncmp(pTemp, "include", 7) ){
                                          pTemp += 7;                                      // skip the "include"
                                          pTemp += strspn(pTemp, " \t");     // skip more whitespace
                                          bSystem = (*pTemp == '<');         // mark if it's a system include or not
                        // forget system files -- we just have to search all the paths
                        // every time and never find them! This change alone speeds a full
                        // depend run on my system from 5 minutes to 3:15
                                          // if (bSystem || (*pTemp == '"')) {
                        if (*pTemp == '"') {
                                                 LPSTR pStart = pTemp + 1;   // mark the start of the string
                                                 pTemp = pStart + strcspn(pStart, ">\" "); // find the end of the string
                                                 *pTemp = 0;                               // terminate the string

                                                 // construct the full pathname from the path part of the 
                                                 // source file and the name listed here
                                                 fullName = srcPath;
                                                 fullName += pStart;
                                                 CFileRecord *pAddMe = AddFile( pStart, fullName, bSystem );
                                                 if (pAddMe) {
                                                        m_includes.Add(pAddMe);
                                                 }
                                          }
                                   }
                            }
            }
            fclose(f);
        }
        delete [] a;
    }

Here is the call graph for this function:

static void CFileRecord::ProcessFiles ( ) [inline, static]

Definition at line 641 of file makedep.cpp.

                              {
        CFileRecord *pRec;
        BOOL bFound;
        POSITION next;
        CString name;

              // search all the files for headers, adding each one to the list when found
              // rather than do it recursively, it simple marks each one it's done
              // and starts over, stopping only when all are marked as done

        next = fileMap.GetStartPosition();
        while( next ){
            fileMap.GetNextAssoc( next, name, *(void**)&pRec );
            if( pRec->m_bVisited == FALSE && pRec->m_bSystem == FALSE ){
                            // mark this file as already done so we don't read it again
                            // to find its headers
                pRec->m_bVisited = TRUE;
                pRec->ProcessFile();
                // Start searching from the beginning again
                            // because ProcessFile may have added new files 
                            // and changed the GetNextAssoc order
                next = fileMap.GetStartPosition();       

            }
        }
    }

Here is the caller graph for this function:

static CString CFileRecord::SourceDirName ( const char *  pPath,
BOOL  bFileName 
) [inline, static]

Definition at line 534 of file makedep.cpp.

                                                                    {
        char path_buffer[_MAX_PATH];
        char drive[_MAX_DRIVE] = "";
        char dir[_MAX_DIR] = "";
        char fname[_MAX_FNAME] = "";
        char ext[_MAX_EXT] = "";
        CString s;

        _splitpath( pPath, drive, dir, fname, ext );

        s = CString(drive) + dir;
        if( bFileName ){
            s += CString("FNAME") + ext;
        }
        else {
            // remove the trailing slash
            s = s.Left( s.GetLength() - 1 );
        }
        return s;
    }

Here is the caller graph for this function:


Member Data Documentation

CMapStringToPtr CFileRecord::fileMap [static]

Definition at line 130 of file makedep.cpp.

CMapStringToPtr CFileRecord::includeMap [static]

Definition at line 132 of file makedep.cpp.

Definition at line 129 of file makedep.cpp.

Definition at line 128 of file makedep.cpp.

Definition at line 127 of file makedep.cpp.

Definition at line 126 of file makedep.cpp.

Definition at line 125 of file makedep.cpp.

Definition at line 124 of file makedep.cpp.

CMapStringToPtr CFileRecord::noDependMap [static]

Definition at line 133 of file makedep.cpp.

CStringArray CFileRecord::orderedFileNames [static]

Definition at line 131 of file makedep.cpp.


The documentation for this class was generated from the following file: