From afd6d53eb6b3f169fa50cea360b982b60e589e6f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 12 Sep 2006 00:56:51 +0000 Subject: Added more goo, it may be good goo. --- build.conf | 2 +- src/build.h | 5 +++++ src/buildparser.cpp | 35 ++++++++++++++++++++++++++++++----- src/buildparser.h | 5 ++++- src/functiondirectoriesin.cpp | 22 ++++++++++++++++++++++ src/functionfactory.cpp | 2 ++ src/functiontargets.cpp | 35 +++++++++++++++++++++++++++++++++++ src/functiontargets.h | 21 +++++++++++++++++++++ 8 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 src/functiontargets.cpp create mode 100644 src/functiontargets.h diff --git a/build.conf b/build.conf index 8f06532..43f176d 100644 --- a/build.conf +++ b/build.conf @@ -1,6 +1,6 @@ # build.conf for build, kind of whacky, eh? -default action: check "build" +default action: check targets() "clean" action: clean "build" "rebuild" action: clean "build", check "build" diff --git a/src/build.h b/src/build.h index 31c8bde..a35b8e2 100644 --- a/src/build.h +++ b/src/build.h @@ -61,6 +61,11 @@ public: return pView; } + TargetMap &getTargetMap() + { + return mTarget; + } + private: TargetMap mTarget; ReqMap mRequires; diff --git a/src/buildparser.cpp b/src/buildparser.cpp index 6c3337f..04147d8 100644 --- a/src/buildparser.cpp +++ b/src/buildparser.cpp @@ -129,7 +129,7 @@ void BuildParser::filterList() } } -StringList BuildParser::buildToStringList( const BuildList &lSrc, const StringList &lIn ) +StringList BuildParser::buildToStringList( const BuildList &lSrc, const StringList &lIn, Build *pPass ) { StringList lOut; @@ -137,7 +137,28 @@ StringList BuildParser::buildToStringList( const BuildList &lSrc, const StringLi { if( (*i).second ) { - (*i).second->execute( NULL, lIn, lOut ); + (*i).second->execute( pPass, lIn, lOut ); + } + else + { + lOut.push_back( (*i).first ); + } + } + + return lOut; +} + +StringList BuildParser::buildToStringListDup( const BuildList &lSrc, const StringList &lIn, Build &bld, const std::string &sCont, VarMap *mExtra, Build *pPass ) +{ + StringList lOut; + + for( BuildList::const_iterator i = lSrc.begin(); i != lSrc.end(); i++ ) + { + if( (*i).second ) + { + Function *pTmp = (*i).second->duplicate( bld, sCont, mExtra ); + pTmp->execute( pPass, lIn, lOut ); + delete pTmp; } else { @@ -384,8 +405,12 @@ Build *BuildParser::genBuild() pTarget->setName( *j ); pTarget->setRule( (*i).second.sRule ); - StringList lInputs = buildToStringList( - (*i).second.lInput, StringList() + VarMap mExtra; + mExtra["target"] = (*j); + + StringList lInputs = buildToStringListDup( + (*i).second.lInput, StringList(), + *bld, *j, &mExtra ); pTarget->getInput().insert( pTarget->getInput().end(), @@ -480,7 +505,7 @@ Build *BuildParser::genBuild() j != (*i).second.end(); j++ ) { StringList lWhat = buildToStringList( - (*j).second, StringList() + (*j).second, StringList(), bld ); for( StringList::iterator k = lWhat.begin(); diff --git a/src/buildparser.h b/src/buildparser.h index dda2d80..3c79a5b 100644 --- a/src/buildparser.h +++ b/src/buildparser.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "build.tab.h" #include "parser.h" @@ -23,6 +24,7 @@ YY_DECL; typedef std::list StringList; typedef std::list FunctionList; typedef std::list PerformList; +typedef std::map VarMap; template class Triplet @@ -115,7 +117,8 @@ public: // List functions void addListFunc(); void filterList(); - StringList buildToStringList( const BuildList &lSrc, const StringList &lIn ); + StringList buildToStringList( const BuildList &lSrc, const StringList &lIn, Build *pPass=NULL ); + StringList buildToStringListDup( const BuildList &lSrc, const StringList &lIn, Build &bld, const std::string &sCont, VarMap *mExtra, Build *pPass=NULL ); private: // List variables BuildList lTmp; diff --git a/src/functiondirectoriesin.cpp b/src/functiondirectoriesin.cpp index 0e90dbc..105e98d 100644 --- a/src/functiondirectoriesin.cpp +++ b/src/functiondirectoriesin.cpp @@ -1,3 +1,5 @@ +#include + #include "functiondirectoriesin.h" #include "plugger.h" @@ -13,6 +15,26 @@ FunctionDirectoriesIn::~FunctionDirectoriesIn() void FunctionDirectoriesIn::execute( Build *bld, const StringList &lInput, StringList &lOutput ) { + DIR *d = opendir( lParams.front().c_str() ); + if( d == NULL ) + throw BuildException( + "Can't open directory %s.", + lParams.front().c_str() + ); + + struct dirent *e; + + //std::string prefix = lParams.front() + "/"; + + while( (e = readdir( d )) ) + { + if( e->d_type == DT_DIR ) + { + lOutput.push_back( e->d_name ); + } + } + + closedir( d ); } Function *FunctionDirectoriesIn::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) diff --git a/src/functionfactory.cpp b/src/functionfactory.cpp index b78cfcb..4a2cd15 100644 --- a/src/functionfactory.cpp +++ b/src/functionfactory.cpp @@ -5,6 +5,7 @@ extern struct PluginInfo filesIn; extern struct PluginInfo regexp; extern struct PluginInfo toString; extern struct PluginInfo commandToList; +extern struct PluginInfo targets; FunctionFactory::FunctionFactory() { @@ -13,6 +14,7 @@ FunctionFactory::FunctionFactory() registerBuiltinPlugin( ®exp ); registerBuiltinPlugin( &toString ); registerBuiltinPlugin( &commandToList ); + registerBuiltinPlugin( &targets ); } FunctionFactory::~FunctionFactory() diff --git a/src/functiontargets.cpp b/src/functiontargets.cpp new file mode 100644 index 0000000..253b585 --- /dev/null +++ b/src/functiontargets.cpp @@ -0,0 +1,35 @@ +#include "functiontargets.h" +#include "plugger.h" +#include "build.h" + +PluginInterface2(targets, FunctionTargets, Function, "Mike Buland", 0, 1 ); + +FunctionTargets::FunctionTargets() +{ +} + +FunctionTargets::~FunctionTargets() +{ +} + +void FunctionTargets::execute( Build *bld, const StringList &lInput, StringList &lOutput ) +{ + if( bld == NULL ) + { + throw BuildException("You cannot call targets() from anywhere, see the manual."); + } + + for( TargetMap::iterator i = bld->getTargetMap().begin(); + i != bld->getTargetMap().end(); i++ ) + { + lOutput.push_back( (*i).first ); + } +} + +Function *FunctionTargets::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +{ + Function *pRet = new FunctionTargets(); + pRet->copyData( this, bld, cont, mExtra ); + return pRet; +} + diff --git a/src/functiontargets.h b/src/functiontargets.h new file mode 100644 index 0000000..8d3a0ed --- /dev/null +++ b/src/functiontargets.h @@ -0,0 +1,21 @@ +#ifndef FUNCTION_TARGETS_H +#define FUNCTION_TARGETS_H + +#include + +#include "function.h" + +class FunctionTargets : public Function +{ +public: + FunctionTargets(); + virtual ~FunctionTargets(); + + virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); + virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); + +private: + +}; + +#endif -- cgit v1.2.3