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