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

📄 sdbmsdemoview.cpp

📁 使用yacc的一个例子
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			m_pTextBuffer->SetLineFlag(0, LF_EXECUTION, TRUE);
			SetCursorPos(CPoint(0, m_nCurLine));
			EnsureVisible(CPoint(0, m_nCurLine));
			return;
		}
	}

	if	(m_nCurLine <= GetCursorPos().y)
		RunToLine(GetCursorPos().y);
}

void CSdbmsDemoView::OnUpdateDebugRunToCursor(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable();
}

void CSdbmsDemoView::OnUpdateIndicatorPosition(CCmdUI* pCmdUI)
{
	CCrystalEditView::OnUpdateIndicatorPosition(pCmdUI);
}
/*
void CSdbmsDemoView::UpdateIndicatorPosition(CCmdUI* pCmdUI)
{
	CCrystalEditView::OnUpdateIndicatorPosition(pCmdUI);
}
*/
//处理该消息,以修正CCrystalEditView中的BUG
void CSdbmsDemoView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	CPoint ptOldPos = GetCursorPos();
	int nOldLineLength = GetLineLength(ptOldPos.y);
	DWORD dwFlags = m_pTextBuffer->GetLineFlags(ptOldPos.y);

	CCrystalEditView::OnChar(nChar, nRepCnt, nFlags);

	//处理回车的情况
	if	((nChar == VK_RETURN) && (ptOldPos.x < nOldLineLength))
	{
		DWORD nIndex = 1;
		for	(int i=0; i<32; i++)
		{
			//设置每一个可能的标志
			if	((dwFlags & nIndex) != 0)
			{
				m_pTextBuffer->SetLineFlag(ptOldPos.y, dwFlags & nIndex, FALSE);
				m_pTextBuffer->SetLineFlag(ptOldPos.y+1, dwFlags & nIndex, TRUE, FALSE);
			}
			nIndex = nIndex << 1;
		}
	}
}

//处理该消息,以修正CCrystalEditView中的BUG及进行其他处理
void CSdbmsDemoView::OnEditDelete()
{
	CPoint ptOldPos = GetCursorPos();
	int nOldLineLength = GetLineLength(ptOldPos.y);
	bool bLastLine = (ptOldPos.y == GetLineCount()-1);
	DWORD dwFlags;

	if	(!bLastLine)
		dwFlags = m_pTextBuffer->GetLineFlags(ptOldPos.y+1);	//得到下一行的行标志

	CCrystalEditView::OnEditDelete();

	if	((ptOldPos.x == nOldLineLength) && !bLastLine)
	{
		//设置行标志
		DWORD nIndex = 1;
		for	(int i=0; i<32; i++)
		{
			//设置每一个可能的标志
			if	((dwFlags & nIndex) != 0)
			{
				m_pTextBuffer->SetLineFlag(ptOldPos.y, dwFlags & nIndex, TRUE, FALSE);
			}
			nIndex = nIndex << 1;
		}

		//更新当前运行行位置
		if	(m_nCurLine > ptOldPos.y)
			m_nCurLine--;
	}
}

//处理该消息,以修正CCrystalEditView中的BUG及进行其他处理
void CSdbmsDemoView::OnEditDeleteBack()
{
	CPoint ptOldPos = GetCursorPos();
	int nOldLineLength = GetLineLength(ptOldPos.y);
	DWORD dwFlags = m_pTextBuffer->GetLineFlags(ptOldPos.y);	//得到当前行的行标志

	CCrystalEditView::OnEditDeleteBack();

	//处理向前删除的情况
	if	((ptOldPos.x == 0) && (ptOldPos.y > 0))
	{
		//设置行标志
		DWORD nIndex = 1;
		for	(int i=0; i<32; i++)
		{
			//设置每一个可能的标志
			if	((dwFlags & nIndex) != 0)
			{
				m_pTextBuffer->SetLineFlag(ptOldPos.y-1, dwFlags & nIndex, TRUE, FALSE);
			}
			nIndex = nIndex << 1;
		}

		//更新当前运行行位置
		if	(m_nCurLine >= ptOldPos.y)
			m_nCurLine--;
	}
}

