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

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

sourceをObjectModuleに入れた

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