C Programming Column
by Al Stevens          

Listing One
// ----- compiler.h
#ifndef COMPILER_H
#define COMPILER_H

#include "Quincy.h"

class Compiler  {
public:
    enum CompileStatus { idle, preprocessing, compiling, assembling, 
        linking, buildinglibrary, finished, aborting, aborted };
    enum CompileAction { none, execute, step, turbodebugger };
protected:
    PROCESS_INFORMATION m_CompileInformation;   // for compiling
    bool m_bLinkCpp;            // true if linking c++
    bool m_bCpp;                // true if compiling c++
    bool m_bFoundDef;           // true if def is in project

    CompileStatus m_CompileStatus;
    CompileStatus m_OldCompileStatus;
    CompileAction m_CompileAction;
    CStringArray m_SourceFiles;     // source files to compile
    CStringArray m_ObjectFiles;     // object files to link
    CStringArray m_LibraryFiles;    // library files to link
    CStringArray m_ResourceFiles;   // resource files to bind

    CString m_strTargetName;    // path of compiler file to build &/or execute
    CString m_strFilename;      // source code file name without path
    CString m_strOldFilename;   // previous name compiled
    CString m_strDefname;       // .def file name
    CString m_strErrorFile;     // error stdout file from compiler

    CString m_strOFile;         // object file path and name
    CString m_strOPath;         // object file path
    CString m_strObjFiles;      // object file list
    CString m_strLibFiles;      // library file list
    bool m_bErrorsOpen;
    DWORD exitcode;
    DWORD ExitCode;
    CStdioFile m_ErrorCStdioFile;
    CErrorLogDialog* m_pdlgErrors;  // error log dialog box
    bool m_bErrorCreated;           // true if error log list has been created
    int m_nErrorLogWidth;           // width of widest message in error log
public:
    // ---- error log
    struct el ErrorLog[maxerrors];
    UINT m_nErrorCount;             // # entries in error/warning log
private:
    static UINT BldProg(void*);
    void CollectErrorMessages();
    void OpenErrorMessagesFile();
    void CloseErrorMessagesFile();
    void CompileStep();
protected:
    CString Enquote(const CString& str) const;
    bool RunCompilerProgram(CString& strCmd, bool bIsRC = false);
    virtual void BuildStdFiles() = 0;
    virtual void BuildResourceScriptCommand(CString& strCmd, 
                                    const CString& strResFile) = 0;
    virtual void BuildResFileCommand(CString& strCmd) = 0;
    virtual void BuildCompilerCommand(CString& strCmd, 
                                                 const CString& strFile) = 0;
    virtual void BuildLibCommand(CString& strCmd) = 0;
    virtual void BuildDLLCommand(CString& strCmd) = 0;
    virtual void BuildDefCommand(CString& strCmd, const CString& strFile) = 0;
    virtual void BuildLinkerCommand(CString& strCmd) = 0;
    virtual void ProcessErrorMessage(char* buf) = 0;
    virtual void CompileOneSource(const CString& strFile);
public:
    Compiler();
    ~Compiler();
    bool OnIdle();
    bool CompileRunning() const
        { return m_CompileStatus != idle; }
    void SetAborting()
        { m_CompileStatus = aborting; }
    void SetBuildingCPP(bool bSet)
        { m_bLinkCpp = bSet; }
    void ClearArrays();
    void AddSourceFile(const CString& rstrSrc);
    void AddObjectFile(const CString& rstrObj);
    void AddResourceFile(const CString& rstrRc);
    virtual void BuildTarget();
    virtual void CompileAllSources();
    virtual int  GatherObjects();
    virtual void BuildLibraryTarget();
    virtual void BuildExeTarget();
    virtual void BuildDLLTarget();
    virtual void GatherLibraries();
    virtual CString MakeObjectFileName(const CString& str) const = 0;
    virtual void AddLibraryFile(const CString& rstrLib) = 0;
    void BuildTarget(const CString& strTargetName, 
                    CompileAction action = none, bool bUseTD = false);
    void ShowErrorLog();
    void ClearErrorLog();
    const CString& GetTargetName() const
        { return m_strTargetName; }
    const CString& GetErrorFile() const
        { return m_strErrorFile; }
};
class GCCCompiler : public Compiler {
    CString m_strPrevLine;      // previous error message line
public:
    CString MakeObjectFileName(const CString& str) const
        { return str + ".o"; }
    void CompileAllSources();
    void CompileOneSource(const CString& strFile);
    void AddLibraryFile(const CString& rstrLib);
    void BuildStdFiles();
    void BuildResourceScriptCommand(CString& strCmd,
                                           const CString& strResFile);
    void BuildResFileCommand(CString& strCmd);
    void BuildCompilerCommand(CString& strCmd, const CString& strFile);
    void BuildLibCommand(CString& strCmd);
    void BuildDLLCommand(CString& strFile);
    void BuildDefCommand(CString& strCmd, const CString& strFile);
    void BuildLinkerCommand(CString& strCmd);
    void ProcessErrorMessage(char* buf);
    void GetLibraryPaths(CString& strCmd);
    void GetGUILibraries(CString& strCmd);
};
class BCCCompiler : public Compiler {
public:
    CString MakeObjectFileName(const CString& str) const
        { return str + ".obj"; }
    void AddLibraryFile(const CString& rstrLib);
    void BuildStdFiles();
    void BuildExeTarget();
    void BuildResourceScriptCommand(CString& strCmd, 
                                           const CString& strResFile);
    void BuildResFileCommand(CString& strCmd);
    void BuildCompilerCommand(CString& strCmd, const CString& strFile);
    void BuildLibCommand(CString& strCmd);
    void BuildDLLCommand(CString& strCmd);
    void BuildDefCommand(CString& strCmd, const CString& strFile);
    void GetLibraryPaths(CString& strCmd);
    void BuildLinkerCommand(CString& strCmd);
    void ProcessErrorMessage(char* buf);
};

#endif




1

