📄 scannerdlg.cpp
字号:
// ScannerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Scanner.h"
#include "ScannerDlg.h"
#include "Vocabulary.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScannerDlg dialog
CScannerDlg::CScannerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScannerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CScannerDlg)
m_result = _T("");
m_source = _T("");
m1 = 0;
m2 = 0;
m3 = 0;
m4 = 0;
m33 = 0;
m7 = 0;
m8 = 0;
m9 = 0;
m10 = _T("");
m11 = _T("");
m12 = _T("");
m13 = _T("");
m18 = 0;
m19 = 0;
m20 = 0;
m21 = 0;
m14 = 0;
m15 = 0;
m16 = 0;
m17 = 0;
m22 = 0;
m23 = 0;
m24 = 0;
m25 = 0;
m26 = 0;
m28 = 0;
m27 = 0;
m29 = 0;
m30 = 0;
m31 = 0;
m32 = 0;
m333 = 0;
m34 = 0;
m35 = 0;
m36 = _T("");
m37 = _T("");
m38 = _T("");
m39 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CScannerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScannerDlg)
DDX_Control(pDX, IDC_EDIT_SOURCE, m_edit_source);
DDX_Control(pDX, IDC_EDIT_RESULT, m_edit_result);
DDX_Text(pDX, IDC_EDIT_RESULT, m_result);
DDX_Text(pDX, IDC_EDIT_SOURCE, m_source);
DDX_Text(pDX, IDC_EDIT2, m1);
DDX_Text(pDX, IDC_EDIT4, m2);
DDX_Text(pDX, IDC_EDIT5, m3);
DDX_Text(pDX, IDC_EDIT6, m4);
DDX_Text(pDX, IDC_EDIT3, m33);
DDX_Text(pDX, IDC_EDIT7, m7);
DDX_Text(pDX, IDC_EDIT8, m8);
DDX_Text(pDX, IDC_EDIT9, m9);
DDX_Text(pDX, IDC_EDIT10, m10);
DDX_Text(pDX, IDC_EDIT11, m11);
DDX_Text(pDX, IDC_EDIT12, m12);
DDX_Text(pDX, IDC_EDIT13, m13);
DDX_Text(pDX, IDC_EDIT18, m18);
DDX_Text(pDX, IDC_EDIT19, m19);
DDX_Text(pDX, IDC_EDIT20, m20);
DDX_Text(pDX, IDC_EDIT21, m21);
DDX_Text(pDX, IDC_EDIT14, m14);
DDX_Text(pDX, IDC_EDIT15, m15);
DDX_Text(pDX, IDC_EDIT16, m16);
DDX_Text(pDX, IDC_EDIT17, m17);
DDX_Text(pDX, IDC_EDIT22, m22);
DDX_Text(pDX, IDC_EDIT23, m23);
DDX_Text(pDX, IDC_EDIT24, m24);
DDX_Text(pDX, IDC_EDIT25, m25);
DDX_Text(pDX, IDC_EDIT26, m26);
DDX_Text(pDX, IDC_EDIT28, m28);
DDX_Text(pDX, IDC_EDIT27, m27);
DDX_Text(pDX, IDC_EDIT29, m29);
DDX_Text(pDX, IDC_EDIT30, m30);
DDX_Text(pDX, IDC_EDIT31, m31);
DDX_Text(pDX, IDC_EDIT32, m32);
DDX_Text(pDX, IDC_EDIT33, m333);
DDX_Text(pDX, IDC_EDIT34, m34);
DDX_Text(pDX, IDC_EDIT35, m35);
DDX_Text(pDX, IDC_EDIT36, m36);
DDX_Text(pDX, IDC_EDIT37, m37);
DDX_Text(pDX, IDC_EDIT38, m38);
DDX_Text(pDX, IDC_EDIT39, m39);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScannerDlg, CDialog)
//{{AFX_MSG_MAP(CScannerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SCAN, OnScan)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_BN_CLICKED(IDC_OPEN, OnOpen)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScannerDlg message handlers
BOOL CScannerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CScannerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CScannerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CScannerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CScannerDlg::OnScan()
{
if(this->strToken.IsEmpty())
{
MessageBox("请先选择一个源文件或者保存你编辑的代码后再进行分析","添加程序",MB_ICONEXCLAMATION);
return;
}
FILE* fpin=fopen(strToken.GetBuffer(0),"r");
// TODO: Add your control notification handler code here
if(ends=true)
{
ch=' ';
code=0;
ends=false;
for(int i=0;i<50;i++)
{
Identifier[i]="";
}
for(i=0;i<50;i++)
{
Const[i]="";
}
for(i=0;i<50;i++)
{
PrimaryKey[i]=0;
}
strToken="";
point=0;
m_result="";
m_source="";
strToken="";
for(i=0;i<50;i++)
{
Symbol[i]="";
}
}
CString cc;
UpdateData(true);
int length=m_source.GetLength();
if(m_source=="")
{
return;
}
while(point<length)
{
ch=GetChar();
GetBC();
if(ch=='/')
{
ch=GetChar();
if(ch=='/')
{
while(ch!='\n')
ch=GetChar();
Retract();
}
else if(ch=='*')
{
a: while(ch!='*')
ch=GetChar();
ch=GetChar();
if(ch!='/')
goto a;
ch=GetChar();
}
}
if(ch=='\\')
{
ch=GetChar();
ch=GetChar();
}
if(IsLetter())
{
while( IsLetter() || IsDigit() )
{
Concat();
ch=GetChar();
}
Retract();
code=Reserve();
if(code==0)
{
value=InsertId();
strToken="";
//return ($ID ,value);
}
else
{
PrimaryKey[code]=1;
strToken="";
//return (code,-);
}
}
else
// {
if(IsDigit())
{
while(IsDigit())
{
Concat();
ch=GetChar();
if(ch=='.')
{
strToken+='.';
ch=GetChar();
}
}
Retract();
value=InsertConst();
//return ( $ int ,value);
}
else
{
value=InsertSymbol();
}
// }
}
m_result="";
ShowOut();
ends=true;
}
char CScannerDlg::GetChar()
{
char ch=m_source.GetAt(point);
// if(point<length)
{
point++;
}
//else
{
// ends=true;
}
return ch;
}
void CScannerDlg::GetBC()
{
while(ch==' ')
{
ch=GetChar();
}
}
BOOL CScannerDlg::IsLetter()
{
if((ch>='A'&& ch<='Z') || (ch>='a' && ch<='z'))
{
return TRUE;
}
return FALSE;
}
BOOL CScannerDlg::IsDigit()
{
if(ch>='0' && ch<='9')
{
return TRUE;
}
return FALSE;
}
void CScannerDlg::Concat()
{
strToken+=ch;
}
void CScannerDlg::Retract()
{
point--;
ch=' ';
}
int CScannerDlg::Reserve()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -