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

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

コード全体のリファクタリングを実施

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