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

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