?? compiler.cpp
字號:
///////////////////////////////////////////////////////////////
// PL/0 Compiler Shell 0.14 (2003.12.30) [Source File]
// Author:Dwing
///////////////////////////////////////////////////////////////
#include"compiler.h" //For Shell
///////////////////////////////////////////////////////////////
HINSTANCE hinst; //Recent Instance
OPENFILENAME ofn; //For Open File Dialog
FILE *fp; //For Open File
zCompile *cp; //編譯器對象指針
int asmnum=0; //目標代碼數量
int errnum=0; //錯誤數量
char buf[65536]; //I/O Buffer
char str[512]; //File Name Buffer
///////////////////////////////////////////////////////////////
void _main() //Program Entry
{
//Get Instance Handle
hinst=GetModuleHandle(0);
//Main DialogBox
DialogBox(hinst,MAKEINTRESOURCE(IDD_MAINDLG),0,(DLGPROC)dlgproc);
}
///////////////////////////////////////////////////////////////
//For MAIN DialogBox
BOOL CALLBACK dlgproc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)
{
int i;
switch(msg)
{
case WM_INITDIALOG:
buf[65535]=0; //結尾清0防止溢出
str[0]=0; //Clear str[]
//Set Window Text Font
SendDlgItemMessage(hdlg,IDC_INPUT,WM_SETFONT,(DWORD)GetStockObject(ANSI_FIXED_FONT),0);
SendDlgItemMessage(hdlg,IDC_ASM,WM_SETFONT,(DWORD)GetStockObject(SYSTEM_FIXED_FONT),0);
SendDlgItemMessage(hdlg,IDC_ERR,WM_SETFONT,(DWORD)GetStockObject(SYSTEM_FIXED_FONT),0);
//填充OPENFILENAME結構體
memset(&ofn,0,sizeof(OPENFILENAME)); //Clear it First
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.hwndOwner=hdlg;
ofn.hInstance=hinst;
ofn.lpstrFilter="所有文件(*.*)\0*.*\0";
ofn.nMaxFile=511; //最大文件名緩沖區長度
ofn.lpstrFile=str; //使用臨時字符串
ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
ofn.lpstrTitle="打開PL/0程序文件";
return 1;
case WM_COMMAND:
switch(LOWORD(wparam))
{
case ID_COMPILE:
SetCursor(LoadCursor(0,IDC_WAIT)); //Please wait...
GetDlgItemText(hdlg,IDC_INPUT,buf,65535); //Get PL/0 Text
cp=new zCompile; //Let's begin to compile...
cp->compile(buf); //Do the most complex part
errnum=cp->geterr(buf); //Get Error Text
SetDlgItemText(hdlg,IDC_ERR,buf); //Display it
asmnum=cp->getasm(buf); //Get ASM Text
SetDlgItemText(hdlg,IDC_ASM,buf); //Display it
delete cp; //The end of Compiling
SetCursor(LoadCursor(0,IDC_ARROW)); //Completed
break;
case ID_RUN:
if(!asmnum)
MessageBox(hdlg,"請先編譯后再運行!","錯誤",MB_ICONERROR);
else
if(errnum)
MessageBox(hdlg,"請先改正錯誤后再運行!","錯誤",MB_ICONERROR);
else
{
fp=fopen("temp.pl0","wb"); //Write to temp file
fprintf(fp,"%u\r\n",asmnum);
fwrite(buf,1,strlen(buf),fp);
fclose(fp);
WinExec("pl0run",1); //Call PL/0 Interpreter
}
break;
case ID_OPEN:
if(!GetOpenFileName(&ofn)) break;
str[512]=0; //防止溢出
if(!(fp=fopen(ofn.lpstrFile,"rb")))
MessageBox(hdlg,str,"無法打開文件!",MB_ICONERROR);
else
{
fseek(fp,0,SEEK_END);
if((i=ftell(fp))>65535)
MessageBox(hdlg,"文件過長(>=64K)!","錯誤",MB_ICONERROR);
else
{
fseek(fp,0,SEEK_SET);
fread(buf,1,i,fp);
buf[i]=0; //防止溢出
SetDlgItemText(hdlg,IDC_INPUT,buf);
}
fclose(fp);
}
break;
case ID_ABOUT:
DialogBox(hinst,MAKEINTRESOURCE(IDD_ABOUT),0,(DLGPROC)abtproc);
}
return 1;
case WM_CLOSE:
EndDialog(hdlg,0);
}
return 0;
}
///////////////////////////////////////////////////////////////
//For ABOUT DialogBox
BOOL CALLBACK abtproc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)
{
switch(msg)
{
case WM_LBUTTONDOWN: //When dragging me...
PostMessage(hdlg,WM_NCLBUTTONDOWN,2,0);
return 1;
case WM_COMMAND:
if(LOWORD(wparam)==IDOK)
EndDialog(hdlg,0);
}
return 0;
}
///////////////////////////////////////////////////////////////
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -