⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quincy.cpp

📁 一个完全使用MFC框架开发的C++编译器的代码。功能十分强大可以编译大型程序。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// Quincy.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include <shlobj.h>
#include <algorithm>
#include <process.h>
#include <ddeml.h>
#include <io.h>
#include "Quincy.h"
#include "AboutDlg.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "QuincyDoc.h"
#include "QuincyView.h"
#include "TextDocument.h"
#include "TextView.h"
#include "stabs.h"

#include "OptionsSheet.h"
#include "BuildDialog.h"
#include "RunOptions.h"
#include "EditorOptions.h"
#include "LinkDialog.h"
#include "QuincyPrintDialog.h"

#include "CommandLineDialog.h"
#include "ErrorLogDialog.h"
#include "ExamineDialog.h"
#include "WatchDialog.h"
#include "debugger.h"
#include "TutDlg.h"
#include "compiler.h"
#include "grep.h"
#include "executor.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CQuincyApp

BEGIN_MESSAGE_MAP(CQuincyApp, CWinApp)
	//{{AFX_MSG_MAP(CQuincyApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_STOPBUILD, OnStop)
	ON_UPDATE_COMMAND_UI(ID_STOPBUILD, OnUpdateStop)
	ON_COMMAND(ID_OPTIONS, OnOptions)
	ON_UPDATE_COMMAND_UI(ID_DEBUG_CLEARBREAKPOINTS, OnUpdateDebugClearbreakpoints)
	ON_COMMAND(ID_DEBUG_CLEARBREAKPOINTS, OnDebugClearbreakpoints)
	ON_COMMAND(ID_DEBUG_STEPOVER, OnDebugStepover)
	ON_UPDATE_COMMAND_UI(ID_DEBUG_EXAMINE, OnUpdateDebugExamine)
	ON_COMMAND(ID_DEBUG_EXAMINE, OnDebugExamine)
	ON_COMMAND(ID_DEBUG_WATCH, OnDebugWatch)
	ON_UPDATE_COMMAND_UI(ID_DEBUG_STEPOVER, OnUpdateDebugStepover)
	ON_COMMAND(ID_HELP, OnHelp)
	ON_COMMAND(ID_RESOURCEEDITOR, OnResourceeditor)
	ON_COMMAND(ID_GREP, OnGrep)
	ON_UPDATE_COMMAND_UI(ID_GREP, OnUpdateGrep)
	ON_UPDATE_COMMAND_UI(ID_RESOURCEEDITOR, OnUpdateResourceeditor)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_VIEW_GDBCONSOLE, OnViewGdbconsole)
	ON_UPDATE_COMMAND_UI(ID_HELP, OnUpdateHelp)
	ON_UPDATE_COMMAND_UI(ID_PROPERTIES, OnUpdateProperties)
	ON_COMMAND(ID_PROPERTIES, OnProperties)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_PRINT_SETUP, OnFilePrintSetup)
#ifdef TYCPP
	// Tutorial commands
	ON_COMMAND(ID_WRITETUTORIAL, OnWritetutorial)
	ON_COMMAND(ID_TYCPP, OnTycpp)
	ON_UPDATE_COMMAND_UI(ID_TYCPP, OnUpdateTycpp)
#endif
END_MESSAGE_MAP()

static const int maxsaveddocuments = 10;	// maximum # of documents remembered when reloading

/////////////////////////////////////////////////////////////////////////////
// CQuincyApp construction

