X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcondition.cpp;h=c80134d237a7707a4f439b7cebd17ff62c9b582d;hb=e89616b514c77e189b93d5a46aa5a5a72e34c3cb;hp=4c9ac0b84453935c8afa3b86cc4cfcdb934afcd9;hpb=36a7c1a4d4d2b45be16c1e5d862af51e0ded1e93;p=builder.git diff --git a/source/condition.cpp b/source/condition.cpp index 4c9ac0b..c80134d 100644 --- a/source/condition.cpp +++ b/source/condition.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of builder -Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include "builder.h" #include "condition.h" @@ -16,18 +9,18 @@ using namespace Msp; Condition::Condition(SourcePackage &p, const string &expr): pkg(p) { - vector parts=split(expr); + vector parts = split(expr); for(vector::iterator i=parts.begin(); i!=parts.end(); ++i) { if(*i=="and") continue; - string::size_type token=i->find_first_of("=!"); + string::size_type token = i->find_first_of("=!"); if(token==string::npos) - expression.insert(StringMap::value_type(*i, "!0")); + expression.insert(StringMap::value_type(*i, "=")); else if(token==0 && (*i)[0]=='!') - expression.insert(StringMap::value_type(*i, "=0")); + expression.insert(StringMap::value_type(i->substr(1), "!")); else expression.insert(StringMap::value_type(i->substr(0, token), i->substr(token))); } @@ -35,24 +28,30 @@ Condition::Condition(SourcePackage &p, const string &expr): bool Condition::eval() { - const Config &conf=pkg.get_config(); + const Config &conf = pkg.get_config(); - bool result=true; + bool result = true; for(StringMap::iterator i=expression.begin(); i!=expression.end(); ++i) { - bool neg=(i->second[0]=='!'); - unsigned start=1; + bool neg = (i->second[0]=='!'); + unsigned start = 1; if(i->second[1]=='=') ++start; + string value = i->second.substr(start); - string value; + bool match = false; if(conf.is_option(i->first)) - value=conf.get_option(i->first).value; + { + if(value.empty()) + match = lexical_cast(conf.get_option(i->first).value); + else + match = (conf.get_option(i->first).value==value); + } else if(i->first=="arch") - value=pkg.get_builder().get_current_arch().get_name(); + match = pkg.get_builder().get_current_arch().match_name(value); - if((value==i->second.substr(start))==neg) - result=false; + if(match==neg) + result = false; } return result;