source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/BasicCompiler.cpp@ 754

Last change on this file since 754 was 750, checked in by イグトランス (egtra), 16 years ago

BOOST_FOREACHを可能なものはVC++ 2005 for eachへ置換(やや速くなる)。

File size: 20.2 KB
RevLine 
[206]1#include "stdafx.h"
[750]2#include <process.h>
3#include <fcntl.h>
4#include <io.h>
[206]5
[312]6#include <ver.h>
[165]7
[14]8#include "BasicCompiler.h"
[4]9
10#if defined HeapAlloc
11#define MEM_MAX 65536
12LPVOID pCheckMem[MEM_MAX];
13int now;
14#undef HeapAlloc
15#undef HeapReAlloc
16LPVOID CheckHeapAlloc(HANDLE hf,DWORD dwFlags,DWORD dwBytes){
17 LPVOID ret;
18 ret=HeapAlloc(hf,dwFlags,dwBytes);
19 pCheckMem[now]=ret;
20
21 //この部分にnowのチェックを挿入
22
23 now++;
24 if(now>=MEM_MAX){
25 MessageBox(0,"pCheckMemの最大値を超えました","Check - BasicCompiler.exe",0);
26 }
27 return ret;
28}
29LPVOID CheckHeapReAlloc(HANDLE hf,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes){
30 int i;
31 LPVOID ret;
32 for(i=0;;i++){
33 if(lpMem==pCheckMem[i]) break;
34 if(i>=MEM_MAX){
35 MessageBox(0,"エラー","Check - BasicCompiler.exe",0);
36 break;
37 }
38 }
39 ret=HeapReAlloc(hf,dwFlags,lpMem,dwBytes);
40 pCheckMem[i]=ret;
41 return ret;
42}
43void HeapDefaultFree(LPVOID lpMem){
44 int i;
45 for(i=0;;i++){
46 if(lpMem==pCheckMem[i]) break;
47 if(i>=MEM_MAX||lpMem==0){
48 MessageBox(0,"エラー","Check - BasicCompiler.exe",0);
49 break;
50 }
51 }
52 pCheckMem[i]=0;
53 HeapFree(hHeap,0,lpMem);
54}
55void CheckHeapCheck(){
56 int i,i2;
57 char temp[100];
58 temp[0]=0;
59 for(i=0,i2=0;i<MEM_MAX;i++){
60 if(pCheckMem[i]){
61 sprintf(temp+lstrlen(temp),"%d\r\n",i);
62 i2++;
63 if(i2==10){
64 lstrcat(temp,"これ以上の未解放が確認されています");
65 break;
66 }
67 }
68 }
69 if(temp[0]) MessageBox(0,temp,"Check - BasicCompiler.exe",0);
70}
71#define HeapAlloc CheckHeapAlloc
72#define HeapReAlloc CheckHeapReAlloc
73#else
74void HeapDefaultFree(LPVOID lpMem){
75 HeapFree(hHeap,0,lpMem);
76}
77#endif
78
79void ts(int i){
80 char temporary[255];
81 sprintf(temporary,"0x%08x",i);
82 MessageBox(0,temporary,"TestMessage",0);
83}
84void ts(int i,int i2){
85 char temporary[255];
86 sprintf(temporary,"0x%08x\r\n0x%08x",i,i2);
87 MessageBox(0,temporary,"TestMessage",0);
88}
[322]89void ts(const char *msg){
[378]90 MessageBox(0,FormatEscapeSequenceStringToDefaultString(msg).c_str(),"TestMessage",0);
[4]91}
[322]92void ts(const char *msg,const char *title){
[378]93 MessageBox(0,FormatEscapeSequenceStringToDefaultString(msg).c_str(),title,0);
[4]94}
[477]95void ts(const std::string msg)
96{
97 ts(msg.c_str());
98}
[4]99
100void epi_check(){
101 //この部分にobpのチェックを挿入
102 //※例 … epi=0x41999 → obp>=0x0999
[276]103/*
[4]104 extern int obp;
[232]105 if(obp>=0x988DE){
106 int test=0;
[276]107 }*/
[4]108}
109
110void GetRelationalPath(char *path,char *dir){
111 //相対パスを取得
112 int i,i2,i3,i4,i5;
113 char temporary[MAX_PATH],temp2[MAX_PATH],temp3[MAX_PATH],temp4[MAX_PATH];
114
115 //ドライブ名をチェック
116 _splitpath(path,temporary,0,0,0);
117 _splitpath(dir,temp2,0,0,0);
118 if(lstrcmpi(temporary,temp2)!=0) return;
119
120 _splitpath(path,0,temporary,0,0);
121 _splitpath(dir,0,temp2,0,0);
122 i=1;i2=1;
123 while(1){
124 i4=i;
125 if(temporary[i-1]=='\\'&&temporary[i]){ //path側
126 for(i3=0;;i++,i3++){
127 if(temporary[i]=='\\'){
128 temp3[i3]=0;
129 i++;
130 break;
131 }
132 temp3[i3]=temporary[i];
133 }
134 }
135 else temp3[0]=0;
136
137 i5=i2;
138 if(temp2[i2-1]=='\\'&&temp2[i2]){ //dir側
139 for(i3=0;;i2++,i3++){
140 if(temp2[i2]=='\\'){
141 temp4[i3]=0;
142 i2++;
143 break;
144 }
145 temp4[i3]=temp2[i2];
146 }
147 }
148 else temp4[0]=0;
149
150 if(temp3[0]=='\0'&&temp4[0]=='\0'){
151 lstrcpy(temp3,".\\");
152 break;
153 }
154
155 if(lstrcmpi(temp3,temp4)!=0){
156 for(i3=0;;i5++){
157 if(temp2[i5]=='\0') break;
158 if(temp2[i5]=='\\') i3++;
159 }
160 if(i3==0) lstrcpy(temp3,".\\");
161 else{
162 temp3[0]=0;
163 for(i2=0;i2<i3;i2++) lstrcat(temp3,"..\\");
164 }
165 lstrcat(temp3,temporary+i4);
166 break;
167 }
168 }
169 _splitpath(path,0,0,temporary,temp2);
170 lstrcat(temp3,temporary);
171 lstrcat(temp3,temp2);
172 lstrcpy(path,temp3);
173}
[523]174void GetFullPath( char *path, const std::string &baseDirPath ){
[4]175 int i,i2,i3,i4;
176 char temporary[MAX_PATH];
177
[139]178 // '/'→'\'
179 for( i=0;path[i];i++ ){
180 if( path[i] == '/' ){
181 path[i]='\\';
182 }
183 }
184
[4]185 if(strstr(path,":")||strstr(path,"\\\\")) return;
186
187 i=0;i2=0;
188 while(1){
189 if(path[i]=='.'&&path[i+1]=='\\') i+=2;
190 if(path[i]=='.'&&path[i+1]=='.'&&path[i+2]=='\\'){
191 i2++;
192 i+=3;
193 }
194 else break;
195 }
196
[477]197 std::string tempBaseDirPath = baseDirPath;
198 if( tempBaseDirPath[tempBaseDirPath.size()-1] != '\\' )
199 {
200 tempBaseDirPath += "\\";
201 }
202
203 i3=(int)tempBaseDirPath.size();i4=0;
[4]204 while(i4<i2){
205 for(i3--;;i3--){
[477]206 if(tempBaseDirPath[i3-1]=='\\'){
[4]207 i4++;
208 break;
209 }
210 }
211 }
[477]212 memcpy(temporary,tempBaseDirPath.c_str(),i3);
[4]213 temporary[i3]=0;
214 lstrcat(temporary,path+i);
215 lstrcpy(path,temporary);
216}
217
[279]218void ShowErrorLine(int LineNum,const char *constFileName){
[4]219 HANDLE hFile;
220 DWORD dw;
[279]221 char FileName[MAX_PATH];
[4]222 char temporary[MAX_PATH];
223
[279]224 lstrcpy( FileName, constFileName );
225
[4]226 if(LineNum==-1) return;
227
228 if(IsWindow(hOwnerEditor)){
229 if(FileName){
230
[279]231 while( !IsFileExist( FileName ) ){
[4]232 char temp2[MAX_PATH],temp3[MAX_PATH];
233 _splitpath(FileName,NULL,NULL,temp2,temp3);
234 lstrcat(temp2,temp3);
235
236 sprintf(temporary,"\"%s\" が見つかりません。格納されているディレクトリを指定してください。",temp2);
237 if(!GetFolder(hOwnerEditor,temp3,temporary)) return;
238
239 if(temp3[lstrlen(temp3)-1]!='\\') lstrcat(temp3,"\\");
240
241 sprintf(FileName,"%s%s",temp3,temp2);
242 }
243
[165]244 hFile=CreateFile(
[719]245 ( ActiveBasic::Common::Environment::GetUserAppDir() + "\\pgm.tmp" ).c_str(),
[165]246 GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_TEMPORARY,NULL);
[4]247 WriteFile(hFile,FileName,lstrlen(FileName),&dw,NULL);
248 CloseHandle(hFile);
249
250 SendMessage(hOwnerEditor,WM_SHOWERROR,LineNum,0);
251 }
252 }
253}
254
255BOOL GetFilePathDialog(HWND hwnd,char *filename,LPSTR Filter,LPSTR Title,BOOL bOpen){
256 OPENFILENAME ofstr;
257 filename[0]=0;
258 ofstr.lStructSize=sizeof(OPENFILENAME);
259 ofstr.hwndOwner=hwnd;
260 ofstr.hInstance=0;
261 ofstr.lpstrFilter=Filter;
262 ofstr.lpstrCustomFilter=NULL;
263 ofstr.nMaxCustFilter=0;
264 ofstr.nFilterIndex=1;
265 ofstr.lpstrFile=filename;
266 ofstr.nMaxFile=MAX_PATH;
267 ofstr.lpstrFileTitle=NULL;
268 ofstr.nMaxFileTitle=0;
269 ofstr.lpstrInitialDir=0;
270 ofstr.lpstrTitle=Title;
271 ofstr.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST;
272 ofstr.nFileOffset=0;
273 ofstr.nFileExtension=0;
274 ofstr.lpstrDefExt="*";
275 ofstr.lCustData=NULL;
276 ofstr.lpfnHook=NULL;
277 ofstr.lpTemplateName=NULL;
278 if(bOpen){
279 if(!GetOpenFileName(&ofstr)) return FALSE;
280 }
281 else{
282 if(!GetSaveFileName(&ofstr)) return FALSE;
283 }
284 return TRUE;
285}
286
287LRESULT CALLBACK ErrorListProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
288 int i,pos;
289 int StartPos,EndPos;
290
291 switch(message){
292 case WM_CHAR:
293 if(GetKeyState(VK_CONTROL)&0x8000){
294 //アクセラレータキーの場合を考慮
295 break;
296 }
297 return 0;
298 case WM_LBUTTONDBLCLK:
299 SendMessage(hwnd,EM_GETSEL,(WPARAM)&pos,0);
300 i=(int)SendMessage(hwnd,EM_LINEFROMCHAR,pos,0);
[465]301 compiler.errorMessenger.ShowErrorLine( i );
[4]302
303 StartPos=(int)SendMessage(hwnd,EM_LINEINDEX,i,0);
304 EndPos=StartPos+(int)SendMessage(hwnd,EM_LINELENGTH,pos,0);
305 SendMessage(hwnd,EM_SETSEL,StartPos,EndPos);
306 return 0;
307 }
308 return CallWindowProc(OldErrorListProc,hwnd,message,wParam,lParam);
309}
310LRESULT CALLBACK DebugListProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
311 switch(message){
312 case WM_CHAR:
313 if(GetKeyState(VK_CONTROL)&0x8000){
314 //アクセラレータキーの場合を考慮
315 break;
316 }
317 return 0;
318 }
319 return CallWindowProc(OldDebugListProc,hwnd,message,wParam,lParam);
320}
321void MakeMessageText(char *buffer,char *msg,int flag){
[467]322 if( program.IsClipCompileView() ){
[4]323 //ProjectView埋め込みがたインターフェイスのとき
324
325 //生成するファイルの相対パスを取得
[467]326 char relationalPath[MAX_PATH];
327 lstrcpy( relationalPath, program.GetOutputFilePath().c_str() );
328 GetRelationalPath( relationalPath, BasicCurDir );
[4]329
330 //////////
331 // 合成
332
333#if defined(JPN)
334 //日本語
335 if(flag==0){
[266]336 if(compiler.IsDll())
337 {
[467]338 sprintf(buffer,"DLLファイル \"%s\" [ %s ]",relationalPath,msg);
[266]339 }
[467]340 else sprintf(buffer,"実行ファイル \"%s\" [ %s ]",relationalPath,msg);
[4]341 }
[467]342 if(flag==1) sprintf(buffer,"\"%s\" を生成しています [ %s ]",relationalPath,msg);
[4]343 if(flag==2) lstrcpy(buffer,msg);
344#else
345 //英語
346 if(flag==0){
[467]347 if(compiler.IsDll()) sprintf(buffer,"DLL file \"%s\" [ %s ]",relationalPath,msg);
348 else sprintf(buffer,"Execution file \"%s\" [ %s ]",relationalPath,msg);
[4]349 }
[467]350 if(flag==1) sprintf(buffer,"Creating \"%s\" [ %s ]",relationalPath,msg);
[4]351 if(flag==2) lstrcpy(buffer,msg);
352#endif
353 }
354 else{
355 //通常ダイアログのとき
356 lstrcpy(buffer,msg);
357 }
358}
359
360void SetPosCenter(HWND hwnd){
361 RECT OwnerRect,rect;
362 int x,y;
363
364 if(IsWindow(hOwnerEditor)) GetWindowRect(hOwnerEditor,&OwnerRect);
365 else{
366 OwnerRect.left=0;
367 OwnerRect.top=0;
368 OwnerRect.right=ScreenX;
369 OwnerRect.bottom=ScreenY;
370 }
371 GetWindowRect(hwnd,&rect);
372
373 x=((OwnerRect.right-OwnerRect.left)-(rect.right-rect.left))/2+OwnerRect.left;
374 y=((OwnerRect.bottom-OwnerRect.top)-(rect.bottom-rect.top))/2+OwnerRect.top;
375 SetWindowPos(hwnd,0,x,y,0,0,SWP_NOSIZE);
376}
377BOOL CALLBACK DlgCompile(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
378 extern HANDLE hDebugProcess;
379 char temporary[MAX_PATH];
380 RECT rect;
381 POINT pos;
382 SIZE size;
383 static POINT pos_List,pos_Progress;
[5]384 static int height_Progress;
[4]385
386 switch(message){
387 case WM_INITDIALOG:
388 pos=pobj_nv->MainDlgPos;
389 GetWindowRect(hwnd,&rect);
390 size.cx=rect.right-rect.left;
391 size.cy=rect.bottom-rect.top;
392 MoveWindow(hwnd,pos.x,pos.y,size.cx,size.cy,1);
393
[467]394 char relationalPath[MAX_PATH];
395 lstrcpy(relationalPath,program.GetOutputFilePath().c_str());
396 GetRelationalPath(relationalPath,BasicCurDir);
397 SetDlgItemText(hwnd,IDC_EXEPATH,relationalPath);
[4]398
399 //"エラー無し"
400 SetDlgItemText(hwnd,IDC_ERRORLIST,STRING_NOERROR);
401
402 //"デバッグ情報無し"
403 SetDlgItemText(hwnd,IDC_DEBUGLIST,STRING_NODEBUGMSG);
404
405 //リストボックスの初期位置
406 GetWindowRect(GetDlgItem(hwnd,IDC_ERRORLIST),&rect);
407 pos_List.x=rect.left;
408 pos_List.y=rect.top;
409 ScreenToClient(hwnd,&pos_List);
410
411 //プログレスバーの初期位置と高さ
412 GetWindowRect(GetDlgItem(hwnd,IDC_PROGRESS),&rect);
413 pos_Progress.x=rect.left;
414 pos_Progress.y=rect.top;
415 ScreenToClient(hwnd,&pos_Progress);
416 height_Progress=rect.bottom-rect.top;
417
418 //バージョン表記
419 sprintf(temporary,"Version %d.%02d.%02d %s",MAJOR_VER,MINOR_VER,REVISION_VER,VER_INFO);
420 SetDlgItemText(hwnd,IDC_STATIC_VERSION,temporary);
421
422 break;
423 case WM_COMMAND:
424 switch(LOWORD(wParam)){
425 case IDOK:
426 GetDlgItemText(hwnd,IDOK,temporary,MAX_PATH);
427
428 //STRING_COMPILE = "コンパイル"
429 if(lstrcmp(temporary,STRING_COMPILE)==0){
[467]430 char tempOutputFileName[MAX_PATH];
431 GetDlgItemText(hwnd,IDC_EXEPATH,tempOutputFileName,MAX_PATH);
432 program.SetOutputFilePath(
433 Jenga::Common::Path::MakeFullPath( tempOutputFileName, BasicCurDir )
434 );
435 _beginthread( &MainThread, NULL, NULL );
[4]436 }
437
438 //STRING_STOP = "中断"
439 else if(lstrcmp(temporary,STRING_STOP)==0){
440 if(hDebugProcess){
441 //デバッグ中のとき
442
443 //プロセスを終了
444 TerminateProcess(hDebugProcess,0);
445 hDebugProcess=0;
446
447 //デバッグダイアログを終了
448 if(hDebugWnd){
449 DestroyWindow(hDebugWnd);
450 }
451 }
452 else{
453 //コンパイル中のとき
454 bStopCompile=1;
455
456 /* メインスレッドで「閉じる」ボタンに変更することで、
457 コンパイルを中断中の早いタイミングでも終了することが可能 */
458 //"閉じる"
459 SetDlgItemText(hwnd,IDOK,STRING_CLOSE);
460 }
461 }
462
463 else{
464 SetFocus(hOwnerEditor);
465 DestroyWindow(hwnd);
466 }
467 return 1;
468 case IDCANCEL:
469 //×ボタン用
470
471 if(hDebugProcess){
472 //デバッグ中のとき
473
474 //プロセスを終了
475 TerminateProcess(hDebugProcess,0);
476 hDebugProcess=0;
477
478 //デバッグダイアログを終了
479 if(hDebugWnd){
480 DestroyWindow(hDebugWnd);
481 }
482 }
483
484 SetFocus(hOwnerEditor);
485 DestroyWindow(hwnd);
486 return 1;
487 case IDC_SHOWERROR:
488 ShowWindow(GetDlgItem(hwnd,IDC_ERRORLIST),SW_SHOW);
489 ShowWindow(GetDlgItem(hwnd,IDC_DEBUGLIST),SW_HIDE);
490 return 1;
491 case IDC_SHOWDEBUG:
492 ShowWindow(GetDlgItem(hwnd,IDC_ERRORLIST),SW_HIDE);
493 ShowWindow(GetDlgItem(hwnd,IDC_DEBUGLIST),SW_SHOW);
494 return 1;
495 }
496 break;
497 case WM_SHOWVARLIST:
[467]498 if( program.IsClipCompileView() ){
[4]499 //埋め込み表示
500 CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_DEBUGGER),hOwnerEditor,(DLGPROC)DlgDebugger,lParam);
501 ShowWindow(hDebugWnd,SW_SHOW);
502
503 SendMessage(hOwnerEditor,WM_SETDEBUGGERVIEW,0,(LPARAM)hDebugWnd);
504 }
505 else{
506 //ポップアップ表示
507 CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_VARLIST),hOwnerEditor,(DLGPROC)DlgVarList,lParam);
508 SetForegroundWindow(hDebugWnd);
509 }
510 return 1;
511 case WM_SIZE:
[467]512 if( program.IsClipCompileView() ){
[4]513 //エラーリストの位置
514 MoveWindow(GetDlgItem(hwnd,IDC_ERRORLIST),
515 pos_List.x,
516 pos_List.y,
517 LOWORD(lParam)-pos_List.x,
518 HIWORD(lParam)-pos_List.y,
519 1);
520
521 //デバッグリストの位置
522 MoveWindow(GetDlgItem(hwnd,IDC_DEBUGLIST),
523 pos_List.x,
524 pos_List.y,
525 LOWORD(lParam)-pos_List.x,
526 HIWORD(lParam)-pos_List.y,
527 1);
528
529 //プログレスバーの位置
530 MoveWindow(GetDlgItem(hwnd,IDC_PROGRESS),
531 pos_Progress.x,
532 pos_Progress.y,
533 LOWORD(lParam)-pos_Progress.x,
534 height_Progress,
535 1);
536 }
537 return 1;
538 case WM_DESTROY:
539 GetWindowRect(hwnd,&rect);
540
[467]541 if( !program.IsClipCompileView() ){
[4]542 pobj_nv->MainDlgPos.x=rect.left;
543 pobj_nv->MainDlgPos.y=rect.top;
544 }
545
546 PostQuitMessage(0);
547 return 1;
548
549
550
551 ///////////////////////
552 // デバッグコマンド
553 ///////////////////////
554
555 case WM_DEBUG_STOP:
556 Debugger_Stop();
557 return 1;
558 case WM_DEBUG_PAUSE:
559 Debugger_Pause();
560 return 1;
561
562
563 case WM_CLOSE_DEBUGGER:
564 if(hDebugWnd){
565 DestroyWindow(hDebugWnd);
566 }
567 return 1;
568 }
569 return 0;
570}
571
[457]572void _Test()
573{
574 Jenga::Common::LoggerSetting loggerSetting;
575 bool result = loggerSetting.WriteXml( Jenga::Common::Environment::GetAppDir() + "\\logger.setting.xml" );
576}
577
578int main()
579{
580 int i;
581 char temporary[1024],temp2[MAX_PATH];
582
583 hInst = GetModuleHandle( NULL );
584
[469]585 // グローバルローケルを日本語にする
[523]586 std::locale::global(std::locale("japanese"));
[470]587 _setmode(_fileno(stdout), _O_BINARY);
[469]588
[457]589 //_Test();
590
591 //MessageBox(0,"starting compiler/debugger","ActiveBasic",MB_OK);
592 trace( "Start ActiveBasic Compiler!" );
593
594 //コモンコントロールを初期化
595 InitCommonControls();
596
597 hHeap=GetProcessHeap();
598 ScreenX=GetSystemMetrics(SM_CXSCREEN);
599 ScreenY=GetSystemMetrics(SM_CYSCREEN);
600
601 //不揮発性データを取得
602 pobj_nv=new CNonVolatile;
603 pobj_nv->load();
604
[477]605 program.Configurate();
606
[467]607 if( !program.AnalysisCommandLines() )
[457]608 {
609 // コマンドラインが不正
610 return 0;
[4]611 }
612
[470]613 bool isSpecifiedSourceFilePathByCommandLine = false;
614 if( program.GetSourceFilePath().size() > 0 )
[467]615 {
[470]616 // ソースファイル名が与えられていたとき
617 isSpecifiedSourceFilePathByCommandLine = true;
618 }
619 else
620 {
621 // ソースファイル名が与えられなかったとき
[467]622 char temp[MAX_PATH];
623 if(!GetFilePathDialog(0,temp,BasicFileFilter,"コンパイルするファイルを指定して下さい",1))
624 {
[4]625 return 0;
[467]626 }
627 program.SetSourceFilePath( temp );
[4]628 }
629
630 //出力ファイル名が与えられなかったとき
[467]631 if( program.GetOutputFilePath().size() == 0 )
632 {
633 char tempOutputFileName[MAX_PATH];
634 _splitpath( program.GetSourceFilePath().c_str(), tempOutputFileName,temporary,temp2,0);
635 lstrcat(tempOutputFileName,temporary);
636 lstrcat(tempOutputFileName,temp2);
[608]637 if( compiler.IsSll() )
[269]638 {
[467]639 if( program.IsDebugRun() || compiler.IsDebug() )
[269]640 {
[467]641 lstrcat(tempOutputFileName,"_debug.abobj");
[269]642 }
643 else
644 {
[467]645 lstrcat(tempOutputFileName,".abobj");
[269]646 }
647 }
648 else
649 {
[467]650 if( program.IsDebugRun() || compiler.IsDebug() )
[269]651 {
[467]652 lstrcat(tempOutputFileName,"_debug.exe");
[269]653 }
654 else
655 {
[467]656 lstrcat(tempOutputFileName,".exe");
[269]657 }
658 }
[467]659
660 program.SetOutputFilePath( tempOutputFileName );
[4]661 }
662
[294]663 {
664 // カレントディレクトリを取得
[302]665 std::string baseDirPath = Jenga::Common::Environment::GetAppDir()+"\\";
[294]666
667 // インクルードディレクトリが指定されなかったとき
[467]668 if( program.GetIncludeDir().size() == 0 )
669 {
[477]670 program.SetIncludeDir( Jenga::Common::Path::MakeFullPath( ".\\Include", ActiveBasic::Common::Environment::GetAbdevRootPath() ) );
[294]671 }
672 else
673 {
674 // インクルードディレクトリを絶対パスに変更
[480]675 program.SetIncludeDir( Jenga::Common::Path::MakeFullPathByCurrentDirectory( program.GetIncludeDir() ) );
[294]676 }
677
678 // ソースファイル名を絶対パスに変換
[480]679 program.SetSourceFilePath( Jenga::Common::Path::MakeFullPathByCurrentDirectory( program.GetSourceFilePath() ) );
[294]680
681 // 出力ファイル名を絶対パスに変換
[480]682 program.SetOutputFilePath( Jenga::Common::Path::MakeFullPathByCurrentDirectory( program.GetOutputFilePath() ) );
[308]683
684 // モジュール名をセット
[467]685 compiler.SetModuleName( Jenga::Common::Path( program.GetOutputFilePath() ).GetFileName() );
[4]686 }
687
[467]688 if( compiler.IsDll() )
689 {
[4]690 //DLLファイル名を取得
[467]691 _splitpath( program.GetOutputFilePath().c_str(),NULL,NULL,szDllName,temporary);
[4]692 lstrcat(szDllName,temporary);
693 }
694
[467]695 if( program.IsDebugRun() )
696 {
[4]697 //コマンドライン、DLLの実行可能アプリケーションを取得
698 HANDLE hFile;
699 DWORD dwAccessBytes;
[165]700 hFile=CreateFile(
[719]701 ( ActiveBasic::Common::Environment::GetUserAppDir() + "\\pgm.tmp" ).c_str(),
[165]702 GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
[4]703 if(hFile!=INVALID_HANDLE_VALUE){
704 ReadFile(hFile,temporary,MAX_PATH,&dwAccessBytes,NULL);
705 CloseHandle(hFile);
706 temporary[dwAccessBytes]=0;
707 }
708 else temporary[0]=0;
709
710 for(i=0;;i++){
711 if(temporary[i]=='\r'&&temporary[i+1]=='\n'||temporary[i]=='\0'){
712 szDebugExeForDll[i]=0;
713 break;
714 }
715 szDebugExeForDll[i]=temporary[i];
716 }
717 if(temporary[i]){
718 lstrcpy(szDebugCmdLine,temporary+i+2);
719 }
720 }
721
[467]722 _splitpath( program.GetSourceFilePath().c_str(), BasicCurDir,temporary,NULL,NULL);
[4]723 lstrcat(BasicCurDir,temporary);
724
[467]725 if( program.IsClipCompileView() ){
[4]726 //ProjectEditor埋め込み型インターフェイス
727 hMainDlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_CLIPMAIN),hOwnerEditor,(DLGPROC)DlgCompile);
728 ShowWindow(hMainDlg,SW_SHOW);
729 SendMessage(hOwnerEditor,WM_SETCOMPILEVIEW,0,(LPARAM)hMainDlg);
730
731 //プログレスバーの色をセットする
732 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETBARCOLOR,0,RGB(255,220,192));
733 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETBKCOLOR,0,RGB(255,255,255));
734 }
735 else{
736 //通常ダイアログインターフェイス
737 hMainDlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_MAIN),hOwnerEditor,(DLGPROC)DlgCompile);
[92]738
[470]739 if( program.IsKickedFromEditor() )
740 {
741 // エディタから起動されたとき
742 PostMessage( hMainDlg, WM_COMMAND, IDOK, 0 );
743 }
[471]744 else if( program.IsShowDlg() )
745 {
746 // コマンドラインでshow_dlgパラメータが指定された場合、ダイアログを表示する
747 // すぐにビルドを開始する
748 ShowWindow(hMainDlg,SW_SHOW);
749 PostMessage( hMainDlg, WM_COMMAND, IDOK, 0 );
750 }
[470]751 else if( isSpecifiedSourceFilePathByCommandLine )
752 {
753 // コマンドラインでソースコード指定があった場合はウィンドウは表示せず、そのままビルドを開始する。
754 MainThread(0);
755
[472]756 trace("Complete ActiveBasic Compiler!");
757
758 ExitProcess( program.GetExitCode() );
[470]759 return 0;
760 }
761 else
762 {
763 ShowWindow(hMainDlg,SW_SHOW);
764 }
[4]765 }
766 SendDlgItemMessage(hMainDlg,IDC_SHOWERROR,BM_SETCHECK,BST_CHECKED,0);
767
768 //エラーリストをサブクラス化
769 OldErrorListProc=(WNDPROC)GetWindowLongPtr(GetDlgItem(hMainDlg,IDC_ERRORLIST),GWLP_WNDPROC);
770 SetWindowLongPtr(GetDlgItem(hMainDlg,IDC_ERRORLIST),GWLP_WNDPROC,(LONG_PTR)ErrorListProc);
771
772 //デバッグリストをサブクラス化
773 OldDebugListProc=(WNDPROC)GetWindowLongPtr(GetDlgItem(hMainDlg,IDC_DEBUGLIST),GWLP_WNDPROC);
774 SetWindowLongPtr(GetDlgItem(hMainDlg,IDC_DEBUGLIST),GWLP_WNDPROC,(LONG_PTR)DebugListProc);
775
[467]776 if( program.IsKickedFromEditor() )
[457]777 {
778 SendMessage(hMainDlg,WM_COMMAND,IDOK,0);
779 }
[4]780
781 MSG msg;
782 while(GetMessage(&msg,0,0,0)){
783 if(IsDialogMessage(hMainDlg,&msg)) continue;
784 TranslateMessage(&msg);
785 DispatchMessage(&msg);
786 }
787
788 //不揮発性データを保存
789 pobj_nv->save();
790 delete pobj_nv;
791 pobj_nv=0;
792
793#if defined HeapAlloc
794 CheckHeapCheck();
795#endif
796
[467]797 if( program.IsClipCompileView() ){
[4]798 SendMessage(hOwnerEditor,WM_DESTROYCOMPILEVIEW,0,0);
799 }
800
[140]801 trace("Complete ActiveBasic Compiler!");
[4]802
[472]803 ExitProcess( program.GetExitCode() );
[140]804
[4]805 return 0;
806}
Note: See TracBrowser for help on using the repository browser.