diff options
Diffstat (limited to '')
-rw-r--r-- | src/action.cpp | 31 | ||||
-rw-r--r-- | src/action.h | 35 | ||||
-rw-r--r-- | src/build.cpp | 24 | ||||
-rw-r--r-- | src/build.h | 5 | ||||
-rw-r--r-- | src/buildparser.cpp | 23 | ||||
-rw-r--r-- | 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() | |||
7 | Action::~Action() | 7 | Action::~Action() |
8 | { | 8 | { |
9 | } | 9 | } |
10 | |||
11 | void Action::addCommand( eAction act, const std::string &sWhat ) | ||
12 | { | ||
13 | lCmds.push_back( Cmd( act, sWhat ) ); | ||
14 | } | ||
15 | |||
16 | void Action::begin() | ||
17 | { | ||
18 | i = lCmds.begin(); | ||
19 | } | ||
20 | |||
21 | bool Action::isEnded() | ||
22 | { | ||
23 | return i == lCmds.end(); | ||
24 | } | ||
25 | |||
26 | void Action::next() | ||
27 | { | ||
28 | i++; | ||
29 | } | ||
30 | |||
31 | Action::eAction Action::getAct() | ||
32 | { | ||
33 | return (*i).act; | ||
34 | } | ||
35 | |||
36 | std::string Action::getWhat() | ||
37 | { | ||
38 | return (*i).sWhat; | ||
39 | } | ||
40 | |||
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 @@ | |||
3 | 3 | ||
4 | #include <stdint.h> | 4 | #include <stdint.h> |
5 | 5 | ||
6 | #include <string> | ||
7 | #include <list> | ||
8 | |||
6 | class Action | 9 | class Action |
7 | { | 10 | { |
8 | public: | 11 | public: |
@@ -15,7 +18,39 @@ public: | |||
15 | Action(); | 18 | Action(); |
16 | virtual ~Action(); | 19 | virtual ~Action(); |
17 | 20 | ||
21 | typedef struct Cmd | ||
22 | { | ||
23 | Cmd( eAction act, const std::string &sWhat ) : | ||
24 | act( act ), sWhat( sWhat ) | ||
25 | {} | ||
26 | eAction act; | ||
27 | std::string sWhat; | ||
28 | } Cmd; | ||
29 | |||
30 | void addCommand( eAction act, const std::string &sWhat ); | ||
31 | |||
32 | void begin(); | ||
33 | bool isEnded(); | ||
34 | void next(); | ||
35 | |||
36 | eAction getAct(); | ||
37 | std::string getWhat(); | ||
38 | |||
39 | void setName( const std::string &sName ) | ||
40 | { | ||
41 | this->sName = sName; | ||
42 | } | ||
43 | |||
44 | std::string getName() | ||
45 | { | ||
46 | return sName; | ||
47 | } | ||
48 | |||
18 | private: | 49 | private: |
50 | typedef std::list<Cmd> CmdList; | ||
51 | CmdList lCmds; | ||
52 | CmdList::iterator i; | ||
53 | std::string sName; | ||
19 | 54 | ||
20 | }; | 55 | }; |
21 | 56 | ||
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() | |||
11 | { | 11 | { |
12 | } | 12 | } |
13 | 13 | ||
14 | void Build::execAction( const std::string &sWhat ) | ||
15 | { | ||
16 | if( mAction.find( sWhat ) == mAction.end() ) | ||
17 | throw BuildException("No action matches %s.", sWhat.c_str() ); | ||
18 | |||
19 | return; | ||
20 | } | ||
21 | |||
14 | void Build::addTarget( Target *pTarget ) | 22 | void Build::addTarget( Target *pTarget ) |
15 | { | 23 | { |
16 | TargetMap::iterator i = mTarget.find( pTarget->getName() ); | 24 | TargetMap::iterator i = mTarget.find( pTarget->getName() ); |
@@ -34,6 +42,11 @@ void Build::addRule( Rule *pRule ) | |||
34 | mRule[pRule->getName()] = pRule; | 42 | mRule[pRule->getName()] = pRule; |
35 | } | 43 | } |
36 | 44 | ||
45 | void Build::addAction( Action *pAction ) | ||
46 | { | ||
47 | mAction[pAction->getName()] = pAction; | ||
48 | } | ||
49 | |||
37 | void Build::set( const std::string &cont, const std::string &var, const std::string &val ) | 50 | void Build::set( const std::string &cont, const std::string &var, const std::string &val ) |
38 | { | 51 | { |
39 | if( cont == "" ) | 52 | if( cont == "" ) |
@@ -149,5 +162,16 @@ void Build::debugDump() | |||
149 | printf(" Produces:\n"); | 162 | printf(" Produces:\n"); |
150 | printf(" Requires:\n"); | 163 | printf(" Requires:\n"); |
151 | } | 164 | } |
165 | |||
166 | printf("Actions:\n"); | ||
167 | for( ActionMap::iterator i = mAction.begin(); i != mAction.end(); i++ ) | ||
168 | { | ||
169 | printf(" %s: ", (*i).first.c_str() ); | ||
170 | for( (*i).second->begin(); !(*i).second->isEnded(); (*i).second->next() ) | ||
171 | { | ||
172 | printf("%d:%s ", (*i).second->getAct(), (*i).second->getWhat().c_str() ); | ||
173 | } | ||
174 | printf("\n"); | ||
175 | } | ||
152 | } | 176 | } |
153 | 177 | ||
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: | |||
19 | Build(); | 19 | Build(); |
20 | virtual ~Build(); | 20 | virtual ~Build(); |
21 | 21 | ||
22 | void execAction( const std::string &sWhat ); | ||
23 | |||
22 | /** | 24 | /** |
23 | * Adds a target to the build. If the target already exists, this will | 25 | * Adds a target to the build. If the target already exists, this will |
24 | * attempt to merge them as best it can. If there are any conflicts, it | 26 | * attempt to merge them as best it can. If there are any conflicts, it |
@@ -28,6 +30,7 @@ public: | |||
28 | void addTarget( Target *pTarget ); | 30 | void addTarget( Target *pTarget ); |
29 | void addRequires( const std::string &who, const std::string &what ); | 31 | void addRequires( const std::string &who, const std::string &what ); |
30 | void addRule( Rule *pRule ); | 32 | void addRule( Rule *pRule ); |
33 | void addAction( Action *pAction ); | ||
31 | 34 | ||
32 | void set( const std::string &cont, const std::string &var, const std::string &val ); | 35 | void set( const std::string &cont, const std::string &var, const std::string &val ); |
33 | void setAdd( const std::string &cont, const std::string &var, const std::string &val ); | 36 | void setAdd( const std::string &cont, const std::string &var, const std::string &val ); |
@@ -42,12 +45,14 @@ private: | |||
42 | typedef std::map<std::string, std::string> VarMap; | 45 | typedef std::map<std::string, std::string> VarMap; |
43 | typedef std::map<std::string, VarMap> ContextMap; | 46 | typedef std::map<std::string, VarMap> ContextMap; |
44 | typedef std::map<std::string, Rule *> RuleMap; | 47 | typedef std::map<std::string, Rule *> RuleMap; |
48 | typedef std::map<std::string, Action *> ActionMap; | ||
45 | 49 | ||
46 | TargetMap mTarget; | 50 | TargetMap mTarget; |
47 | ReqMap mRequires; | 51 | ReqMap mRequires; |
48 | VarMap mVars; | 52 | VarMap mVars; |
49 | ContextMap mContVars; | 53 | ContextMap mContVars; |
50 | RuleMap mRule; | 54 | RuleMap mRule; |
55 | ActionMap mAction; | ||
51 | 56 | ||
52 | //std::map<std::string, Rule *> mRule; | 57 | //std::map<std::string, Rule *> mRule; |
53 | //Action *pActDefault; | 58 | //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() | |||
441 | bld->addRule( pRule ); | 441 | bld->addRule( pRule ); |
442 | } | 442 | } |
443 | 443 | ||
444 | for( ActionTmpList::iterator i = lActions.begin(); | ||
445 | i != lActions.end(); i++ ) | ||
446 | { | ||
447 | Action *pAct = new Action; | ||
448 | pAct->setName( (*i).first ); | ||
449 | |||
450 | for( ActionTmpCmdList::iterator j = (*i).second.begin(); | ||
451 | j != (*i).second.end(); j++ ) | ||
452 | { | ||
453 | StringList lWhat = buildToStringList( | ||
454 | (*j).second, StringList() | ||
455 | ); | ||
456 | |||
457 | for( StringList::iterator k = lWhat.begin(); | ||
458 | k != lWhat.end(); k++ ) | ||
459 | { | ||
460 | pAct->addCommand( (Action::eAction)((*j).first), *k ); | ||
461 | } | ||
462 | } | ||
463 | |||
464 | bld->addAction( pAct ); | ||
465 | } | ||
466 | |||
444 | return bld; | 467 | return bld; |
445 | } | 468 | } |
446 | 469 | ||
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[] ) | |||
87 | //} | 87 | //} |
88 | 88 | ||
89 | //if( prm.bDebug ) | 89 | //if( prm.bDebug ) |
90 | { | 90 | //{ |
91 | printf("\n\n----------\nDebug dump\n----------\n"); | 91 | // printf("\n\n----------\nDebug dump\n----------\n"); |
92 | bld.debugDump(); | 92 | // bld.debugDump(); |
93 | } | 93 | //} |
94 | printf("\n\n----------\nDebug dump\n----------\n"); | 94 | // printf("\n\n----------\nDebug dump\n----------\n"); |
95 | pBuild->debugDump(); | 95 | // pBuild->debugDump(); |
96 | //else | 96 | //else |
97 | { | 97 | { |
98 | //if( prm.sAction > 0 ) | 98 | if( prm.sAction > 0 ) |
99 | // bld.build( prm.sAction ); | 99 | pBuild->execAction( prm.sAction.getString() ); |
100 | //else | 100 | else |
101 | // bld.build(); | 101 | pBuild->execAction(""); |
102 | } | 102 | } |
103 | |||
104 | delete pBuild; | ||
103 | } | 105 | } |
104 | 106 | ||