aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/build.cpp93
-rw-r--r--src/build.h11
-rw-r--r--src/builder.cpp38
-rw-r--r--src/builder.h8
-rw-r--r--src/function.h2
-rw-r--r--src/functionfilesin.cpp23
-rw-r--r--src/functionregexp.cpp17
-rw-r--r--src/regexp.cpp78
-rw-r--r--src/regexp.h36
-rw-r--r--src/rule.h31
10 files changed, 331 insertions, 6 deletions
diff --git a/src/build.cpp b/src/build.cpp
index d9a8b39..ec97ccb 100644
--- a/src/build.cpp
+++ b/src/build.cpp
@@ -29,6 +29,62 @@ void Build::addRequires( const std::string &who, const std::string &what )
29 mRequires[who].push_back( what ); 29 mRequires[who].push_back( what );
30} 30}
31 31
32void Build::addRule( Rule *pRule )
33{
34 mRule[pRule->getName()] = pRule;
35}
36
37void Build::set( const std::string &cont, const std::string &var, const std::string &val )
38{
39 if( cont == "" )
40 {
41 mVars[var] = val;
42 }
43 else
44 {
45 mContVars[cont][var] = val;
46 }
47}
48
49void Build::setAdd( const std::string &cont, const std::string &var, const std::string &val )
50{
51 if( cont == "" )
52 {
53 mVars[var] = getVar( cont, var ) + " " + val;
54 }
55 else
56 {
57 mContVars[cont][var] = getVar( cont, var ) + " " + val;
58 }
59}
60
61std::string Build::getVar( const std::string &cont, const std::string &var )
62{
63 if( cont == "" )
64 {
65 if( mVars.find(var) == mVars.end() )
66 {
67 if( getenv( var.c_str() ) == NULL )
68 {
69 mVars[var] = "";
70 }
71 else
72 {
73 mVars[var] = getenv( var.c_str() );
74 }
75 }
76 return mVars[var];
77 }
78 else
79 {
80 if( mContVars[cont].find(var) == mContVars[cont].end() )
81 {
82 mContVars[cont][var] = getVar( "", var );
83 }
84 return mContVars[cont][var];
85 }
86}
87
32void Build::debugDump() 88void Build::debugDump()
33{ 89{
34 printf("Requires:\n"); 90 printf("Requires:\n");
@@ -45,5 +101,42 @@ void Build::debugDump()
45 } 101 }
46 printf("\n"); 102 printf("\n");
47 } 103 }
104
105 printf("Targets:\n");
106 for( TargetMap::iterator i = mTarget.begin(); i != mTarget.end(); i++ )
107 {
108 printf(" %s:\n", (*i).first.c_str() );
109 printf(" Rule: %s\n", (*i).second->getRule().c_str() );
110 printf(" Input: ");
111 for( StringList::iterator j = (*i).second->getInput().begin();
112 j != (*i).second->getInput().end(); j++ )
113 {
114 if( j != (*i).second->getInput().begin() )
115 printf(", ");
116 printf("%s", (*j).c_str() );
117 }
118 printf("\n");
119 }
120
121 printf("Global Variables:\n");
122 for( VarMap::iterator i = mVars.begin(); i != mVars.end(); i++ )
123 {
124 printf(" \"%s\" = \"%s\"\n", (*i).first.c_str(), (*i).second.c_str() );
125 }
126
127 printf("Context Variables:\n");
128 for( ContextMap::iterator i = mContVars.begin(); i != mContVars.end(); i++ )
129 {
130 printf(" %s:\n", (*i).first.c_str() );
131
132 for( VarMap::iterator j = (*i).second.begin();
133 j != (*i).second.end(); j++ )
134 {
135 printf(" \"%s\" = \"%s\"\n",
136 (*j).first.c_str(),
137 (*j).second.c_str()
138 );
139 }
140 }
48} 141}
49 142
diff --git a/src/build.h b/src/build.h
index 00acbfc..fe71d30 100644
--- a/src/build.h
+++ b/src/build.h
@@ -27,6 +27,11 @@ public:
27 */ 27 */
28 void addTarget( Target *pTarget ); 28 void addTarget( Target *pTarget );
29 void addRequires( const std::string &who, const std::string &what ); 29 void addRequires( const std::string &who, const std::string &what );
30 void addRule( Rule *pRule );
31
32 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 );
34 std::string getVar( const std::string &cont, const std::string &var );
30 35
31 void debugDump(); 36 void debugDump();
32 37
@@ -34,9 +39,15 @@ private:
34 typedef std::map<std::string, Target *> TargetMap; 39 typedef std::map<std::string, Target *> TargetMap;
35 typedef std::list<std::string> StringList; 40 typedef std::list<std::string> StringList;
36 typedef std::map<std::string, StringList> ReqMap; 41 typedef std::map<std::string, StringList> ReqMap;
42 typedef std::map<std::string, std::string> VarMap;
43 typedef std::map<std::string, VarMap> ContextMap;
44 typedef std::map<std::string, Rule *> RuleMap;
37 45
38 TargetMap mTarget; 46 TargetMap mTarget;
39 ReqMap mRequires; 47 ReqMap mRequires;
48 VarMap mVars;
49 ContextMap mContVars;
50 RuleMap mRule;
40 51
41 //std::map<std::string, Rule *> mRule; 52 //std::map<std::string, Rule *> mRule;
42 //Action *pActDefault; 53 //Action *pActDefault;
diff --git a/src/builder.cpp b/src/builder.cpp
index 4d377a8..1e916ab 100644
--- a/src/builder.cpp
+++ b/src/builder.cpp
@@ -134,7 +134,14 @@ void Builder::addListFunc()
134 134
135void Builder::filterList() 135void Builder::filterList()
136{ 136{
137 printf("Filters aren't done yet.\n"); 137 StringList lTmp2;
138 StringList lIn = buildToStringList( lTmp, StringList() );
139 pTmpFunc->execute( lIn, lTmp2 );
140 lTmp.clear();
141 for( StringList::iterator i = lTmp2.begin(); i != lTmp2.end(); i++ )
142 {
143 lTmp.push_back( BuildListItem( *i, NULL ) );
144 }
138} 145}
139 146
140StringList Builder::buildToStringList( const BuildList &lSrc, const StringList &lIn ) 147StringList Builder::buildToStringList( const BuildList &lSrc, const StringList &lIn )
@@ -353,6 +360,21 @@ Build *Builder::genBuild()
353{ 360{
354 Build *bld = new Build; 361 Build *bld = new Build;
355 362
363 for( SetVarList::iterator i = lGlobalVars.begin();
364 i != lGlobalVars.end(); i++ )
365 {
366 switch( (*i).third )
367 {
368 case setSet:
369 bld->set( "", (*i).first, (*i).second );
370 break;
371
372 case setAdd:
373 bld->setAdd( "", (*i).first, (*i).second );
374 break;
375 }
376 }
377
356 for( TargetTmpList::iterator i = lTargetTmp.begin(); 378 for( TargetTmpList::iterator i = lTargetTmp.begin();
357 i != lTargetTmp.end(); i++ ) 379 i != lTargetTmp.end(); i++ )
358 { 380 {
@@ -388,6 +410,20 @@ Build *Builder::genBuild()
388 { 410 {
389 bld->addRequires( (*j), (*k) ); 411 bld->addRequires( (*j), (*k) );
390 } 412 }
413 for( SetVarList::iterator k = (*i).second.lVar.begin();
414 k != (*i).second.lVar.end(); k++ )
415 {
416 switch( (*k).third )
417 {
418 case setSet:
419 bld->set( *j, (*k).first, (*k).second );
420 break;
421
422 case setAdd:
423 bld->setAdd( *j, (*k).first, (*k).second );
424 break;
425 }
426 }
391 } 427 }
392 } 428 }
393 429
diff --git a/src/builder.h b/src/builder.h
index 8d72627..367769f 100644
--- a/src/builder.h
+++ b/src/builder.h
@@ -20,6 +20,8 @@ class TargetFactory;
20YY_DECL; 20YY_DECL;
21 21
22typedef std::list<std::string> StringList; 22typedef std::list<std::string> StringList;
23typedef std::list<Function *> FunctionList;
24typedef std::list<Perform *> PerformList;
23 25
24template<class tx, class ty, class tz> 26template<class tx, class ty, class tz>
25class Triplet 27class Triplet
@@ -137,14 +139,14 @@ private: // Rule variables
137 Function *pMatches; 139 Function *pMatches;
138 BuildList lProduces; 140 BuildList lProduces;
139 BuildList lRequires; 141 BuildList lRequires;
140 std::list<Function *> lFilter; 142 FunctionList lFilter;
141 std::list<Perform *> lPerform; 143 PerformList lPerform;
142 }; 144 };
143 145
144 typedef std::list<RuleInfo> RuleTmpList; 146 typedef std::list<RuleInfo> RuleTmpList;
145 RuleTmpList lRuleTmp; 147 RuleTmpList lRuleTmp;
146 148
147public: // Functions for dealing with actions 149public: // Action functions
148 void addAction(); 150 void addAction();
149 void addAction( const char *sName ); 151 void addAction( const char *sName );
150 void addCommand( int nType ); 152 void addCommand( int nType );
diff --git a/src/function.h b/src/function.h
index 1a71f8a..0e8f49e 100644
--- a/src/function.h
+++ b/src/function.h
@@ -13,7 +13,7 @@ public:
13 void addParam( const char *str ); 13 void addParam( const char *str );
14 virtual void execute( const StringList &lInput, StringList &lOutput )=0; 14 virtual void execute( const StringList &lInput, StringList &lOutput )=0;
15 15
16private: 16protected:
17 StringList lParams; 17 StringList lParams;
18 18
19}; 19};
diff --git a/src/functionfilesin.cpp b/src/functionfilesin.cpp
index 0d65c13..3e1233a 100644
--- a/src/functionfilesin.cpp
+++ b/src/functionfilesin.cpp
@@ -1,5 +1,8 @@
1#include <dirent.h>
2
1#include "functionfilesin.h" 3#include "functionfilesin.h"
2#include "plugger.h" 4#include "plugger.h"
5#include "build.h"
3 6
4PluginInterface2(filesIn, FunctionFilesIn, Function, "Mike Buland", 0, 1 ); 7PluginInterface2(filesIn, FunctionFilesIn, Function, "Mike Buland", 0, 1 );
5 8
@@ -13,5 +16,25 @@ FunctionFilesIn::~FunctionFilesIn()
13 16
14void FunctionFilesIn::execute( const StringList &lInput, StringList &lOutput ) 17void FunctionFilesIn::execute( const StringList &lInput, StringList &lOutput )
15{ 18{
19 DIR *d = opendir( lParams.front().c_str() );
20 if( d == NULL )
21 throw BuildException(
22 "Can't open directory %s.",
23 lParams.front().c_str()
24 );
25
26 struct dirent *e;
27
28 std::string prefix = lParams.front() + "/";
29
30 while( (e = readdir( d )) )
31 {
32 if( e->d_type == DT_REG )
33 {
34 lOutput.push_back( prefix + e->d_name );
35 }
36 }
37
38 closedir( d );
16} 39}
17 40
diff --git a/src/functionregexp.cpp b/src/functionregexp.cpp
index 462e93c..d1491e6 100644
--- a/src/functionregexp.cpp
+++ b/src/functionregexp.cpp
@@ -1,5 +1,6 @@
1#include "functionregexp.h" 1#include "functionregexp.h"
2#include "plugger.h" 2#include "plugger.h"
3#include "regexp.h"
3 4
4PluginInterface2(regexp, FunctionRegexp, Function, "Mike Buland", 0, 1 ); 5PluginInterface2(regexp, FunctionRegexp, Function, "Mike Buland", 0, 1 );
5 6
@@ -13,5 +14,21 @@ FunctionRegexp::~FunctionRegexp()
13 14
14void FunctionRegexp::execute( const StringList &lInput, StringList &lOutput ) 15void FunctionRegexp::execute( const StringList &lInput, StringList &lOutput )
15{ 16{
17 if( lParams.size() == 1 )
18 {
19 RegExp re( lParams.front().c_str() );
20
21 for( StringList::const_iterator i = lInput.begin();
22 i != lInput.end(); i++ )
23 {
24 if( re.execute( (*i).c_str() ) )
25 {
26 lOutput.push_back( *i );
27 }
28 }
29 }
30 else
31 {
32 }
16} 33}
17 34
diff --git a/src/regexp.cpp b/src/regexp.cpp
new file mode 100644
index 0000000..f79be97
--- /dev/null
+++ b/src/regexp.cpp
@@ -0,0 +1,78 @@
1#include "regexp.h"
2#include "build.h" // For BuildException
3#include "staticstring.h"
4
5RegExp::RegExp() :
6 bCompiled( false ),
7 aSubStr( NULL )
8{
9}
10
11RegExp::RegExp( const char *sSrc ) :
12 bCompiled( false ),
13 aSubStr( NULL )
14{
15 compile( sSrc );
16}
17
18RegExp::~RegExp()
19{
20 if( bCompiled )
21 {
22 regfree( &re );
23 delete[] aSubStr;
24 }
25}
26
27void RegExp::compile( const char *sSrc )
28{
29 if( bCompiled )
30 {
31 regfree( &re );
32 delete[] aSubStr;
33 bCompiled = false;
34 }
35
36 int nErr = regcomp( &re, sSrc, REG_EXTENDED|REG_NEWLINE );
37 if( nErr )
38 {
39 size_t length = regerror( nErr, &re, NULL, 0 );
40 char *buffer = new char[length];
41 (void) regerror( nErr, &re, buffer, length );
42 StaticString s( buffer );
43 delete[] buffer;
44 throw BuildException( s.getString() );
45 }
46 bCompiled = true;
47 this->sSrc = sSrc;
48
49 nSubStr = re.re_nsub+1;
50 aSubStr = new regmatch_t[nSubStr];
51}
52
53int RegExp::getNumSubStrings()
54{
55 return nSubStr;
56}
57
58bool RegExp::execute( const char *sSrc )
59{
60 sTest = sSrc;
61 if( regexec( &re, sSrc, nSubStr, aSubStr, 0 ) )
62 return false;
63 return true;
64}
65
66std::pair<int,int> RegExp::getSubStringRange( int nIndex )
67{
68 return std::pair<int,int>( aSubStr[nIndex].rm_so, aSubStr[nIndex].rm_eo );
69}
70
71std::string RegExp::getSubString( int nIndex )
72{
73 return std::string(
74 sTest.getString()+aSubStr[nIndex].rm_so,
75 aSubStr[nIndex].rm_eo - aSubStr[nIndex].rm_so
76 );
77}
78
diff --git a/src/regexp.h b/src/regexp.h
new file mode 100644
index 0000000..96f3747
--- /dev/null
+++ b/src/regexp.h
@@ -0,0 +1,36 @@
1#ifndef REG_EXP_H
2#define REG_EXP_H
3
4#include <string>
5#include <stdint.h>
6#include <regex.h>
7#include <utility>
8#include "staticstring.h"
9
10class RegExp
11{
12public:
13 RegExp();
14 RegExp( const char *sSrc );
15 virtual ~RegExp();
16
17 void compile( const char *sSrc );
18 int getNumSubStrings();
19 bool execute( const char *sSrc );
20 std::pair<int,int> getSubStringRange( int nIndex );
21 std::string getSubString( int nIndex );
22 const char *getSource()
23 {
24 return sSrc;
25 }
26
27private:
28 StaticString sSrc;
29 StaticString sTest;
30 regex_t re;
31 bool bCompiled;
32 int nSubStr;
33 regmatch_t *aSubStr;
34};
35
36#endif
diff --git a/src/rule.h b/src/rule.h
index 065ab9e..ff251ca 100644
--- a/src/rule.h
+++ b/src/rule.h
@@ -2,7 +2,14 @@
2#define RULE_H 2#define RULE_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include <string>
6#include <list>
5 7
8class Function;
9class Perform;
10
11typedef std::list<Function *> FunctionList;
12typedef std::list<Perform *> PerformList;
6 13
7class Rule 14class Rule
8{ 15{
@@ -10,8 +17,30 @@ public:
10 Rule(); 17 Rule();
11 virtual ~Rule(); 18 virtual ~Rule();
12 19
13private: 20 std::string getName()
21 {
22 return sName;
23 }
24
25 void setName( const std::string &sName )
26 {
27 this->sName = sName;
28 }
14 29
30 FunctionList &getFunctionList()
31 {
32 return lFilter;
33 }
34
35 PerformList &getPerformList()
36 {
37 return lPerform;
38 }
39
40private:
41 std::string sName;
42 FunctionList lFilter;
43 PerformList lPerform;
15}; 44};
16 45
17#endif 46#endif