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

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

バージョン情報をver.hに独立させた。

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