From fe5de4801bfe7926e116585e2f71399cb664dfb2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 7 Sep 2006 00:45:14 +0000 Subject: Really getting there, the rest of the work should be in the build class and related build-time components! --- src/action.cpp | 31 +++++++++++++++++++++++++++++++ src/action.h | 35 +++++++++++++++++++++++++++++++++++ src/build.cpp | 24 ++++++++++++++++++++++++ src/build.h | 5 +++++ src/buildparser.cpp | 23 +++++++++++++++++++++++ src/main.cpp | 22 ++++++++++++---------- 6 files changed, 130 insertions(+), 10 deletions(-) diff --git a/src/action.cpp b/src/action.cpp index cdf50e8..be11f48 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -7,3 +7,34 @@ Action::Action() Action::~Action() { } + +void Action::addCommand( eAction act, const std::string &sWhat ) +{ + lCmds.push_back( Cmd( act, sWhat ) ); +} + +void Action::begin() +{ + i = lCmds.begin(); +} + +bool Action::isEnded() +{ + return i == lCmds.end(); +} + +void Action::next() +{ + i++; +} + +Action::eAction Action::getAct() +{ + return (*i).act; +} + +std::string Action::getWhat() +{ + return (*i).sWhat; +} + diff --git a/src/action.h b/src/action.h index 4ec3b4a..4f9a88e 100644 --- a/src/action.h +++ b/src/action.h @@ -3,6 +3,9 @@ #include +#include +#include + class Action { public: @@ -15,7 +18,39 @@ public: Action(); virtual ~Action(); + typedef struct Cmd + { + Cmd( eAction act, const std::string &sWhat ) : + act( act ), sWhat( sWhat ) + {} + eAction act; + std::string sWhat; + } Cmd; + + void addCommand( eAction act, const std::string &sWhat ); + + void begin(); + bool isEnded(); + void next(); + + eAction getAct(); + std::string getWhat(); + + void setName( const std::string &sName ) + { + this->sName = sName; + } + + std::string getName() + { + return sName; + } + private: + typedef std::list CmdList; + CmdList lCmds; + CmdList::iterator i; + std::string sName; }; diff --git a/src/build.cpp b/src/build.cpp index 03d3c5a..bf867af 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -11,6 +11,14 @@ Build::~Build() { } +void Build::execAction( const std::string &sWhat ) +{ + if( mAction.find( sWhat ) == mAction.end() ) + throw BuildException("No action matches %s.", sWhat.c_str() ); + + return; +} + void Build::addTarget( Target *pTarget ) { TargetMap::iterator i = mTarget.find( pTarget->getName() ); @@ -34,6 +42,11 @@ void Build::addRule( Rule *pRule ) mRule[pRule->getName()] = pRule; } +void Build::addAction( Action *pAction ) +{ + mAction[pAction->getName()] = pAction; +} + void Build::set( const std::string &cont, const std::string &var, const std::string &val ) { if( cont == "" ) @@ -149,5 +162,16 @@ void Build::debugDump() printf(" Produces:\n"); printf(" Requires:\n"); } + + printf("Actions:\n"); + for( ActionMap::iterator i = mAction.begin(); i != mAction.end(); i++ ) + { + printf(" %s: ", (*i).first.c_str() ); + for( (*i).second->begin(); !(*i).second->isEnded(); (*i).second->next() ) + { + printf("%d:%s ", (*i).second->getAct(), (*i).second->getWhat().c_str() ); + } + printf("\n"); + } } diff --git a/src/build.h b/src/build.h index fe71d30..77e40fa 100644 --- a/src/build.h +++ b/src/build.h @@ -19,6 +19,8 @@ public: Build(); virtual ~Build(); + void execAction( const std::string &sWhat ); + /** * Adds a target to the build. If the target already exists, this will * attempt to merge them as best it can. If there are any conflicts, it @@ -28,6 +30,7 @@ public: void addTarget( Target *pTarget ); void addRequires( const std::string &who, const std::string &what ); void addRule( Rule *pRule ); + void addAction( Action *pAction ); void set( const std::string &cont, const std::string &var, const std::string &val ); void setAdd( const std::string &cont, const std::string &var, const std::string &val ); @@ -42,12 +45,14 @@ private: typedef std::map VarMap; typedef std::map ContextMap; typedef std::map RuleMap; + typedef std::map ActionMap; TargetMap mTarget; ReqMap mRequires; VarMap mVars; ContextMap mContVars; RuleMap mRule; + ActionMap mAction; //std::map mRule; //Action *pActDefault; diff --git a/src/buildparser.cpp b/src/buildparser.cpp index 5ebcfd3..90e21e2 100644 --- a/src/buildparser.cpp +++ b/src/buildparser.cpp @@ -441,6 +441,29 @@ Build *BuildParser::genBuild() bld->addRule( pRule ); } + for( ActionTmpList::iterator i = lActions.begin(); + i != lActions.end(); i++ ) + { + Action *pAct = new Action; + pAct->setName( (*i).first ); + + for( ActionTmpCmdList::iterator j = (*i).second.begin(); + j != (*i).second.end(); j++ ) + { + StringList lWhat = buildToStringList( + (*j).second, StringList() + ); + + for( StringList::iterator k = lWhat.begin(); + k != lWhat.end(); k++ ) + { + pAct->addCommand( (Action::eAction)((*j).first), *k ); + } + } + + bld->addAction( pAct ); + } + return bld; } diff --git a/src/main.cpp b/src/main.cpp index 9dbf046..02cb9d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,18 +87,20 @@ int main( int argc, char *argv[] ) //} //if( prm.bDebug ) - { - printf("\n\n----------\nDebug dump\n----------\n"); - bld.debugDump(); - } - printf("\n\n----------\nDebug dump\n----------\n"); - pBuild->debugDump(); + //{ + // printf("\n\n----------\nDebug dump\n----------\n"); + // bld.debugDump(); + //} + // printf("\n\n----------\nDebug dump\n----------\n"); + // pBuild->debugDump(); //else { - //if( prm.sAction > 0 ) - // bld.build( prm.sAction ); - //else - // bld.build(); + if( prm.sAction > 0 ) + pBuild->execAction( prm.sAction.getString() ); + else + pBuild->execAction(""); } + + delete pBuild; } -- cgit v1.2.3