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

📄 smartcdoc.cpp

📁 词法分析程序
💻 CPP
字号:
// SmartCDoc.cpp : implementation of the CSmartCDoc class
//

#include "stdafx.h"
#include "SmartC.h"
#include "OutputTreeView.h"

#include "SmartCDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSmartCDoc

IMPLEMENT_DYNCREATE(CSmartCDoc, CDocument)

BEGIN_MESSAGE_MAP(CSmartCDoc, CDocument)
	//{{AFX_MSG_MAP(CSmartCDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSmartCDoc construction/destruction

CSmartCDoc::CSmartCDoc()
{
	// TODO: add one-time construction code here
	outputfront.next=NULL;
	outputfront.pchar=NULL;
	errorfront.next=NULL;
	errorfront.pchar=NULL;
	output_linenum=0;//记录输出窗口行数
	error_linenum=0;
	error_charnum=0;
}

CSmartCDoc::~CSmartCDoc()
{
	freenode(0);//delete output list
	freenode(1);//delete error list
}

BOOL CSmartCDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	((CEditView*)m_viewList.GetHead())->SetWindowText(NULL);

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CSmartCDoc serialization

void CSmartCDoc::Serialize(CArchive& ar)
{
	// CEditView contains an edit control which handles all serialization
	((CEditView*)m_viewList.GetHead())->SerializeRaw(ar);
}

/////////////////////////////////////////////////////////////////////////////
// CSmartCDoc diagnostics

#ifdef _DEBUG
void CSmartCDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CSmartCDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSmartCDoc commands
////////my fuction
//insert a new node in the node list at the rear
//the list contains the infromantion used in the ouputview or errorview
//whichview 0:ouputview ouputfront 1:errorview errorfront
//attention! the ouput_linenum and error_linenum used in the view's scroll
void CSmartCDoc::insertline(int whichview,char* string)
{
	int len=strlen(string);
	Node* temp;
	POSITION pos;
	COutputTreeView* pView;
	switch(whichview)
	{
/*	case 0:
		temp=&outputfront;
		output_linenum++;
		break;*/
	case 1:
		temp=&errorfront;
		error_linenum++;
		if((unsigned)error_charnum <strlen(string))
			error_charnum=strlen(string);
		break;
	case 0:
		pos = GetFirstViewPosition();
		GetNextView(pos);
		pView=(COutputTreeView*) GetNextView(pos);
		pView->InsertItem(string);
		pView->UpdateWindow();
		break;
	default:
		return;
		break;
	}
	if(whichview!=0)
	{
		while(temp->next)
		{
			temp=temp->next;
		}
		temp->next=new Node;
		temp->next->next=NULL;
		temp->next->pchar=new char[len+1];
		strcpy(temp->next->pchar,string);
	}
}
//this fuction must be called after insertline()
//delete node list
//whichview 0:ouputview ouputfront 1:errorview errorfront
//attention! the ouput_linenum and error_linenum used in the view's scroll
void CSmartCDoc::freenode(int whichview)
{
	Node* temp;
	switch(whichview)
	{
	case 0:
		while(outputfront.next)
		{
			temp=outputfront.next;
			outputfront.next=outputfront.next->next;
			delete [] temp->pchar;
			delete temp;
		}
		output_linenum=0;
		break;
	case 1:
		while(errorfront.next)
		{
			temp=errorfront.next;
			errorfront.next=errorfront.next->next;
			delete [] temp->pchar;
			delete temp;
		}
		error_linenum=0;
		error_charnum=0;
		break;
	default:
		return;
		break;
	}
}

⌨️ 快捷键说明

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