Back to index

enigmail  1.4.3
Classes | Functions | Variables
makedep.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <ctype.h>
#include <afxcoll.h>
#include <afxtempl.h>

Go to the source code of this file.

Classes

class  CFileRecord

Functions

BOOL PASCAL _AfxFullPath (LPSTR lpszPathOut, LPCSTR lpszFileIn)
void AddIncludeDirectory (char *pString)
BOOL FileExists (const char *pString)
void FixPathName (CString &str)
void FATName (CString &csLONGName)
int main (int argc, char **argv)

Variables

int mainReturn = 0
BOOL b16 = FALSE
BOOL bSimple = FALSE
FILE * pAltFile = stdout
CStringArray includeDirectories

Function Documentation

BOOL PASCAL _AfxFullPath ( LPSTR  lpszPathOut,
LPCSTR  lpszFileIn 
)

Definition at line 58 of file makedep.cpp.

{
        OFSTRUCT of;
        if (OpenFile(lpszFileIn, &of, OF_PARSE) != HFILE_ERROR)
        {
                // of.szPathName is in the OEM character set
                OemToAnsi(of.szPathName, lpszPathOut);
                AnsiUpper(lpszPathOut); // paths in upper case just to be sure
                return TRUE;
        }
        else
        {
                TRACE1("Warning: could not parse the path %Fs\n", lpszFileIn);
                lstrcpy(lpszPathOut, lpszFileIn);  // take it literally
                AnsiUpper(lpszPathOut); // paths in upper case just to be sure
                return FALSE;
        }
}

Here is the caller graph for this function:

void AddIncludeDirectory ( char *  pString)

Definition at line 80 of file makedep.cpp.

                                         {
    CString s = pString;
       int len = s.GetLength();
    if(len > 0 && s[len - 1] != '\\' ){
        s += "\\";
    }
    includeDirectories.Add(s);
}

Here is the caller graph for this function:

void FATName ( CString &  csLONGName)

Definition at line 107 of file makedep.cpp.

{
    //  Only relevant for 16 bits.
    if(b16) {
        //  Convert filename to FAT (8.3) equivalent.
        char aBuffer[2048];

        if(GetShortPathName(csLONGName, aBuffer, 2048)) {
            csLONGName = aBuffer;
        }
    }
}

Here is the caller graph for this function:

BOOL FileExists ( const char *  pString)

Definition at line 89 of file makedep.cpp.

                                      {
    struct _stat buf;
    int result;

    result = _stat( pString, &buf );
    return (result == 0);
}

Here is the caller graph for this function:

void FixPathName ( CString &  str)

