aboutsummaryrefslogtreecommitdiff
path: root/src/rule.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/rule.cpp195
1 files changed, 0 insertions, 195 deletions
diff --git a/src/rule.cpp b/src/rule.cpp
deleted file mode 100644
index ce37e93..0000000
--- a/src/rule.cpp
+++ /dev/null
@@ -1,195 +0,0 @@
1#include "rule.h"
2#include "perform.h"
3#include "performcmd.h"
4#include "builder.h" // for BuildException
5
6Rule::Rule( const char *sName ) :
7 sName( sName ),
8 bNoProduces( true )
9{
10 lProduces.push_back("{target}");
11}
12
13Rule::~Rule()
14{
15}
16
17void Rule::debug()
18{
19 printf(" Rule %s:\n",
20 sName.getString()
21 );
22 printf(" Produces: ");
23 if( lProduces.empty() )
24 printf("{target}");
25 else
26 {
27 for( std::list<std::string>::iterator i = lProduces.begin();
28 i != lProduces.end(); i++ )
29 {
30 if( i != lProduces.begin() )
31 printf(", ");
32 printf("%s", (*i).c_str() );
33 }
34 }
35 printf("\n Matches ");
36 if( mHow == matchOne )
37 printf("one ");
38 else if( mHow == matchAll )
39 printf("all ");
40 printf("/%s/\n", rWhat.getSource() );
41
42 printf(" Performs ");
43 if( pHow == perfCommand )
44 printf("command ");
45 printf("\"%s\"\n", sPerfCmd.getString() );
46}
47
48void Rule::addProduces( const char *sP )
49{
50 if( bNoProduces )
51 {
52 lProduces.clear();
53 bNoProduces = false;
54 }
55 lProduces.push_back( sP );
56}
57
58void Rule::setMatches( Matches how, const char *sW )
59{
60 rWhat.compile( sW );
61 mHow = how;
62}
63
64void Rule::setPerforms( ePerform pwhat, const char *sperfcmd )
65{
66 pHow = pwhat;
67 sPerfCmd = sperfcmd;
68}
69
70Perform *Rule::buildCommand( Builder &bld, const char *sCmd, Builder::varmap *vars )
71{
72 return new PerformCmd(
73 bld.varRepl( sCmd, (*vars)["target"].c_str(), vars ).c_str(),
74 (*vars)["target"].c_str()
75 );
76}
77
78std::list<std::string> Rule::execute( Builder &bld, std::list<std::string> lInput, std::list<Perform *> &lPerf, const char *sTarget )
79{
80 bld.requiresRegexp( false );
81 std::list<Rule *> lRule = bld.findRuleChain( this );
82 /*
83 if( !lRule.empty() )
84 {
85 printf("Rule %s chains to: ", sName.getString() );
86 for( std::list<Rule *>::iterator i = lRule.begin();
87 i != lRule.end(); i++ )
88 {
89 if( i != lRule.begin() )
90 printf(", ");
91 printf("%s", (*i)->sName.getString() );
92 }
93 printf("\n");
94 }*/
95
96 std::list<std::string> lOutput;
97 std::string sMatches;
98
99 for( std::list<Rule *>::iterator i = lRule.begin(); i != lRule.end(); i++ )
100 {
101 std::list<std::string> lTmp = (*i)->execute( bld, lInput, lPerf );
102 lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
103 }
104
105 std::list<std::string> lTest;
106 lTest.insert( lTest.end(), lInput.begin(), lInput.end() );
107 lTest.insert( lTest.end(), lOutput.begin(), lOutput.end() );
108
109 cleanList( lTest );
110
111 for( std::list<std::string>::iterator i = lTest.begin();
112 i != lTest.end(); i++ )
113 {
114 if( rWhat.execute( (*i).c_str() ) )
115 {
116 Builder::varmap *revars = bld.regexVars( &rWhat );
117 for( std::list<std::string>::iterator j = lProduces.begin();
118 j != lProduces.end(); j++ )
119 {
120 if( mHow == matchOne )
121 {
122 lOutput.push_back(
123 bld.varRepl(
124 (*j).c_str(),
125 "",
126 revars
127 )
128 );
129 (*revars)["target"] = (sTarget==NULL)?
130 (lOutput.back().c_str()):(sTarget);
131 (*revars)["match"] = (*i).c_str();
132 Perform *p = buildCommand(
133 bld,
134 sPerfCmd,
135 revars
136 );
137 lPerf.push_back( p );
138
139 bld.requires(
140 (*revars)["target"].c_str(),
141 (*revars)["match"].c_str()
142 );
143 }
144 else if( mHow == matchAll )
145 {
146 sMatches += " ";
147 sMatches += (*i);
148
149 bld.requires(
150 sTarget,
151 (*i).c_str()
152 );
153 }
154 }
155 delete revars;
156 }
157 }
158 //std::list<std::string> lTmp = findTargets( bld, lTest, sMatches, sTarget );
159 //lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
160
161 if( mHow == matchAll )
162 {
163 lOutput.push_back(
164 bld.varRepl(
165 sTarget,
166 sTarget,
167 NULL
168 )
169 );
170 Builder::varmap vars;
171 vars["target"] = sTarget;
172 vars["match"] = sMatches;
173 Perform *p = buildCommand(
174 bld,
175 sPerfCmd,
176 &vars
177 );
178 lPerf.push_back( p );
179 }
180
181 return lOutput;
182}
183
184bool Rule::willChain( Rule *pRule )
185{
186 for( std::list<std::string>::iterator i = pRule->lProduces.begin();
187 i != pRule->lProduces.end(); i++ )
188 {
189 if( rWhat.execute( (*i).c_str() ) )
190 return true;
191 }
192
193 return false;
194}
195