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

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

BasicSysDirをGetAppDirに置き換えた

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