debugger: Formatting;

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2019-01-18 17:04:34 +01:00
parent 2196cb8419
commit f713369a01
16 changed files with 949 additions and 824 deletions
+13 -13
View File
@@ -1,17 +1,16 @@
#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();
@@ -26,25 +25,26 @@ BOOL DebuggerApp::InitInstance(){
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->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 ){
Debugger* _cdecl debuggerGetDebugger(void* mod, void* env)
{
debuggerApp.mainFrame()->setRuntime(mod, env);
return debuggerApp.mainFrame();
}
+62 -46
View File
@@ -1,7 +1,7 @@
#include "stdafx.hpp"
#include "debugtree.hpp"
#include "prefs.hpp"
#include "stdafx.hpp"
//#include "basic.hpp"
@@ -10,13 +10,12 @@ 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 ){
int DebugTree::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CTreeCtrl::OnCreate(lpCreateStruct);
SetBkColor(prefs.rgb_bkgrnd);
@@ -26,15 +25,21 @@ int DebugTree::OnCreate( LPCREATESTRUCT lpCreateStruct ){
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;
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+=",";
if (k)
s += ",";
s += itoa(v->sizes[k] - 1);
}
return s + "]";
@@ -42,8 +47,8 @@ static string typeTag( Type *t ){
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;
ConstType* ct = d->type->constType();
@@ -69,12 +74,16 @@ HTREEITEM DebugTree::insertVar( void *var,Decl *d,const string &name,HTREEITEM i
s += "=" + ftoa(*(float*)var);
} else if (t->stringType()) {
BBStr* str = *(BBStr**)var;
if( str ) s+="=\""+*str+'\"';
else s+="=\"\"";
if (str)
s += "=\"" + *str + '\"';
else
s += "=\"\"";
} else if (st) {
var = *(void**)var;
if( var ) var=*(void**)var;
if( !var ) s+=" (Null)";
if (var)
var = *(void**)var;
if (!var)
s += " (Null)";
}
}
@@ -114,19 +123,17 @@ HTREEITEM DebugTree::insertVar( void *var,Decl *d,const string &name,HTREEITEM i
/******************************* CONSTS ***********************************/
ConstsTree::ConstsTree(){
}
void ConstsTree::reset( Environ *env ){
ConstsTree::ConstsTree() {}
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->kind & (DECL_GLOBAL)))
continue;
if (d->type->constType()) {
char name[256];
d->getName(name);
@@ -137,24 +144,26 @@ void ConstsTree::reset( Environ *env ){
/******************************* GLOBALS **********************************/
GlobalsTree::GlobalsTree():module(0),envron(0){
}
GlobalsTree::GlobalsTree() : module(0), envron(0) {}
void GlobalsTree::reset( Module *mod,Environ *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; k < envron->decls->size(); ++k) {
Decl* d = envron->decls->decls[k];
if( !(d->kind & (DECL_GLOBAL) ) ) continue;
if (!(d->kind & (DECL_GLOBAL)))
continue;
if (!d->type->constType()) {
char name[256];
d->getName(name);
@@ -167,21 +176,24 @@ void GlobalsTree::refresh(){
/******************************** LOCALS **********************************/
LocalsTree::LocalsTree():envron(0){
}
LocalsTree::LocalsTree() : envron(0) {}
void LocalsTree::reset( Environ *env ){
void LocalsTree::reset(Environ* env)
{
envron = env;
}
void LocalsTree::refresh(){
if( !envron || !frames.size() ) return;
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;
if (!item || item != frames[n].item)
break;
item = GetNextSiblingItem(item);
}
@@ -193,33 +205,37 @@ void LocalsTree::refresh(){
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] );
if (n < frames.size() - 1)
refreshFrame(frames[n]);
}
refreshFrame(frames.back());
}
void LocalsTree::refreshFrame( const Frame &f ){
void LocalsTree::refreshFrame(const Frame& f)
{
HTREEITEM it = GetChildItem(f.item);
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;
if (!(d->kind & (DECL_LOCAL | DECL_PARAM)))
continue;
char name[256];
d->getName(name);
if( !isalpha( name[0] ) ) continue;
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 ){
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();
}
+7 -3
View File
@@ -2,13 +2,13 @@
#ifndef DEBUGTREE_H
#define DEBUGTREE_H
#include "linker.hpp"
#include "environ.hpp"
#include "linker.hpp"
class DebugTree : public CTreeCtrl {
int st_nest;
protected:
protected:
HTREEITEM insertVar(void* var, Decl* d, const string& name, HTREEITEM it, HTREEITEM parent);
public:
@@ -31,6 +31,7 @@ public:
class GlobalsTree : public DebugTree {
Module* module;
Environ* envron;
public:
GlobalsTree();
@@ -64,7 +65,10 @@ public:
void popFrame();
int size()const{ return frames.size(); }
int size() const
{
return frames.size();
}
};
#endif
+89 -76
View File
@@ -1,19 +1,15 @@
#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
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)
@@ -38,15 +34,17 @@ BEGIN_MESSAGE_MAP( MainFrame,CFrameWnd )
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(){
MainFrame::~MainFrame()
{
map<const char*, SourceFile*>::iterator it;
for( it=files.begin();it!=files.end();++it ) delete it->second;
for (it = files.begin(); it != files.end(); ++it)
delete it->second;
}
int MainFrame::OnCreate( LPCREATESTRUCT lpCreateStruct ){
int MainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CFrameWnd::OnCreate(lpCreateStruct);
prefs.open();
@@ -54,8 +52,7 @@ int MainFrame::OnCreate( LPCREATESTRUCT lpCreateStruct ){
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);
@@ -63,11 +60,15 @@ int MainFrame::OnCreate( LPCREATESTRUCT lpCreateStruct ){
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<toolcnt;++k ) if( toolbuts[k]!=ID_SEPARATOR ) ++n;
for (int k = 0; k < toolcnt; ++k)
if (toolbuts[k] != ID_SEPARATOR)
++n;
SIZE imgsz, butsz;
imgsz.cx=bm.bmWidth/n;imgsz.cy=bm.bmHeight;
butsz.cx=imgsz.cx+7;butsz.cy=imgsz.cy+6;
imgsz.cx = bm.bmWidth / n;
imgsz.cy = bm.bmHeight;
butsz.cx = imgsz.cx + 7;
butsz.cy = imgsz.cy + 6;
toolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS);
toolBar.SetBitmap(toolbmp);
@@ -75,41 +76,27 @@ int MainFrame::OnCreate( LPCREATESTRUCT lpCreateStruct ){
toolBar.SetButtons(toolbuts, toolcnt);
//Tabber
tabber.Create(
WS_VISIBLE|WS_CHILD|
TCS_HOTTRACK,
CRect( 0,0,0,0 ),this,1 );
tabber.Create(WS_VISIBLE | WS_CHILD | TCS_HOTTRACK, CRect(0, 0, 0, 0), this, 1);
tabber.SetFont(&prefs.tabsFont);
//Second tabber
tabber2.Create(
WS_VISIBLE|WS_CHILD|
TCS_HOTTRACK,
CRect( 0,0,0,0 ),this,2 );
tabber2.Create(WS_VISIBLE | WS_CHILD | TCS_HOTTRACK, CRect(0, 0, 0, 0), this, 2);
tabber2.SetFont(&prefs.tabsFont);
//Debug Log
debug_log.Create(
WS_CHILD|WS_HSCROLL|WS_VSCROLL|
ES_NOHIDESEL|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL,
debug_log.Create(WS_CHILD | WS_HSCROLL | WS_VSCROLL | ES_NOHIDESEL | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
CRect(0, 0, 0, 0), &tabber, 1);
tabber.insert(0, &debug_log, "Debug log");
//Debug trees
locals_tree.Create(
WS_VISIBLE|WS_CHILD|
TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS,
CRect( 0,0,0,0 ),&tabber2,3 );
locals_tree.Create(WS_VISIBLE | WS_CHILD | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS, CRect(0, 0, 0, 0),
&tabber2, 3);
globals_tree.Create(
WS_VISIBLE|WS_CHILD|
TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS,
CRect( 0,0,0,0 ),&tabber2,3 );
globals_tree.Create(WS_VISIBLE | WS_CHILD | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS, CRect(0, 0, 0, 0),
&tabber2, 3);
consts_tree.Create(
WS_VISIBLE|WS_CHILD|
TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS,
CRect( 0,0,0,0 ),&tabber2,3 );
consts_tree.Create(WS_VISIBLE | WS_CHILD | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS, CRect(0, 0, 0, 0),
&tabber2, 3);
tabber2.insert(0, &locals_tree, "Locals");
tabber2.insert(1, &globals_tree, "Globals");
@@ -121,7 +108,8 @@ int MainFrame::OnCreate( LPCREATESTRUCT lpCreateStruct ){
return 0;
}
void MainFrame::setState( int n ){
void MainFrame::setState(int n)
{
state = n;
SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, 0, TRUE, TRUE);
if (shouldRun()) {
@@ -133,31 +121,39 @@ void MainFrame::setState( int n ){
}
}
void MainFrame::OnClose(){
void MainFrame::OnClose()
{
cmdEnd();
}
void MainFrame::OnSize( UINT type,int sw,int sh ){
void MainFrame::OnSize(UINT type, int sw, int sh)
{
CFrameWnd::OnSize(type, sw, sh);
CRect r,t;GetClientRect( &r );
CRect r, t;
GetClientRect(&r);
int x = r.left, y = r.top, w = r.Width(), h = r.Height();
toolBar.GetWindowRect( &t );y+=t.Height();h-=t.Height();
toolBar.GetWindowRect(&t);
y += t.Height();
h -= t.Height();
tabber.MoveWindow(x, y, w - 240, h);
tabber2.MoveWindow(x + w - 240, y, 240, h);
}
void MainFrame::setRuntime( void *mod,void *env ){
void MainFrame::setRuntime(void* mod, void* env)
{
consts_tree.reset((Environ*)env);
globals_tree.reset((Module*)mod, (Environ*)env);
locals_tree.reset((Environ*)env);
}
void MainFrame::showCurStmt(){
if( !cur_file ) return;
void MainFrame::showCurStmt()
{
if (!cur_file)
return;
SourceFile* t = sourceFile(cur_file);
@@ -168,29 +164,35 @@ void MainFrame::showCurStmt(){
locals_tree.refresh();
}
void MainFrame::debugRun(){
void MainFrame::debugRun()
{
setState(RUNNING);
}
void MainFrame::debugStop(){
void MainFrame::debugStop()
{
step_level = locals_tree.size();
setState(STOPPED);
showCurStmt();
}
void MainFrame::debugStmt( int pos,const char *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);
}
void MainFrame::debugEnter( void *frame,void *env,const char *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();
@@ -198,11 +200,13 @@ void MainFrame::debugEnter( void *frame,void *env,const char *func ){
setState(RUNNING);
}
void MainFrame::debugLeave(){
void MainFrame::debugLeave()
{
locals_tree.popFrame();
}
void MainFrame::debugMsg( const char *msg,bool serious ){
void MainFrame::debugMsg(const char* msg, bool serious)
{
if (serious) {
::MessageBox(0, msg, "Runtime Error", MB_OK | MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND);
} else {
@@ -210,47 +214,54 @@ void MainFrame::debugMsg( const char *msg,bool serious ){
}
}
void MainFrame::debugLog( const char *msg ){
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(){
void MainFrame::cmdStop()
{
::PostMessage(0, WM_STOP, 0, 0);
}
void MainFrame::cmdRun(){
void MainFrame::cmdRun()
{
step_level = -1;
::PostMessage(0, WM_RUN, 0, 0);
}
void MainFrame::cmdEnd(){
void MainFrame::cmdEnd()
{
::PostMessage(0, WM_END, 0, 0);
setState(ENDING);
}
void MainFrame::cmdStepOver(){
void MainFrame::cmdStepOver()
{
::PostMessage(0, WM_RUN, 0, 0);
}
void MainFrame::cmdStepInto(){
void MainFrame::cmdStepInto()
{
step_level = locals_tree.size() + 1;
::PostMessage(0, WM_RUN, 0, 0);
}
void MainFrame::cmdStepOut(){
void MainFrame::cmdStepOut()
{
step_level = locals_tree.size() - 1;
::PostMessage(0, WM_RUN, 0, 0);
}
SourceFile *MainFrame::sourceFile(const char *file){
if( !file ) file="<unknown>";
SourceFile* MainFrame::sourceFile(const char* file)
{
if (!file)
file = "<unknown>";
map<const char*, SourceFile*>::const_iterator it = files.find(file);
@@ -266,9 +277,7 @@ SourceFile *MainFrame::sourceFile(const char *file){
int tab = files.size();
t->Create(
WS_CHILD|WS_HSCROLL|WS_VSCROLL|
ES_NOHIDESEL|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL,
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")) {
@@ -285,8 +294,10 @@ SourceFile *MainFrame::sourceFile(const char *file){
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;
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);
@@ -294,7 +305,8 @@ SourceFile *MainFrame::sourceFile(const char *file){
return t;
}
void MainFrame::updateCmdUI( CCmdUI *ui ){
void MainFrame::updateCmdUI(CCmdUI* ui)
{
if (state != RUNNING && state != STOPPED) {
ui->Enable(false);
return;
@@ -315,7 +327,8 @@ void MainFrame::updateCmdUI( CCmdUI *ui ){
}
}
void MainFrame::OnWindowPosChanging( WINDOWPOS *pos ){
void MainFrame::OnWindowPosChanging(WINDOWPOS* pos)
{
RECT rect;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
+6 -4
View File
@@ -2,13 +2,12 @@
#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 {
Tabber tabber;
Tabber tabber2;
CToolBar toolBar;
@@ -22,7 +21,10 @@ class MainFrame : public CFrameWnd,public Debugger{
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 < locals_tree.size();
}
public:
MainFrame();
+71 -39
View File
@@ -1,15 +1,15 @@
#include "stdafx.hpp"
#include "prefs.hpp"
#include "debuggerapp.hpp"
#include <fstream>
#include "debuggerapp.hpp"
#include "stdafx.hpp"
#define SWAPRB(x) ((((x) >> 16) & 0xff) | ((x)&0xff00) | (((x)&0xff) << 16))
Prefs prefs;
void Prefs::open(){
void Prefs::open()
{
homeDir = getenv("blitzpath");
AddFontResource((homeDir + "/cfg/blitz.fon").c_str());
@@ -18,45 +18,72 @@ void Prefs::open(){
bool prg_windowed;
ifstream in((homeDir + "/cfg/blitzide.prefs").c_str());
if( !in.good() ) return;
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;
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;
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;
string s;
int h;
in >> s;
in >> h;
t = t.substr(5);
if (t == "editor") {
font_editor=s;font_editor_height=h;
font_editor = s;
font_editor_height = h;
} else if (t == "tabs") {
font_tabs=s;font_tabs_height=h;
font_tabs = s;
font_tabs_height = h;
} else if (t == "debug") {
font_debug=s;font_debug_height=h;
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;
string s;
in >> 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);
int n = s[k];
rgb = (rgb << 4) | (n <= '9' ? n - '0' : (n & 31) + 9);
}
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;
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") {
@@ -68,8 +95,10 @@ void Prefs::open(){
} 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 );
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);
@@ -80,16 +109,18 @@ void Prefs::open(){
createFonts();
}
void Prefs::close(){
void Prefs::close()
{
ofstream out((homeDir + "cfg\\blitzide.prefs").c_str());
if( !out.good() ) return;
if (!out.good())
return;
out << "prg_debug\t" << prg_debug << endl;
out << "prg_lastbuild\t" << prg_lastbuild << endl;
out << "win_maximized\t" << win_maximized << endl;
out << "win_notoolbar\t" << win_notoolbar << endl;
out<<"win_rect\t"<<win_rect.left<<' '<<win_rect.top<<' '<<win_rect.right<<' '<<win_rect.bottom<<endl;
out << "win_rect\t" << win_rect.left << ' ' << win_rect.top << ' ' << win_rect.right << ' ' << win_rect.bottom
<< endl;
out << "font_editor\t" << font_editor << ' ' << font_editor_height << endl;
out << "font_tabs\t" << font_tabs << ' ' << font_tabs_height << endl;
out << "font_debug\t" << font_debug << ' ' << font_debug_height << endl;
@@ -114,12 +145,13 @@ void Prefs::close(){
RemoveFontResource((homeDir + "cfg\\blitz.fon").c_str());
}
void Prefs::setDefault(){
void Prefs::setDefault()
{
prg_debug = true;
win_rect.left = win_rect.top = 0;
win_rect.right=640;win_rect.bottom=480;
win_rect.right = 640;
win_rect.bottom = 480;
win_maximized = false;
win_notoolbar = false;
@@ -160,8 +192,8 @@ void Prefs::setDefault(){
createFonts();
}
void Prefs::createFonts(){
void Prefs::createFonts()
{
editFont.Detach();
tabsFont.Detach();
debugFont.Detach();
-1
View File
@@ -41,7 +41,6 @@ public:
void close();
private:
void setDefault();
void createFonts();
};
+11 -9
View File
@@ -1,20 +1,19 @@
#include "stdafx.hpp"
#include "sourcefile.hpp"
#include "prefs.hpp"
#include "stdafx.hpp"
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 ){
int SourceFile::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CRichEditCtrl::OnCreate(lpCreateStruct);
SetReadOnly(true);
@@ -33,7 +32,8 @@ int SourceFile::OnCreate( LPCREATESTRUCT lpCreateStruct ){
return 0;
}
void SourceFile::highLight( int row,int col ){
void SourceFile::highLight(int row, int col)
{
int pos = LineIndex(row) + col;
HideSelection(true, false);
bool quote = false;
@@ -42,8 +42,10 @@ void SourceFile::highLight( int row,int col ){
SetSel(end, end + 1);
auto txt = GetSelText();
if( txt[0]=='\"' ) quote=!quote;
if( !quote && (txt[0]==':' || !isprint(txt[0] )) ) break;
if (txt[0] == '\"')
quote = !quote;
if (!quote && (txt[0] == ':' || !isprint(txt[0])))
break;
++end;
}
HideSelection(false, false);
+3 -3
View File
@@ -4,14 +4,14 @@
#pragma warning(disable : 4786)
#include <afxwin.h> // Core
#include <afxcmn.h> // Common Controls
#include <afxrich.h> // CRich edit
#include <afxwin.h> // Core
#include <map>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <vector>
using namespace std;
+40 -30
View File
@@ -1,16 +1,20 @@
#include "stdafx.hpp"
int atoi( const string &s ){
int atoi(const string& s)
{
return atoi(s.c_str());
}
double atof( const string &s ){
double atof(const string& s)
{
return atof(s.c_str());
}
string itoa( int n ){
char buff[32]; _itoa( n,buff,10 );
string itoa(int n)
{
char buff[32];
_itoa(n, buff, 10);
return string(buff);
}
@@ -50,8 +54,8 @@ string itoa( int n ){
/////////////
//By FLOYD!//
/////////////
string ftoa( float n ){
string ftoa(float n)
{
static const int digits = 6;
int eNeg = -4, ePos = 8; // limits for e notation.
@@ -61,14 +65,12 @@ string ftoa( float n ){
int dec, sign;
if (_finite(n)) {
// 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);
if (dec <= eNeg + 1 || dec > ePos) {
_gcvt(n, digits, buffer);
t = buffer;
return t;
@@ -78,36 +80,34 @@ string ftoa( float n ){
// 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
}
else if( dec < digits ){
} else if (dec < digits) {
t = t.substr(0, dec) + "." + t.substr(dec);
}
else{
} 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' );
while (--p > dp1 && t[p] == '0')
;
t = string(t, 0, ++p);
return sign ? "-" + t : t;
} // 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 tolower(const string& s)
{
string t = s;
for( int k=0;k<t.size();++k ) t[k]=tolower(t[k]);
for (int k = 0; k < t.size(); ++k)
t[k] = tolower(t[k]);
return t;
}
string toupper( const string &s ){
string toupper(const string& s)
{
string t = s;
for( int k=0;k<t.size();++k ) t[k]=toupper(t[k]);
for (int k = 0; k < t.size(); ++k)
t[k] = toupper(t[k]);
return t;
}
string fullfilename( const string &t ){
string fullfilename(const string& t)
{
char buff[MAX_PATH + 1], *p;
GetFullPathName(t.c_str(), MAX_PATH, buff, &p);
return string(buff);
}
string filenamepath( const string &t ){
string filenamepath(const string& t)
{
char buff[MAX_PATH + 1], *p;
GetFullPathName(t.c_str(), MAX_PATH, buff, &p);
if( !p ) return "";
*p=0;return string(buff);
if (!p)
return "";
*p = 0;
return string(buff);
}
string filenamefile( const string &t ){
string filenamefile(const string& t)
{
char buff[MAX_PATH + 1], *p;
GetFullPathName(t.c_str(), MAX_PATH, buff, &p);
if( !p ) return "";
if (!p)
return "";
return string(p);
}
+101 -53
View File
@@ -1,7 +1,7 @@
#include "stdafx.hpp"
#include "tabber.hpp"
#include <WinUser.h>
#include "stdafx.hpp"
IMPLEMENT_DYNAMIC(Tabber, CTabCtrl)
BEGIN_MESSAGE_MAP(Tabber, CTabCtrl)
@@ -10,68 +10,90 @@ BEGIN_MESSAGE_MAP( Tabber,CTabCtrl )
ON_NOTIFY_REFLECT(TCN_SELCHANGE, tcn_selChange)
END_MESSAGE_MAP()
static CRect tabsRect( CTabCtrl &t ){
static CRect tabsRect(CTabCtrl& t)
{
CRect r(0, 0, 0, 0);
int n = t.GetItemCount();
for (int k = 0; k < n; ++k) {
CRect c;
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;
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;
r = tabsRect(*this);
h-=r.Height();y+=r.Height();
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 ){
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 );
CBrush br;
br.Attach(hb);
if( curr<0 ) dc->FillRect( &c,&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 );
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 ){
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);
@@ -79,63 +101,85 @@ void Tabber::refresh(){
wnd->ShowWindow(SW_SHOWNA);
}
Tabber::Tab *Tabber::getTab( int index )const{
if( index<0 || index>=tabs.size() ) return 0;
Tabber::Tab* Tabber::getTab(int index) const
{
if (index < 0 || index >= tabs.size())
return 0;
Tabs::const_iterator it = tabs.begin();
while( index-- ) ++it;
while (index--)
++it;
return *it;
}
void Tabber::tcn_selChange( NMHDR *p,LRESULT *result ){
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<index;++k ) ++it;
for (int k = 0; k < index; ++k)
++it;
Tab* tab = new Tab(w, t);
tabs.insert(it, tab);
InsertItem(index, t.c_str());
if( curr<0 ) setCurrent( index );
if (curr < 0)
setCurrent(index);
}
void Tabber::remove( int index ){
if( index<0 || index>=tabs.size() ) return;
void Tabber::remove(int index)
{
if (index < 0 || index >= tabs.size())
return;
CWnd* w = getTabWnd(index);
Tabs::iterator it = tabs.begin();
for( int k=0;k<index;++k ) ++it;
delete *it;tabs.erase( it );
for (int k = 0; k < index; ++k)
++it;
delete *it;
tabs.erase(it);
DeleteItem(index);
if( curr>=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;
refresh();
SetCurSel(curr);
if( w ) w->ShowWindow( SW_HIDE );
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};
@@ -143,20 +187,24 @@ void Tabber::setTabText( int index,const string &t ){
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{
CWnd* Tabber::getTabWnd(int index) const
{
Tab* t = getTab(index);
return t ? t->wnd : 0;
}
string Tabber::getTabText( int index )const{
string Tabber::getTabText(int index) const
{
Tab* t = getTab(index);
return t ? t->text : "";
}
+1 -2
View File
@@ -39,8 +39,7 @@ private:
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<Tab*> Tabs;