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

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

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

File size: 20.2 KB
Line 
1#include "stdafx.h"
2#include <process.h>
3#include <fcntl.h>
4#include <io.h>
5
6#include <ver.h>
7
8#include "BasicCompiler.h"
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}
89void ts(const char *msg){
90 MessageBox(0,FormatEscapeSequenceStringToDefaultString(msg).c_str(),"TestMessage",0);
91}
92void ts(const char *msg,const char *title){
93 MessageBox(0,FormatEscapeSequenceStringToDefaultString(msg).c_str(),title,0);
94}
95void ts(const std::string msg)
96{
97 ts(msg.c_str());
98}
99
100void epi_check(){
101 //この部分にobpのチェックを挿入
102 //※例 … epi=0x41999 → obp>=0x0999
103/*
104 extern int obp;
105 if(obp>=0x988DE){
106 int test=0;
107 }*/
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}
174void GetFullPath( char *path, const std::string &baseDirPath ){
175 int i,i2,i3,i4;
176 char temporary[MAX_PATH];
177
178 // '/'→'\'
179 for( i=0;path[i];i++ ){
180 if( path[i] == '/' ){
181 path[i]='\\';
182 }
183 }
184
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
197 std::string tempBaseDirPath = baseDirPath;
198 if( tempBaseDirPath[tempBaseDirPath.size()-1] != '\\' )
199 {
200 tempBaseDirPath += "\\";
201 }
202
203 i3=(int)tempBaseDirPath.size();i4=0;
204 while(i4<i2){
205 for(i3--;;i3--){
206 if(tempBaseDirPath[i3-1]=='\\'){
207 i4++;
208 break;
209 }
210 }
211 }
212 memcpy(temporary,tempBaseDirPath.c_str(),i3);
213 temporary[i3]=0;
214 lstrcat(temporary,path+i);
215 lstrcpy(path,temporary);
216}
217
218void ShowErrorLine(int LineNum,const char *constFileName){
219 HANDLE hFile;
220 DWORD dw;
221 char FileName[MAX_PATH];
222 char temporary[MAX_PATH];
223
224 lstrcpy( FileName, constFileName );
225
226 if(LineNum==-1) return;
227
228 if(IsWindow(hOwnerEditor)){
229 if(FileName){
230
231 while( !IsFileExist( FileName ) ){
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
244 hFile=CreateFile(
245 ( ActiveBasic::Common::Environment::GetUserAppDir() + "\\pgm.tmp" ).c_str(),
246 GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_TEMPORARY,NULL);
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);
301 compiler.errorMessenger.ShowErrorLine( i );
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){
322 if( program.IsClipCompileView() ){
323 //ProjectView埋め込みがたインターフェイスのとき
324
325 //生成するファイルの相対パスを取得
326 char relationalPath[MAX_PATH];
327 lstrcpy( relationalPath, program.GetOutputFilePath().c_str() );
328 GetRelationalPath( relationalPath, BasicCurDir );
329
330 //////////
331 // 合成
332
333#if defined(JPN)
334 //日本語
335 if(flag==0){
336 if(compiler.IsDll())
337 {
338 sprintf(buffer,"DLLファイル \"%s\" [ %s ]",relationalPath,msg);
339 }
340 else sprintf(buffer,"実行ファイル \"%s\" [ %s ]",relationalPath,msg);
341 }
342 if(flag==1) sprintf(buffer,"\"%s\" を生成しています [ %s ]",relationalPath,msg);
343 if(flag==2) lstrcpy(buffer,msg);
344#else
345 //英語
346 if(flag==0){
347 if(compiler.IsDll()) sprintf(buffer,"DLL file \"%s\" [ %s ]",relationalPath,msg);
348 else sprintf(buffer,"Execution file \"%s\" [ %s ]",relationalPath,msg);
349 }
350 if(flag==1) sprintf(buffer,"Creating \"%s\" [ %s ]",relationalPath,msg);
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;
384 static int height_Progress;
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
394 char relationalPath[MAX_PATH];
395 lstrcpy(relationalPath,program.GetOutputFilePath().c_str());
396 GetRelationalPath(relationalPath,BasicCurDir);
397 SetDlgItemText(hwnd,IDC_EXEPATH,relationalPath);
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){
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 );
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:
498 if( program.IsClipCompileView() ){
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:
512 if( program.IsClipCompileView() ){
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
541 if( !program.IsClipCompileView() ){
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
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
585 // グローバルローケルを日本語にする
586 std::locale::global(std::locale("japanese"));
587 _setmode(_fileno(stdout), _O_BINARY);
588
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
605 program.Configurate();
606
607 if( !program.AnalysisCommandLines() )
608 {
609 // コマンドラインが不正
610 return 0;
611 }
612
613 bool isSpecifiedSourceFilePathByCommandLine = false;
614 if( program.GetSourceFilePath().size() > 0 )
615 {
616 // ソースファイル名が与えられていたとき
617 isSpecifiedSourceFilePathByCommandLine = true;
618 }
619 else
620 {
621 // ソースファイル名が与えられなかったとき
622 char temp[MAX_PATH];
623 if(!GetFilePathDialog(0,temp,BasicFileFilter,"コンパイルするファイルを指定して下さい",1))
624 {
625 return 0;
626 }
627 program.SetSourceFilePath( temp );
628 }
629
630 //出力ファイル名が与えられなかったとき
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);
637 if( compiler.IsSll() )
638 {
639 if( program.IsDebugRun() || compiler.IsDebug() )
640 {
641 lstrcat(tempOutputFileName,"_debug.abobj");
642 }
643 else
644 {
645 lstrcat(tempOutputFileName,".abobj");
646 }
647 }
648 else
649 {
650 if( program.IsDebugRun() || compiler.IsDebug() )
651 {
652 lstrcat(tempOutputFileName,"_debug.exe");
653 }
654 else
655 {
656 lstrcat(tempOutputFileName,".exe");
657 }
658 }
659
660 program.SetOutputFilePath( tempOutputFileName );
661 }
662
663 {
664 // カレントディレクトリを取得
665 std::string baseDirPath = Jenga::Common::Environment::GetAppDir()+"\\";
666
667 // インクルードディレクトリが指定されなかったとき
668 if( program.GetIncludeDir().size() == 0 )
669 {
670 program.SetIncludeDir( Jenga::Common::Path::MakeFullPath( ".\\Include", ActiveBasic::Common::Environment::GetAbdevRootPath() ) );
671 }
672 else
673 {
674 // インクルードディレクトリを絶対パスに変更
675 program.SetIncludeDir( Jenga::Common::Path::MakeFullPathByCurrentDirectory( program.GetIncludeDir() ) );
676 }
677
678 // ソースファイル名を絶対パスに変換
679 program.SetSourceFilePath( Jenga::Common::Path::MakeFullPathByCurrentDirectory( program.GetSourceFilePath() ) );
680
681 // 出力ファイル名を絶対パスに変換
682 program.SetOutputFilePath( Jenga::Common::Path::MakeFullPathByCurrentDirectory( program.GetOutputFilePath() ) );
683
684 // モジュール名をセット
685 compiler.SetModuleName( Jenga::Common::Path( program.GetOutputFilePath() ).GetFileName() );
686 }
687
688 if( compiler.IsDll() )
689 {
690 //DLLファイル名を取得
691 _splitpath( program.GetOutputFilePath().c_str(),NULL,NULL,szDllName,temporary);
692 lstrcat(szDllName,temporary);
693 }
694
695 if( program.IsDebugRun() )
696 {
697 //コマンドライン、DLLの実行可能アプリケーションを取得
698 HANDLE hFile;
699 DWORD dwAccessBytes;
700 hFile=CreateFile(
701 ( ActiveBasic::Common::Environment::GetUserAppDir() + "\\pgm.tmp" ).c_str(),
702 GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
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
722 _splitpath( program.GetSourceFilePath().c_str(), BasicCurDir,temporary,NULL,NULL);
723 lstrcat(BasicCurDir,temporary);
724
725 if( program.IsClipCompileView() ){
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);
738
739 if( program.IsKickedFromEditor() )
740 {
741 // エディタから起動されたとき
742 PostMessage( hMainDlg, WM_COMMAND, IDOK, 0 );
743 }
744 else if( program.IsShowDlg() )
745 {
746 // コマンドラインでshow_dlgパラメータが指定された場合、ダイアログを表示する
747 // すぐにビルドを開始する
748 ShowWindow(hMainDlg,SW_SHOW);
749 PostMessage( hMainDlg, WM_COMMAND, IDOK, 0 );
750 }
751 else if( isSpecifiedSourceFilePathByCommandLine )
752 {
753 // コマンドラインでソースコード指定があった場合はウィンドウは表示せず、そのままビルドを開始する。
754 MainThread(0);
755
756 trace("Complete ActiveBasic Compiler!");
757
758 ExitProcess( program.GetExitCode() );
759 return 0;
760 }
761 else
762 {
763 ShowWindow(hMainDlg,SW_SHOW);
764 }
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
776 if( program.IsKickedFromEditor() )
777 {
778 SendMessage(hMainDlg,WM_COMMAND,IDOK,0);
779 }
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
797 if( program.IsClipCompileView() ){
798 SendMessage(hOwnerEditor,WM_DESTROYCOMPILEVIEW,0,0);
799 }
800
801 trace("Complete ActiveBasic Compiler!");
802
803 ExitProcess( program.GetExitCode() );
804
805 return 0;
806}
Note: See TracBrowser for help on using the repository browser.