CQuincyApp::CQuincyApp()
{
	m_pEditorView = 0;
	m_pCompiler = 0;
	m_pGrep = 0;
	m_pExecutor = 0;
	m_bPrintLineNos = false;
	m_bCpp = false;
	m_bDoLink = false;
	m_pView = 0;
	m_bDebugging = false;
	m_bExceptions = false;
	m_bRTTI = false;
	m_bStrict = false;
	m_bBrowser = false;
	m_maxundos = 1024;
	m_style = 0;
	m_nOptimize = 0;
	m_nExitCode = 0;
	m_pdlgWatch = new CWatchDialog;
	m_pdlgExamine = new CExamineDialog;
	m_pdlgGdbConsole = new GdbConsole;
	m_bBypassChangeTest = false;
	m_CommandLinePromptOption = 0;
	m_pDebugger = 0;
	m_ConsoleRect.SetRectEmpty();
	stepping = false;
#ifdef TYCPP
	m_bReadTutorial = false;
	m_bTutorialDisplayed = false;
	m_bIsTutorial = false;
	m_pCTutDlg = 0;
	m_bTutCreated = false;
#endif
	m_bGrepIsInstalled = false;
	m_bAStyleIsInstalled = false;
	m_bWEditResIsInstalled = false;
	m_bCompilerIsInstalled = false;
	m_bWatchCreated = false;
	m_bGdbConsoleCreated = false;

	m_bSyntaxColors = false;
	m_backgroundcolor = RGB(255,255,255);
	m_normalcolor     = RGB(0,0,0);
	m_keywordcolor    = RGB(0,0,255);
	m_commentcolor    = RGB(0,128,0);
	m_stringcolor     = RGB(255,0,0);
	m_defaultfontheight = 13;
	m_defaultfontwidth = 8;
	m_fontheight = m_defaultfontheight;
	m_fontwidth  = m_defaultfontwidth;
	m_fontheight = FW_NORMAL;
//	m_fontface = "Courier";
}

