From 9d9f75e6da9885e256097a2eabd0ccb951a40651 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 12 Sep 2006 18:19:05 +0000 Subject: Fixed the viewers, and some other good goo. --- src/action.h | 5 +++ src/build.cpp | 12 +++++- src/build.h | 2 + src/main.cpp | 35 ++++++++-------- src/targetfile.cpp | 4 ++ src/viewer.cpp | 10 ++++- src/viewer.h | 4 +- src/viewerfactory.cpp | 2 + src/viewerpercent.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/viewerpercent.h | 36 ++++++++++++++++ src/viewerplain.cpp | 2 +- src/viewerplain.h | 2 +- 12 files changed, 205 insertions(+), 23 deletions(-) create mode 100644 src/viewerpercent.cpp create mode 100644 src/viewerpercent.h (limited to 'src') diff --git a/src/action.h b/src/action.h index 4f9a88e..0e08192 100644 --- a/src/action.h +++ b/src/action.h @@ -33,6 +33,11 @@ public: bool isEnded(); void next(); + int size() + { + return lCmds.size(); + } + eAction getAct(); std::string getWhat(); diff --git a/src/build.cpp b/src/build.cpp index 13a2aee..88d1207 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -10,7 +10,6 @@ Build::Build() : pView( NULL ), bCacheUpdated( false ) { - pView = ViewerFactory::getInstance().instantiate("plain"); } Build::~Build() @@ -29,6 +28,11 @@ Build::~Build() } } +void Build::setView( const std::string &sView ) +{ + pView = ViewerFactory::getInstance().instantiate( sView.c_str() ); +} + void Build::setCache( const std::string &sFileName ) { sCacheName = sFileName; @@ -70,6 +74,8 @@ void Build::execAction( const std::string &sWhat ) Action *pAct = mAction[sWhat]; + pView->beginAction( sWhat, pAct->size() ); + for( pAct->begin(); !pAct->isEnded(); pAct->next() ) { if( mTarget.find( pAct->getWhat() ) == mTarget.end() ) @@ -79,7 +85,7 @@ void Build::execAction( const std::string &sWhat ) sWhat.c_str() ); Target *pTarget = mTarget[pAct->getWhat()]; - pView->beginCommand( pAct->getAct(), pAct->getWhat(), 0 ); + pView->beginCommand( pAct->getAct(), pAct->getWhat() ); switch( pAct->getAct() ) { case Action::actCheck: @@ -93,6 +99,8 @@ void Build::execAction( const std::string &sWhat ) pView->endCommand(); } + pView->endAction(); + return; } diff --git a/src/build.h b/src/build.h index 1477938..e0f60ec 100644 --- a/src/build.h +++ b/src/build.h @@ -67,6 +67,8 @@ public: return mTarget; } + void setView( const std::string &sView ); + void setCache( const std::string &sFileName ); bool getCached( const std::string &sID, int nTime, StringList &lOut ); void updateCache( const std::string &sID, FunctionList &lFunc, StringList &lOut ); diff --git a/src/main.cpp b/src/main.cpp index 712213b..fa1608f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,8 @@ public: Param() : sFile("build.conf"), sCache(".build.cache"), - bDebug( false ) + bDebug( false ), + sView("plain") { addHelpBanner("Build r?\n\n"); addParam("file", 'f', &sFile, @@ -24,7 +25,7 @@ public: addParam("cache", &sCache, "Set an alternative cache file." ); addParam('d', &bDebug, - "Print out a debug dump of the read build.conf", "true" ); + "Print out a debug dump of the build.conf", NULL, "true" ); addParam("help", mkproc(ParamProc::help), "This help"); //pViewer = new ViewerPlain; @@ -48,6 +49,7 @@ public: int procViewPercent( int argc, char *argv[] ) { + sView = "percent"; //delete pViewer; //pViewer = new ViewerPercent; } @@ -60,6 +62,7 @@ public: std::string sCache; std::string sFile; + std::string sView; StaticString sAction; //Viewer *pViewer; bool bDebug; @@ -79,6 +82,19 @@ int main( int argc, char *argv[] ) { pBuild = bld.load( prm.sFile.c_str() ); pBuild->setCache( prm.sCache ); + pBuild->setView( prm.sView ); + if( prm.bDebug ) + { + printf("\n\n----------\nDebug dump\n----------\n"); + bld.debugDump(); + } + else + { + if( prm.sAction > 0 ) + pBuild->execAction( prm.sAction.getString() ); + else + pBuild->execAction(""); + } } catch( BuildException &e ) { @@ -87,21 +103,6 @@ int main( int argc, char *argv[] ) return 1; } - //if( prm.bDebug ) - //{ - // printf("\n\n----------\nDebug dump\n----------\n"); - // bld.debugDump(); - //} - //else - { - if( prm.sAction > 0 ) - pBuild->execAction( prm.sAction.getString() ); - else - pBuild->execAction(""); - } - //printf("\n\n----------\nDebug dump\n----------\n"); - //pBuild->debugDump(); - delete pBuild; } diff --git a/src/targetfile.cpp b/src/targetfile.cpp index dd0de9e..ddb1c18 100644 --- a/src/targetfile.cpp +++ b/src/targetfile.cpp @@ -23,6 +23,8 @@ void TargetFile::check( Build &bld ) pRule->setTarget( getName() ); StringList lFinal = pRule->execute( bld, getInput(), lPerf ); + bld.getView()->beginPerforms( lPerf.size() ); + for( PerformList::iterator i = lPerf.begin(); i != lPerf.end(); i++ ) { time_t tTarget = getTime( bld, (*i)->getTarget() ); @@ -53,6 +55,8 @@ void TargetFile::check( Build &bld ) } } } + + bld.getView()->endPerforms(); } void TargetFile::clean( Build &bld ) diff --git a/src/viewer.cpp b/src/viewer.cpp index 51acc3b..5998316 100644 --- a/src/viewer.cpp +++ b/src/viewer.cpp @@ -16,7 +16,15 @@ void Viewer::endAction() { } -void Viewer::beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ) +void Viewer::beginCommand( Action::eAction nAct, const std::string &sTarget ) +{ +} + +void Viewer::beginPerforms( int nCount ) +{ +} + +void Viewer::endPerforms() { } diff --git a/src/viewer.h b/src/viewer.h index 93cebb7..86410f0 100644 --- a/src/viewer.h +++ b/src/viewer.h @@ -16,8 +16,10 @@ public: virtual void beginAction( const std::string &sName, int nCommands ); virtual void endAction(); - virtual void beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ); + virtual void beginCommand( Action::eAction nAct, const std::string &sTarget ); virtual void endCommand(); + virtual void beginPerforms( int nCount ); + virtual void endPerforms(); virtual void beginRequiresCheck( bool bCached, const std::string &sName ); virtual void endRequiresCheck(); diff --git a/src/viewerfactory.cpp b/src/viewerfactory.cpp index 3778c37..3dbc232 100644 --- a/src/viewerfactory.cpp +++ b/src/viewerfactory.cpp @@ -1,10 +1,12 @@ #include "viewerfactory.h" extern struct PluginInfo plain; +extern struct PluginInfo percent; ViewerFactory::ViewerFactory() { registerBuiltinPlugin( &plain ); + registerBuiltinPlugin( &percent ); } ViewerFactory::~ViewerFactory() diff --git a/src/viewerpercent.cpp b/src/viewerpercent.cpp new file mode 100644 index 0000000..289c900 --- /dev/null +++ b/src/viewerpercent.cpp @@ -0,0 +1,114 @@ +#include "viewerpercent.h" +#include "perform.h" +#include "plugger.h" + +PluginInterface2( percent, ViewerPercent, Viewer, "Mike Buland", 0, 1 ); + +ViewerPercent::ViewerPercent() : + nWidth( 15 ) +{ +} + +ViewerPercent::~ViewerPercent() +{ +} + +void ViewerPercent::beginAction( const std::string &sName, int nCommands ) +{ + nTotalCommands = nCommands; + nCurCommand = 0; +} + +void ViewerPercent::endAction() +{ +} + +void ViewerPercent::beginCommand( Action::eAction nAct, const std::string &sTarget ) +{ + this->sTarget = sTarget; + nCurCommand++; +} + +void ViewerPercent::endCommand() +{ + printf("\n"); +} + +void ViewerPercent::beginPerforms( int nCount ) +{ + nTotalPerforms = nCount; + nCurPerform = 0; + nLastLen = 0; +} + +void ViewerPercent::endPerforms() +{ + int nLen = printf("\r[%2d/%-2d] %s [", + nCurCommand, nTotalCommands, + sTarget.c_str() ); + for( int j = 0; j < nWidth; j++ ) + { + fputc('#', stdout ); + } + nLen += nWidth; + nLen += printf("] 100%%"); + + if( nLastLen > nLen ) + { + int jmax = nLastLen-nLen; + for( int j = 0; j < jmax; j++ ) + { + fputc(' ', stdout ); + } + } + nLastLen = 0; + + fflush( stdout ); +} + +void ViewerPercent::beginRequiresCheck( bool bCached, const std::string &sName ) +{ +} + +void ViewerPercent::endRequiresCheck() +{ +} + +void ViewerPercent::beginPerform( Perform *pPerform ) +{ + nCurPerform++; + int nLen = printf("\r[%2d/%-2d] %s [", + nCurCommand, nTotalCommands, + sTarget.c_str() ); + int jmax = nCurPerform*nWidth/nTotalPerforms; + for( int j = 0; j < jmax; j++ ) + { + fputc('#', stdout ); + } + jmax = nWidth-jmax; + for( int j = 0; j < jmax; j++ ) + { + fputc(' ', stdout ); + } + nLen += nWidth; + nLen += printf("] %-2d%% %s", + nCurPerform*100/nTotalPerforms, + pPerform->getTarget().c_str() ); + + if( nLastLen > nLen ) + { + jmax = nLastLen-nLen; + for( int j = 0; j < jmax; j++ ) + { + fputc(' ', stdout ); + } + } + nLastLen = nLen; + + fflush( stdout ); +} + +void ViewerPercent::endPerform() +{ +} + diff --git a/src/viewerpercent.h b/src/viewerpercent.h new file mode 100644 index 0000000..96412cb --- /dev/null +++ b/src/viewerpercent.h @@ -0,0 +1,36 @@ +#ifndef VIEWER_PERCENT_H +#define VIEWER_PERCENT_H + +#include + +#include "viewer.h" + +class ViewerPercent : public Viewer +{ +public: + ViewerPercent(); + virtual ~ViewerPercent(); + + virtual void beginCommand( Action::eAction nAct, const std::string &sTarget ); + virtual void endCommand(); + + virtual void beginRequiresCheck( bool bCached, const std::string &sName ); + virtual void endRequiresCheck(); + virtual void beginPerform( Perform *pPerform ); + virtual void endPerform(); + virtual void beginPerforms( int nCount ); + virtual void endPerforms(); + virtual void beginAction( const std::string &sName, int nCommands ); + virtual void endAction(); + +private: + int nTotalCommands; + int nCurCommand; + int nTotalPerforms; + int nCurPerform; + std::string sTarget; + int nLastLen; + int nWidth; +}; + +#endif diff --git a/src/viewerplain.cpp b/src/viewerplain.cpp index b6f2095..5690215 100644 --- a/src/viewerplain.cpp +++ b/src/viewerplain.cpp @@ -12,7 +12,7 @@ ViewerPlain::~ViewerPlain() { } -void ViewerPlain::beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ) +void ViewerPlain::beginCommand( Action::eAction nAct, const std::string &sTarget ) { printf("--- %s ---\n", sTarget.c_str() ); } diff --git a/src/viewerplain.h b/src/viewerplain.h index 6e37c28..978d50b 100644 --- a/src/viewerplain.h +++ b/src/viewerplain.h @@ -11,7 +11,7 @@ public: ViewerPlain(); virtual ~ViewerPlain(); - virtual void beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ); + virtual void beginCommand( Action::eAction nAct, const std::string &sTarget ); virtual void endCommand(); virtual void beginRequiresCheck( bool bCached, const std::string &sName ); -- cgit v1.2.3