source: dev/trunk/abdev/BasicCompiler_Common/BasicCompiler.cpp@ 165

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