CQuincyApp::~CQuincyApp()
{
	delete m_pdlgWatch;
	delete m_pdlgExamine;
	delete m_pDebugger;
	delete m_pdlgGdbConsole;
#ifdef TYCPP
	delete m_pCTutDlg;
#endif
	delete m_pCompiler;
	delete m_pGrep;
	delete m_pExecutor;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CQuincyApp object

CQuincyApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CQuincyApp initialization

// Add a static BOOL that indicates whether the class was
// registered so that we can unregister it in ExitInstance
static BOOL bClassRegistered = FALSE;

BOOL CQuincyApp::InitInstance()
{
	// If a previous instance of the application is already running,
	// then activate it and return FALSE from InitInstance to
	// end the execution of this instance.

	if(!FirstInstance())
		return FALSE;

	// Register our unique class name that we wish to use
	WNDCLASS wndcls;

	memset(&wndcls, 0, sizeof(WNDCLASS));   // start with NULL
										  // defaults

	wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
	wndcls.lpfnWndProc = ::DefWindowProc;
	wndcls.hInstance = AfxGetInstanceHandle();
	wndcls.hIcon = LoadIcon(IDR_MAINFRAME); // or load a different
										  // icon
	wndcls.hCursor = LoadCursor( IDC_ARROW );
	wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
	wndcls.lpszMenuName = NULL;

	// Specify our own class name for using FindWindow later
	wndcls.lpszClassName = _T("QuincyAppClass");

	// Register new class and exit if it fails
	if(!AfxRegisterClass(&wndcls))
	{
		TRACE("Class Registration Failed\n");
		return FALSE;
	}
	bClassRegistered = TRUE;


/////////////////////////////////////////////////////////
	SetRegistryKey("Al Stevens Programs");

    osversion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&osversion);

	// --- need some paths for looking for compilers, tutorials, tools
	m_strQuincyBinPath = m_pszHelpFilePath;
	int nIndex = m_strQuincyBinPath.ReverseFind('\\');
	ASSERT(nIndex > 0);
	m_strQuincyBinPath = m_strQuincyBinPath.Left(nIndex);

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif
	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// ---- load Quincy's INI options
	m_bAutoindent = GetProfileInt("Options", "AutoIndent", 1);
	m_taboption   = GetProfileInt("Options", "Tabs", 0);
	m_bSyntaxColors = GetProfileInt("Options", "Syntax Colors", 1);
	m_tabstops = GetProfileInt("Options", "Tab Stops", 4);
	m_maxundos = GetProfileInt("Options", "Max Undos", 1024);

	m_strCompiler    = GetProfileString("Directories", "Compiler");
	m_strDebugger    = GetProfileString("Directories", "Debugger");
	m_strRuntimeDirectory = GetProfileString("Directories", "Runtime");
	m_bPrintLineNos = GetProfileInt("Options", "Print Line Numbers", 0) != 0;

	m_backgroundcolor = GetProfileInt("Options", "Background Color",  RGB(255,255,255));
	m_normalcolor     = GetProfileInt("Options", "Normal Color",      RGB(0,0,0));
	m_keywordcolor    = GetProfileInt("Options", "Keyword Color",     RGB(0,0,255));
	m_commentcolor    = GetProfileInt("Options", "Comment Color",     RGB(0,128,0));
	m_stringcolor     = GetProfileInt("Options", "String Color",      RGB(0,0,0));

	m_fontheight = GetProfileInt("Options",    "Font Height", 13);
	m_fontwidth  = GetProfileInt("Options",    "Font Width",  8);
	m_fontweight = GetProfileInt("Options",    "Font Weight", FW_NORMAL);
//	m_fontface   = GetProfileString("Options", "Font Face", "Courier");

	m_style           = GetProfileInt("Options", "Style", 0); 
	m_command		  = GetProfileString("Options", "Command");

#ifdef TYCPP
	m_bTutorialDisplayed = GetProfileInt("Tutorial",    "Displayed", 1);
#endif
	m_bDebugging = GetProfileInt("Options", "Debugging", 1);
	m_bExceptions = GetProfileInt("Options", "Exceptions", 0);
	m_bRTTI = GetProfileInt("Options", "RTTI", 0);
	m_bStrict = GetProfileInt("Options", "Strict", 0);
	m_strCommandLine = GetProfileString("Options", "Command Line");
	m_strCmdLineOptions = GetProfileString("Options", "Compiler Command Line Options");
	m_CommandLinePromptOption = GetProfileInt("Options", "Command Line Prompt", 0);
	m_nOptimize = GetProfileInt("Options", "Optimize", 0);
	CString strBuffer = GetProfileString("Settings", "Console Position");
	if (!strBuffer.IsEmpty())
		_stscanf (strBuffer, "%i:%i:%i:%i",
			&m_ConsoleRect.left,
			&m_ConsoleRect.top,
			&m_ConsoleRect.right,
			&m_ConsoleRect.bottom);

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CMultiDocTemplate* pDocTemplate;

	pDocTemplate = new CMultiDocTemplate(
		IDR_CPPTEMPLATE,
		RUNTIME_CLASS(CTextDocument),	// document class
		RUNTIME_CLASS(CChildFrame),		// frame class
		RUNTIME_CLASS(CTextView));		// view class
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_CTEMPLATE,
		RUNTIME_CLASS(CTextDocument),	// document class
		RUNTIME_CLASS(CChildFrame),		// frame class
		RUNTIME_CLASS(CTextView));		// view class
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_HTEMPLATE,
		RUNTIME_CLASS(CTextDocument),	// document class
		RUNTIME_CLASS(CChildFrame),		// frame class
		RUNTIME_CLASS(CTextView));		// view class
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_PROJTYPE,
		RUNTIME_CLASS(CQuincyDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CQuincyView));
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_RCTEMPLATE,
		RUNTIME_CLASS(CTextDocument),	// document class
		RUNTIME_CLASS(CChildFrame),		// frame class
		RUNTIME_CLASS(CTextView));		// view class
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_DEFTEMPLATE,
		RUNTIME_CLASS(CTextDocument),	// document class
		RUNTIME_CLASS(CChildFrame),		// frame class
		RUNTIME_CLASS(CTextView));		// view class
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_EDITORTYPE,
		RUNTIME_CLASS(CTextDocument),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CTextView));
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	m_pMainWnd = pMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return false;

	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

	CWnd* pFocusWnd = 0;

	// Enable DDE Execute open
	EnableShellOpen();

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// ------- find path to TEMP disk space if any
	char* tempenv;
	if ((tempenv = getenv("TEMP")) != 0)	{
		m_strTempPath = tempenv;
		if (m_strTempPath.GetLength() && m_strTempPath[m_strTempPath.GetLength()-1] != '\\')
			m_strTempPath += "\\";
	}

	SetCompilerPaths();
//	TestDebuggerPath();

	SetBrowserPath();

