From df5286fe3bca619beb4771da1ffa8ace9613e9e5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 18 Aug 2006 17:21:02 +0000 Subject: Gutted, deleted almost all the source, too many changes to keep it around, we'll see what happens next. --- build.conf | 47 +-- src/action.cpp | 63 ---- src/action.h | 45 --- src/build.l | 32 +- src/build.y | 285 +++++------------ src/builder.cpp | 825 -------------------------------------------------- src/builder.h | 196 ------------ src/cache.cpp | 149 --------- src/cache.h | 33 -- src/command.cpp | 34 --- src/command.h | 42 --- src/filetarget.cpp | 178 ----------- src/filetarget.h | 32 -- src/main.cpp | 2 +- src/perform.cpp | 11 - src/perform.h | 25 -- src/performcmd.cpp | 25 -- src/performcmd.h | 21 -- src/regexp.cpp | 78 ----- src/regexp.h | 36 --- src/rule.cpp | 195 ------------ src/rule.h | 63 ---- src/target.cpp | 46 --- src/target.h | 39 --- src/viewer.cpp | 62 ---- src/viewer.h | 33 -- src/viewermake.cpp | 62 ---- src/viewermake.h | 28 -- src/viewerpercent.cpp | 58 ---- src/viewerpercent.h | 30 -- src/viewerplain.cpp | 61 ---- src/viewerplain.h | 31 -- 32 files changed, 99 insertions(+), 2768 deletions(-) delete mode 100644 src/action.cpp delete mode 100644 src/action.h delete mode 100644 src/builder.cpp delete mode 100644 src/builder.h delete mode 100644 src/cache.cpp delete mode 100644 src/cache.h delete mode 100644 src/command.cpp delete mode 100644 src/command.h delete mode 100644 src/filetarget.cpp delete mode 100644 src/filetarget.h delete mode 100644 src/perform.cpp delete mode 100644 src/perform.h delete mode 100644 src/performcmd.cpp delete mode 100644 src/performcmd.h delete mode 100644 src/regexp.cpp delete mode 100644 src/regexp.h delete mode 100644 src/rule.cpp delete mode 100644 src/rule.h delete mode 100644 src/target.cpp delete mode 100644 src/target.h delete mode 100644 src/viewer.cpp delete mode 100644 src/viewer.h delete mode 100644 src/viewermake.cpp delete mode 100644 src/viewermake.h delete mode 100644 src/viewerpercent.cpp delete mode 100644 src/viewerpercent.h delete mode 100644 src/viewerplain.cpp delete mode 100644 src/viewerplain.h diff --git a/build.conf b/build.conf index dc847c8..8bbe679 100644 --- a/build.conf +++ b/build.conf @@ -1,27 +1,38 @@ -# This is a build file for build +default action: check "build", check "cleanup" -default action: check build -"clean" action: clean build +["build", "cleanup"]: + rule "exe", + target file, + set "CXXFLAGS" = "-lBob", + input [files("src/{target}"), files("src/shared")] -create file build from files in src using rule exe +[directoryName("src/tests")] filter /src\/tests/(.*)/tests\/{re:1}/: + rule "exe", + target prefix "tests/", + target file, + input files("src/tests/{target}") -set CXXFLAGS += "-ggdb" +[directories("src/tests"), aoeua]: + rule "exe", + target file, + input files("src/{target}") -set CXXFLAGS += "-Ilibbu++/src" -set LDFLAGS += "-Llibbu++ -lbu++" +"build": + input [files("src"), "boy.cpp"] filter /.*\.cpp$/, + input filter /.*\.cpp$/, + requires ["bob.cpp", "libbuild.a", "libbu++/libbu++.a"] -build requires "libbu++/libbu++.a" +"bob.cpp": set "aoeu" = "food", requires "bob.bastard" -/(.*)\.o$/ requires from command "g++ {CXXFLAGS} -M {re:1}.c*" +rule "exe" + matches /(.*)\.o$/, + input filter toSpaces(), + perform command("stuff") -rule exe matches all /(.*)\.o$/ perform command ... - "g++ {match} {LDFLAGS} -o {target}" +rule "cpp": + matches /(.*)\.cpp$/, + produces "{re:1}.o", + requires commandToList( make, "g++ -M {match}"), + perform command("stuff") -rule cpp matches one /(.*)\.c(pp)?$/ produces "{re:1}.o" perform command ... - "g++ {CXXFLAGS} -c -o {target} {match}" -rule bison matches one /(.*)\.y$/ produces "{re:1}.tab.c", "{re:1}.tab.h", ... - "{re:1}.output" perform command "bison -v -b{re:1} {match}" - -rule flex matches one /(.*)\.l$/ produces "{re:1}.yy.c" perform ... - command "flex --bison-bridge --bison-locations -o {target} {match}" diff --git a/src/action.cpp b/src/action.cpp deleted file mode 100644 index 51868eb..0000000 --- a/src/action.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "action.h" -#include "command.h" -#include "builder.h" - -Action::Action() : - bDefault( true ), - sName("") -{ -} - -Action::Action( const char *sName ) : - bDefault( false ), - sName( sName ) -{ -} - -Action::~Action() -{ -} - -void Action::add( Command *pCmd ) -{ - lCommand.push_back( pCmd ); -} - -void Action::add( int nType, const char *sCmd ) -{ - lRegExCommand.push_back( std::pair( nType, sCmd ) ); -} - -void Action::debug() -{ - if( bDefault ) - printf(" action default:\n"); - else - printf(" action \"%s\":\n", sName.getString() ); - - for( std::list::iterator i = lCommand.begin(); - i != lCommand.end(); i++ ) - { - (*i)->debug(); - } -} - -void Action::execute( Builder &bld ) -{ - for( std::list >::iterator i = - lRegExCommand.begin(); i != lRegExCommand.end(); i++ ) - { - std::list lTmp = bld.findTargets( (*i).second.c_str() ); - for( std::list::iterator j = lTmp.begin(); - j != lTmp.end(); j++ ) - { - add( new Command( (Command::CmdType)(*i).first, (*j).c_str() ) ); - } - } - for( std::list::iterator i = lCommand.begin(); - i != lCommand.end(); i++ ) - { - (*i)->execute( bld ); - } -} - diff --git a/src/action.h b/src/action.h deleted file mode 100644 index a5555a3..0000000 --- a/src/action.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef ACTION_H -#define ACTION_H - -#include -#include "staticstring.h" - -class Command; -class Builder; - -class Action -{ -public: - Action(); - Action( const char *sName ); - virtual ~Action(); - - void add( Command *pCmd ); - void add( int nType, const char *sCmd ); - - const char *getName() - { - return sName; - } - bool isDefault() - { - return bDefault; - } - - int getNumCommands() - { - return lCommand.size(); - } - - void debug(); - - void execute( class Builder &bld ); - -private: - bool bDefault; - StaticString sName; - std::list lCommand; - std::list > lRegExCommand; -}; - -#endif diff --git a/src/build.l b/src/build.l index 3107431..b174681 100644 --- a/src/build.l +++ b/src/build.l @@ -18,43 +18,24 @@ std::string strbuf; %} %% -[,:=] return yytext[0]; +[,:=[\]] return yytext[0]; "+=" return TOK_ADDSET; "default" return TOK_DEFAULT; "action" return TOK_ACTION; -"create" return TOK_CREATE; -"file" return TOK_FILE; -"from" return TOK_FROM; -"files" return TOK_FILES; -"in" return TOK_IN; -"using" return TOK_USING; "rule" return TOK_RULE; "requires" return TOK_REQUIRES; -"for" return TOK_FOR; "set" return TOK_SET; "matches" return TOK_MATCHES; -"matching" return TOK_MATCHING; -"all" return TOK_ALL; -"one" return TOK_ONE; "perform" return TOK_PERFORM; "produces" return TOK_PRODUCES; -"command" return TOK_COMMAND; "check" return TOK_CHECK; "clean" return TOK_CLEAN; -"directories" return TOK_DIRECTORIES; -"targets" return TOK_TARGETS; -"..."\n { - yylloc->last_line += 1; - yylloc->first_line = yylloc->last_line; - yylloc->first_column = yylloc->last_column = 0; -} \n+ { yylloc->last_line += yyleng; yylloc->first_line = yylloc->last_line; yylloc->first_column = yylloc->last_column = 0; - return TOK_EOL; } [ \t\r]* { @@ -77,17 +58,6 @@ std::string strbuf; "#".* /* single line comment */ -[^ \t\r\n\'\":+=,/][^ \t\r\n\'\":+=,]* { - yylval->strval = stringdup( yytext ); - return STRING; -} - -[^ \t\r\n\'\":+=,/][^ \t\r\n\'\"+=,]+[^ \t\r\n\'\":+=,] { - yylval->strval = stringdup( yytext ); - return STRING; -} - - \" { BEGIN( strdq ); strbuf = ""; diff --git a/src/build.y b/src/build.y index d1f3945..a624418 100644 --- a/src/build.y +++ b/src/build.y @@ -20,268 +20,119 @@ void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ); %error-verbose %union { char *strval; + int tval; } %token STRING "string literal" %token REGEXP "regular expression" +%token TARGETTYPE "target type" +%token FUNCTION "function name" %token TOK_ADDSET "+=" %token TOK_DEFAULT "default" %token TOK_ACTION "action" -%token TOK_CREATE "create" -%token TOK_FILE "file" -%token TOK_FROM "from" -%token TOK_FILES "files" -%token TOK_IN "in" -%token TOK_USING "using" +%token TOK_CHECK "check" +%token TOK_CLEAN "clean" %token TOK_RULE "rule" -%token TOK_REQUIRES "requires" -%token TOK_FOR "for" +%token TOK_TARGET "target" %token TOK_SET "set" +%token TOK_INPUT "input" +%token TOK_FILTER "filter" +%token TOK_PREFIX "prefix" +%token TOK_REQUIRES "requires" %token TOK_MATCHES "matches" -%token TOK_MATCHING "matching" -%token TOK_ALL "all" -%token TOK_ONE "one" %token TOK_PERFORM "perform" %token TOK_PRODUCES "produces" -%token TOK_COMMAND "command" -%token TOK_CHECK "check" -%token TOK_CLEAN "clean" -%token TOK_DIRECTORIES "directories" -%token TOK_TARGETS "targets" -%token TOK_EOL "end of line" + %token ',' ':' '=' %destructor { delete[] $$; } STRING %% +// General input format input: - | input fullline + | input rule + | input action + | input target ; -fullline: TOK_EOL - | line TOK_EOL - ; - -line: TOK_DEFAULT TOK_ACTION ':' - { - bld.add( new Action() ); - } - actionlst - | STRING TOK_ACTION ':' - { - bld.add( new Action( $1 ) ); - } - actionlst - | TOK_FOR fortypes TOK_MATCHING REGEXP - { - bld.setFilter( $4 ); - } - augments - { - bld.endList(); - } - listcmds - | STRING TOK_REQUIRES - { - bld.setTmp( $1 ); - bld.requiresRegexp( false ); - } - reqcompletion - | REGEXP TOK_REQUIRES - { - bld.setTmp( $1 ); - bld.requiresRegexp( true ); - } - reqcompletion - | listcmds - | TOK_FOR STRING - { - bld.startList( STRING ); - bld.addListItem( $2 ); - } - listcmds - { - - } - | rule +// Rule interpretation +rule: TOK_RULE STRING ':' rulecmds ; -fortypes: TOK_DIRECTORIES - { - bld.startList( TOK_DIRECTORIES ); - } - | TOK_TARGETS - { - bld.startList( TOK_TARGETS ); - } - | TOK_FILES - { - bld.startList( TOK_FILES ); - } - ; - -augments: - | TOK_IN STRING - { - bld.augmentList( $2 ); - } +rulecmds: rulecmd + | rulecmds ',' rulecmd ; -reqcompletion: reqlst - | TOK_FROM TOK_COMMAND STRING - { - bld.requiresFromCommand( bld.getTmp(), $3 ); - } - ; +rulecmd: TOK_MATCHES REGEXP + | TOK_PRODUCES STRING + | TOK_REQUIRES list + | TOK_INPUT TOK_FILTER REGEXP + | TOK_INPUT TOK_FILTER func + | TOK_PERFORM func + ; -reqlst: STRING - { - bld.requires( bld.getTmp(), $1 ); - } - | reqlst ',' STRING - { - bld.requires( bld.getTmp(), $3 ); - } +// Action interpretation +action: TOK_DEFAULT TOK_ACTION ':' actioncmds + | STRING TOK_ACTION ':' actioncmds ; -listcmds: TOK_SET setexpr - | TOK_CREATE createwhat TOK_FROM createfrom TOK_USING createusing - { - bld.endTarget(); - } - ; - -createwhat: TOK_FILE STRING - { - bld.addTarget( TOK_FILE, $2 ); - } +actioncmds: actioncmd + | actioncmds ',' actioncmd ; -createfrom: TOK_FILES TOK_IN - { - bld.setTargetInputType( TOK_FILES ); - } - createfromdirlst - ; - -createfromdirlst: createfromdir - | createfromdirlst ',' createfromdir - ; +actioncmd: actioncmdtype list + ; -createfromdir: STRING - { - bld.addTargetInput( $1 ); - } +actioncmdtype: TOK_CHECK + | TOK_CLEAN ; -createusing: TOK_RULE STRING - { - bld.setTargetRule( $2 ); - } - ; - -actionlst: action - | actionlst ',' action - ; +// Target interpretation -action: TOK_CHECK STRING - { - bld.add( new Command( Command::cmdCheck, $2 ) ); - } - | TOK_CHECK REGEXP - { - bld.addRegexCommand( Command::cmdCheck, $2 ); - } - | TOK_CLEAN STRING - { - bld.add( new Command( Command::cmdClean, $2 ) ); - } - | TOK_CLEAN REGEXP - { - bld.addRegexCommand( Command::cmdClean, $2 ); - } +target: list ':' targetcmds ; -setexpr: STRING '=' STRING - { - bld.varSet( $1, $3 ); - } - | STRING TOK_ADDSET STRING - { - bld.varAddSet( $1, $3 ); - } - | STRING '=' TOK_FROM TOK_COMMAND STRING - { - bld.varSet( $1, bld.cmdToString( $5 ).c_str() ); - } - | STRING TOK_ADDSET TOK_FROM TOK_COMMAND STRING - { - bld.varSet( $1, bld.cmdToString( $5 ).c_str() ); - } - ; +targetcmds: targetcmd + | targetcmds ',' targetcmd + ; + +targetcmd: TOK_RULE STRING + | TOK_TARGET TOK_PREFIX STRING + | TOK_TARGET TARGETTYPE + | TOK_INPUT list + | TOK_REQUIRES list + ; -rule: TOK_RULE STRING - { - bld.add( new Rule( $2 ) ); - } - rulesublst TOK_PERFORM rulecompletion +// list goo + +list: listitem listfilter + | '[' listitems ']' listfilter ; -rulesublst: rulesub - | rulesublst rulesub +listfilter: + | TOK_FILTER REGEXP + | TOK_FILTER func ; -rulesub: TOK_MATCHES rulematches - | TOK_PRODUCES produceslst - ; +listitems: listitem + | listitems ',' listitem + ; -produceslst: STRING - { - bld.lastRule()->addProduces( $1 ); - } - | produceslst ',' STRING - { - bld.lastRule()->addProduces( $3 ); - } - ; +listitem: STRING + | func + ; -rulematches: TOK_ALL REGEXP - { - try - { - bld.lastRule()->setMatches( Rule::matchAll, $2 ); - } - catch( BuildException &e ) - { - std::string s("RegExp compile error: "); - s += e.what(); - yyerror( &yyloc, bld, s.c_str() ); - return 1; - } - } - | TOK_ONE REGEXP - { - try - { - bld.lastRule()->setMatches( Rule::matchOne, $2 ); - } - catch( BuildException &e ) - { - std::string s("RegExp compile error: "); - s += e.what(); - yyerror( &yyloc, bld, s.c_str() ); - return 1; - } - } - ; +// Function -rulecompletion: TOK_COMMAND STRING - { - bld.lastRule()->setPerforms( Rule::perfCommand, $2 ); - } - ; +func: FUNCTION '(' funcparams ')' + ; + +funcparams: + | STRING + | funcparams ',' STRING + ; %% diff --git a/src/builder.cpp b/src/builder.cpp deleted file mode 100644 index 8c3bbbb..0000000 --- a/src/builder.cpp +++ /dev/null @@ -1,825 +0,0 @@ -#include -#include -#include -#include - -#include "builder.h" -#include "action.h" -#include "command.h" -#include "target.h" -#include "filetarget.h" -#include "build.tab.h" -#include "rule.h" -#include "viewer.h" -#include "cache.h" -#include "serializerbinary.h" - -subExceptionDef( BuildException ) - -Builder::Builder( Viewer &rView ) : - pDefaultAction( NULL ), - pLastAddedAction( NULL ), - sTmp(""), - sContext(""), - rView( rView ), - bUsingList( false ) -{ -} - -Builder::~Builder() -{ - if( sCacheFile.getLength() > 0 ) - { - try - { - SerializerBinary ar( sCacheFile, Serializer::save ); - - ar << cRequires; - } - catch( ExceptionBase &e ) - { - } - } -} - -void yyparse( Builder &bld ); - -void Builder::load( const char *sFN ) -{ - file = sFN; - - scanBegin(); - yyparse( *this ); - scanEnd(); -} - -void Builder::build( const char *sAct ) -{ - Action *pAct; - if( sAct == NULL ) - pAct = pDefaultAction; - else - { - if( mAction.find( sAct ) == mAction.end() ) - throw BuildException("No action matches '%s'.", sAct ); - pAct = mAction[sAct]; - } - - rView.beginAction( sAct, pAct->getNumCommands() ); - - pAct->execute( *this ); - - rView.endAction(); -} - -void Builder::setCache( const std::string &sFile ) -{ - sCacheFile = sFile.c_str(); - - try - { - SerializerBinary ar( sCacheFile, Serializer::load ); - - ar >> cRequires; - } - catch( ExceptionBase &e ) - { - } -} - -void Builder::execute( Action *pAct ) -{ - pAct->execute( *this ); -} - -void Builder::add( Action *pAct ) -{ - if( pAct->isDefault() ) - { - if( pDefaultAction ) - throw BuildException("There's already a default exception"); - pDefaultAction = pAct; - } - else - { - mAction[pAct->getName()] = pAct; - } - pLastAddedAction = pAct; -} - -void Builder::add( Command *pCmd ) -{ - if( pLastAddedAction ) - { - pLastAddedAction->add( pCmd ); - } -} - -void Builder::addRegexCommand( int nType, const char *sReg ) -{ - if( pLastAddedAction ) - { - pLastAddedAction->add( nType, sReg ); - } -} - -void Builder::add( Rule *pRule ) -{ - pLastAddedRule = pRule; - mRule[pRule->getName()] = pRule; -} - -void Builder::add( Target *pTarg ) -{ - pLastAddedTarget = pTarg; - mTarget[pTarg->getName()] = pTarg; -} - -void Builder::addTarget( int tokType, const char *sName ) -{ - nTargetType = tokType; - sTargetName = sName; -} - -void Builder::setTargetInputType( int tokType ) -{ - nTargetInputType = tokType; -} - -void Builder::addTargetInput( const char *sInput ) -{ - lsTargetInput.push_back( sInput ); -} - -void Builder::setTargetRule( const char *sRule ) -{ - sTargetRule = sRule; -} - -void Builder::endTarget() -{ - if( bUsingList == false ) - { - switch( nTargetType ) - { - case TOK_FILE: - add( new FileTarget( sTargetName.c_str() ) ); - switch( nTargetInputType ) - { - case TOK_FILES: - for( std::list::iterator - i = lsTargetInput.begin(); - i != lsTargetInput.end(); i++ ) - { - ((FileTarget *)lastTarget())->addInputDir( - (*i).c_str() - ); - } - break; - } - lastTarget()->setRule( sTargetRule.c_str() ); - break; - } - } - else - { - switch( nTargetType ) - { - case TOK_FILE: - for( std::list > >::iterator j = lTok.begin(); j != lTok.end(); j++ ) - { - std::string sName = varRepl( sTargetName.c_str(), "", &(*j).second ); - add( new FileTarget( sName.c_str() ) ); - switch( nTargetInputType ) - { - case TOK_FILES: - for( std::list::iterator - i = lsTargetInput.begin(); - i != lsTargetInput.end(); i++ ) - { - std::string sInput = varRepl( - (*i).c_str(), "", - &(*j).second - ); - ((FileTarget *)lastTarget())->addInputDir( - sInput.c_str() - ); - } - break; - } - lastTarget()->setRule( sTargetRule.c_str() ); - } - break; - } - } - - clearList(); -} - -void Builder::debug() -{ - printf("Actions:\n"); - pDefaultAction->debug(); - for( std::map::iterator i = mAction.begin(); - i != mAction.end(); i++ ) - { - (*i).second->debug(); - } - - printf("Targets:\n"); - for( std::map::iterator i = mTarget.begin(); - i != mTarget.end(); i++ ) - { - (*i).second->debug(); - } - - printf("Rules:\n"); - for( std::map::iterator i = mRule.begin(); - i != mRule.end(); i++ ) - { - (*i).second->debug(); - } - - printf("Variables:\n"); - for( varmap::iterator i = mVar.begin(); i != mVar.end(); i++ ) - { - printf(" %s = \"%s\"\n", (*i).first.c_str(), (*i).second.c_str() ); - } - - printf("Variables (by context):\n"); - for( std::map::iterator j = mContVar.begin(); - j != mContVar.end(); j++ ) - { - printf(" %s:\n", (*j).first.c_str() ); - for( varmap::iterator i = (*j).second.begin(); - i != (*j).second.end(); i++ ) - { - printf(" %s = \"%s\"\n", - (*i).first.c_str(), (*i).second.c_str() ); - } - } - - printf("Dependancies:\n"); - for( std::map *>::iterator i = - mRequires.begin(); i != mRequires.end(); i++ ) - { - printf(" %s: ", (*i).first.c_str() ); - std::list *pList = (*i).second; - int i = 0; - for( std::list::iterator j = pList->begin(); - j != pList->end(); j++ ) - { - if( j != pList->begin() ) - printf(", "); - printf("%s", (*j).c_str() ); - if( i++ >= 3 ) - { - printf("..."); - break; - } - } - printf("\n"); - } -} - -void Builder::checkVar( const char *cont, const char *sName ) -{ - if( cont[0] != '\0' ) - { - varmap &mmVar = mContVar[cont]; - if( mmVar.find( sName ) == mmVar.end() ) - { - checkVar( "", sName ); - mmVar[sName] = mVar[sName]; - } - } - else - { - if( mVar.find( sName ) == mVar.end() ) - { - char *env = getenv( sName ); - if( env ) - mVar[sName] = env; - else - mVar[sName] = ""; - } - } -} - -void Builder::varSet( const char *sName, const char *sValue ) -{ - if( bUsingList ) - { - for( std::list > >::iterator i = lTok.begin(); i != lTok.end(); i++ ) - { - checkVar( (*i).first.c_str(), sName ); - - std::string newVal = varRepl( sValue, (*i).first.c_str(), &(*i).second ); - - mContVar[(*i).first.c_str()][sName] = newVal; - } - } - else - { - checkVar( sContext, sName ); - - std::string newVal = varRepl( sValue, sContext, NULL ); - - if( sContext[0] == '\0' ) - { - mVar[sName] = newVal; - } - else - { - mContVar[sContext.getString()][sName] = newVal; - } - } -} - -void Builder::varAddSet( const char *sName, const char *sValue ) -{ - checkVar( sContext, sName ); - - std::string newVal = varRepl( sValue, sContext, NULL ); - - if( sContext[0] == '\0' ) - { - std::string s = mVar[sName]; - s += " "; - s += newVal; - mVar[sName] = s; - } - else - { - std::string s = mContVar[sContext.getString()][sName]; - s += " "; - s += newVal; - mContVar[sContext.getString()][sName] = s; - } -} - -void Builder::processRequires( std::list &lInput ) -{ - // These are cheap and handy to have all the time - for( regreqlist::iterator i = lRequiresRegexp.begin(); - i != lRequiresRegexp.end(); i++ ) - { - RegExp *re = (*i).first; - for( std::list::iterator j = lInput.begin(); - j != lInput.end(); j++ ) - { - if( re->execute( (*j).c_str() ) ) - { - varmap *revars = regexVars( re ); - requiresNormal( - (*j).c_str(), - varRepl( - (*i).second.c_str(), - "", - revars - ).c_str() - ); - delete revars; - } - } - } - -} - -void Builder::genRequiresFor( const char *sName, time_t tNewTime ) -{ - Cache::Entry *ent = cRequires.get( sName ); - if( ent && tNewTime > 0 ) - { - if( ent->tCreated >= tNewTime ) - { - for( std::list::iterator i = ent->lData.begin(); - i != ent->lData.end(); i++ ) - { - requiresNormal( - sName, - (*i).c_str() - ); - } - - return; - } - } - - ent = new Cache::Entry; - ent->tCreated = tNewTime; - - for( regreqlist::iterator i = lRequiresRegexpCommand.begin(); - i != lRequiresRegexpCommand.end(); i++ ) - { - RegExp *re = (*i).first; - if( re->execute( sName ) ) - { - varmap *revars = regexVars( re ); - std::string s = varRepl( (*i).second.c_str(), "", revars ); - rView.beginExtraRequiresCheck( s.c_str() ); - rView.executeCmd( s.c_str() ); - FILE *fcmd = popen( s.c_str(), "r" ); - std::string rhs; - bool bHeader = true; - for(;;) - { - if( feof( fcmd ) ) - break; - int cc = fgetc( fcmd ); - if( cc == EOF ) - break; - unsigned char c = cc; - if( bHeader ) - { - if( c == ':' ) - bHeader = false; - } - else - { - if( c == ' ' || c == '\t' ) - { - if( rhs != "" ) - { - requiresNormal( - sName, - rhs.c_str() - ); - ent->lData.push_back( rhs ); - rhs = ""; - } - } - else - { - if( c == '\\' ) - c = fgetc( fcmd ); - if( c != '\n' ) - rhs += c; - } - } - } - if( rhs != "" ) - { - requiresNormal( - sName, - rhs.c_str() - ); - ent->lData.push_back( rhs ); - rhs = ""; - } - pclose( fcmd ); - delete revars; - rView.endExtraRequiresCheck(); - } - } - - cRequires.put( sName, ent ); -} - -std::map *Builder::regexVars( RegExp *re ) -{ - varmap *map = new varmap; - - int jmax = re->getNumSubStrings(); - for( int j = 0; j < jmax; j++ ) - { - char buf[8]; - sprintf( buf, "re:%d", j ); - (*map)[buf] = re->getSubString( j ); - } - - return map; -} - -void Builder::regexVars( RegExp *re, varmap &map ) -{ - int jmax = re->getNumSubStrings(); - for( int j = 0; j < jmax; j++ ) - { - char buf[8]; - sprintf( buf, "re:%d", j ); - map[buf] = re->getSubString( j ); - } -} - -void Builder::requires( const char *sBase, const char *sReq ) -{ - if( bReqRegexp ) - { - requiresRegexp( sBase, sReq ); - } - else - { - requiresNormal( sBase, sReq ); - } -} - -void Builder::requiresNormal( const char *sBase, const char *sReq ) -{ - std::list *pList = NULL; - if( mRequires.find(sBase) == mRequires.end() ) - { - pList = new std::list; - mRequires[sBase] = pList; - } - else - { - pList = mRequires[sBase]; - } - - pList->push_back( sReq ); -} - -void Builder::requiresRegexp( const char *sBase, const char *sReq ) -{ - lRequiresRegexp.push_back( - std::pair( - new RegExp( sBase ), - sReq - ) - ); -} - -void Builder::requiresFromCommand( const char *sBase, const char *sCmd ) -{ - lRequiresRegexpCommand.push_back( - std::pair( - new RegExp( sBase ), - sCmd - ) - ); -} - -void Builder::setContext( const char *sCont ) -{ - sContext = sCont; -} - -void Builder::setContext() -{ - setContext(""); -} - -bool Builder::hasVar( varmap *pMap, std::string &var ) -{ - if( pMap == NULL ) - return false; - if( pMap->find( var ) == pMap->end() ) - return false; - return true; -} - -std::string Builder::varRepl( const char *sSrc, const char *cont, varmap *mExtra ) -{ - varmap *mCont = NULL; - if( cont[0] != '\0' ) - { - if( mContVar.find( cont ) != mContVar.end() ) - mCont = &mContVar[cont]; - } - - std::string out; - std::string var; - bool bVar = false; - - for( const char *s = sSrc; *s; s++ ) - { - if( *s == '{' ) - { - bVar = true; - continue; - } - else if( *s == '}' && bVar ) - { - if( hasVar( mExtra, var ) ) - { - out += (*mExtra)[var]; - } - else if( hasVar( mCont, var ) ) - { - out += (*mCont)[var]; - } - else if( hasVar( &mVar, var ) ) - { - out += mVar[var]; - } - var = ""; - bVar = false; - continue; - } - - if( bVar == true ) - { - var += *s; - } - else - { - out += *s; - } - } - - return out; -} - -Rule *Builder::getRule( const char *sName ) -{ - if( mRule.find( sName ) != mRule.end() ) - return mRule[sName]; - - throw BuildException("No rule named %s registered.", sName ); - return NULL; -} - -std::list Builder::findRuleChain( Rule *pRule ) -{ - std::list ret; - - for( std::map::iterator i = mRule.begin(); - i != mRule.end(); i++ ) - { - if( pRule == (*i).second ) - continue; - - if( pRule->willChain( (*i).second ) ) - { - ret.push_back( (*i).second ); - } - } - - return ret; -} - -void cleanList( std::list &lst ) -{ - std::map m; - - for( std::list::iterator i = lst.begin(); i != lst.end(); i++ ) - { - if( m.find( *i ) == m.end() ) - m[ *i ] = true; - else - { - std::list::iterator j = i; - j--; - lst.erase( i ); - i = j; - } - } -} - -void Builder::error( const std::string &err ) -{ - throw BuildException( err.c_str() ); -} - -void Builder::error( YYLTYPE *locp, const std::string &err ) -{ - std::stringstream s; - s << file << ":" << locp->first_line << "." << locp->first_column; - if( locp->first_line != locp->last_line ) - s << "-" << locp->last_line << "." << locp->last_column; - else if( locp->first_column != locp->last_column ) - s << "-" << locp->last_column; - s << ": " << err; - throw BuildException( s.str().c_str() ); -} - -void Builder::startList( int tokType ) -{ - bUsingList = true; - lTok.clear(); - bTokFiltered = false; - nTokType = tokType; -} - -void Builder::setFilter( const char *sRegExp ) -{ - rTok.compile( sRegExp ); - bTokFiltered = true; -} - -void Builder::augmentList( const char *sFrom ) -{ - switch( nTokType ) - { - case TOK_DIRECTORIES: - { - DIR *dir = opendir( sFrom ); - if( dir == NULL ) - { - printf("dir: %s\n", sFrom ); - throw BuildException( strerror( errno ) ); - } - - std::string base; - base += sFrom; - base += "/"; - - struct dirent *de; - - while( (de = readdir( dir )) ) - { - if( de->d_type != DT_DIR ) - continue; - if( de->d_name[0] == '.' || de->d_name[0] == '\0' ) - continue; - - std::string s( base ); - s += de->d_name; - addListItem( s.c_str() ); - } - - closedir( dir ); - } - break; - - default: - break; - } -} - -void Builder::endList() -{ - switch( nTokType ) - { - case TOK_TARGETS: - for( std::map::iterator i = - mTarget.begin(); i != mTarget.end(); i++ ) - { - addListItem( (*i).first ); - } - break; - } -} - -void Builder::addListItem( const char *sItem ) -{ - std::map mVars; - mVars["match"] = sItem; - if( bTokFiltered ) - { - if( rTok.execute( sItem ) ) - { - regexVars( &rTok, mVars ); - } - else - { - return; - } - } - lTok.push_back( - std::pair >( - sItem, mVars - ) - ); -} - -void Builder::clearList() -{ - lTok.clear(); - lsTargetInput.clear(); - bUsingList = false; -} - -std::list Builder::findTargets( const char *sRegex ) -{ - RegExp r( sRegex ); - - std::list lTmp; - - for( std::map::iterator i = mTarget.begin(); - i != mTarget.end(); i++ ) - { - if( r.execute( (*i).first ) ) - { - lTmp.push_back( (*i).first ); - } - } - - return lTmp; -} - -std::string Builder::cmdToString( const char *sCmd ) -{ - std::string buf; - FILE *pr = popen( sCmd, "r" ); - if( pr == NULL ) - throw BuildException("Couldn't execute program \"%s\"", sCmd ); - - char cbuf[2048]; - - for(;;) - { - int nRead = fread( cbuf, 1, 2048, pr ); - for( int j = 0; j < nRead; j++ ) - if( cbuf[j] != '\n' && cbuf[j] != '\r' ) - buf.append( cbuf+j, 1 ); - if( feof( pr ) ) - break; - } - - pclose( pr ); - - return buf; -} - diff --git a/src/builder.h b/src/builder.h deleted file mode 100644 index c570dbb..0000000 --- a/src/builder.h +++ /dev/null @@ -1,196 +0,0 @@ -#ifndef BUILDER_H -#define BUILDER_H - -#include -#include -#include -#include "build.tab.h" -#include "exceptionbase.h" -#include "staticstring.h" -#include "regexp.h" -#include "cache.h" - -subExceptionDecl( BuildException ) - -class Builder; -class Action; -class Command; -class Rule; -class Target; -class Viewer; -class Cache; - -#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld ) -YY_DECL; - -class Builder -{ - struct ltstr - { - bool operator()(const char* s1, const char* s2) const - { - return strcmp(s1, s2) < 0; - } - }; - -public: - Builder( Viewer &rView ); - virtual ~Builder(); - - void load( const char *sFN ); - void build( const char *sAct=NULL ); - void execute( Action *pAct ); - - void error( YYLTYPE *locp, const std::string &m ); - void error( const std::string &m ); - - std::string file; - - Viewer &view() - { - return rView; - } - - void startList( int tokType ); - void setFilter( const char *sRegExp ); - void augmentList( const char *sFrom ); - void addListItem( const char *sItem ); - void clearList(); - void endList(); - - void addTarget( int tokType, const char *sName ); - void setTargetInputType( int tokType ); - void addTargetInput( const char *sInput ); - void setTargetRule( const char *sRule ); - void endTarget(); - - void setCache( const std::string &sFile ); - void add( Action *pAct ); - void add( Command *pCmd ); - void addRegexCommand( int nType, const char *sReg ); - void add( Rule *pRule ); - void add( Target *pTarg ); - void varSet( const char *sName, const char *sValue ); - void varAddSet( const char *sName, const char *sValue ); - Rule *getRule( const char *sName ); - std::list findRuleChain( Rule *pRule ); - void processRequires( std::list &lInput ); - void requires( const char *sBase, const char *sReq ); - void requiresFromCommand( const char *sBase, const char *sReq ); - void genRequiresFor( const char *sName, time_t tNewTime ); - std::list findTargets( const char *sRegex ); - void requiresRegexp( bool on ) - { - bReqRegexp = on; - } - bool isRequiresRegexp() - { - return bReqRegexp; - } - void setContext( const char *sCont ); - void setContext(); - - bool hasDefaultAction() - { - return pDefaultAction != NULL; - } - - void debug(); - - Rule *lastRule() - { - return pLastAddedRule; - } - - Target *lastTarget() - { - return pLastAddedTarget; - } - - void setTmp( const char *s ) - { - sTmp = s; - } - - const char *getTmp() - { - return sTmp; - } - - Target *getTarget( const char *sName ) - { - if( mTarget.find( sName ) == mTarget.end() ) - throw BuildException("Target %s not found.", sName ); - - return mTarget[sName]; - } - - std::list *getRequires( const char *sReq ) - { - if( mRequires.find(sReq) == mRequires.end() ) - return NULL; - return mRequires[sReq]; - } - - typedef std::map varmap; - varmap *regexVars( RegExp *re ); - void regexVars( RegExp *re, varmap &map ); - std::string varRepl( const char *sSrc, const char *cont, varmap *mExtra ); - - std::string cmdToString( const char *sCmd ); - -private: - void requiresNormal( const char *sBase, const char *sReq ); - void requiresRegexp( const char *sBase, const char *sReq ); - void checkVar( const char *cont, const char *sName ); - void scanBegin(); - void scanEnd(); - - bool hasVar( varmap *pMap, std::string &var ); - - Action *pDefaultAction; - Action *pLastAddedAction; - std::map mAction; - - Rule *pLastAddedRule; - std::map mRule; - - Target *pLastAddedTarget; - std::map mTarget; - - varmap mVar; - - std::map *> mRequires; - - typedef std::list > regreqlist; - regreqlist lRequiresRegexp; - regreqlist lRequiresRegexpCommand; - - std::map mContVar; - StaticString sContext; - - StaticString sTmp; - - bool bReqRegexp; - - Viewer &rView; - - StaticString sCacheFile; - class Cache cRequires; - - std::list > > lTok; - bool bTokFiltered; - int nTokType; - RegExp rTok; - - int nTargetType; - int nTargetInputType; - std::string sTargetName; - std::list lsTargetInput; - std::string sTargetRule; - bool bUsingList; -}; - -void cleanList( std::list &lst ); - -#endif diff --git a/src/cache.cpp b/src/cache.cpp deleted file mode 100644 index 10971b1..0000000 --- a/src/cache.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "cache.h" -#include "serializer.h" -#include "staticstring.h" - -Cache::Cache() -{ -} - -Cache::~Cache() -{ - for( std::map::iterator i = mCache.begin(); - i != mCache.end(); i++ ) - { - delete (*i).second; - } -} - -void Cache::serialize( class Serializer &ar ) -{ - if( ar.isLoading() ) - { - int sCache, sData, sIndex; - - ar >> sIndex; - StaticString *Index = new StaticString[sIndex]; - for( int i = 0; i < sIndex; i++ ) - { - ar >> Index[i]; - } - - ar >> sCache; - int nTmp; - for( int i = 0; i < sCache; i++ ) - { - Entry *e = new Entry; - ar >> e->tCreated; - ar >> sData; - std::list &lData = e->lData; - for( int j = 0; j < sData; j++ ) - { - ar >> nTmp; - lData.push_back( Index[nTmp].getString() ); - } - ar >> nTmp; - mCache[Index[nTmp].getString()] = e; - } - /* - int sCache, sData; - ar >> sCache; - std::string sTmp; - - for( int i = 0; i < sCache; i++ ) - { - Entry *e = new Entry; - ar >> e->tCreated; - ar >> sData; - std::list &lData = e->lData; - for( int j = 0; j < sData; j++ ) - { - ar >> sTmp; - lData.push_back( sTmp ); - } - ar >> sTmp; - mCache[sTmp] = e; - } - */ - } - else - { - std::map mIndex; - for( std::map::iterator i = mCache.begin(); - i != mCache.end(); i++ ) - { - mIndex[(*i).first] = 0; - std::list &lData = (*i).second->lData; - for( std::list::iterator j = lData.begin(); - j != lData.end(); j++ ) - { - mIndex[(*j)] = 0; - } - } - - ar << mIndex.size(); - int cnt = 0; - for( std::map::iterator i = mIndex.begin(); - i != mIndex.end(); i++ ) - { - (*i).second = cnt; - cnt++; - std::string s = ((*i).first); - ar << s; - } - - ar << mCache.size(); - for( std::map::iterator i = mCache.begin(); - i != mCache.end(); i++ ) - { - ar << (*i).second->tCreated; - std::list &lData = (*i).second->lData; - ar << lData.size(); - for( std::list::iterator j = lData.begin(); - j != lData.end(); j++ ) - { - ar << mIndex[(*j)]; - } - - ar << mIndex[(*i).first]; - } - - - /* - ar << mCache.size(); - for( std::map::iterator i = mCache.begin(); - i != mCache.end(); i++ ) - { - ar << (*i).second->tCreated; - std::list &lData = (*i).second->lData; - ar << lData.size(); - for( std::list::iterator j = lData.begin(); - j != lData.end(); j++ ) - { - ar << (*j); - } - - std::string str = (*i).first; - ar << str; - } - */ - } -} - -Cache::Entry *Cache::get( const std::string &id ) -{ - std::map::iterator i = mCache.find( id ); - if( i != mCache.end() ) - return (*i).second; - - return NULL; -} - -void Cache::put( const std::string &id, Entry *data ) -{ - std::map::iterator i = mCache.find( id ); - if( i != mCache.end() ) - delete (*i).second; - - mCache[id] = data; -} - diff --git a/src/cache.h b/src/cache.h deleted file mode 100644 index 944aa24..0000000 --- a/src/cache.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef CACHE_H -#define CACHE_H - -#include -#include -#include "serializable.h" -#include -#include -#include - -class Cache : public Serializable -{ -public: - Cache(); - virtual ~Cache(); - - virtual void serialize( class Serializer &ar ); - - class Entry - { - public: - int tCreated; - std::list lData; - }; - - Entry *get( const std::string &id ); - void put( const std::string &id, Entry *data ); - -private: - std::map mCache; -}; - -#endif diff --git a/src/command.cpp b/src/command.cpp deleted file mode 100644 index ea5ade3..0000000 --- a/src/command.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "command.h" -#include "builder.h" -#include "target.h" - -Command::Command( CmdType cmd, const char *sTarget ) : - nType( cmd ), - sTarget( sTarget ) -{ -} - -Command::~Command() -{ -} - -void Command::debug() -{ - static const char *cmdt[]={"Check", "Clean"}; - printf(" command: %s %s\n", cmdt[ nType ], sTarget.getString() ); -} - -void Command::execute( Builder &bld ) -{ - switch( nType ) - { - case cmdCheck: - bld.getTarget( sTarget )->check( bld ); - break; - - case cmdClean: - bld.getTarget( sTarget )->clean( bld ); - break; - } -} - diff --git a/src/command.h b/src/command.h deleted file mode 100644 index 495c749..0000000 --- a/src/command.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef COMMAND_H -#define COMMAND_H - -#include -#include "staticstring.h" - -class Builder; - -class Command -{ -public: - enum CmdType - { - cmdCheck = 0, - cmdClean - }; - -public: - Command( CmdType cmd, const char *sTarget ); - virtual ~Command(); - - CmdType getType() - { - return nType; - } - - const char *getTarget() - { - return sTarget; - } - - void debug(); - - void execute( class Builder &bld ); - -private: - CmdType nType; - StaticString sTarget; - -}; - -#endif diff --git a/src/filetarget.cpp b/src/filetarget.cpp deleted file mode 100644 index 0d47e6f..0000000 --- a/src/filetarget.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#include -#include - -#include "perform.h" -#include "rule.h" -#include "filetarget.h" -#include "builder.h" // for BuildException -#include "viewer.h" - -FileTarget::FileTarget( const char *sName ) : - Target( sName ) -{ -} - -FileTarget::~FileTarget() -{ -} - -void FileTarget::debug() -{ - Target::debug(); - printf(" type: FileTarget\n"); -} - -char *gnu_getcwd() -{ - size_t size = 1024; - - while (1) - { - char *buffer = new char[size]; - if (getcwd (buffer, size) == buffer) - return buffer; - delete[] buffer; - if (errno != ERANGE) - return 0; - size *= 2; - } -} - -void FileTarget::addInputDir( const char *sDir ) -{ - DIR *dir = opendir( sDir ); - if( dir == NULL ) - { - throw BuildException( strerror( errno ) ); - } - - char *cwd = gnu_getcwd(); - std::string base;//( cwd ); - //base += "/"; - base += sDir; - base += "/"; - delete[] cwd; - - struct dirent *de; - - while( (de = readdir( dir )) ) - { - if( de->d_name[0] == '.' || de->d_name[0] == '\0' ) - continue; - - std::string s( base ); - s += de->d_name; - addInput( s.c_str() ); - } - - closedir( dir ); -} - -//int nNew, nCache; - -void FileTarget::check( Builder &bld ) -{ - //nNew = nCache = 0; - Rule *pRule = bld.getRule( sRule ); - - std::list perf; - std::list tmp = pRule->execute( bld, lInput, perf, getName() ); - lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); - - bld.view().beginTarget( getName(), "file", "check", lOutput.size() ); - - bld.processRequires( lOutput ); - - for( std::list::iterator i = perf.begin(); - i != perf.end(); i++ ) - { - bld.view().beginPerform( *i ); - bool bExtraReqs = false; - time_t target = getTime( bld, std::string((*i)->getTarget()) ); - std::list *lReqs = bld.getRequires( (*i)->getTarget() ); - if( lReqs == NULL ) - { - printf("No dependancies: %s\n", (*i)->getTarget() ); - continue; - } - time_t rebuild = target; - for( std::list::iterator j = lReqs->begin(); - j != lReqs->end(); j++ ) - { - time_t srcfile = getTime( bld, *j ); - if( srcfile < rebuild ) - rebuild = srcfile; - if( srcfile > target ) - { - bld.view().beginExecute(); - (*i)->execute( bld ); - updateTime( (*i)->getTarget() ); - bld.view().endExecute(); - break; - } - if( bExtraReqs == false ) - { - std::list::iterator k = j; - k++; - if( k == lReqs->end() ) - { - bExtraReqs = true; - bld.genRequiresFor( (*i)->getTarget(), rebuild ); - } - } - } - bld.view().endPerform(); - } - - //printf("Cache hits %d, %d new (%f%%)\n", nCache, nNew, nCache/ (double)(nNew+nCache)*100.0 ); - - bld.view().endTarget(); -} - -void FileTarget::clean( Builder &bld ) -{ - Rule *pRule = bld.getRule( sRule ); - - std::list perf; - std::list tmp = pRule->execute( bld, lInput, perf, getName() ); - lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); - - for( std::list::iterator i = lOutput.begin(); - i != lOutput.end(); i++ ) - { - unlink( (*i).c_str() ); - } -} - -time_t FileTarget::getTime( Builder &bld, std::string str ) -{ - std::map::iterator i = mTimes.find( str ); - if( i != mTimes.end() ) - { - //nCache++; - bld.view().beginRequiresCheck( true, str.c_str() ); - bld.view().endRequiresCheck(); - return (*i).second; - } - - bld.view().beginRequiresCheck( false, str.c_str() ); - struct stat st; - stat( str.c_str(), &st ); - - mTimes[str] = st.st_mtime; - - //nNew++; - - bld.view().endRequiresCheck(); - - return st.st_mtime; -} - -void FileTarget::updateTime( std::string str ) -{ - struct stat st; - stat( str.c_str(), &st ); - - mTimes[str] = st.st_mtime; -} - diff --git a/src/filetarget.h b/src/filetarget.h deleted file mode 100644 index c78c2fd..0000000 --- a/src/filetarget.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef FILE_TARGET_H -#define FILE_TARGET_H - -#include -#include -#include -#include -#include -#include "target.h" - -class FileTarget : public Target -{ -public: - FileTarget( const char *sName ); - virtual ~FileTarget(); - - virtual void debug(); - - void addInputDir( const char *sDir ); - - virtual void check( class Builder &bld ); - virtual void clean( class Builder &bld ); - - time_t getTime( class Builder &bld, std::string str ); - void updateTime( std::string str ); - -private: - std::map mTimes; - -}; - -#endif diff --git a/src/main.cpp b/src/main.cpp index c1df482..2b4baa5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,7 @@ class Param : public ParamProc public: Param() : sFile("build.conf"), - sCache("build.cache"), + sCache(".build.cache"), bDebug( false ) { addHelpBanner("Build r?\n\n"); diff --git a/src/perform.cpp b/src/perform.cpp deleted file mode 100644 index c96d70f..0000000 --- a/src/perform.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "perform.h" - -Perform::Perform( const char *sTarget ) : - sTarget( sTarget ) -{ -} - -Perform::~Perform() -{ -} - diff --git a/src/perform.h b/src/perform.h deleted file mode 100644 index 914f3b0..0000000 --- a/src/perform.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef PERFORM_H -#define PERFORM_H - -#include -#include "staticstring.h" - -class Perform -{ -public: - Perform( const char *sTarget ); - virtual ~Perform(); - - virtual void execute( class Builder &bld ) = 0; - - const char *getTarget() - { - return sTarget; - } - -private: - StaticString sTarget; - -}; - -#endif diff --git a/src/performcmd.cpp b/src/performcmd.cpp deleted file mode 100644 index 8eafc66..0000000 --- a/src/performcmd.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "performcmd.h" -#include "builder.h" -#include "viewer.h" - -PerformCmd::PerformCmd( const char *sCmd, const char *sTarget ) : - Perform( sTarget ), - sCommand( sCmd ) -{ -} - -PerformCmd::~PerformCmd() -{ -} - -void PerformCmd::execute( class Builder &bld ) -{ - bld.view().executeCmd( sCommand ); - int ret; - if( (ret = system( sCommand.getString() )) != 0 ) - { - printf("Error code: %d\n", WEXITSTATUS(ret) ); - exit( WEXITSTATUS(ret) ); - } -} - diff --git a/src/performcmd.h b/src/performcmd.h deleted file mode 100644 index 59510a6..0000000 --- a/src/performcmd.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef PERFORM_CMD_H -#define PERFORM_CMD_H - -#include - -#include "perform.h" -#include "staticstring.h" - -class PerformCmd : public Perform -{ -public: - PerformCmd( const char *sCmd, const char *sTarget ); - virtual ~PerformCmd(); - - virtual void execute( class Builder &bld ); - -private: - StaticString sCommand; -}; - -#endif diff --git a/src/regexp.cpp b/src/regexp.cpp deleted file mode 100644 index e5a3535..0000000 --- a/src/regexp.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "regexp.h" -#include "builder.h" // For BuildException -#include "staticstring.h" - -RegExp::RegExp() : - bCompiled( false ), - aSubStr( NULL ) -{ -} - -RegExp::RegExp( const char *sSrc ) : - bCompiled( false ), - aSubStr( NULL ) -{ - compile( sSrc ); -} - -RegExp::~RegExp() -{ - if( bCompiled ) - { - regfree( &re ); - delete[] aSubStr; - } -} - -void RegExp::compile( const char *sSrc ) -{ - if( bCompiled ) - { - regfree( &re ); - delete[] aSubStr; - bCompiled = false; - } - - int nErr = regcomp( &re, sSrc, REG_EXTENDED|REG_NEWLINE ); - if( nErr ) - { - size_t length = regerror( nErr, &re, NULL, 0 ); - char *buffer = new char[length]; - (void) regerror( nErr, &re, buffer, length ); - StaticString s( buffer ); - delete[] buffer; - throw BuildException( s.getString() ); - } - bCompiled = true; - this->sSrc = sSrc; - - nSubStr = re.re_nsub+1; - aSubStr = new regmatch_t[nSubStr]; -} - -int RegExp::getNumSubStrings() -{ - return nSubStr; -} - -bool RegExp::execute( const char *sSrc ) -{ - sTest = sSrc; - if( regexec( &re, sSrc, nSubStr, aSubStr, 0 ) ) - return false; - return true; -} - -std::pair RegExp::getSubStringRange( int nIndex ) -{ - return std::pair( aSubStr[nIndex].rm_so, aSubStr[nIndex].rm_eo ); -} - -std::string RegExp::getSubString( int nIndex ) -{ - return std::string( - sTest.getString()+aSubStr[nIndex].rm_so, - aSubStr[nIndex].rm_eo - aSubStr[nIndex].rm_so - ); -} - diff --git a/src/regexp.h b/src/regexp.h deleted file mode 100644 index 96f3747..0000000 --- a/src/regexp.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef REG_EXP_H -#define REG_EXP_H - -#include -#include -#include -#include -#include "staticstring.h" - -class RegExp -{ -public: - RegExp(); - RegExp( const char *sSrc ); - virtual ~RegExp(); - - void compile( const char *sSrc ); - int getNumSubStrings(); - bool execute( const char *sSrc ); - std::pair getSubStringRange( int nIndex ); - std::string getSubString( int nIndex ); - const char *getSource() - { - return sSrc; - } - -private: - StaticString sSrc; - StaticString sTest; - regex_t re; - bool bCompiled; - int nSubStr; - regmatch_t *aSubStr; -}; - -#endif 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 @@ -#include "rule.h" -#include "perform.h" -#include "performcmd.h" -#include "builder.h" // for BuildException - -Rule::Rule( const char *sName ) : - sName( sName ), - bNoProduces( true ) -{ - lProduces.push_back("{target}"); -} - -Rule::~Rule() -{ -} - -void Rule::debug() -{ - printf(" Rule %s:\n", - sName.getString() - ); - printf(" Produces: "); - if( lProduces.empty() ) - printf("{target}"); - else - { - for( std::list::iterator i = lProduces.begin(); - i != lProduces.end(); i++ ) - { - if( i != lProduces.begin() ) - printf(", "); - printf("%s", (*i).c_str() ); - } - } - printf("\n Matches "); - if( mHow == matchOne ) - printf("one "); - else if( mHow == matchAll ) - printf("all "); - printf("/%s/\n", rWhat.getSource() ); - - printf(" Performs "); - if( pHow == perfCommand ) - printf("command "); - printf("\"%s\"\n", sPerfCmd.getString() ); -} - -void Rule::addProduces( const char *sP ) -{ - if( bNoProduces ) - { - lProduces.clear(); - bNoProduces = false; - } - lProduces.push_back( sP ); -} - -void Rule::setMatches( Matches how, const char *sW ) -{ - rWhat.compile( sW ); - mHow = how; -} - -void Rule::setPerforms( ePerform pwhat, const char *sperfcmd ) -{ - pHow = pwhat; - sPerfCmd = sperfcmd; -} - -Perform *Rule::buildCommand( Builder &bld, const char *sCmd, Builder::varmap *vars ) -{ - return new PerformCmd( - bld.varRepl( sCmd, (*vars)["target"].c_str(), vars ).c_str(), - (*vars)["target"].c_str() - ); -} - -std::list Rule::execute( Builder &bld, std::list lInput, std::list &lPerf, const char *sTarget ) -{ - bld.requiresRegexp( false ); - std::list lRule = bld.findRuleChain( this ); - /* - if( !lRule.empty() ) - { - printf("Rule %s chains to: ", sName.getString() ); - for( std::list::iterator i = lRule.begin(); - i != lRule.end(); i++ ) - { - if( i != lRule.begin() ) - printf(", "); - printf("%s", (*i)->sName.getString() ); - } - printf("\n"); - }*/ - - std::list lOutput; - std::string sMatches; - - for( std::list::iterator i = lRule.begin(); i != lRule.end(); i++ ) - { - std::list lTmp = (*i)->execute( bld, lInput, lPerf ); - lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() ); - } - - std::list lTest; - lTest.insert( lTest.end(), lInput.begin(), lInput.end() ); - lTest.insert( lTest.end(), lOutput.begin(), lOutput.end() ); - - cleanList( lTest ); - - for( std::list::iterator i = lTest.begin(); - i != lTest.end(); i++ ) - { - if( rWhat.execute( (*i).c_str() ) ) - { - Builder::varmap *revars = bld.regexVars( &rWhat ); - for( std::list::iterator j = lProduces.begin(); - j != lProduces.end(); j++ ) - { - if( mHow == matchOne ) - { - lOutput.push_back( - bld.varRepl( - (*j).c_str(), - "", - revars - ) - ); - (*revars)["target"] = (sTarget==NULL)? - (lOutput.back().c_str()):(sTarget); - (*revars)["match"] = (*i).c_str(); - Perform *p = buildCommand( - bld, - sPerfCmd, - revars - ); - lPerf.push_back( p ); - - bld.requires( - (*revars)["target"].c_str(), - (*revars)["match"].c_str() - ); - } - else if( mHow == matchAll ) - { - sMatches += " "; - sMatches += (*i); - - bld.requires( - sTarget, - (*i).c_str() - ); - } - } - delete revars; - } - } - //std::list lTmp = findTargets( bld, lTest, sMatches, sTarget ); - //lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() ); - - if( mHow == matchAll ) - { - lOutput.push_back( - bld.varRepl( - sTarget, - sTarget, - NULL - ) - ); - Builder::varmap vars; - vars["target"] = sTarget; - vars["match"] = sMatches; - Perform *p = buildCommand( - bld, - sPerfCmd, - &vars - ); - lPerf.push_back( p ); - } - - return lOutput; -} - -bool Rule::willChain( Rule *pRule ) -{ - for( std::list::iterator i = pRule->lProduces.begin(); - i != pRule->lProduces.end(); i++ ) - { - if( rWhat.execute( (*i).c_str() ) ) - return true; - } - - return false; -} - diff --git a/src/rule.h b/src/rule.h deleted file mode 100644 index b7c0049..0000000 --- a/src/rule.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef RULE_H -#define RULE_H - -#include -#include -#include -#include "regexp.h" -#include "staticstring.h" -#include "builder.h" - -class Perform; - -class Rule -{ -public: - enum Matches - { - matchOne, - matchAll - }; - - enum ePerform - { - perfCommand - }; - -public: - Rule( const char *sName ); - virtual ~Rule(); - - const char *getName() - { - return sName; - } - - void debug(); - - void addProduces( const char *sProduces ); - void setMatches( Matches how, const char *sWhat ); - void setPerforms( ePerform pwhat, const char *sPerfCmd ); - - bool willChain( Rule *pRule ); - - std::list execute( class Builder &bld, std::list lInput, std::list &lPerf, const char *sTarget=NULL ); - -private: - class Perform *buildCommand( class Builder &bld, const char *sCmd, Builder::varmap *vars ); - std::list findTargets( class Builder &bld, std::list &lIn, std::string &sMatches, const char *sTarget ); - StaticString sName; - std::list lProduces; - - Matches mHow; - RegExp rWhat; - //StaticString sWhat; - //regex_t rWhat; - - ePerform pHow; - StaticString sPerfCmd; - - bool bNoProduces; -}; - -#endif diff --git a/src/target.cpp b/src/target.cpp deleted file mode 100644 index 8f4cc4b..0000000 --- a/src/target.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "target.h" - -Target::Target( const char *sName ) : - sName( sName ) -{ -} - -Target::~Target() -{ -} - -void Target::setRule( const char *sRule ) -{ - this->sRule = sRule; -} - -void Target::debug() -{ - printf(" %s:\n Rule: %s\n", - sName.getString(), - sRule.getString() - ); - printf(" Input list:\n"); - for( std::list::iterator i = lInput.begin(); - i != lInput.end(); i++ ) - { - printf(" %s\n", (*i).c_str() ); - } - printf(" Output list:\n"); - for( std::list::iterator i = lOutput.begin(); - i != lOutput.end(); i++ ) - { - printf(" %s\n", (*i).c_str() ); - } -} - -void Target::addInput( const char *sInput ) -{ - lInput.push_back( sInput ); -} - -void Target::addOutput( const char *sOutput ) -{ - lOutput.push_back( sOutput ); -} - diff --git a/src/target.h b/src/target.h deleted file mode 100644 index 59c5d7e..0000000 --- a/src/target.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef TARGET_H -#define TARGET_H - -#include -#include -#include -#include "staticstring.h" - -class Target -{ -public: - Target( const char *sName ); - virtual ~Target(); - - const char *getName() - { - return sName; - } - - void setRule( const char *sRule ); - - virtual void debug(); - - void addInput( const char *sInput ); - void addOutput( const char *sOutput ); - - virtual void check( class Builder &bld ) = 0; - virtual void clean( class Builder &bld ) = 0; - -protected: - StaticString sName; - StaticString sRule; - - std::list lInput; - std::list lOutput; - -}; - -#endif diff --git a/src/viewer.cpp b/src/viewer.cpp deleted file mode 100644 index ed6abfb..0000000 --- a/src/viewer.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "viewer.h" - -Viewer::Viewer() -{ -} - -Viewer::~Viewer() -{ -} - -void Viewer::beginAction( const char *sName, int nCommands ) -{ -} - -void Viewer::endAction() -{ -} - -void Viewer::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) -{ -} - -void Viewer::endTarget() -{ -} - -void Viewer::beginPerform( Perform *pPerf ) -{ -} - -void Viewer::beginRequiresCheck( bool bCached, const char *sName ) -{ -} - -void Viewer::endRequiresCheck() -{ -} - -void Viewer::beginExtraRequiresCheck( const char *sCommand ) -{ -} - -void Viewer::endExtraRequiresCheck() -{ -} - -void Viewer::beginExecute() -{ -} - -void Viewer::executeCmd( const char *sCmd ) -{ -} - -void Viewer::endExecute() -{ -} - -void Viewer::endPerform() -{ -} - diff --git a/src/viewer.h b/src/viewer.h deleted file mode 100644 index 8f2a595..0000000 --- a/src/viewer.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef VIEWER_H -#define VIEWER_H - -#include - -class Perform; - -class Viewer -{ -public: - Viewer(); - virtual ~Viewer(); - - virtual void beginAction( const char *sName, int nCommands ); - virtual void endAction(); - virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); - virtual void endTarget(); - - virtual void beginPerform( Perform *pPerf ); - virtual void beginRequiresCheck( bool bCached, const char *sName ); - virtual void endRequiresCheck(); - virtual void beginExtraRequiresCheck( const char *sCommand ); - virtual void endExtraRequiresCheck(); - virtual void beginExecute(); - virtual void executeCmd( const char *sCmd ); - virtual void endExecute(); - virtual void endPerform(); - -private: - -}; - -#endif diff --git a/src/viewermake.cpp b/src/viewermake.cpp deleted file mode 100644 index 7f63552..0000000 --- a/src/viewermake.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include "viewermake.h" -#include "perform.h" - -ViewerMake::ViewerMake() -{ -} - -ViewerMake::~ViewerMake() -{ -} - -void ViewerMake::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) -{ - //sAction = sName; - //bPrinted = false; -} - -void ViewerMake::printHead() -{ - /* - if( bPrinted == false ) - { - printf("--- %s ---\n", sAction.getString() ); - bPrinted = true; - }*/ -} - -void ViewerMake::endTarget() -{ - /*if( bPrinted == true ) - { - printf("\n"); - } - else - { - printf("Nothing to be done for %s.\n", sAction.getString() ); - }*/ -} - -void ViewerMake::beginPerform( Perform *pPerf ) -{ - //sTarget = pPerf->getTarget(); -} - -void ViewerMake::beginExtraRequiresCheck( const char *sCommand ) -{ - //printHead(); - //printf(" check: %s\n", sTarget.getString() ); -} - -void ViewerMake::beginExecute() -{ - //printHead(); - //printf(" build: %s\n", sTarget.getString() ); -} - -void ViewerMake::executeCmd( const char *sCmd ) -{ - printf("%s\n", sCmd ); -} - diff --git a/src/viewermake.h b/src/viewermake.h deleted file mode 100644 index 767d0bd..0000000 --- a/src/viewermake.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef VIEWER_MAKE_H -#define VIEWER_MAKE_H - -#include - -#include "viewer.h" -#include "staticstring.h" - -class ViewerMake : public Viewer -{ -public: - ViewerMake(); - virtual ~ViewerMake(); - - virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); - virtual void endTarget(); - - virtual void beginPerform( Perform *pPerf ); - virtual void beginExtraRequiresCheck( const char *sCommand ); - void printHead(); - virtual void beginExecute(); - virtual void executeCmd( const char *sCmd ); - -private: - -}; - -#endif diff --git a/src/viewerpercent.cpp b/src/viewerpercent.cpp deleted file mode 100644 index 0b0344b..0000000 --- a/src/viewerpercent.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "viewerpercent.h" -#include "perform.h" - -ViewerPercent::ViewerPercent() : - nWidth( 25 ) -{ -} - -ViewerPercent::~ViewerPercent() -{ -} - -void ViewerPercent::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) -{ - printf("--- %s ---\n", sName ); - nMax = nPerforms; - nCount = 0; - nLastLen = 0; -} - -void ViewerPercent::endTarget() -{ - printf("\n\n"); -} - -void ViewerPercent::beginPerform( Perform *pPerf ) -{ - sTarget = pPerf->getTarget(); -} - -void ViewerPercent::beginExecute() -{ -} - -void ViewerPercent::endPerform() -{ - nCount++; - - int nPer = (nCount*nWidth)/nMax; - fputc( '[', stdout ); - for( int j = 0; j < nPer; j++ ) - fputc('=', stdout ); - for( int j = nPer; j < nWidth; j++ ) - fputc(' ', stdout ); - //fputc(']', stdout ); - - printf("] %s", sTarget.getString() ); - - int diff = nLastLen-sTarget; - for( int j = 0; j < diff; j++ ) - fputc(' ', stdout ); - - nLastLen = sTarget; - - fputc('\r', stdout ); - fflush( stdout ); -} - diff --git a/src/viewerpercent.h b/src/viewerpercent.h deleted file mode 100644 index d575940..0000000 --- a/src/viewerpercent.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef VIEWER_PERCENT_H -#define VIEWER_PERCENT_H - -#include - -#include "viewer.h" -#include "staticstring.h" - -class ViewerPercent : public Viewer -{ -public: - ViewerPercent(); - virtual ~ViewerPercent(); - - virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); - virtual void endTarget(); - - virtual void beginPerform( Perform *pPerf ); - virtual void beginExecute(); - virtual void endPerform(); - -private: - class StaticString sTarget; - int nLastLen; - int nWidth; - int nMax; - int nCount; -}; - -#endif diff --git a/src/viewerplain.cpp b/src/viewerplain.cpp deleted file mode 100644 index 52b798b..0000000 --- a/src/viewerplain.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include "viewerplain.h" -#include "perform.h" - -ViewerPlain::ViewerPlain() -{ -} - -ViewerPlain::~ViewerPlain() -{ -} - -void ViewerPlain::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) -{ - sAction = sName; - bPrinted = false; -} - -void ViewerPlain::printHead() -{ - if( bPrinted == false ) - { - printf("--- %s ---\n", sAction.getString() ); - bPrinted = true; - } -} - -void ViewerPlain::endTarget() -{ - if( bPrinted == true ) - { - printf("\n"); - } - else - { - printf("Nothing to be done for %s.\n", sAction.getString() ); - } -} - -void ViewerPlain::beginPerform( Perform *pPerf ) -{ - sTarget = pPerf->getTarget(); -} - -void ViewerPlain::beginExtraRequiresCheck( const char *sCommand ) -{ - printHead(); - printf(" check: %s\n", sTarget.getString() ); -} - -void ViewerPlain::beginExecute() -{ - printHead(); - printf(" build: %s\n", sTarget.getString() ); -} - -void ViewerPlain::executeCmd( const char *sCmd ) -{ - //printf("--> %s\n", sCmd ); -} - diff --git a/src/viewerplain.h b/src/viewerplain.h deleted file mode 100644 index 4c88a0f..0000000 --- a/src/viewerplain.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef VIEWER_PLAIN_H -#define VIEWER_PLAIN_H - -#include - -#include "viewer.h" -#include "staticstring.h" - -class ViewerPlain : public Viewer -{ -public: - ViewerPlain(); - virtual ~ViewerPlain(); - - virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); - virtual void endTarget(); - - virtual void beginPerform( Perform *pPerf ); - virtual void beginExtraRequiresCheck( const char *sCommand ); - void printHead(); - virtual void beginExecute(); - virtual void executeCmd( const char *sCmd ); - -private: - class StaticString sAction; - bool bPrinted; - class StaticString sTarget; - -}; - -#endif -- cgit v1.2.3