aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/action.h5
-rw-r--r--src/build.cpp12
-rw-r--r--src/build.h2
-rw-r--r--src/main.cpp35
-rw-r--r--src/targetfile.cpp4
-rw-r--r--src/viewer.cpp10
-rw-r--r--src/viewer.h4
-rw-r--r--src/viewerfactory.cpp2
-rw-r--r--src/viewerpercent.cpp114
-rw-r--r--src/viewerpercent.h36
-rw-r--r--src/viewerplain.cpp2
-rw-r--r--src/viewerplain.h2
12 files changed, 205 insertions, 23 deletions
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:
33 bool isEnded(); 33 bool isEnded();
34 void next(); 34 void next();
35 35
36 int size()
37 {
38 return lCmds.size();
39 }
40
36 eAction getAct(); 41 eAction getAct();
37 std::string getWhat(); 42 std::string getWhat();
38 43
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() :
10 pView( NULL ), 10 pView( NULL ),
11 bCacheUpdated( false ) 11 bCacheUpdated( false )
12{ 12{
13 pView = ViewerFactory::getInstance().instantiate("plain");
14} 13}
15 14
16Build::~Build() 15Build::~Build()
@@ -29,6 +28,11 @@ Build::~Build()
29 } 28 }
30} 29}
31 30
31void Build::setView( const std::string &sView )
32{
33 pView = ViewerFactory::getInstance().instantiate( sView.c_str() );
34}
35
32void Build::setCache( const std::string &sFileName ) 36void Build::setCache( const std::string &sFileName )
33{ 37{
34 sCacheName = sFileName; 38 sCacheName = sFileName;
@@ -70,6 +74,8 @@ void Build::execAction( const std::string &sWhat )
70 74
71 Action *pAct = mAction[sWhat]; 75 Action *pAct = mAction[sWhat];
72 76
77 pView->beginAction( sWhat, pAct->size() );
78
73 for( pAct->begin(); !pAct->isEnded(); pAct->next() ) 79 for( pAct->begin(); !pAct->isEnded(); pAct->next() )
74 { 80 {
75 if( mTarget.find( pAct->getWhat() ) == mTarget.end() ) 81 if( mTarget.find( pAct->getWhat() ) == mTarget.end() )
@@ -79,7 +85,7 @@ void Build::execAction( const std::string &sWhat )
79 sWhat.c_str() 85 sWhat.c_str()
80 ); 86 );
81 Target *pTarget = mTarget[pAct->getWhat()]; 87 Target *pTarget = mTarget[pAct->getWhat()];
82 pView->beginCommand( pAct->getAct(), pAct->getWhat(), 0 ); 88 pView->beginCommand( pAct->getAct(), pAct->getWhat() );
83 switch( pAct->getAct() ) 89 switch( pAct->getAct() )
84 { 90 {
85 case Action::actCheck: 91 case Action::actCheck:
@@ -93,6 +99,8 @@ void Build::execAction( const std::string &sWhat )
93 pView->endCommand(); 99 pView->endCommand();
94 } 100 }
95 101
102 pView->endAction();
103
96 return; 104 return;
97} 105}
98 106
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:
67 return mTarget; 67 return mTarget;
68 } 68 }
69 69
70 void setView( const std::string &sView );
71
70 void setCache( const std::string &sFileName ); 72 void setCache( const std::string &sFileName );
71 bool getCached( const std::string &sID, int nTime, StringList &lOut ); 73 bool getCached( const std::string &sID, int nTime, StringList &lOut );
72 void updateCache( const std::string &sID, FunctionList &lFunc, StringList &lOut ); 74 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:
12 Param() : 12 Param() :
13 sFile("build.conf"), 13 sFile("build.conf"),
14 sCache(".build.cache"), 14 sCache(".build.cache"),
15 bDebug( false ) 15 bDebug( false ),
16 sView("plain")
16 { 17 {
17 addHelpBanner("Build r?\n\n"); 18 addHelpBanner("Build r?\n\n");
18 addParam("file", 'f', &sFile, 19 addParam("file", 'f', &sFile,
@@ -24,7 +25,7 @@ public:
24 addParam("cache", &sCache, 25 addParam("cache", &sCache,
25 "Set an alternative cache file." ); 26 "Set an alternative cache file." );
26 addParam('d', &bDebug, 27 addParam('d', &bDebug,
27 "Print out a debug dump of the read build.conf", "true" ); 28 "Print out a debug dump of the build.conf", NULL, "true" );
28 addParam("help", mkproc(ParamProc::help), 29 addParam("help", mkproc(ParamProc::help),
29 "This help"); 30 "This help");
30 //pViewer = new ViewerPlain; 31 //pViewer = new ViewerPlain;
@@ -48,6 +49,7 @@ public:
48 49
49 int procViewPercent( int argc, char *argv[] ) 50 int procViewPercent( int argc, char *argv[] )
50 { 51 {
52 sView = "percent";
51 //delete pViewer; 53 //delete pViewer;
52 //pViewer = new ViewerPercent; 54 //pViewer = new ViewerPercent;
53 } 55 }
@@ -60,6 +62,7 @@ public:
60 62
61 std::string sCache; 63 std::string sCache;
62 std::string sFile; 64 std::string sFile;
65 std::string sView;
63 StaticString sAction; 66 StaticString sAction;
64 //Viewer *pViewer; 67 //Viewer *pViewer;
65 bool bDebug; 68 bool bDebug;
@@ -79,6 +82,19 @@ int main( int argc, char *argv[] )
79 { 82 {
80 pBuild = bld.load( prm.sFile.c_str() ); 83 pBuild = bld.load( prm.sFile.c_str() );
81 pBuild->setCache( prm.sCache ); 84 pBuild->setCache( prm.sCache );
85 pBuild->setView( prm.sView );
86 if( prm.bDebug )
87 {
88 printf("\n\n----------\nDebug dump\n----------\n");
89 bld.debugDump();
90 }
91 else
92 {
93 if( prm.sAction > 0 )
94 pBuild->execAction( prm.sAction.getString() );
95 else
96 pBuild->execAction("");
97 }
82 } 98 }
83 catch( BuildException &e ) 99 catch( BuildException &e )
84 { 100 {
@@ -87,21 +103,6 @@ int main( int argc, char *argv[] )
87 return 1; 103 return 1;
88 } 104 }
89 105
90 //if( prm.bDebug )
91 //{
92 // printf("\n\n----------\nDebug dump\n----------\n");
93 // bld.debugDump();
94 //}
95 //else
96 {
97 if( prm.sAction > 0 )
98 pBuild->execAction( prm.sAction.getString() );
99 else
100 pBuild->execAction("");
101 }
102 //printf("\n\n----------\nDebug dump\n----------\n");
103 //pBuild->debugDump();
104
105 delete pBuild; 106 delete pBuild;
106} 107}
107 108
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 )
23 pRule->setTarget( getName() ); 23 pRule->setTarget( getName() );
24 StringList lFinal = pRule->execute( bld, getInput(), lPerf ); 24 StringList lFinal = pRule->execute( bld, getInput(), lPerf );
25 25
26 bld.getView()->beginPerforms( lPerf.size() );
27
26 for( PerformList::iterator i = lPerf.begin(); i != lPerf.end(); i++ ) 28 for( PerformList::iterator i = lPerf.begin(); i != lPerf.end(); i++ )
27 { 29 {
28 time_t tTarget = getTime( bld, (*i)->getTarget() ); 30 time_t tTarget = getTime( bld, (*i)->getTarget() );
@@ -53,6 +55,8 @@ void TargetFile::check( Build &bld )
53 } 55 }
54 } 56 }
55 } 57 }
58
59 bld.getView()->endPerforms();
56} 60}
57 61
58void TargetFile::clean( Build &bld ) 62void 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()
16{ 16{
17} 17}
18 18
19void Viewer::beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ) 19void Viewer::beginCommand( Action::eAction nAct, const std::string &sTarget )
20{
21}
22
23void Viewer::beginPerforms( int nCount )
24{
25}
26
27void Viewer::endPerforms()
20{ 28{
21} 29}
22 30
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:
16 virtual void beginAction( const std::string &sName, int nCommands ); 16 virtual void beginAction( const std::string &sName, int nCommands );
17 virtual void endAction(); 17 virtual void endAction();
18 18
19 virtual void beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ); 19 virtual void beginCommand( Action::eAction nAct, const std::string &sTarget );
20 virtual void endCommand(); 20 virtual void endCommand();
21 virtual void beginPerforms( int nCount );
22 virtual void endPerforms();
21 23
22 virtual void beginRequiresCheck( bool bCached, const std::string &sName ); 24 virtual void beginRequiresCheck( bool bCached, const std::string &sName );
23 virtual void endRequiresCheck(); 25 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 @@
1#include "viewerfactory.h" 1#include "viewerfactory.h"
2 2
3extern struct PluginInfo plain; 3extern struct PluginInfo plain;
4extern struct PluginInfo percent;
4 5
5ViewerFactory::ViewerFactory() 6ViewerFactory::ViewerFactory()
6{ 7{
7 registerBuiltinPlugin( &plain ); 8 registerBuiltinPlugin( &plain );
9 registerBuiltinPlugin( &percent );
8} 10}
9 11
10ViewerFactory::~ViewerFactory() 12ViewerFactory::~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 @@
1#include "viewerpercent.h"
2#include "perform.h"
3#include "plugger.h"
4
5PluginInterface2( percent, ViewerPercent, Viewer, "Mike Buland", 0, 1 );
6
7ViewerPercent::ViewerPercent() :
8 nWidth( 15 )
9{
10}
11
12ViewerPercent::~ViewerPercent()
13{
14}
15
16void ViewerPercent::beginAction( const std::string &sName, int nCommands )
17{
18 nTotalCommands = nCommands;
19 nCurCommand = 0;
20}
21
22void ViewerPercent::endAction()
23{
24}
25
26void ViewerPercent::beginCommand( Action::eAction nAct, const std::string &sTarget )
27{
28 this->sTarget = sTarget;
29 nCurCommand++;
30}
31
32void ViewerPercent::endCommand()
33{
34 printf("\n");
35}
36
37void ViewerPercent::beginPerforms( int nCount )
38{
39 nTotalPerforms = nCount;
40 nCurPerform = 0;
41 nLastLen = 0;
42}
43
44void ViewerPercent::endPerforms()
45{
46 int nLen = printf("\r[%2d/%-2d] %s [",
47 nCurCommand, nTotalCommands,
48 sTarget.c_str() );
49 for( int j = 0; j < nWidth; j++ )
50 {
51 fputc('#', stdout );
52 }
53 nLen += nWidth;
54 nLen += printf("] 100%%");
55
56 if( nLastLen > nLen )
57 {
58 int jmax = nLastLen-nLen;
59 for( int j = 0; j < jmax; j++ )
60 {
61 fputc(' ', stdout );
62 }
63 }
64 nLastLen = 0;
65
66 fflush( stdout );
67}
68
69void ViewerPercent::beginRequiresCheck( bool bCached, const std::string &sName )
70{
71}
72
73void ViewerPercent::endRequiresCheck()
74{
75}
76
77void ViewerPercent::beginPerform( Perform *pPerform )
78{
79 nCurPerform++;
80 int nLen = printf("\r[%2d/%-2d] %s [",
81 nCurCommand, nTotalCommands,
82 sTarget.c_str() );
83 int jmax = nCurPerform*nWidth/nTotalPerforms;
84 for( int j = 0; j < jmax; j++ )
85 {
86 fputc('#', stdout );
87 }
88 jmax = nWidth-jmax;
89 for( int j = 0; j < jmax; j++ )
90 {
91 fputc(' ', stdout );
92 }
93 nLen += nWidth;
94 nLen += printf("] %-2d%% %s",
95 nCurPerform*100/nTotalPerforms,
96 pPerform->getTarget().c_str() );
97
98 if( nLastLen > nLen )
99 {
100 jmax = nLastLen-nLen;
101 for( int j = 0; j < jmax; j++ )
102 {
103 fputc(' ', stdout );
104 }
105 }
106 nLastLen = nLen;
107
108 fflush( stdout );
109}
110
111void ViewerPercent::endPerform()
112{
113}
114
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 @@
1#ifndef VIEWER_PERCENT_H
2#define VIEWER_PERCENT_H
3
4#include <stdint.h>
5
6#include "viewer.h"
7
8class ViewerPercent : public Viewer
9{
10public:
11 ViewerPercent();
12 virtual ~ViewerPercent();
13
14 virtual void beginCommand( Action::eAction nAct, const std::string &sTarget );
15 virtual void endCommand();
16
17 virtual void beginRequiresCheck( bool bCached, const std::string &sName );
18 virtual void endRequiresCheck();
19 virtual void beginPerform( Perform *pPerform );
20 virtual void endPerform();
21 virtual void beginPerforms( int nCount );
22 virtual void endPerforms();
23 virtual void beginAction( const std::string &sName, int nCommands );
24 virtual void endAction();
25
26private:
27 int nTotalCommands;
28 int nCurCommand;
29 int nTotalPerforms;
30 int nCurPerform;
31 std::string sTarget;
32 int nLastLen;
33 int nWidth;
34};
35
36#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()
12{ 12{
13} 13}
14 14
15void ViewerPlain::beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ) 15void ViewerPlain::beginCommand( Action::eAction nAct, const std::string &sTarget )
16{ 16{
17 printf("--- %s ---\n", sTarget.c_str() ); 17 printf("--- %s ---\n", sTarget.c_str() );
18} 18}
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:
11 ViewerPlain(); 11 ViewerPlain();
12 virtual ~ViewerPlain(); 12 virtual ~ViewerPlain();
13 13
14 virtual void beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ); 14 virtual void beginCommand( Action::eAction nAct, const std::string &sTarget );
15 virtual void endCommand(); 15 virtual void endCommand();
16 16
17 virtual void beginRequiresCheck( bool bCached, const std::string &sName ); 17 virtual void beginRequiresCheck( bool bCached, const std::string &sName );