#ifdef TYCPP
	LoadTutorials();
	int nDocno = 0;

	bool bCmdFile = false;

	// --- suppress initial FileNew command on startup
	if (cmdInfo.m_nShellCommand != CCommandLineInfo::FileNew)	{
		if (cmdInfo.m_strFileName != "tutorial")
		{
			if (IsTutorial(cmdInfo.m_strFileName))
			{
				// --- reading a .tut file
				m_bReadTutorial = true;
				int nIndex = cmdInfo.m_strFileName.ReverseFind('\\');
				if (nIndex == -1)	{
					char path[MAX_PATH];
					getcwd(path, MAX_PATH);
					m_strTutorial = path;
					m_strTutorial += "\\";
				}
				m_strTutorial += cmdInfo.m_strFileName;
			}
			else if (!ProcessShellCommand(cmdInfo))
				return false;
			else
			{
				// ---- loading file from command line
				bCmdFile = true;
				CString strPath = GetFilePath(cmdInfo.m_strFileName);
				if (!strPath.IsEmpty())
					_chdir(strPath);
			}
		}
	}

	else if (!m_bIsTutorial || !m_bTutorialDisplayed)	{
		// ----- reload documents from the previous session
		CString strProfile;
		for (; nDocno < maxsaveddocuments; nDocno++)	{
			strProfile.Format("Document%d", nDocno+1);
			CString strDocument = GetProfileString("Documents", strProfile, 0);
			if (strDocument.IsEmpty())
				break;

			if (OpenDocumentFile(strDocument))	{
				// --- if the document was maximized on exit, maximize it now
				strProfile.Format("Document%d Maximized", nDocno+1);
				bool bIsMax = GetProfileInt("Documents", strProfile, 0);
				if (bIsMax)
					// --- by coincidence, GetTextView works for project document, too
					pFocusWnd = MaximizeDocument(strDocument);
			}
		}
	}

	if (!bCmdFile)	{
		// ---- reload tutorial info from the previous session
		m_strTutorial = GetProfileString("Tutorial", "Current", 0);
		// ---- reload working directory from the previous session
		CString strPath = GetProfileString("Directories", "Current", 0);
		// ------ change to current working directory
		if (!strPath.IsEmpty())
			_chdir(strPath);
	}
#else
	int nDocno = 0;

	bool bCmdFile = false;

	// --- suppress initial FileNew command on startup
	if (cmdInfo.m_nShellCommand != CCommandLineInfo::FileNew)	{
		if (!ProcessShellCommand(cmdInfo))
			return false;
		// ---- loading file from command line
		bCmdFile = true;
		CString strPath = GetFilePath(cmdInfo.m_strFileName);
		if (!strPath.IsEmpty())
			_chdir(strPath);
	}
	else	{
		// ----- reload documents from the previous session
		CString strProfile;
		for (; nDocno < maxsaveddocuments; nDocno++)	{
			strProfile.Format("Document%d", nDocno+1);
			CString strDocument = GetProfileString("Documents", strProfile, 0);
			if (strDocument.IsEmpty())
				break;

			if (OpenDocumentFile(strDocument))	{
				// --- if the document was maximized on exit, maximize it now
				strProfile.Format("Document%d Maximized", nDocno+1);
				bool bIsMax = GetProfileInt("Documents", strProfile, 0);
				if (bIsMax)
					// --- by coincidence, GetTextView works for project document, too
					pFocusWnd = MaximizeDocument(strDocument);
			}
		}
	}

	if (!bCmdFile)	{
		// ---- reload working directory from the previous session
		CString strPath = GetProfileString("Directories", "Current", 0);
		// ------ change to current working directory
		if (!strPath.IsEmpty())
			_chdir(strPath);
	}

#endif

	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	if (pFocusWnd != 0)
		pFocusWnd->SetFocus();

#ifdef TYCPP

	if (!bCmdFile && m_bIsTutorial && nDocno == 0 && m_bTutorialDisplayed)	{
		OnTycpp();
		ASSERT(m_pCTutDlg != 0);
		m_pCTutDlg->LoadSelectedTutorial();
	}
	// --- disable tycpp command if tutorial not present
	if (!m_bIsTutorial)
		((CMainFrame*)pMainFrame)->HideTYCPPCommand();
#endif

	return true;
}




void CQuincyApp::SetBrowserPath()
{
	char path[MAX_PATH];
	m_bBrowser = (reinterpret_cast<int>(FindExecutable((m_strQuincyInstallPath + "\\quincy2002.htm").GetBuffer(0), 0, path))) > 32;
}
/*
void CQuincyApp::TestDebuggerPath()
{
	if (m_strDebugger.IsEmpty())	{
		m_strDebugger = m_strQuincyInstallPath + "\\gdb\\";
		for (int i = 0; i < 2; i++)	
			if (_access(m_strDebugger + "gdb.exe", 0) != 0)
				m_strDebugger = m_strToolsPath;
	}
	if (_access(m_strDebugger + "gdb.exe", 0) != 0)
		AfxMessageBox(	"No Debugger found. Install gdb.exe "
			"and set the debugger's installation path in the "
			"Tools/Options dialog's Build tab.", MB_ICONSTOP);
}
*/
void CQuincyApp::SetCompilerPaths()
{
	delete m_pCompiler;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -