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

Last change on this file since 154 was 140, checked in by dai_9181, 17 years ago

traceログ機能を搭載
動的メンバをstl::vectorにまとめた
シンボルをクラス化した

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