diff --git a/debugger/debugger.hpp b/debugger/debugger.hpp index 813c6e3..5a0ab40 100644 --- a/debugger/debugger.hpp +++ b/debugger/debugger.hpp @@ -2,18 +2,18 @@ #ifndef DEBUGGER_H #define DEBUGGER_H -class Debugger{ -public: - virtual void debugRun()=0; - virtual void debugStop()=0; - virtual void debugStmt( int srcpos,const char *file )=0; - virtual void debugEnter( void *frame,void *env,const char *func )=0; - virtual void debugLeave()=0; - virtual void debugLog( const char *msg )=0; - virtual void debugMsg( const char *msg,bool serious )=0; - virtual void debugSys( void *msg )=0; +class Debugger { + public: + virtual void debugRun() = 0; + virtual void debugStop() = 0; + virtual void debugStmt(int srcpos, const char* file) = 0; + virtual void debugEnter(void* frame, void* env, const char* func) = 0; + virtual void debugLeave() = 0; + virtual void debugLog(const char* msg) = 0; + virtual void debugMsg(const char* msg, bool serious) = 0; + virtual void debugSys(void* msg) = 0; }; -extern "C" _declspec(dllexport) Debugger * _cdecl debuggerGetDebugger( void *mod,void *env ); +extern "C" _declspec(dllexport) Debugger* _cdecl debuggerGetDebugger(void* mod, void* env); #endif diff --git a/debugger/debuggerapp.cpp b/debugger/debuggerapp.cpp index 3e212f2..59abccf 100644 --- a/debugger/debuggerapp.cpp +++ b/debugger/debuggerapp.cpp @@ -1,50 +1,50 @@ -#include "stdafx.hpp" -#include "debugger.hpp" #include "debuggerapp.hpp" -#include "resource.hpp" +#include "debugger.hpp" #include "prefs.hpp" +#include "resource.hpp" +#include "stdafx.hpp" DebuggerApp debuggerApp; -DebuggerApp::~DebuggerApp(){ -} - -BOOL DebuggerApp::InitInstance(){ +DebuggerApp::~DebuggerApp() {} +BOOL DebuggerApp::InitInstance() +{ AfxInitRichEdit(); - main_frame=new MainFrame(); + main_frame = new MainFrame(); - m_pMainWnd=main_frame; + m_pMainWnd = main_frame; RECT rect; - SystemParametersInfo( SPI_GETWORKAREA,0,&rect,0 ); + SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); - int x=rect.left; - int w=rect.right-x; - int h=240; - int y=rect.bottom-h; + int x = rect.left; + int w = rect.right - x; + int h = 240; + int y = rect.bottom - h; - main_frame->Create( 0,"Blitz Debugger", - WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN, - CRect( x,y,x+w,y+h ) ); - main_frame->ShowWindow( SW_SHOW ); + main_frame->Create(0, "Blitz Debugger", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CRect(x, y, x + w, y + h)); + main_frame->ShowWindow(SW_SHOW); main_frame->UpdateWindow(); return TRUE; } -int DebuggerApp::ExitInstance(){ +int DebuggerApp::ExitInstance() +{ main_frame->DestroyWindow(); return 0; } -MainFrame *DebuggerApp::mainFrame(){ +MainFrame* DebuggerApp::mainFrame() +{ return debuggerApp.main_frame; } -Debugger * _cdecl debuggerGetDebugger( void *mod,void *env ){ - debuggerApp.mainFrame()->setRuntime( mod,env ); +Debugger* _cdecl debuggerGetDebugger(void* mod, void* env) +{ + debuggerApp.mainFrame()->setRuntime(mod, env); return debuggerApp.mainFrame(); } \ No newline at end of file diff --git a/debugger/debuggerapp.hpp b/debugger/debuggerapp.hpp index 626f0d6..c040cc0 100644 --- a/debugger/debuggerapp.hpp +++ b/debugger/debuggerapp.hpp @@ -4,16 +4,16 @@ #include "mainframe.hpp" -class DebuggerApp : public CWinApp{ - MainFrame *main_frame; +class DebuggerApp : public CWinApp { + MainFrame* main_frame; -public: + public: ~DebuggerApp(); virtual BOOL InitInstance(); - virtual int ExitInstance(); + virtual int ExitInstance(); - MainFrame *mainFrame(); + MainFrame* mainFrame(); }; extern DebuggerApp debuggerApp; diff --git a/debugger/debugtree.cpp b/debugger/debugtree.cpp index 5d4ce66..621bea0 100644 --- a/debugger/debugtree.cpp +++ b/debugger/debugtree.cpp @@ -1,225 +1,241 @@ -#include "stdafx.hpp" #include "debugtree.hpp" #include "prefs.hpp" +#include "stdafx.hpp" //#include "basic.hpp" -IMPLEMENT_DYNAMIC( DebugTree,CTreeCtrl ) -BEGIN_MESSAGE_MAP( DebugTree,CTreeCtrl ) - ON_WM_CREATE() +IMPLEMENT_DYNAMIC(DebugTree, CTreeCtrl) +BEGIN_MESSAGE_MAP(DebugTree, CTreeCtrl) +ON_WM_CREATE() END_MESSAGE_MAP() -DebugTree::DebugTree():st_nest(0){ -} +DebugTree::DebugTree() : st_nest(0) {} -DebugTree::~DebugTree(){ -} +DebugTree::~DebugTree() {} -int DebugTree::OnCreate( LPCREATESTRUCT lpCreateStruct ){ - CTreeCtrl::OnCreate( lpCreateStruct ); +int DebugTree::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + CTreeCtrl::OnCreate(lpCreateStruct); - SetBkColor( prefs.rgb_bkgrnd ); - SetTextColor( prefs.rgb_default ); - SetFont( &prefs.debugFont ); + SetBkColor(prefs.rgb_bkgrnd); + SetTextColor(prefs.rgb_default); + SetFont(&prefs.debugFont); return 0; } -static string typeTag( Type *t ){ - if( t->intType() ) return ""; - if( t->floatType() ) return "#"; - if( t->stringType() ) return "$"; - if( StructType *s=t->structType() ) return "."+s->ident; - if( VectorType *v=t->vectorType() ){ - string s=typeTag( v->elementType )+"["; - for( int k=0;ksizes.size();++k ){ - if( k ) s+=","; - s+=itoa( v->sizes[k]-1 ); +static string typeTag(Type* t) +{ + if (t->intType()) + return ""; + if (t->floatType()) + return "#"; + if (t->stringType()) + return "$"; + if (StructType* s = t->structType()) + return "." + s->ident; + if (VectorType* v = t->vectorType()) { + string s = typeTag(v->elementType) + "["; + for (int k = 0; k < v->sizes.size(); ++k) { + if (k) + s += ","; + s += itoa(v->sizes[k] - 1); } - return s+"]"; + return s + "]"; } return ""; } -HTREEITEM DebugTree::insertVar( void *var,Decl *d,const string &name,HTREEITEM it,HTREEITEM parent ){ +HTREEITEM DebugTree::insertVar(void* var, Decl* d, const string& name, HTREEITEM it, HTREEITEM parent) +{ + string s = name; - string s=name; + ConstType* ct = d->type->constType(); + StructType* st = d->type->structType(); + VectorType* vt = d->type->vectorType(); - ConstType *ct=d->type->constType(); - StructType *st=d->type->structType(); - VectorType *vt=d->type->vectorType(); - - if( ct ){ - Type *t=ct->valueType; - s+=typeTag(t); - if( t->intType() ){ - s+="="+itoa( ct->intValue ); - }else if( t->floatType() ){ - s+="="+ftoa( ct->floatValue ); - }else if( t->stringType() ){ - s+="=\""+ct->stringValue+'\"'; + if (ct) { + Type* t = ct->valueType; + s += typeTag(t); + if (t->intType()) { + s += "=" + itoa(ct->intValue); + } else if (t->floatType()) { + s += "=" + ftoa(ct->floatValue); + } else if (t->stringType()) { + s += "=\"" + ct->stringValue + '\"'; } - }else if( var ){ - Type *t=d->type; - s+=typeTag( t ); - if( t->intType() ){ - s+="="+itoa( *(int*)var ); - }else if( t->floatType() ){ - s+="="+ftoa( *(float*)var ); - }else if( t->stringType() ){ - BBStr *str=*(BBStr**)var; - if( str ) s+="=\""+*str+'\"'; - else s+="=\"\""; - }else if( st ){ - var=*(void**)var; - if( var ) var=*(void**)var; - if( !var ) s+=" (Null)"; + } else if (var) { + Type* t = d->type; + s += typeTag(t); + if (t->intType()) { + s += "=" + itoa(*(int*)var); + } else if (t->floatType()) { + s += "=" + ftoa(*(float*)var); + } else if (t->stringType()) { + BBStr* str = *(BBStr**)var; + if (str) + s += "=\"" + *str + '\"'; + else + s += "=\"\""; + } else if (st) { + var = *(void**)var; + if (var) + var = *(void**)var; + if (!var) + s += " (Null)"; } } - if( it ){ - if( GetItemText( it )!=s.c_str() ){ - SetItemText( it,s.c_str() ); + if (it) { + if (GetItemText(it) != s.c_str()) { + SetItemText(it, s.c_str()); } - }else{ - it=InsertItem( s.c_str(),parent ); + } else { + it = InsertItem(s.c_str(), parent); } ++st_nest; - if( st ){ - if( var ){ - if( st_nest<4 ){ - HTREEITEM st_it=GetChildItem( it ); - for( int k=0;kfields->size();++k ){ - Decl *st_d=st->fields->decls[k]; - void *st_var=(char*)var+st_d->offset; + if (st) { + if (var) { + if (st_nest < 4) { + HTREEITEM st_it = GetChildItem(it); + for (int k = 0; k < st->fields->size(); ++k) { + Decl* st_d = st->fields->decls[k]; + void* st_var = (char*)var + st_d->offset; char name[256]; - st_d->getName( name ); + st_d->getName(name); - st_it=insertVar( st_var,st_d,name,st_it,it ); + st_it = insertVar(st_var, st_d, name, st_it, it); } } - }else{ - while( HTREEITEM t=GetChildItem( it ) ){ - DeleteItem( t ); + } else { + while (HTREEITEM t = GetChildItem(it)) { + DeleteItem(t); } } } --st_nest; - return it ? GetNextSiblingItem( it ) : 0; + return it ? GetNextSiblingItem(it) : 0; } /******************************* CONSTS ***********************************/ -ConstsTree::ConstsTree(){ -} +ConstsTree::ConstsTree() {} -void ConstsTree::reset( Environ *env ){ - - HTREEITEM it=GetChildItem( TVI_ROOT ); - - for( int k=0;kdecls->size();++k ){ - - Decl *d=env->decls->decls[k]; - if( !(d->kind & (DECL_GLOBAL) ) ) continue; - if( d->type->constType() ){ +void ConstsTree::reset(Environ* env) +{ + HTREEITEM it = GetChildItem(TVI_ROOT); + for (int k = 0; k < env->decls->size(); ++k) { + Decl* d = env->decls->decls[k]; + if (!(d->kind & (DECL_GLOBAL))) + continue; + if (d->type->constType()) { char name[256]; - d->getName( name ); + d->getName(name); - it=insertVar( 0,d,name,it,TVI_ROOT ); + it = insertVar(0, d, name, it, TVI_ROOT); } } } /******************************* GLOBALS **********************************/ -GlobalsTree::GlobalsTree():module(0),envron(0){ +GlobalsTree::GlobalsTree() : module(0), envron(0) {} + +void GlobalsTree::reset(Module* mod, Environ* env) +{ + module = mod; + envron = env; } -void GlobalsTree::reset( Module *mod,Environ *env ){ - module=mod; - envron=env; -} +void GlobalsTree::refresh() +{ + if (!module || !envron) + return; -void GlobalsTree::refresh(){ - if( !module || !envron ) return; - - HTREEITEM it=GetChildItem( TVI_ROOT ); - - for( int k=0;kdecls->size();++k ){ - Decl *d=envron->decls->decls[k]; - if( !(d->kind & (DECL_GLOBAL) ) ) continue; - if( !d->type->constType() ){ + HTREEITEM it = GetChildItem(TVI_ROOT); + for (int k = 0; k < envron->decls->size(); ++k) { + Decl* d = envron->decls->decls[k]; + if (!(d->kind & (DECL_GLOBAL))) + continue; + if (!d->type->constType()) { char name[256]; - d->getName( name ); + d->getName(name); - void *var=0; - module->findSymbol( ("_v"+string(name)).c_str(),(int*)&var ); - it=insertVar( var,d,name,it,TVI_ROOT ); + void* var = 0; + module->findSymbol(("_v" + string(name)).c_str(), (int*)&var); + it = insertVar(var, d, name, it, TVI_ROOT); } } } /******************************** LOCALS **********************************/ -LocalsTree::LocalsTree():envron(0){ +LocalsTree::LocalsTree() : envron(0) {} + +void LocalsTree::reset(Environ* env) +{ + envron = env; } -void LocalsTree::reset( Environ *env ){ - envron=env; +void LocalsTree::refresh() +{ + if (!envron || !frames.size()) + return; + + HTREEITEM item = GetChildItem(TVI_ROOT); + + int n = 0; + for (n = 0; n < frames.size(); ++n) { + if (!item || item != frames[n].item) + break; + item = GetNextSiblingItem(item); + } + + while (item) { + HTREEITEM next = GetNextSiblingItem(item); + DeleteItem(item); + item = next; + } + + for (; n < frames.size(); ++n) { + item = frames[n].item = InsertItem(frames[n].func, TVI_ROOT, TVI_LAST); + if (n < frames.size() - 1) + refreshFrame(frames[n]); + } + + refreshFrame(frames.back()); } -void LocalsTree::refresh(){ - if( !envron || !frames.size() ) return; +void LocalsTree::refreshFrame(const Frame& f) +{ + HTREEITEM it = GetChildItem(f.item); - HTREEITEM item=GetChildItem( TVI_ROOT ); - - int n=0; - for( n=0;ndecls->size();++n ){ - Decl *d=f.env->decls->decls[n]; - if( !(d->kind & (DECL_LOCAL|DECL_PARAM) ) ) continue; + for (int n = 0; n < f.env->decls->size(); ++n) { + Decl* d = f.env->decls->decls[n]; + if (!(d->kind & (DECL_LOCAL | DECL_PARAM))) + continue; char name[256]; - d->getName( name ); + d->getName(name); - if( !isalpha( name[0] ) ) continue; - it=insertVar( (char*)f.frame+d->offset,d,name,it,f.item ); + if (!isalpha(name[0])) + continue; + it = insertVar((char*)f.frame + d->offset, d, name, it, f.item); } } -void LocalsTree::pushFrame( void *f,void *e,const char *func ){ - frames.push_back( Frame( f,(Environ*)e,func ) ); +void LocalsTree::pushFrame(void* f, void* e, const char* func) +{ + frames.push_back(Frame(f, (Environ*)e, func)); } -void LocalsTree::popFrame(){ +void LocalsTree::popFrame() +{ frames.pop_back(); } - diff --git a/debugger/debugtree.hpp b/debugger/debugtree.hpp index 452f344..95d47f9 100644 --- a/debugger/debugtree.hpp +++ b/debugger/debugtree.hpp @@ -2,69 +2,73 @@ #ifndef DEBUGTREE_H #define DEBUGTREE_H -#include "linker.hpp" #include "environ.hpp" +#include "linker.hpp" -class DebugTree : public CTreeCtrl{ +class DebugTree : public CTreeCtrl { int st_nest; -protected: - HTREEITEM insertVar( void *var,Decl *d,const string &name,HTREEITEM it,HTREEITEM parent ); + protected: + HTREEITEM insertVar(void* var, Decl* d, const string& name, HTREEITEM it, HTREEITEM parent); -public: + public: DebugTree(); ~DebugTree(); - DECLARE_DYNAMIC( DebugTree ) + DECLARE_DYNAMIC(DebugTree) DECLARE_MESSAGE_MAP() - afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct ); + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); }; -class ConstsTree : public DebugTree{ -public: +class ConstsTree : public DebugTree { + public: ConstsTree(); - void reset( Environ *env ); + void reset(Environ* env); }; -class GlobalsTree : public DebugTree{ - Module *module; - Environ *envron; -public: +class GlobalsTree : public DebugTree { + Module* module; + Environ* envron; + + public: GlobalsTree(); - void reset( Module *mod,Environ *env ); + void reset(Module* mod, Environ* env); void refresh(); }; -class LocalsTree : public DebugTree{ - Module *module; - Environ *envron; - struct Frame{ - void *frame; - Environ *env; - const char *func; - HTREEITEM item; - Frame( void *f,Environ *e,const char *fn ):frame(f),env(e),func(fn),item(0){} +class LocalsTree : public DebugTree { + Module* module; + Environ* envron; + struct Frame { + void* frame; + Environ* env; + const char* func; + HTREEITEM item; + Frame(void* f, Environ* e, const char* fn) : frame(f), env(e), func(fn), item(0) {} }; vector frames; - void refreshFrame( const Frame &f ); + void refreshFrame(const Frame& f); -public: + public: LocalsTree(); - void reset( Environ *env ); + void reset(Environ* env); void refresh(); - void pushFrame( void *frame,void *env,const char *func ); + void pushFrame(void* frame, void* env, const char* func); void popFrame(); - int size()const{ return frames.size(); } + int size() const + { + return frames.size(); + } }; #endif diff --git a/debugger/mainframe.cpp b/debugger/mainframe.cpp index 25547b4..7540ed2 100644 --- a/debugger/mainframe.cpp +++ b/debugger/mainframe.cpp @@ -1,325 +1,338 @@ -#include "stdafx.hpp" #include "mainframe.hpp" -#include "resource.hpp" #include "debuggerapp.hpp" #include "prefs.hpp" +#include "resource.hpp" +#include "stdafx.hpp" -#define WM_IDLEUPDATECMDUI 0x0363 // wParam == bDisableIfNoHandler +#define WM_IDLEUPDATECMDUI 0x0363 // wParam == bDisableIfNoHandler -enum{ - WM_STOP=WM_USER+1,WM_RUN,WM_END -}; +enum { WM_STOP = WM_USER + 1, WM_RUN, WM_END }; -enum{ - STARTING,RUNNING,STOPPED,ENDING -}; +enum { STARTING, RUNNING, STOPPED, ENDING }; -IMPLEMENT_DYNAMIC( MainFrame,CFrameWnd ) -BEGIN_MESSAGE_MAP( MainFrame,CFrameWnd ) - ON_WM_CREATE() - ON_WM_SIZE() - ON_WM_CLOSE() - ON_WM_WINDOWPOSCHANGING() +IMPLEMENT_DYNAMIC(MainFrame, CFrameWnd) +BEGIN_MESSAGE_MAP(MainFrame, CFrameWnd) +ON_WM_CREATE() +ON_WM_SIZE() +ON_WM_CLOSE() +ON_WM_WINDOWPOSCHANGING() - ON_COMMAND( ID_STOP,cmdStop ) - ON_COMMAND( ID_RUN,cmdRun ) - ON_COMMAND( ID_STEPOVER,cmdStepOver ) - ON_COMMAND( ID_STEPINTO,cmdStepInto ) - ON_COMMAND( ID_STEPOUT,cmdStepOut ) - ON_COMMAND( ID_END,cmdEnd ) +ON_COMMAND(ID_STOP, cmdStop) +ON_COMMAND(ID_RUN, cmdRun) +ON_COMMAND(ID_STEPOVER, cmdStepOver) +ON_COMMAND(ID_STEPINTO, cmdStepInto) +ON_COMMAND(ID_STEPOUT, cmdStepOut) +ON_COMMAND(ID_END, cmdEnd) - ON_UPDATE_COMMAND_UI( ID_STOP,updateCmdUI ) - ON_UPDATE_COMMAND_UI( ID_RUN,updateCmdUI ) - ON_UPDATE_COMMAND_UI( ID_STEPOVER,updateCmdUI ) - ON_UPDATE_COMMAND_UI( ID_STEPINTO,updateCmdUI ) - ON_UPDATE_COMMAND_UI( ID_STEPOUT,updateCmdUI ) - ON_UPDATE_COMMAND_UI( ID_END,updateCmdUI ) +ON_UPDATE_COMMAND_UI(ID_STOP, updateCmdUI) +ON_UPDATE_COMMAND_UI(ID_RUN, updateCmdUI) +ON_UPDATE_COMMAND_UI(ID_STEPOVER, updateCmdUI) +ON_UPDATE_COMMAND_UI(ID_STEPINTO, updateCmdUI) +ON_UPDATE_COMMAND_UI(ID_STEPOUT, updateCmdUI) +ON_UPDATE_COMMAND_UI(ID_END, updateCmdUI) END_MESSAGE_MAP() -MainFrame::MainFrame():state(STARTING),step_level(-1),cur_pos(0),cur_file(0){ +MainFrame::MainFrame() : state(STARTING), step_level(-1), cur_pos(0), cur_file(0) {} + +MainFrame::~MainFrame() +{ + map::iterator it; + for (it = files.begin(); it != files.end(); ++it) + delete it->second; } -MainFrame::~MainFrame(){ - map::iterator it; - for( it=files.begin();it!=files.end();++it ) delete it->second; -} - -int MainFrame::OnCreate( LPCREATESTRUCT lpCreateStruct ){ - CFrameWnd::OnCreate( lpCreateStruct ); +int MainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + CFrameWnd::OnCreate(lpCreateStruct); prefs.open(); - string tb=prefs.homeDir+"/cfg/dbg_toolbar.bmp"; + string tb = prefs.homeDir + "/cfg/dbg_toolbar.bmp"; //Toolbar - HBITMAP toolbmp=(HBITMAP)LoadImage( - 0,tb.c_str(),IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_LOADMAP3DCOLORS ); + HBITMAP toolbmp = (HBITMAP)LoadImage(0, tb.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS); BITMAP bm; - GetObject( toolbmp,sizeof(bm),&bm ); + GetObject(toolbmp, sizeof(bm), &bm); - int n=0; - UINT toolbuts[]={ ID_STOP,ID_RUN,ID_STEPOVER,ID_STEPINTO,ID_STEPOUT,ID_END }; - int toolcnt=sizeof(toolbuts)/sizeof(UINT); - for( int k=0;k>16)&0xffff,col=cur_pos&0xffff; - t->highLight( row,col ); + int row = (cur_pos >> 16) & 0xffff, col = cur_pos & 0xffff; + t->highLight(row, col); globals_tree.refresh(); locals_tree.refresh(); } -void MainFrame::debugRun(){ - setState( RUNNING ); +void MainFrame::debugRun() +{ + setState(RUNNING); } -void MainFrame::debugStop(){ - step_level=locals_tree.size(); - setState( STOPPED ); +void MainFrame::debugStop() +{ + step_level = locals_tree.size(); + setState(STOPPED); showCurStmt(); } -void MainFrame::debugStmt( int pos,const char *file ){ - cur_pos=pos; - cur_file=file; +void MainFrame::debugStmt(int pos, const char* file) +{ + cur_pos = pos; + cur_file = file; - if( shouldRun() ) return; + if (shouldRun()) + return; - ::PostMessage( 0,WM_STOP,0,0 ); + ::PostMessage(0, WM_STOP, 0, 0); } -void MainFrame::debugEnter( void *frame,void *env,const char *func ){ - locals_tree.pushFrame( frame,env,func ); +void MainFrame::debugEnter(void* frame, void* env, const char* func) +{ + locals_tree.pushFrame(frame, env, func); - if( locals_tree.size()>1 ) return; + if (locals_tree.size() > 1) + return; globals_tree.refresh(); locals_tree.refresh(); - setState( RUNNING ); + setState(RUNNING); } -void MainFrame::debugLeave(){ +void MainFrame::debugLeave() +{ locals_tree.popFrame(); } -void MainFrame::debugMsg( const char *msg,bool serious ){ - if( serious ){ - ::MessageBox( 0,msg,"Runtime Error",MB_OK|MB_ICONWARNING|MB_TOPMOST|MB_SETFOREGROUND ); - }else{ - ::MessageBox( 0,msg,"Runtime Message",MB_OK|MB_ICONINFORMATION|MB_TOPMOST|MB_SETFOREGROUND ); +void MainFrame::debugMsg(const char* msg, bool serious) +{ + if (serious) { + ::MessageBox(0, msg, "Runtime Error", MB_OK | MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND); + } else { + ::MessageBox(0, msg, "Runtime Message", MB_OK | MB_ICONINFORMATION | MB_TOPMOST | MB_SETFOREGROUND); } } -void MainFrame::debugLog( const char *msg ){ - debug_log.ReplaceSel( msg ); - debug_log.ReplaceSel( "\n" ); - tabber.setCurrent( 0 ); - setState( state ); +void MainFrame::debugLog(const char* msg) +{ + debug_log.ReplaceSel(msg); + debug_log.ReplaceSel("\n"); + tabber.setCurrent(0); + setState(state); } -void MainFrame::debugSys( void *m ){ +void MainFrame::debugSys(void* m) {} + +void MainFrame::cmdStop() +{ + ::PostMessage(0, WM_STOP, 0, 0); } -void MainFrame::cmdStop(){ - ::PostMessage( 0,WM_STOP,0,0 ); +void MainFrame::cmdRun() +{ + step_level = -1; + ::PostMessage(0, WM_RUN, 0, 0); } -void MainFrame::cmdRun(){ - step_level=-1; - ::PostMessage( 0,WM_RUN,0,0 ); +void MainFrame::cmdEnd() +{ + ::PostMessage(0, WM_END, 0, 0); + setState(ENDING); } -void MainFrame::cmdEnd(){ - ::PostMessage( 0,WM_END,0,0 ); - setState( ENDING ); +void MainFrame::cmdStepOver() +{ + ::PostMessage(0, WM_RUN, 0, 0); } -void MainFrame::cmdStepOver(){ - ::PostMessage( 0,WM_RUN,0,0 ); +void MainFrame::cmdStepInto() +{ + step_level = locals_tree.size() + 1; + ::PostMessage(0, WM_RUN, 0, 0); } -void MainFrame::cmdStepInto(){ - step_level=locals_tree.size()+1; - ::PostMessage( 0,WM_RUN,0,0 ); +void MainFrame::cmdStepOut() +{ + step_level = locals_tree.size() - 1; + ::PostMessage(0, WM_RUN, 0, 0); } -void MainFrame::cmdStepOut(){ - step_level=locals_tree.size()-1; - ::PostMessage( 0,WM_RUN,0,0 ); -} +SourceFile* MainFrame::sourceFile(const char* file) +{ + if (!file) + file = ""; -SourceFile *MainFrame::sourceFile(const char *file){ + map::const_iterator it = files.find(file); - if( !file ) file=""; - - map::const_iterator it=files.find( file ); - - if( it!=files.end() ){ - tabber.setCurrent( file_tabs[file] ); + if (it != files.end()) { + tabber.setCurrent(file_tabs[file]); return it->second; } //crete new source file - SourceFile *t=new SourceFile(); + SourceFile* t = new SourceFile(); - it=files.insert( make_pair(file,t) ).first; + it = files.insert(make_pair(file, t)).first; - int tab=files.size(); + int tab = files.size(); - t->Create( - WS_CHILD|WS_HSCROLL|WS_VSCROLL| - ES_NOHIDESEL|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL, - CRect( 0,0,0,0 ),&tabber,1 ); + t->Create(WS_CHILD | WS_HSCROLL | WS_VSCROLL | ES_NOHIDESEL | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, + CRect(0, 0, 0, 0), &tabber, 1); - if( FILE *f=fopen( file,"rb" ) ){ - fseek( f,0,SEEK_END ); - int sz=ftell( f ); - fseek( f,0,SEEK_SET ); - char *buf=new char[sz+1]; - fread( buf,sz,1,f ); - buf[sz]=0; - t->ReplaceSel( buf ); + if (FILE* f = fopen(file, "rb")) { + fseek(f, 0, SEEK_END); + int sz = ftell(f); + fseek(f, 0, SEEK_SET); + char* buf = new char[sz + 1]; + fread(buf, sz, 1, f); + buf[sz] = 0; + t->ReplaceSel(buf); delete[] buf; fclose(f); } - file_tabs.insert( make_pair(file,tab) ); + file_tabs.insert(make_pair(file, tab)); - if(const char *p=strrchr(file,'/') ) file=p+1; - if(const char *p=strrchr(file,'\\') ) file=p+1; - tabber.insert( tab,t,file ); + if (const char* p = strrchr(file, '/')) + file = p + 1; + if (const char* p = strrchr(file, '\\')) + file = p + 1; + tabber.insert(tab, t, file); - tabber.setCurrent( tab ); + tabber.setCurrent(tab); return t; } -void MainFrame::updateCmdUI( CCmdUI *ui ){ - if( state!=RUNNING && state!=STOPPED ){ - ui->Enable( false ); +void MainFrame::updateCmdUI(CCmdUI* ui) +{ + if (state != RUNNING && state != STOPPED) { + ui->Enable(false); return; } - switch( ui->m_nID ){ + switch (ui->m_nID) { case ID_STOP: - ui->Enable( shouldRun() ); + ui->Enable(shouldRun()); break; case ID_RUN: case ID_STEPOVER: case ID_STEPINTO: case ID_STEPOUT: - ui->Enable( !shouldRun() ); + ui->Enable(!shouldRun()); break; case ID_END: - ui->Enable( true ); + ui->Enable(true); break; } } -void MainFrame::OnWindowPosChanging( WINDOWPOS *pos ){ +void MainFrame::OnWindowPosChanging(WINDOWPOS* pos) +{ RECT rect; - SystemParametersInfo( SPI_GETWORKAREA,0,&rect,0 ); + SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); - pos->x=rect.left; - pos->cx=rect.right-pos->x; - pos->cy=rect.bottom-pos->y; + pos->x = rect.left; + pos->cx = rect.right - pos->x; + pos->cy = rect.bottom - pos->y; } diff --git a/debugger/mainframe.hpp b/debugger/mainframe.hpp index bd642d7..85453af 100644 --- a/debugger/mainframe.hpp +++ b/debugger/mainframe.hpp @@ -2,51 +2,53 @@ #ifndef MAINFRAME_H #define MAINFRAME_H -#include "tabber.hpp" #include "debugger.hpp" -#include "sourcefile.hpp" #include "debugtree.hpp" +#include "sourcefile.hpp" +#include "tabber.hpp" -class MainFrame : public CFrameWnd,public Debugger{ +class MainFrame : public CFrameWnd, public Debugger { + Tabber tabber; + Tabber tabber2; + CToolBar toolBar; + SourceFile debug_log; + ConstsTree consts_tree; + GlobalsTree globals_tree; + LocalsTree locals_tree; + map file_tabs; + map files; - Tabber tabber; - Tabber tabber2; - CToolBar toolBar; - SourceFile debug_log; - ConstsTree consts_tree; - GlobalsTree globals_tree; - LocalsTree locals_tree; - map file_tabs; - map files; + int state, step_level, cur_pos; + const char* cur_file; - int state,step_level,cur_pos; - const char *cur_file; + bool shouldRun() const + { + return step_level < locals_tree.size(); + } - bool shouldRun()const{ return step_level +#include "debuggerapp.hpp" +#include "stdafx.hpp" -#define SWAPRB(x) ( (((x)>>16)&0xff) | ((x)&0xff00) | (((x)&0xff)<<16) ) +#define SWAPRB(x) ((((x) >> 16) & 0xff) | ((x)&0xff00) | (((x)&0xff) << 16)) Prefs prefs; -void Prefs::open(){ +void Prefs::open() +{ + homeDir = getenv("blitzpath"); - homeDir=getenv( "blitzpath" ); - - AddFontResource( (homeDir+"/cfg/blitz.fon").c_str() ); + AddFontResource((homeDir + "/cfg/blitz.fon").c_str()); setDefault(); bool prg_windowed; - ifstream in( (homeDir+"/cfg/blitzide.prefs").c_str() ); - if( !in.good() ) return; + ifstream in((homeDir + "/cfg/blitzide.prefs").c_str()); + if (!in.good()) + return; - while( !in.eof() ){ - string t;in>>t; - if( !t.size() ) continue; - while( in.peek()=='\t' ) in.ignore(); - if( t=="prg_debug" ) in>>prg_debug; - else if( t=="prg_lastbuild" ) getline( in,prg_lastbuild ); - else if( t=="prg_windowed" ) in>>prg_windowed; - else if( t=="win_maximized" ) in>>win_maximized; - else if( t=="win_notoolbar" ) in>>win_notoolbar; - else if( t=="win_rect" ){ - in>>win_rect.left;in>>win_rect.top; - in>>win_rect.right;in>>win_rect.bottom; - }else if( t.substr( 0,5 )=="font_" ){ - string s;int h;in>>s;in>>h; - t=t.substr( 5 ); - if( t=="editor" ){ - font_editor=s;font_editor_height=h; - }else if( t=="tabs" ){ - font_tabs=s;font_tabs_height=h; - }else if( t=="debug" ){ - font_debug=s;font_debug_height=h; + while (!in.eof()) { + string t; + in >> t; + if (!t.size()) + continue; + while (in.peek() == '\t') + in.ignore(); + if (t == "prg_debug") + in >> prg_debug; + else if (t == "prg_lastbuild") + getline(in, prg_lastbuild); + else if (t == "prg_windowed") + in >> prg_windowed; + else if (t == "win_maximized") + in >> win_maximized; + else if (t == "win_notoolbar") + in >> win_notoolbar; + else if (t == "win_rect") { + in >> win_rect.left; + in >> win_rect.top; + in >> win_rect.right; + in >> win_rect.bottom; + } else if (t.substr(0, 5) == "font_") { + string s; + int h; + in >> s; + in >> h; + t = t.substr(5); + if (t == "editor") { + font_editor = s; + font_editor_height = h; + } else if (t == "tabs") { + font_tabs = s; + font_tabs_height = h; + } else if (t == "debug") { + font_debug = s; + font_debug_height = h; } - }else if( t.substr( 0,4 )=="rgb_" ){ - t=t.substr(4); - string s;in>>s;int rgb=0; - for( int k=0;k> s; + int rgb = 0; + for (int k = 0; k < s.size(); ++k) { + int n = s[k]; + rgb = (rgb << 4) | (n <= '9' ? n - '0' : (n & 31) + 9); } - rgb=SWAPRB(rgb); + rgb = SWAPRB(rgb); - if( t=="bkgrnd" ) rgb_bkgrnd=rgb; - else if( t=="string" ) rgb_string=rgb; - else if( t=="ident" ) rgb_ident=rgb; - else if( t=="keyword" ) rgb_keyword=rgb; - else if( t=="comment" ) rgb_comment=rgb; - else if( t=="digit" ) rgb_digit=rgb; - else if( t=="default" ) rgb_default=rgb; - }else if( t=="edit_tabs" ){ - in>>edit_tabs; - }else if( t=="edit_blkcursor" ){ - in>>edit_blkcursor; - }else if( t=="edit_backup" ){ - in>>edit_backup; - }else if( t=="img_toolbar" ){ - getline( in,img_toolbar ); - }else if( t=="cmd_line" ){ - getline( in,cmd_line ); - }else if( t=="file_recent" ){ - string l;getline( in,l ); - if( recentFiles.size()<10 ) recentFiles.push_back( l ); - }else{ - string s="Unrecognized option '"+t+"' in blitzide.prefs"; - MessageBox( 0,s.c_str(),"Error in preferences",MB_OK ); + if (t == "bkgrnd") + rgb_bkgrnd = rgb; + else if (t == "string") + rgb_string = rgb; + else if (t == "ident") + rgb_ident = rgb; + else if (t == "keyword") + rgb_keyword = rgb; + else if (t == "comment") + rgb_comment = rgb; + else if (t == "digit") + rgb_digit = rgb; + else if (t == "default") + rgb_default = rgb; + } else if (t == "edit_tabs") { + in >> edit_tabs; + } else if (t == "edit_blkcursor") { + in >> edit_blkcursor; + } else if (t == "edit_backup") { + in >> edit_backup; + } else if (t == "img_toolbar") { + getline(in, img_toolbar); + } else if (t == "cmd_line") { + getline(in, cmd_line); + } else if (t == "file_recent") { + string l; + getline(in, l); + if (recentFiles.size() < 10) + recentFiles.push_back(l); + } else { + string s = "Unrecognized option '" + t + "' in blitzide.prefs"; + MessageBox(0, s.c_str(), "Error in preferences", MB_OK); setDefault(); return; } @@ -80,95 +109,98 @@ void Prefs::open(){ createFonts(); } -void Prefs::close(){ +void Prefs::close() +{ + ofstream out((homeDir + "cfg\\blitzide.prefs").c_str()); + if (!out.good()) + return; - ofstream out( (homeDir+"cfg\\blitzide.prefs").c_str() ); - if( !out.good() ) return; - - out<<"prg_debug\t"< recentFiles; @@ -40,8 +40,7 @@ public: void open(); void close(); -private: - + private: void setDefault(); void createFonts(); }; diff --git a/debugger/resource.hpp b/debugger/resource.hpp index c1b18b5..90c6e0b 100644 --- a/debugger/resource.hpp +++ b/debugger/resource.hpp @@ -2,22 +2,22 @@ // Microsoft Developer Studio generated include file. // Used by debugger.rc // -#define IDB_BITMAP1 101 -#define ID_STOP 1001 -#define ID_RUN 1002 -#define ID_STEPOVER 1003 -#define ID_STEPINTO 1004 -#define ID_STEPOUT 1005 -#define ID_END 1006 -#define ID_TRACE 1007 +#define IDB_BITMAP1 101 +#define ID_STOP 1001 +#define ID_RUN 1002 +#define ID_STEPOVER 1003 +#define ID_STEPINTO 1004 +#define ID_STEPOUT 1005 +#define ID_END 1006 +#define ID_TRACE 1007 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 103 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 108 +#define _APS_NEXT_RESOURCE_VALUE 103 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 108 #endif #endif diff --git a/debugger/sourcefile.cpp b/debugger/sourcefile.cpp index e7a61c3..7b81f6c 100644 --- a/debugger/sourcefile.cpp +++ b/debugger/sourcefile.cpp @@ -1,51 +1,53 @@ -#include "stdafx.hpp" #include "sourcefile.hpp" #include "prefs.hpp" +#include "stdafx.hpp" -IMPLEMENT_DYNAMIC( SourceFile,CRichEditCtrl ) -BEGIN_MESSAGE_MAP( SourceFile,CRichEditCtrl ) - ON_WM_CREATE() +IMPLEMENT_DYNAMIC(SourceFile, CRichEditCtrl) +BEGIN_MESSAGE_MAP(SourceFile, CRichEditCtrl) +ON_WM_CREATE() END_MESSAGE_MAP() -SourceFile::SourceFile(){ -} +SourceFile::SourceFile() {} -SourceFile::~SourceFile(){ -} +SourceFile::~SourceFile() {} -int SourceFile::OnCreate( LPCREATESTRUCT lpCreateStruct ){ - CRichEditCtrl::OnCreate( lpCreateStruct ); +int SourceFile::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + CRichEditCtrl::OnCreate(lpCreateStruct); - SetReadOnly( true ); - SetFont( &prefs.editFont ); - SetBackgroundColor( false,prefs.rgb_bkgrnd ); + SetReadOnly(true); + SetFont(&prefs.editFont); + SetBackgroundColor(false, prefs.rgb_bkgrnd); - CHARFORMAT fmt={sizeof( fmt )}; - fmt.dwMask=CFM_COLOR; - fmt.crTextColor=prefs.rgb_default; + CHARFORMAT fmt = {sizeof(fmt)}; + fmt.dwMask = CFM_COLOR; + fmt.crTextColor = prefs.rgb_default; - SetSel( 0,-1 ); - SetDefaultCharFormat( fmt ); - SetSelectionCharFormat( fmt ); - SetSel( 0,0 ); + SetSel(0, -1); + SetDefaultCharFormat(fmt); + SetSelectionCharFormat(fmt); + SetSel(0, 0); return 0; } -void SourceFile::highLight( int row,int col ){ - int pos=LineIndex( row )+col; - HideSelection( true,false ); - bool quote=false; - int end=pos,len=GetTextLength(); - while( end // Core -#include // Common Controls -#include // CRich edit +#include // Common Controls +#include // CRich edit +#include // Core -#include #include -#include +#include #include +#include using namespace std; //some stuff that should be in std libs -int atoi( const string &s ); -double atof( const string &s ); -string itoa( int n ); -string ftoa( float n ); -string tolower( const string &s ); -string toupper( const string &s ); -string fullfilename( const string &t ); -string filenamepath( const string &t ); -string filenamefile( const string &t ); +int atoi(const string& s); +double atof(const string& s); +string itoa(int n); +string ftoa(float n); +string tolower(const string& s); +string toupper(const string& s); +string fullfilename(const string& t); +string filenamepath(const string& t); +string filenamefile(const string& t); #endif \ No newline at end of file diff --git a/debugger/stdutil.cpp b/debugger/stdutil.cpp index d394747..95a2b53 100644 --- a/debugger/stdutil.cpp +++ b/debugger/stdutil.cpp @@ -1,24 +1,28 @@ #include "stdafx.hpp" -int atoi( const string &s ){ - return atoi( s.c_str() ); +int atoi(const string& s) +{ + return atoi(s.c_str()); } -double atof( const string &s ){ - return atof( s.c_str() ); +double atof(const string& s) +{ + return atof(s.c_str()); } -string itoa( int n ){ - char buff[32]; _itoa( n,buff,10 ); - return string( buff ); +string itoa(int n) +{ + char buff[32]; + _itoa(n, buff, 10); + return string(buff); } //static int _finite( double n ){ // definition: exponent anything but 2047. // // int e; // 11 bit exponent -// const int eMax = 2047; // 0x7ff, all bits = 1 -// +// const int eMax = 2047; // 0x7ff, all bits = 1 +// // int *pn = (int *) &n; // // e = *++pn; // Intel order! @@ -30,8 +34,8 @@ string itoa( int n ){ //static int _isnan( double n ){ // definition: exponent 2047, nonzero fraction. // // int e; // 11 bit exponent -// const int eMax = 2047; // 0x7ff, all bits = 1 -// +// const int eMax = 2047; // 0x7ff, all bits = 1 +// // int *pn = (int *) &n; // // e = *++pn; // Intel order! @@ -50,64 +54,60 @@ string itoa( int n ){ ///////////// //By FLOYD!// ///////////// -string ftoa( float n ){ +string ftoa(float n) +{ + static const int digits = 6; - static const int digits=6; + int eNeg = -4, ePos = 8; // limits for e notation. - int eNeg = -4, ePos = 8; // limits for e notation. - - char buffer[50]; // from MSDN example, 25 would probably suffice + char buffer[50]; // from MSDN example, 25 would probably suffice string t; - int dec, sign; + int dec, sign; - if ( _finite( n ) ){ + if (_finite(n)) { + // if ( digits < 1 ) digits = 1; // less than one digit is nonsense + // if ( digits > 8 ) digits = 8; // practical maximum for float -// if ( digits < 1 ) digits = 1; // less than one digit is nonsense -// if ( digits > 8 ) digits = 8; // practical maximum for float - - t = _ecvt( n, digits, &dec, &sign ); + t = _ecvt(n, digits, &dec, &sign); - if ( dec <= eNeg + 1 || dec > ePos ){ - - _gcvt( n, digits, buffer ); + if (dec <= eNeg + 1 || dec > ePos) { + _gcvt(n, digits, buffer); t = buffer; return t; } - + // Here is the tricky case. We want a nicely formatted // number with no e-notation or multiple trailing zeroes. - - if ( dec <= 0 ){ - t = "0." + string( -dec, '0' ) + t; - dec = 1; // new location for decimal point + if (dec <= 0) { + t = "0." + string(-dec, '0') + t; + dec = 1; // new location for decimal point - } - else if( dec < digits ){ + } else if (dec < digits) { + t = t.substr(0, dec) + "." + t.substr(dec); - t = t.substr( 0, dec ) + "." + t.substr( dec ); - - } - else{ - - t = t + string( dec - digits, '0' ) + ".0"; + } else { + t = t + string(dec - digits, '0') + ".0"; dec += dec - digits; - } - + // Finally, trim off excess zeroes. - int dp1 = dec + 1, p = t.length(); - while( --p > dp1 && t[p] == '0' ); - t = string( t, 0, ++p ); + int dp1 = dec + 1, p = t.length(); + while (--p > dp1 && t[p] == '0') + ; + t = string(t, 0, ++p); return sign ? "-" + t : t; - } // end of finite case + } // end of finite case - if ( _isnan( n ) ) return "NaN"; - if ( n > 0.0 ) return "Infinity"; - if ( n < 0.0 ) return "-Infinity"; + if (_isnan(n)) + return "NaN"; + if (n > 0.0) + return "Infinity"; + if (n < 0.0) + return "-Infinity"; abort(); } @@ -149,34 +149,44 @@ string ftoa( float n ){ } */ -string tolower( const string &s ){ - string t=s; - for( int k=0;k +#include "stdafx.hpp" -IMPLEMENT_DYNAMIC( Tabber,CTabCtrl ) -BEGIN_MESSAGE_MAP( Tabber,CTabCtrl ) - ON_WM_SIZE() - ON_WM_ERASEBKGND() - ON_NOTIFY_REFLECT( TCN_SELCHANGE,tcn_selChange ) +IMPLEMENT_DYNAMIC(Tabber, CTabCtrl) +BEGIN_MESSAGE_MAP(Tabber, CTabCtrl) +ON_WM_SIZE() +ON_WM_ERASEBKGND() +ON_NOTIFY_REFLECT(TCN_SELCHANGE, tcn_selChange) END_MESSAGE_MAP() -static CRect tabsRect( CTabCtrl &t ){ - CRect r(0,0,0,0); - int n=t.GetItemCount(); - for( int k=0;kr.right ) r.right=c.right; - if( c.topr.bottom ) r.bottom=c.bottom; + t.GetItemRect(k, &c); + if (c.left < r.left) + r.left = c.left; + if (c.right > r.right) + r.right = c.right; + if (c.top < r.top) + r.top = c.top; + if (c.bottom > r.bottom) + r.bottom = c.bottom; } return r; } -CRect Tabber::getInnerRect(){ +CRect Tabber::getInnerRect() +{ CRect r; - GetClientRect( &r ); - int x=2,y=2,w=r.Width()-4,h=r.Height()-4; + GetClientRect(&r); + int x = 2, y = 2, w = r.Width() - 4, h = r.Height() - 4; - r=tabsRect( *this ); - h-=r.Height();y+=r.Height(); + r = tabsRect(*this); + h -= r.Height(); + y += r.Height(); - r.left=x;r.top=y;r.right=x+w;r.bottom=y+h; + r.left = x; + r.top = y; + r.right = x + w; + r.bottom = y + h; return r; } -Tabber::Tabber(): -listener(0),curr(-1){ +Tabber::Tabber() : listener(0), curr(-1) {} + +Tabber::~Tabber() +{ + for (; tabs.size(); tabs.pop_back()) + delete tabs.back(); } -Tabber::~Tabber(){ - for( ;tabs.size();tabs.pop_back() ) delete tabs.back(); -} - -void Tabber::OnSize( UINT type,int w,int h ){ - CTabCtrl::OnSize( type,w,h ); +void Tabber::OnSize(UINT type, int w, int h) +{ + CTabCtrl::OnSize(type, w, h); refresh(); } -BOOL Tabber::OnEraseBkgnd( CDC *dc ){ - CRect c;GetClientRect( &c ); +BOOL Tabber::OnEraseBkgnd(CDC* dc) +{ + CRect c; + GetClientRect(&c); - HBRUSH hb=(HBRUSH)GetClassLong( m_hWnd,GCL_HBRBACKGROUND ); - CBrush br;br.Attach( hb ); + HBRUSH hb = (HBRUSH)GetClassLong(m_hWnd, GCL_HBRBACKGROUND); + CBrush br; + br.Attach(hb); - if( curr<0 ) dc->FillRect( &c,&br ); - else{ - CRect i=getInnerRect(); - CRect t( c.left,c.top,i.right,i.top );dc->FillRect( &t,&br ); - CRect r( i.right,c.top,c.right,i.bottom );dc->FillRect( &r,&br ); - CRect b( i.left,i.bottom,c.right,c.bottom );dc->FillRect( &b,&br ); - CRect l( c.left,i.top,i.left,c.bottom );dc->FillRect( &l,&br ); + if (curr < 0) + dc->FillRect(&c, &br); + else { + CRect i = getInnerRect(); + CRect t(c.left, c.top, i.right, i.top); + dc->FillRect(&t, &br); + CRect r(i.right, c.top, c.right, i.bottom); + dc->FillRect(&r, &br); + CRect b(i.left, i.bottom, c.right, c.bottom); + dc->FillRect(&b, &br); + CRect l(c.left, i.top, i.left, c.bottom); + dc->FillRect(&l, &br); } return true; } -void Tabber::setListener( TabberListener *l ){ - listener=l; +void Tabber::setListener(TabberListener* l) +{ + listener = l; } -void Tabber::refresh(){ - if( curr<0 ) return; +void Tabber::refresh() +{ + if (curr < 0) + return; - CRect r=getInnerRect(); - CWnd *wnd=getTabWnd( curr ); - wnd->MoveWindow( r.left,r.top,r.Width(),r.Height() ); - wnd->ShowWindow( SW_SHOWNA ); + CRect r = getInnerRect(); + CWnd* wnd = getTabWnd(curr); + wnd->MoveWindow(r.left, r.top, r.Width(), r.Height()); + wnd->ShowWindow(SW_SHOWNA); } -Tabber::Tab *Tabber::getTab( int index )const{ - if( index<0 || index>=tabs.size() ) return 0; - Tabs::const_iterator it=tabs.begin(); - while( index-- ) ++it; +Tabber::Tab* Tabber::getTab(int index) const +{ + if (index < 0 || index >= tabs.size()) + return 0; + Tabs::const_iterator it = tabs.begin(); + while (index--) + ++it; return *it; } -void Tabber::tcn_selChange( NMHDR *p,LRESULT *result ){ - setCurrent( GetCurSel() ); +void Tabber::tcn_selChange(NMHDR* p, LRESULT* result) +{ + setCurrent(GetCurSel()); } -void Tabber::insert( int index,CWnd *w,const string &t ){ - if( index<0 || index>tabs.size() ) return; +void Tabber::insert(int index, CWnd* w, const string& t) +{ + if (index < 0 || index > tabs.size()) + return; - Tabs::iterator it=tabs.begin(); - for( int k=0;k=tabs.size() ) return; +void Tabber::remove(int index) +{ + if (index < 0 || index >= tabs.size()) + return; - CWnd *w=getTabWnd( index ); + CWnd* w = getTabWnd(index); - Tabs::iterator it=tabs.begin(); - for( int k=0;k=tabs.size() ) curr=tabs.size()-1; + if (curr >= tabs.size()) + curr = tabs.size() - 1; refresh(); - if( curr>=0 ) SetCurSel( curr ); - if( w ) w->ShowWindow( SW_HIDE ); - if( listener ) listener->currentSet( this,curr ); + if (curr >= 0) + SetCurSel(curr); + if (w) + w->ShowWindow(SW_HIDE); + if (listener) + listener->currentSet(this, curr); } -void Tabber::setCurrent( int index ){ - if( index<0 || index>=tabs.size() ) return; +void Tabber::setCurrent(int index) +{ + if (index < 0 || index >= tabs.size()) + return; - if( index!=curr ){ - CWnd *w=getTabWnd( curr ); - curr=index; + if (index != curr) { + CWnd* w = getTabWnd(curr); + curr = index; refresh(); - SetCurSel( curr ); - if( w ) w->ShowWindow( SW_HIDE ); + SetCurSel(curr); + if (w) + w->ShowWindow(SW_HIDE); } - if( listener ) listener->currentSet( this,curr ); + if (listener) + listener->currentSet(this, curr); } -void Tabber::setTabText( int index,const string &t ){ - if( index<0 || index>=tabs.size() ) return; +void Tabber::setTabText(int index, const string& t) +{ + if (index < 0 || index >= tabs.size()) + return; - string s=t+'\0'; - TCITEM tc={ TCIF_TEXT }; - tc.pszText=(char*)s.data(); - SetItem( index,&tc ); + string s = t + '\0'; + TCITEM tc = {TCIF_TEXT}; + tc.pszText = (char*)s.data(); + SetItem(index, &tc); } -int Tabber::size()const{ +int Tabber::size() const +{ return tabs.size(); } -int Tabber::getCurrent()const{ +int Tabber::getCurrent() const +{ return curr; } -CWnd *Tabber::getTabWnd( int index )const{ - Tab *t=getTab( index ); +CWnd* Tabber::getTabWnd(int index) const +{ + Tab* t = getTab(index); return t ? t->wnd : 0; } -string Tabber::getTabText( int index )const{ - Tab *t=getTab( index ); +string Tabber::getTabText(int index) const +{ + Tab* t = getTab(index); return t ? t->text : ""; } \ No newline at end of file diff --git a/debugger/tabber.hpp b/debugger/tabber.hpp index af06592..15ee36e 100644 --- a/debugger/tabber.hpp +++ b/debugger/tabber.hpp @@ -4,53 +4,52 @@ class Tabber; -class TabberListener{ -public: - virtual void currentSet( Tabber *tabber,int index )=0; +class TabberListener { + public: + virtual void currentSet(Tabber* tabber, int index) = 0; }; -class Tabber : public CTabCtrl{ -public: +class Tabber : public CTabCtrl { + public: Tabber(); ~Tabber(); - void setListener( TabberListener *l ); + void setListener(TabberListener* l); - void insert( int index,CWnd *wnd,const string &text ); - void remove( int index ); - void setCurrent( int index ); - void setTabText( int index,const string &t ); + void insert(int index, CWnd* wnd, const string& text); + void remove(int index); + void setCurrent(int index); + void setTabText(int index, const string& t); - int size()const; - int getCurrent()const; - CWnd *getTabWnd( int index )const; - string getTabText( int index )const; + int size() const; + int getCurrent() const; + CWnd* getTabWnd(int index) const; + string getTabText(int index) const; - DECLARE_DYNAMIC( Tabber ) + DECLARE_DYNAMIC(Tabber) DECLARE_MESSAGE_MAP() - afx_msg void OnSize( UINT type,int w,int h ); - afx_msg BOOL OnEraseBkgnd( CDC *dc ); - afx_msg void tcn_selChange( NMHDR *p,LRESULT *result ); + afx_msg void OnSize(UINT type, int w, int h); + afx_msg BOOL OnEraseBkgnd(CDC* dc); + afx_msg void tcn_selChange(NMHDR* p, LRESULT* result); -private: - TabberListener *listener; + private: + TabberListener* listener; - struct Tab{ - CWnd *wnd; + struct Tab { + CWnd* wnd; string text; - Tab( CWnd *w,const string &t ):wnd(w),text(t){ - } + Tab(CWnd* w, const string& t) : wnd(w), text(t) {} }; typedef list Tabs; Tabs tabs; - int curr; + int curr; - void refresh(); + void refresh(); CRect getInnerRect(); - Tab *getTab( int index )const; + Tab* getTab(int index) const; }; #endif