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

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