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

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

BasicSourceのシリアライズがうまくいっていない

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