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

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