//求当前运行的有效行(主要是计算';'的位置)
CString CSdbmsDemoView::GetCurValidLine()
{
	CString strValidLine;
	bool bRemark = false;
	int nRemarkStart, nRemarkEnd;
	int nLineCount = GetLineCount();
	ASSERT(m_nCurLine < nLineCount);

	while (m_nCurLine < nLineCount)
	{
		int nLength = GetLineLength(m_nCurLine);
		CString strLine = GetLineChars(m_nCurLine++);
		strLine = strLine.Left(nLength);
		strLine.TrimLeft();
		strLine.TrimRight();

		//前面行中有'/*'字符
		if	(bRemark)
		{
			nRemarkEnd = strLine.Find(_T("*/"));	//查找'*/'字符
			if	(nRemarkEnd != -1)
			{
				strLine = strLine.Right(strLine.GetLength() - nRemarkEnd - 2);
				bRemark = false;
				if	(strValidLine.IsEmpty() && strLine.IsEmpty())	//如果是注释行则返回
					return "";
			}
			else
				continue;
		}

		strValidLine += strLine;

		ASSERT(!bRemark);

		while (!strValidLine.IsEmpty())
		{
			nRemarkStart = strValidLine.Find(_T("/*"));	//是否有'/*'
			if	(nRemarkStart != -1)
			{
				nRemarkEnd = strValidLine.Find(_T("*/"));	//是否有'*/'
				if	(nRemarkEnd != -1)
				{
					//去掉'/*'和'*/'中间的字符
					strValidLine = strValidLine.Left(nRemarkStart) + 
							strValidLine.Right(strValidLine.GetLength() - nRemarkEnd - 2);
					if	(strValidLine.IsEmpty())	//如果是注释行则返回
						return "";
				}
				else
				{
					//去掉'/*'后的字符
					strValidLine = strValidLine.Left(nRemarkStart);
					bRemark = true;
					break;
				}
			}
			else
				break;
		}
			
		if	(bRemark)
			continue;

		nRemarkStart = strValidLine.Find(_T("//"));	//是否有'//'注释
		if	(nRemarkStart != -1)
		{
			strValidLine = strValidLine.Left(nRemarkStart);	//求掉'//'后的字符
			if	(strValidLine.IsEmpty())	//如果是注释行则返回
				return "";
		}

		if	(strValidLine.ReverseFind(_T(';')) != -1)	//是否找到';'
		{
			//过滤其后的空行
			while (m_nCurLine < GetLineCount())
			{
				nLength = GetLineLength(m_nCurLine);
				strLine = GetLineChars(m_nCurLine);
				strLine = strLine.Left(nLength);
				strLine.TrimLeft();
				strLine.TrimRight();

				if	(strLine.IsEmpty())
					m_nCurLine++;
				else
					break;
			}
			return	strValidLine;
		}
		else
			strValidLine += " ";	//加个空格
	}

	return	strValidLine;
}

void CSdbmsDemoView::Init()
{
	g_sdbms.InitSystem();

	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	pMainWnd->m_wndOutputBar.Init();
}

void CSdbmsDemoView::AdjustBreakpoints()
{
	int nOldCurLine = m_nCurLine;

	m_nCurLine = 0;
	while (m_nCurLine < GetLineCount())
	{
		int nLastLine = m_nCurLine;
		GetCurValidLine();

		bool bBreak = false;
		for (int i=nLastLine+1; i<m_nCurLine; i++)
		{
			if	(m_pTextBuffer->GetLineFlags(i) & LF_BREAKPOINT)//是否设置了断点
			{
				m_pTextBuffer->SetLineFlag(i, LF_BREAKPOINT, FALSE, FALSE);
				bBreak = true;
			}
		}
		
		//把断点调在第一行
		if	(bBreak)	
			m_pTextBuffer->SetLineFlag(nLastLine, LF_BREAKPOINT, TRUE, FALSE);
	}

	m_nCurLine = nOldCurLine;
}

void CSdbmsDemoView::RunToLine(int nLine)
{
	int nOldCurLine = m_nCurLine;
	CString strText, strTemp;

 	while (m_nCurLine < GetLineCount())
	{
		int nLength = GetLineLength(m_nCurLine);
		CString strLine = GetLineChars(m_nCurLine);
		strLine = strLine.Left(nLength);
		strLine.TrimLeft();
		strLine.TrimRight();

		//去除空行
		if	(strLine.IsEmpty())
		{
			m_nCurLine++;
			continue;
		}

		nOldCurLine = m_nCurLine;
		strTemp = GetCurValidLine();
		
		if	(m_nCurLine >= GetLineCount())
		{
			strText += strTemp;
			break;
		}

		if	(m_nCurLine <= nLine || strTemp.IsEmpty())
		{
			strText += strTemp;
			nOldCurLine = m_nCurLine;
		}

		if	(m_nCurLine > nLine && !strTemp.IsEmpty())
			break;

		if	(GetLineFlags(m_nCurLine) & LF_BREAKPOINT)
			break;
	}

	g_strSQL = (LPSTR)(LPCTSTR)strText;
	yyparse();
	
	if	((m_nCurLine == GetLineCount()) &&
		 (nLine == GetLineCount() || strTemp.IsEmpty()))
	{
		m_bExecuting = FALSE;
		m_bBeginDebug = FALSE;
		m_nCurLine = 0;
		m_pTextBuffer->SetLineFlag(-1, LF_EXECUTION, FALSE);//清除运行标志
	}
	else
	{
		m_nCurLine = nOldCurLine;
		m_pTextBuffer->SetLineFlag(m_nCurLine, LF_EXECUTION, TRUE);//设置运行标志
		SetCursorPos(CPoint(0, m_nCurLine));
		EnsureVisible(CPoint(0, m_nCurLine));
	}
}

//过滤空行及注释行
void CSdbmsDemoView::Trim()
{
	int nOldLine;
	while (m_nCurLine < GetLineCount())
	{
		int nLength = GetLineLength(m_nCurLine);
		CString strLine = GetLineChars(m_nCurLine);
		strLine = strLine.Left(nLength);
		strLine.TrimLeft();
		strLine.TrimRight();

		//去除空行
		if	(strLine.IsEmpty())
		{
			m_nCurLine++;
			continue;
		}

		//去除注释行
		nOldLine = m_nCurLine;
		if	(GetCurValidLine().IsEmpty())
		{
			continue;
		}
		else
		{
			m_nCurLine = nOldLine;
			break;
		}
	}
}

⌨️ 快捷键说明

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