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

📄 find.cpp

📁 编译原理--词法扫描
💻 CPP
字号:
// Find.cpp : implementation file
//

#include "stdafx.h"
#include "scan.h"
#include "Find.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFind dialog
//extern symtab_root; 
//extern void QueryString(int i,char* string,symtab_node* np,CListCtrl &lc);



CFind::CFind(CWnd* pParent /*=NULL*/)
	: CDialog(CFind::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFind)
	m_Edit_String = _T("");
	//}}AFX_DATA_INIT

	m_string=new char[255];
}


void CFind::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFind)
	DDX_Control(pDX, IDC_LIST_FIND, m_ListCtrl_Find);
	DDX_Text(pDX, IDC_EDIT_STRING, m_Edit_String);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFind, CDialog)
	//{{AFX_MSG_MAP(CFind)
	ON_BN_CLICKED(IDC_BUTTON_FIND, OnButtonFind)
	ON_EN_CHANGE(IDC_EDIT_STRING, OnChangeEditString)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFind message handlers

void CFind::OnButtonFind() 
{
	m_string=(char*)m_Edit_String.GetBuffer(255); /* get the string that user wants to query */
	m_i=0;
	m_ListCtrl_Find.DeleteAllItems();   /* clear all the items in ListCtrl */
	FindString(m_symtab_node_root);     /* get the root of the binary tree */
}

void CFind::OnChangeEditString() 
{
	UpdateData();
}



BOOL CFind::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_ListCtrl_Find.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
	m_ListCtrl_Find.InsertColumn(0,"Line",LVCFMT_LEFT,40);
	m_ListCtrl_Find.InsertColumn(1,"Type",LVCFMT_LEFT,80);
	m_ListCtrl_Find.InsertColumn(2,"Name",LVCFMT_LEFT,60);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/* use binary search */
void CFind::FindString(const symtab_node2 *np)
{
	char str[255]={0};
	while(np)
	{
		if(strcmp(m_string,np->name)==0)
		{
			sprintf(str,"%d",np->lineno);
			m_ListCtrl_Find.UpdateData(FALSE);
			m_ListCtrl_Find.InsertItem(m_i,str);
			m_ListCtrl_Find.SetItemText(m_i,1,np->type);
			m_ListCtrl_Find.SetItemText(m_i++,2,np->name);
		}
		np=strcmp(m_string,np->name) <0 ? np->left : np->right ;
	}
}

⌨️ 快捷键说明

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