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

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

静的リンクライブラリにより、複数のグローバル領域が存在することになったのでそれぞれを関数ベースに分けた

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