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

Last change on this file since 461 was 461, checked in by dai_9181, 16 years ago

smoothieプロジェクトが不要になったため、破棄。

File size: 21.6 KB
Line 
1#include "stdafx.h"
2
3#include <shlwapi.h>
4
5#include <jenga/include/common/Path.h>
6
7#include <Program.h>
8#include <Compiler.h>
9#include <ver.h>
10
11#include "BasicCompiler.h"
12
13#if defined HeapAlloc
14#define MEM_MAX 65536
15LPVOID pCheckMem[MEM_MAX];
16int now;
17#undef HeapAlloc
18#undef HeapReAlloc
19LPVOID CheckHeapAlloc(HANDLE hf,DWORD dwFlags,DWORD dwBytes){
20 LPVOID ret;
21 ret=HeapAlloc(hf,dwFlags,dwBytes);
22 pCheckMem[now]=ret;
23
24 //この部分にnowのチェックを挿入
25
26 now++;
27 if(now>=MEM_MAX){
28 MessageBox(0,"pCheckMemの最大値を超えました","Check - BasicCompiler.exe",0);
29 }
30 return ret;
31}
32LPVOID CheckHeapReAlloc(HANDLE hf,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes){
33 int i;
34 LPVOID ret;
35 for(i=0;;i++){
36 if(lpMem==pCheckMem[i]) break;
37 if(i>=MEM_MAX){
38 MessageBox(0,"エラー","Check - BasicCompiler.exe",0);
39 break;
40 }
41 }
42 ret=HeapReAlloc(hf,dwFlags,lpMem,dwBytes);
43 pCheckMem[i]=ret;
44 return ret;
45}
46void HeapDefaultFree(LPVOID lpMem){
47 int i;
48 for(i=0;;i++){
49 if(lpMem==pCheckMem[i]) break;
50 if(i>=MEM_MAX||lpMem==0){
51 MessageBox(0,"エラー","Check - BasicCompiler.exe",0);
52 break;
53 }
54 }
55 pCheckMem[i]=0;
56 HeapFree(hHeap,0,lpMem);
57}
58void CheckHeapCheck(){
59 int i,i2;
60 char temp[100];
61 temp[0]=0;
62 for(i=0,i2=0;i<MEM_MAX;i++){
63 if(pCheckMem[i]){
64 sprintf(temp+lstrlen(temp),"%d\r\n",i);
65 i2++;
66 if(i2==10){
67 lstrcat(temp,"これ以上の未解放が確認されています");
68 break;
69 }
70 }
71 }
72 if(temp[0]) MessageBox(0,temp,"Check - BasicCompiler.exe",0);
73}
74#define HeapAlloc CheckHeapAlloc
75#define HeapReAlloc CheckHeapReAlloc
76#else
77void HeapDefaultFree(LPVOID lpMem){
78 HeapFree(hHeap,0,lpMem);
79}
80#endif
81
82void ts(int i){
83 char temporary[255];
84 sprintf(temporary,"0x%08x",i);
85 MessageBox(0,temporary,"TestMessage",0);
86}
87void ts(int i,int i2){
88 char temporary[255];
89 sprintf(temporary,"0x%08x\r\n0x%08x",i,i2);
90 MessageBox(0,temporary,"TestMessage",0);
91}
92void ts(const char *msg){
93 MessageBox(0,FormatEscapeSequenceStringToDefaultString(msg).c_str(),"TestMessage",0);
94}
95void ts(const char *msg,const char *title){
96 MessageBox(0,FormatEscapeSequenceStringToDefaultString(msg).c_str(),title,0);
97}
98
99void epi_check(){
100 //この部分にobpのチェックを挿入
101 //※例 … epi=0x41999 → obp>=0x0999
102/*
103 extern int obp;
104 if(obp>=0x988DE){
105 int test=0;
106 }*/
107}
108
109void GetRelationalPath(char *path,char *dir){
110 //相対パスを取得
111 int i,i2,i3,i4,i5;
112 char temporary[MAX_PATH],temp2[MAX_PATH],temp3[MAX_PATH],temp4[MAX_PATH];
113
114 //ドライブ名をチェック
115 _splitpath(path,temporary,0,0,0);
116 _splitpath(dir,temp2,0,0,0);
117 if(lstrcmpi(temporary,temp2)!=0) return;
118
119 _splitpath(path,0,temporary,0,0);
120 _splitpath(dir,0,temp2,0,0);
121 i=1;i2=1;
122 while(1){
123 i4=i;
124 if(temporary[i-1]=='\\'&&temporary[i]){ //path側
125 for(i3=0;;i++,i3++){
126 if(temporary[i]=='\\'){
127 temp3[i3]=0;
128 i++;
129 break;
130 }
131 temp3[i3]=temporary[i];
132 }
133 }
134 else temp3[0]=0;
135
136 i5=i2;
137 if(temp2[i2-1]=='\\'&&temp2[i2]){ //dir側
138 for(i3=0;;i2++,i3++){
139 if(temp2[i2]=='\\'){
140 temp4[i3]=0;
141 i2++;
142 break;
143 }
144 temp4[i3]=temp2[i2];
145 }
146 }
147 else temp4[0]=0;
148
149 if(temp3[0]=='\0'&&temp4[0]=='\0'){
150 lstrcpy(temp3,".\\");
151 break;
152 }
153
154 if(lstrcmpi(temp3,temp4)!=0){
155 for(i3=0;;i5++){
156 if(temp2[i5]=='\0') break;
157 if(temp2[i5]=='\\') i3++;
158 }
159 if(i3==0) lstrcpy(temp3,".\\");
160 else{
161 temp3[0]=0;
162 for(i2=0;i2<i3;i2++) lstrcat(temp3,"..\\");
163 }
164 lstrcat(temp3,temporary+i4);
165 break;
166 }
167 }
168 _splitpath(path,0,0,temporary,temp2);
169 lstrcat(temp3,temporary);
170 lstrcat(temp3,temp2);
171 lstrcpy(path,temp3);
172}
173void GetFullPath( char *path, const string &baseDirPath ){
174 int i,i2,i3,i4;
175 char temporary[MAX_PATH];
176
177 // '/'→'\'
178 for( i=0;path[i];i++ ){
179 if( path[i] == '/' ){
180 path[i]='\\';
181 }
182 }
183
184 if(strstr(path,":")||strstr(path,"\\\\")) return;
185
186 i=0;i2=0;
187 while(1){
188 if(path[i]=='.'&&path[i+1]=='\\') i+=2;
189 if(path[i]=='.'&&path[i+1]=='.'&&path[i+2]=='\\'){
190 i2++;
191 i+=3;
192 }
193 else break;
194 }
195
196 i3=(int)baseDirPath.size();i4=0;
197 while(i4<i2){
198 for(i3--;;i3--){
199 if(baseDirPath[i3-1]=='\\'){
200 i4++;
201 break;
202 }
203 }
204 }
205 memcpy(temporary,baseDirPath.c_str(),i3);
206 temporary[i3]=0;
207 lstrcat(temporary,path+i);
208 lstrcpy(path,temporary);
209}
210std::string GetApplicationBaseFullPath( const std::string &relationalPath )
211{
212 char fullPath[1024];
213 lstrcpy( fullPath, relationalPath.c_str() );
214 GetFullPath( fullPath, Jenga::Common::Environment::GetAppDir() );
215 return fullPath;
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 ( Jenga::Common::Environment::GetAppDir() + "\\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 ShowErrorLine(pErrorInfo[i].line,pErrorInfo[i].FileName);
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 char temporary[MAX_PATH];
323 if(bClipCompileView){
324 //ProjectView埋め込みがたインターフェイスのとき
325
326 //生成するファイルの相対パスを取得
327 lstrcpy(temporary,OutputFileName);
328 GetRelationalPath(temporary,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 ]",temporary,msg);
339 }
340 else sprintf(buffer,"実行ファイル \"%s\" [ %s ]",temporary,msg);
341 }
342 if(flag==1) sprintf(buffer,"\"%s\" を生成しています [ %s ]",temporary,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 ]",temporary,msg);
348 else sprintf(buffer,"Execution file \"%s\" [ %s ]",temporary,msg);
349 }
350 if(flag==1) sprintf(buffer,"Creating \"%s\" [ %s ]",temporary,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 DWORD dw;
381 RECT rect;
382 POINT pos;
383 SIZE size;
384 static POINT pos_List,pos_Progress;
385 static int height_Progress;
386
387 switch(message){
388 case WM_INITDIALOG:
389 pos=pobj_nv->MainDlgPos;
390 GetWindowRect(hwnd,&rect);
391 size.cx=rect.right-rect.left;
392 size.cy=rect.bottom-rect.top;
393 MoveWindow(hwnd,pos.x,pos.y,size.cx,size.cy,1);
394
395 lstrcpy(temporary,OutputFileName);
396 GetRelationalPath(temporary,BasicCurDir);
397 SetDlgItemText(hwnd,IDC_EXEPATH,temporary);
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 GetDlgItemText(hwnd,IDC_EXEPATH,OutputFileName,MAX_PATH);
431 GetFullPath(OutputFileName,BasicCurDir);
432 CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)MainThread,0,0,&dw);
433 }
434
435 //STRING_STOP = "中断"
436 else if(lstrcmp(temporary,STRING_STOP)==0){
437 if(hDebugProcess){
438 //デバッグ中のとき
439
440 //プロセスを終了
441 TerminateProcess(hDebugProcess,0);
442 hDebugProcess=0;
443
444 //デバッグダイアログを終了
445 if(hDebugWnd){
446 DestroyWindow(hDebugWnd);
447 }
448 }
449 else{
450 //コンパイル中のとき
451 bStopCompile=1;
452
453 /* メインスレッドで「閉じる」ボタンに変更することで、
454 コンパイルを中断中の早いタイミングでも終了することが可能 */
455 //"閉じる"
456 SetDlgItemText(hwnd,IDOK,STRING_CLOSE);
457 }
458 }
459
460 else{
461 SetFocus(hOwnerEditor);
462 DestroyWindow(hwnd);
463 }
464 return 1;
465 case IDCANCEL:
466 //×ボタン用
467
468 if(hDebugProcess){
469 //デバッグ中のとき
470
471 //プロセスを終了
472 TerminateProcess(hDebugProcess,0);
473 hDebugProcess=0;
474
475 //デバッグダイアログを終了
476 if(hDebugWnd){
477 DestroyWindow(hDebugWnd);
478 }
479 }
480
481 SetFocus(hOwnerEditor);
482 DestroyWindow(hwnd);
483 return 1;
484 case IDC_SHOWERROR:
485 ShowWindow(GetDlgItem(hwnd,IDC_ERRORLIST),SW_SHOW);
486 ShowWindow(GetDlgItem(hwnd,IDC_DEBUGLIST),SW_HIDE);
487 return 1;
488 case IDC_SHOWDEBUG:
489 ShowWindow(GetDlgItem(hwnd,IDC_ERRORLIST),SW_HIDE);
490 ShowWindow(GetDlgItem(hwnd,IDC_DEBUGLIST),SW_SHOW);
491 return 1;
492 }
493 break;
494 case WM_SHOWVARLIST:
495 if(bClipCompileView){
496 //埋め込み表示
497 CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_DEBUGGER),hOwnerEditor,(DLGPROC)DlgDebugger,lParam);
498 ShowWindow(hDebugWnd,SW_SHOW);
499
500 SendMessage(hOwnerEditor,WM_SETDEBUGGERVIEW,0,(LPARAM)hDebugWnd);
501 }
502 else{
503 //ポップアップ表示
504 CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_VARLIST),hOwnerEditor,(DLGPROC)DlgVarList,lParam);
505 SetForegroundWindow(hDebugWnd);
506 }
507 return 1;
508 case WM_SIZE:
509 if(bClipCompileView){
510 //エラーリストの位置
511 MoveWindow(GetDlgItem(hwnd,IDC_ERRORLIST),
512 pos_List.x,
513 pos_List.y,
514 LOWORD(lParam)-pos_List.x,
515 HIWORD(lParam)-pos_List.y,
516 1);
517
518 //デバッグリストの位置
519 MoveWindow(GetDlgItem(hwnd,IDC_DEBUGLIST),
520 pos_List.x,
521 pos_List.y,
522 LOWORD(lParam)-pos_List.x,
523 HIWORD(lParam)-pos_List.y,
524 1);
525
526 //プログレスバーの位置
527 MoveWindow(GetDlgItem(hwnd,IDC_PROGRESS),
528 pos_Progress.x,
529 pos_Progress.y,
530 LOWORD(lParam)-pos_Progress.x,
531 height_Progress,
532 1);
533 }
534 return 1;
535 case WM_DESTROY:
536 GetWindowRect(hwnd,&rect);
537
538 if(!bClipCompileView){
539 pobj_nv->MainDlgPos.x=rect.left;
540 pobj_nv->MainDlgPos.y=rect.top;
541 }
542
543 PostQuitMessage(0);
544 return 1;
545
546
547
548 ///////////////////////
549 // デバッグコマンド
550 ///////////////////////
551
552 case WM_DEBUG_STOP:
553 Debugger_Stop();
554 return 1;
555 case WM_DEBUG_PAUSE:
556 Debugger_Pause();
557 return 1;
558
559
560 case WM_CLOSE_DEBUGGER:
561 if(hDebugWnd){
562 DestroyWindow(hDebugWnd);
563 }
564 return 1;
565 }
566 return 0;
567}
568
569bool AnalysisCommandLines( bool &isFromEditor )
570{
571 // 値を初期化
572 isFromEditor = false;
573
574 // コマンドラインを解析
575 const Jenga::Common::CmdLines cmdLines( PathGetArgs( GetCommandLine() ) );
576 int cmdLineIndex = 0;
577
578 if( cmdLines.size() == 0 )
579 {
580 // 何も指定されていないとき
581 return true;
582 }
583
584 if( cmdLines[cmdLineIndex].IsNamelessCommand() )
585 {
586 // 先頭に無名コマンドがきた場合、ソースファイル名として認識する
587 lstrcpy( SourceFileName, cmdLines[cmdLineIndex].GetParameter().c_str() );
588
589 cmdLineIndex ++;
590
591 if( cmdLines.size() == 1 )
592 {
593 // ソースファイル名のみの指定だったとき
594 return true;
595 }
596
597 // 出力ファイル名を取得
598 if( cmdLines[cmdLineIndex].IsNamelessCommand() )
599 {
600 // 二番目にも無名コマンドがきた場合、ソースファイル名として認識する
601 lstrcpy( OutputFileName, cmdLines[cmdLineIndex].GetParameter().c_str() );
602
603 cmdLineIndex ++;
604 }
605 }
606
607 for( ; cmdLineIndex < static_cast<int>(cmdLines.size()); cmdLineIndex++ )
608 {
609 const Jenga::Common::CmdLine &cmdLine = cmdLines[cmdLineIndex];
610
611 if( cmdLine.GetCommand() == "wnd" )
612 {
613 // 親エディタのウィンドウ ハンドル
614 isFromEditor = true;
615 sscanf( cmdLine.GetParameter().c_str(), "%08x", &hOwnerEditor );
616 }
617 else if( cmdLine.GetCommand() == "debug" )
618 {
619 // デバッグ ビルド
620 compiler.SetDebugMark( true );
621 }
622 else if( cmdLine.GetCommand() == "run" )
623 {
624 // デバッグ実行
625 bDebugRun = 1;
626 }
627 else if( cmdLine.GetCommand() == "attach" )
628 {
629 // アタッチ
630 bDebugRun=1;
631 bAttach=1;
632 sscanf( cmdLine.GetParameter().c_str(), "%08x", &dwAttachProcessId );
633 }
634 else if( cmdLine.GetCommand() == "dll" )
635 {
636 // DLLとしてビルド
637 compiler.SetTargetModuleType( Compiler::Dll );
638 }
639 else if( cmdLine.GetCommand() == "static_library" )
640 {
641 // 静的リンクライブラリとしてビルド
642 compiler.SetTargetModuleType( Compiler::StaticLibrary );
643 }
644 else if( cmdLine.GetCommand() == "unicode" )
645 {
646 // Unicode
647 compiler.SetUnicodeMark( true );
648 typeOfPtrChar = MAKE_PTR_TYPE(DEF_WORD,1);
649 typeOfPtrUChar = MAKE_PTR_TYPE(DEF_WORD,1);
650 }
651 else if( cmdLine.GetCommand() == "clip_compile_view" )
652 {
653 //埋め込み型コンパイラビュー
654 bClipCompileView = 1;
655 }
656 else if( cmdLine.GetCommand() == "include_dir" )
657 {
658 //インクルード ディレクトリ
659 lstrcpy( szIncludeDir, cmdLine.GetParameter().c_str() );
660 }
661 else
662 {
663 // 不正なコマンド
664 std::string keyword = cmdLine.GetCommand();
665 if( keyword.size() == 0 )
666 {
667 keyword = cmdLine.GetParameter();
668 }
669 std::cout << keyword << " コマンドとして認識できません。" << std::endl;
670 return false;
671 }
672 }
673
674 return true;
675}
676
677void _Test()
678{
679 Jenga::Common::LoggerSetting loggerSetting;
680 bool result = loggerSetting.WriteXml( Jenga::Common::Environment::GetAppDir() + "\\logger.setting.xml" );
681}
682
683int main()
684{
685 int i;
686 char temporary[1024],temp2[MAX_PATH];
687
688 hInst = GetModuleHandle( NULL );
689
690 //_Test();
691
692 //MessageBox(0,"starting compiler/debugger","ActiveBasic",MB_OK);
693 trace( "Start ActiveBasic Compiler!" );
694
695 //コモンコントロールを初期化
696 InitCommonControls();
697
698 hHeap=GetProcessHeap();
699 ScreenX=GetSystemMetrics(SM_CXSCREEN);
700 ScreenY=GetSystemMetrics(SM_CYSCREEN);
701
702 //不揮発性データを取得
703 pobj_nv=new CNonVolatile;
704 pobj_nv->load();
705
706 bool isFromEditor;
707 if( !AnalysisCommandLines( isFromEditor ) )
708 {
709 // コマンドラインが不正
710 return 0;
711 }
712
713 //ソースファイル名が与えられなかったとき
714 if(SourceFileName[0]=='\0'){
715 if(!GetFilePathDialog(0,SourceFileName,BasicFileFilter,"コンパイルするファイルを指定して下さい",1))
716 return 0;
717 }
718
719 //出力ファイル名が与えられなかったとき
720 if(OutputFileName[0]=='\0'){
721 _splitpath(SourceFileName,OutputFileName,temporary,temp2,0);
722 lstrcat(OutputFileName,temporary);
723 lstrcat(OutputFileName,temp2);
724 if( compiler.IsStaticLibrary() )
725 {
726 if( bDebugRun || compiler.IsDebug() )
727 {
728 lstrcat(OutputFileName,"_debug.abobj");
729 }
730 else
731 {
732 lstrcat(OutputFileName,".abobj");
733 }
734 }
735 else
736 {
737 if( bDebugRun || compiler.IsDebug() )
738 {
739 lstrcat(OutputFileName,"_debug.exe");
740 }
741 else
742 {
743 lstrcat(OutputFileName,".exe");
744 }
745 }
746 }
747
748 {
749 // カレントディレクトリを取得
750 std::string baseDirPath = Jenga::Common::Environment::GetAppDir()+"\\";
751
752 // インクルードディレクトリが指定されなかったとき
753 if(szIncludeDir[0]=='\0'){
754 lstrcpy(szIncludeDir,".\\Include\\");
755
756 // インクルードディレクトリを絶対パスに変更
757 GetFullPath(szIncludeDir,baseDirPath.c_str());
758 }
759 else
760 {
761 // インクルードディレクトリを絶対パスに変更
762 GetFullPath(szIncludeDir,baseDirPath.c_str());
763 }
764
765 // ソースファイル名を絶対パスに変換
766 GetFullPath(SourceFileName,baseDirPath.c_str());
767
768 // 出力ファイル名を絶対パスに変換
769 GetFullPath(OutputFileName,baseDirPath.c_str());
770
771 // モジュール名をセット
772 compiler.SetModuleName( Jenga::Common::Path( OutputFileName ).GetFileName() );
773 }
774
775 if( compiler.IsDll() ){
776 //DLLファイル名を取得
777 _splitpath(OutputFileName,NULL,NULL,szDllName,temporary);
778 lstrcat(szDllName,temporary);
779 }
780
781 if(bDebugRun){
782 //コマンドライン、DLLの実行可能アプリケーションを取得
783 HANDLE hFile;
784 DWORD dwAccessBytes;
785 hFile=CreateFile(
786 ( Jenga::Common::Environment::GetAppDir() + "\\pgm.tmp" ).c_str(),
787 GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
788 if(hFile!=INVALID_HANDLE_VALUE){
789 ReadFile(hFile,temporary,MAX_PATH,&dwAccessBytes,NULL);
790 CloseHandle(hFile);
791 temporary[dwAccessBytes]=0;
792 }
793 else temporary[0]=0;
794
795 for(i=0;;i++){
796 if(temporary[i]=='\r'&&temporary[i+1]=='\n'||temporary[i]=='\0'){
797 szDebugExeForDll[i]=0;
798 break;
799 }
800 szDebugExeForDll[i]=temporary[i];
801 }
802 if(temporary[i]){
803 lstrcpy(szDebugCmdLine,temporary+i+2);
804 }
805 }
806
807 _splitpath(SourceFileName,BasicCurDir,temporary,NULL,NULL);
808 lstrcat(BasicCurDir,temporary);
809
810 //エラーリスト情報を初期化
811 pErrorInfo=(ERRORINFO *)HeapAlloc(hHeap,0,1);
812 ErrorNum=0;
813 CompileMsgNum=0;
814 WarningNum=0;
815 bError=0;
816
817 if(bClipCompileView){
818 //ProjectEditor埋め込み型インターフェイス
819 hMainDlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_CLIPMAIN),hOwnerEditor,(DLGPROC)DlgCompile);
820 ShowWindow(hMainDlg,SW_SHOW);
821 SendMessage(hOwnerEditor,WM_SETCOMPILEVIEW,0,(LPARAM)hMainDlg);
822
823 //プログレスバーの色をセットする
824 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETBARCOLOR,0,RGB(255,220,192));
825 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETBKCOLOR,0,RGB(255,255,255));
826 }
827 else{
828 //通常ダイアログインターフェイス
829 hMainDlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_MAIN),hOwnerEditor,(DLGPROC)DlgCompile);
830
831#ifdef _DEBUG
832 // VC++によるデバッグの場合は画面を出さない
833 // ※別スレッドのウィンドウ ループとの不整合性がデッドロックを生む場合がある(特にステップ実行時など)
834 PostMessage( hMainDlg, WM_COMMAND, IDOK, 0 );
835#else
836 ShowWindow(hMainDlg,SW_SHOW);
837#endif
838 }
839 SendDlgItemMessage(hMainDlg,IDC_SHOWERROR,BM_SETCHECK,BST_CHECKED,0);
840
841 //エラーリストをサブクラス化
842 OldErrorListProc=(WNDPROC)GetWindowLongPtr(GetDlgItem(hMainDlg,IDC_ERRORLIST),GWLP_WNDPROC);
843 SetWindowLongPtr(GetDlgItem(hMainDlg,IDC_ERRORLIST),GWLP_WNDPROC,(LONG_PTR)ErrorListProc);
844
845 //デバッグリストをサブクラス化
846 OldDebugListProc=(WNDPROC)GetWindowLongPtr(GetDlgItem(hMainDlg,IDC_DEBUGLIST),GWLP_WNDPROC);
847 SetWindowLongPtr(GetDlgItem(hMainDlg,IDC_DEBUGLIST),GWLP_WNDPROC,(LONG_PTR)DebugListProc);
848
849 if( isFromEditor )
850 {
851 SendMessage(hMainDlg,WM_COMMAND,IDOK,0);
852 }
853
854 MSG msg;
855 while(GetMessage(&msg,0,0,0)){
856 if(IsDialogMessage(hMainDlg,&msg)) continue;
857 TranslateMessage(&msg);
858 DispatchMessage(&msg);
859 }
860
861 //エラーリスト情報を解放
862 for(i=0;i<ErrorNum;i++){
863 if(pErrorInfo[i].FileName) HeapDefaultFree(pErrorInfo[i].FileName);
864 }
865 HeapDefaultFree(pErrorInfo);
866
867 //不揮発性データを保存
868 pobj_nv->save();
869 delete pobj_nv;
870 pobj_nv=0;
871
872#if defined HeapAlloc
873 CheckHeapCheck();
874#endif
875
876 if(bClipCompileView){
877 SendMessage(hOwnerEditor,WM_DESTROYCOMPILEVIEW,0,0);
878 }
879
880 trace("Complete ActiveBasic Compiler!");
881
882 ExitProcess( 0 );
883
884 return 0;
885}
Note: See TracBrowser for help on using the repository browser.