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

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

コマンドライン解析モジュールをリファクタリング。

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