Definition at line 97 of file makedep.cpp.

                               {
       str.MakeUpper();            // all upper case

       // now switch all forward slashes to back slashes
       int index;
       while ((index = str.Find('/')) != -1) {
              str.SetAt(index, '\\');
       }
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 675 of file makedep.cpp.

                                 {
    int i = 1;
    char *pStr;
    static int iRecursion = 0;     //     Track levels of recursion.
       static CString outputFileName;
    
    // Entering.
    iRecursion++;

    while( i < argc ){
        if( argv[i][0] == '-' || argv[i][0] == '/' ){
            switch( argv[i][1] ){

            case 'i':
            case 'I':
                if( argv[i][2] != 0 ){
                    pStr = &(argv[i][2]);
                }
                else {
                    i++;
                    pStr = argv[i];
                }
                if( pStr == 0 || *pStr == '-' || *pStr == '/' ){
                    goto usage;
                }
                else {
                    AddIncludeDirectory( pStr );
                }
                break;

            case 'f':
            case 'F':
                if( argv[i][2] != 0 ){
                    pStr = &(argv[i][2]);
                }
                else {
                    i++;
                    pStr = argv[i];
                }
                if( pStr == 0 || *pStr == '-' || *pStr == '/'){
                    goto usage;
                }
                else {
                    CStdioFile f;
                    CString s;
                    if( f.Open( pStr, CFile::modeRead ) ){
                        while(f.ReadString(s)){
                            s.TrimLeft();
                            s.TrimRight();
                            if( s.GetLength() ){
                                CFileRecord::AddFile( s, NULL, FALSE, TRUE );
                            }
                        } 
                        f.Close();
                    }
                    else {
                        fprintf(stderr,"makedep: file not found: %s", pStr );
                        exit(-1);
                    }
                }
                break;

            case 'o':
            case 'O':
                if( argv[i][2] != 0 ){
                    pStr = &(argv[i][2]);
                }
                else {
                    i++;
                    pStr = argv[i];
                }
                if( pStr == 0 || *pStr == '-' || *pStr == '/'){
                    goto usage;
                }
                else {
                    CStdioFile f;
                    CString s;
                                   outputFileName = pStr;
                                   if(!(pAltFile = fopen(pStr, "w+")))       {
                        fprintf(stderr, "makedep: file not found: %s", pStr );
                        exit(-1);
                    }
                }
                break;

            case '1':
                if( argv[i][2] == '6')  {
                    b16 = TRUE;
                }
                break;

            case 's':
            case 'S':
                bSimple = TRUE;
                break;



            case 'h':
            case 'H':
            case '?':
            usage:
                fprintf(stderr, "usage: makedep -I <dirname> -F <filelist> <filename>\n"
                       "  -I <dirname>    Directory name, can be repeated\n"
                       "  -F <filelist>   List of files to scan, one per line\n"
                       "  -O <outputFile> File to write output, default stdout\n");
                exit(-1);
            }
        }
        else if( argv[i][0] == '@' ){
              //     file contains our commands.
               CStdioFile f;
           CString s;
           int iNewArgc = 0;
           char **apNewArgv = new char*[5000];
                     memset(apNewArgv, 0, sizeof(apNewArgv));

                     //     First one is always the name of the exe.
                     apNewArgv[0] = argv[0];
                     iNewArgc++;

                     const char *pTraverse;
                     const char *pBeginArg;
               if( f.Open( &argv[i][1], CFile::modeRead ) ){
               while( iNewArgc < 5000 && f.ReadString(s) )     {
                                   //     Scan the string for args, and do the right thing.
                                   pTraverse = (const char *)s;
                                   while(iNewArgc < 5000 && *pTraverse)      {
                                          if(isspace(*pTraverse))     {
                                                        pTraverse++;
                                                        continue;
                                          }

                                          //     Extract to next space.
                                          pBeginArg = pTraverse;
                                          do     {
                                                 pTraverse++;
                                          }
                                          while(*pTraverse && !isspace(*pTraverse));
                                          apNewArgv[iNewArgc] = new char[pTraverse - pBeginArg + 1];
                                          memset(apNewArgv[iNewArgc], 0, pTraverse - pBeginArg + 1);
                                          strncpy(apNewArgv[iNewArgc], pBeginArg, pTraverse - pBeginArg);
                                          iNewArgc++;
                                   }
                   } 
               f.Close();
              }
              
              //     Recurse if needed.
              if(iNewArgc > 1)     {
                     main(iNewArgc, apNewArgv);
              }
              
              //     Free off the argvs (but not the very first one which we didn't allocate).
              while(iNewArgc > 1)  {
                     iNewArgc--;
                     delete [] apNewArgv[iNewArgc];
              }
              delete [] apNewArgv;
        }
        else {
            CFileRecord::AddFile( argv[i], NULL, FALSE, TRUE );
        }
        i++;
    }
    
    // Only of the very bottom level of recursion do we do this.
    if(iRecursion == 1)     {

              // only write the results out if no errors encountered
              if (mainReturn == 0) {
                     CFileRecord::ProcessFiles();
            if( !bSimple ){
                     CFileRecord::PrintTargets("OBJ_FILES", "\\");
                if(b16) {
                         CFileRecord::PrintTargets("LINK_OBJS", "+\\");
                }
                else    {
                         CFileRecord::PrintTargets("LINK_OBJS", "^");
                }
                CFileRecord::PrintSources();
                CFileRecord::PrintBuildRules();
            }
              CFileRecord::PrintDependancies();
              }
           
              if(pAltFile != stdout)      {
                     fclose(pAltFile);
                     if (mainReturn != 0) {
                            remove(outputFileName);     // kill output file if returning an error
                     }
              }
       }
       iRecursion--;

    if (iRecursion == 0 )
    {
        // last time through -- clean up allocated CFileRecords!
        CFileRecord *pFRec;
        CString     name;
        POSITION    next;

        next = CFileRecord::fileMap.GetStartPosition();
        while( next ){
            CFileRecord::fileMap.GetNextAssoc( next, name, *(void**)&pFRec );
            delete pFRec;
        }
    }

    return mainReturn;
}

Here is the call graph for this function:


Variable Documentation

BOOL b16 = FALSE

Definition at line 49 of file makedep.cpp.

BOOL bSimple = FALSE

Definition at line 50 of file makedep.cpp.

CStringArray includeDirectories

Definition at line 54 of file makedep.cpp.

int mainReturn = 0

Definition at line 48 of file makedep.cpp.

FILE* pAltFile = stdout

Definition at line 52 of file makedep.cpp.