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

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