source: dev/BasicCompiler_Common/BasicCompiler.cpp@ 139

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

クラス情報取得時のクラス先読み処理で名前空間の関係が崩れてしまうバグを修正。
インクルードパスに'/'文字を含めたときに'
'として判断するようにした。

File size: 20.2 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
551 //コモンコントロールを初期化
552 InitCommonControls();
553
554 hHeap=GetProcessHeap();
555 ScreenX=GetSystemMetrics(SM_CXSCREEN);
556 ScreenY=GetSystemMetrics(SM_CYSCREEN);
557
558 hInst=hThisInst;
559
560 GetModuleFileName(hInst,temporary,MAX_PATH);
561 _splitpath(temporary,BasicSystemDir,temp2,NULL,NULL);
562 lstrcat(BasicSystemDir,temp2);
563
564 //不揮発性データを取得
565 pobj_nv=new CNonVolatile;
566 pobj_nv->load();
567
568 //ソースファイル名を取得
569 i=0;
570 if(lpCmdLine[0]!='/'){
571 if(lpCmdLine[0]=='\"'){
572 for(i=1,i2=0;;i++,i2++){
573 if(lpCmdLine[i]=='\"'){
574 SourceFileName[i2]=0;
575 break;
576 }
577 SourceFileName[i2]=lpCmdLine[i];
578 if(lpCmdLine[i]=='\0') break;
579 }
580 i++;
581 while(lpCmdLine[i]==' ') i++;
582 }
583 else{
584 for(i=0;;i++){
585 if(lpCmdLine[i]==' '){
586 SourceFileName[i]=0;
587 break;
588 }
589 SourceFileName[i]=lpCmdLine[i];
590 if(lpCmdLine[i]=='\0') break;
591 }
592 while(lpCmdLine[i]==' ') i++;
593 }
594 }
595
596 BOOL bFromEditor=0;
597 bDll=0;
598 OutputFileName[0]=0;
599 if(lpCmdLine[i]&&lpCmdLine[i]!='/'){
600 if(lpCmdLine[i]=='\"'){
601 for(i++,i2=0;;i++,i2++){
602 if(lpCmdLine[i]=='\"'){
603 OutputFileName[i2]=0;
604 break;
605 }
606 OutputFileName[i2]=lpCmdLine[i];
607 if(lpCmdLine[i]=='\0') break;
608 }
609 i++;
610 while(lpCmdLine[i]==' ') i++;
611 }
612 else{
613 for(i2=0;;i++,i2++){
614 if(lpCmdLine[i]==' '){
615 OutputFileName[i2]=0;
616 break;
617 }
618 OutputFileName[i2]=lpCmdLine[i];
619 if(lpCmdLine[i]=='\0') break;
620 }
621 while(lpCmdLine[i]==' ') i++;
622 }
623 }
624
625 KillSpaces(lpCmdLine+i,temporary);
626 i=0;
627 while(temporary[i]=='/'){
628 for(i++,i2=0;;i++,i2++){
629 if(temporary[i]=='/'){
630 temp2[i2]=0;
631 break;
632 }
633 if(temporary[i]==':'){
634 temp2[i2]=0;
635 break;
636 }
637 temp2[i2]=temporary[i];
638 if(temporary[i]=='\0') break;
639 }
640
641 char temp3[MAX_PATH];
642 if(temporary[i]==':'){
643 i++;
644 if(temporary[i]=='\"'){
645 for(i++,i2=0;;i++,i2++){
646 if(temporary[i]=='\"'){
647 temp3[i2]=0;
648 RemoveStringQuotes(temp3);
649 i++;
650 break;
651 }
652 temp3[i2]=temporary[i];
653 if(temporary[i]=='\0') break;
654 }
655 }
656 else{
657 for(i2=0;;i++,i2++){
658 if(temporary[i]=='/'){
659 temp3[i2]=0;
660 break;
661 }
662 if(temporary[i]==':'){
663 temp3[i2]=0;
664 break;
665 }
666 temp3[i2]=temporary[i];
667 if(temporary[i]=='\0') break;
668 }
669 }
670 }
671 else temp3[0]=0;
672
673
674 /////////////////////////
675 // コマンドラインを調査
676 /////////////////////////
677
678 //ウィンドウハンドル
679 if(lstrcmp(temp2,"wnd")==0){
680 bFromEditor=1;
681
682 if(temp3[0]) sscanf(temp3,"%08x",&hOwnerEditor);
683 }
684
685 //デバッグコンパイル
686 else if(lstrcmp(temp2,"debug")==0) bDebugCompile=1;
687
688 //デバッグ実行
689 else if(lstrcmp(temp2,"run")==0) bDebugRun=1;
690
691 //デバッグ実行(アタッチする)
692 else if(lstrcmp(temp2,"attach")==0){
693 bDebugRun=1;
694 bAttach=1;
695
696 if(temp3[0]) sscanf(temp3,"%08x",&dwAttachProcessId);
697 }
698
699 //DLL生成
700 else if(lstrcmp(temp2,"dll")==0) bDll=1;
701
702 //Unicode
703 else if( lstrcmp( temp2, "unicode" ) ==0 ){
704 isUnicode = true;
705 typeOfPtrChar = MAKE_PTR_TYPE(DEF_WORD,1);
706 typeOfPtrUChar = MAKE_PTR_TYPE(DEF_WORD,1);
707 }
708
709 //埋め込み型コンパイラビュー
710 else if(lstrcmp(temp2,"clip_compile_view")==0) bClipCompileView=1;
711
712 //インクルードディレクトリ
713 else if(lstrcmp(temp2,"include_dir")==0){
714 lstrcpy(szIncludeDir,temp3);
715 }
716 }
717
718 //ソースファイル名が与えられなかったとき
719 if(SourceFileName[0]=='\0'){
720 if(!GetFilePathDialog(0,SourceFileName,BasicFileFilter,"コンパイルするファイルを指定して下さい",1))
721 return 0;
722 }
723
724 //出力ファイル名が与えられなかったとき
725 if(OutputFileName[0]=='\0'){
726 _splitpath(SourceFileName,OutputFileName,temporary,temp2,0);
727 lstrcat(OutputFileName,temporary);
728 lstrcat(OutputFileName,temp2);
729 if(bDebugCompile||bDebugRun) lstrcat(OutputFileName,"_debug.exe");
730 else lstrcat(OutputFileName,".exe");
731 }
732
733 //インクルードディレクトリが指定されなかったとき
734 if(szIncludeDir[0]=='\0'){
735 lstrcpy(szIncludeDir,".\\Include\\");
736 }
737
738 //インクルードディレクトリを絶対パスに変更
739 GetFullPath(szIncludeDir,BasicSystemDir);
740
741 if(bDll){
742 //DLLファイル名を取得
743 _splitpath(OutputFileName,NULL,NULL,szDllName,temporary);
744 lstrcat(szDllName,temporary);
745 }
746
747 if(bDebugRun){
748 //コマンドライン、DLLの実行可能アプリケーションを取得
749 HANDLE hFile;
750 DWORD dwAccessBytes;
751 sprintf(temporary,"%spgm.tmp",BasicSystemDir);
752 hFile=CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
753 if(hFile!=INVALID_HANDLE_VALUE){
754 ReadFile(hFile,temporary,MAX_PATH,&dwAccessBytes,NULL);
755 CloseHandle(hFile);
756 temporary[dwAccessBytes]=0;
757 }
758 else temporary[0]=0;
759
760 for(i=0;;i++){
761 if(temporary[i]=='\r'&&temporary[i+1]=='\n'||temporary[i]=='\0'){
762 szDebugExeForDll[i]=0;
763 break;
764 }
765 szDebugExeForDll[i]=temporary[i];
766 }
767 if(temporary[i]){
768 lstrcpy(szDebugCmdLine,temporary+i+2);
769 }
770 }
771
772 _splitpath(SourceFileName,BasicCurDir,temporary,NULL,NULL);
773 lstrcat(BasicCurDir,temporary);
774
775 //エラーリスト情報を初期化
776 pErrorInfo=(ERRORINFO *)HeapAlloc(hHeap,0,1);
777 ErrorNum=0;
778 CompileMsgNum=0;
779 WarningNum=0;
780 bError=0;
781
782 if(bClipCompileView){
783 //ProjectEditor埋め込み型インターフェイス
784 hMainDlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_CLIPMAIN),hOwnerEditor,(DLGPROC)DlgCompile);
785 ShowWindow(hMainDlg,SW_SHOW);
786 SendMessage(hOwnerEditor,WM_SETCOMPILEVIEW,0,(LPARAM)hMainDlg);
787
788 //プログレスバーの色をセットする
789 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETBARCOLOR,0,RGB(255,220,192));
790 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETBKCOLOR,0,RGB(255,255,255));
791 }
792 else{
793 //通常ダイアログインターフェイス
794 hMainDlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_MAIN),hOwnerEditor,(DLGPROC)DlgCompile);
795
796#ifdef _DEBUG
797 // VC++によるデバッグの場合は画面を出さない
798 // ※別スレッドのウィンドウ ループとの不整合性がデッドロックを生む場合がある(特にステップ実行時など)
799 PostMessage( hMainDlg, WM_COMMAND, IDOK, 0 );
800#else
801 ShowWindow(hMainDlg,SW_SHOW);
802#endif
803 }
804 SendDlgItemMessage(hMainDlg,IDC_SHOWERROR,BM_SETCHECK,BST_CHECKED,0);
805
806 //エラーリストをサブクラス化
807 OldErrorListProc=(WNDPROC)GetWindowLongPtr(GetDlgItem(hMainDlg,IDC_ERRORLIST),GWLP_WNDPROC);
808 SetWindowLongPtr(GetDlgItem(hMainDlg,IDC_ERRORLIST),GWLP_WNDPROC,(LONG_PTR)ErrorListProc);
809
810 //デバッグリストをサブクラス化
811 OldDebugListProc=(WNDPROC)GetWindowLongPtr(GetDlgItem(hMainDlg,IDC_DEBUGLIST),GWLP_WNDPROC);
812 SetWindowLongPtr(GetDlgItem(hMainDlg,IDC_DEBUGLIST),GWLP_WNDPROC,(LONG_PTR)DebugListProc);
813
814 if(bFromEditor) SendMessage(hMainDlg,WM_COMMAND,IDOK,0);
815
816 MSG msg;
817 while(GetMessage(&msg,0,0,0)){
818 if(IsDialogMessage(hMainDlg,&msg)) continue;
819 TranslateMessage(&msg);
820 DispatchMessage(&msg);
821 }
822
823 //エラーリスト情報を解放
824 for(i=0;i<ErrorNum;i++){
825 if(pErrorInfo[i].FileName) HeapDefaultFree(pErrorInfo[i].FileName);
826 }
827 HeapDefaultFree(pErrorInfo);
828
829 //不揮発性データを保存
830 pobj_nv->save();
831 delete pobj_nv;
832 pobj_nv=0;
833
834#if defined HeapAlloc
835 CheckHeapCheck();
836#endif
837
838 if(bClipCompileView){
839 SendMessage(hOwnerEditor,WM_DESTROYCOMPILEVIEW,0,0);
840 }
841
842
843 return 0;
844}
Note: See TracBrowser for help on using the repository browser.