Ejemplo n.º 1
0
int Porting::findRule(const RuleList &rules, const QString &q3)
{
    for (int i=0; i<rules.count(); ++i)
        if (rules.at(i).first == q3)
            return i;
    return -1;
}
Ejemplo n.º 2
0
bool LabEngine::doActionRuleSub(int16 action, int16 roomNum, const CloseData *closePtr, bool allowDefaults) {
	action++;

	if (closePtr) {
		RuleList *rules = &(_rooms[_roomNum]._rules);

		if (rules->empty() && (roomNum == 0)) {
			_resource->readViews(roomNum);
			rules = &(_rooms[roomNum]._rules);
		}

		for (RuleList::iterator rule = rules->begin(); rule != rules->end(); ++rule) {
			if ((rule->_ruleType == kRuleTypeAction) &&
				((rule->_param1 == action) || ((rule->_param1 == 0) && allowDefaults))) {
				if (((rule->_param2 == closePtr->_closeUpType) ||
					  ((rule->_param2 == 0) && allowDefaults)) ||
					  ((action == 1) && (rule->_param2 == -closePtr->_closeUpType))) {
					if (checkConditions(rule->_condition)) {
						doActions(rule->_actionList);
						return true;
					}
				}
			}
		}
	}

	return false;
}
Ejemplo n.º 3
0
void Maker::EnterSuffixTerminals()
{
    RuleList *rl = RuleContainer::Instance()->Lookup(".SUFFIXES");
    if (rl)
    {
        for (RuleList::iterator it = rl->begin(); it != rl->end(); ++it)
        {
            std::string value = (*it)->GetPrerequisites();
            while (value.size())
            {
                std::string target = "%" + Eval::ExtractFirst(value, " ");
                RuleList *ruleList = RuleContainer::Instance()->Lookup(target);
                if (!ruleList)
                {
                    ruleList = new RuleList(target);
                    //if (ruleList)
                    {
                        Rule *rule = new Rule(target, "", "", NULL, "<implicitbuild>", 1);
                        //if (rule)
                            ruleList->Add(rule);
                    }
                }
            }
        }
    }
}
Ejemplo n.º 4
0
void Maker::EnterSpecificRule(RuleList *l, const std::string &stem, 
                              const std::string &preferredPath, bool outerMost)
{
    std::string target = Eval::ReplaceStem(stem, l->GetTarget());
    RuleList *ruleList = RuleContainer::Instance()->Lookup(target);
    if (!ruleList)
    {
        ruleList = new RuleList(target);
//        if (ruleList)
        {
            *RuleContainer::Instance() += ruleList;
            ruleList->SetTargetPatternStem(stem);
        }
    }
    std::string orderPrereq;
    std::string prereq;
    Command *commands = NULL;
    for (RuleList::iterator it = l->begin(); it != l->end(); ++it)
    {
        if (!commands)
            commands = (*it)->GetCommands();
        std::string working = (*it)->GetPrerequisites();
        while (working.size())
        {
            std::string temp = Eval::ExtractFirst(working, " ");
            temp = Eval::ReplaceStem(stem, temp);
            if (prereq.size())
                prereq += " ";
            prereq += temp;
        }
        working = (*it)->GetOrderPrerequisites();
        while (working.size())
        {
            std::string temp = Eval::ExtractFirst(working, " ");
            temp = Eval::ReplaceStem(stem, temp);
            if (orderPrereq.size())
                orderPrereq += " ";
            orderPrereq += temp;
        }
    }
    Rule *rule = new Rule(target, prereq, orderPrereq, commands, "<implicitbuild>", 1);
//    if (rule)
        ruleList->InsertFirst(rule);
    if (!outerMost)
    {
        Parser p(".INTERMEDIATE: " + target, "<implicitbuild>", 1, false);
        p.Parse();
    }
//	Time tv;
    // for vpaths...
//	GetFileTime(target, preferredPath, tv);
}
Ejemplo n.º 5
0
void Resource::readRule(Common::File *file, RuleList &rules) {
	rules.clear();
	while (file->readByte() == 1) {
		rules.push_back(Rule());
		Rule &rule = rules.back();

		rule._ruleType = (RuleType)file->readSint16LE();
		rule._param1 = file->readSint16LE();
		rule._param2 = file->readSint16LE();
		rule._condition = readConditions(file);
		readAction(file, rule._actionList);
	}
}
Ejemplo n.º 6
0
bool Maker::OnList(const std::string &goal, char *what)
{
    bool rv = false;
    RuleList *rl = RuleContainer::Instance()->Lookup(what);
    if (rl)
    {
        for (RuleList::iterator it = rl->begin(); !rv && it != rl->end(); ++it)
        {
            std::string value = (*it)->GetPrerequisites();	
            rv = ScanList(value, goal);
        }
    }
    return rv;
}
Ejemplo n.º 7
0
void Maker::EnterDefaultRule(const std::string &goal, RuleList *dflt)
{
    if (!RuleContainer::Instance()->Lookup(goal))
    {
        Command *commands = NULL;
        for (RuleList::iterator it = dflt->begin(); !commands && it != dflt->end(); ++it)
            commands = (*it)->GetCommands();
        RuleList *ruleList = new RuleList(goal);
//        if (ruleList)
        {
            *RuleContainer::Instance() += ruleList;
            Rule *rule = new Rule(goal, "", "", commands, "<implicitbuild>", 1);
//            if (rule)
                ruleList->Add(rule);
        }
    }
}
Ejemplo n.º 8
0
QgsRuleBased3DRenderer *QgsRuleBased3DRenderer::clone() const
{
  Rule *rootRule = mRootRule->clone();

  // normally with clone() the individual rules get new keys (UUID), but here we want to keep
  // the tree of rules intact, so that other components that may use the rule keys work nicely (e.g. map themes)
  rootRule->setRuleKey( mRootRule->ruleKey() );
  RuleList origDescendants = mRootRule->descendants();
  RuleList clonedDescendants = rootRule->descendants();
  Q_ASSERT( origDescendants.count() == clonedDescendants.count() );
  for ( int i = 0; i < origDescendants.count(); ++i )
    clonedDescendants[i]->setRuleKey( origDescendants[i]->ruleKey() );

  QgsRuleBased3DRenderer *r = new QgsRuleBased3DRenderer( rootRule );
  r->mLayerRef = mLayerRef;
  return r;
}
Ejemplo n.º 9
0
int MakeMain::Run(int argc, char **argv, char **env)
{
    char *p = getenv("MAKEFLAGS");
    if (p)
    {
        Variable *v = new Variable("MAKEFLAGS", p, Variable::f_recursive, Variable::o_environ);
        *VariableContainer::Instance() += v;
        p = getenv("MAKEOVERRIDES");
        if (p)
        {
            Variable *v = new Variable("MAKEOVERRIDES", p, Variable::f_recursive, Variable::o_environ);
            *VariableContainer::Instance() += v;
        }
        Eval r(v->GetValue(), false);
        std::string cmdLine = r.Evaluate();
        Dispatch(cmdLine.c_str());
    }
    if (!switchParser.Parse(&argc, argv) || help.GetValue() || help2.GetValue())
    {
        Utils::banner(argv[0]);
        Utils::usage(argv[0], usageText);
    }
    if (dir.GetValue().size())
    {
        cwd = OS::GetWorkingDir();
        if (!OS::SetWorkingDir(dir.GetValue()))
        {
            std::cout << "Cannot set working dir to: " << dir.GetValue() << std::endl;
            return 2;
        }
    }
    if (printDir.GetValue())
    {
        std::cout << OS::GetWorkingDir() << std::endl;
    }
    if (cancelKeep.GetValue())
    {
        cancelKeep.SetValue(false);
        keepGoing.SetValue(false);
    }
    
    bool done = false;
    Eval::Init();
    Eval::SetWarnings(warnUndef.GetValue());
    while (!done && !Eval::GetErrCount())
    {
        VariableContainer::Instance()->Clear();
        RuleContainer::Instance()->Clear();
        Include::Instance()->Clear();
        Maker::ClearFirstGoal();
        LoadEnvironment(env);
        LoadCmdDefines();
        SetVariable("MAKE", argv[0], Variable::o_environ, false);
        Variable *v = VariableContainer::Instance()->Lookup("SHELL");
        if (!v)
        {
            v = VariableContainer::Instance()->Lookup("COMSPEC");
            if (!v)
                v = VariableContainer::Instance()->Lookup("ComSpec");
            if (v)
            {
                std::string val = v->GetValue();
                SetVariable("SHELL", val, Variable::o_environ, true);
            }
        }
        std::string goals;
        for (int i=1; i < argc; i++)
        {
            if (goals.size())
                goals += " ";
            goals += argv[i];
        }
        SetVariable("MAKECMDGOALS", goals, Variable::o_command_line, false);
        SetMakeFlags();
        if (restarts)
        {
            std::strstream str;
            std::string temp;
            str << restarts;
            str >> temp;
            SetVariable("MAKE_RESTARTS", temp, Variable::o_command_line, false);
        }
        v = VariableContainer::Instance()->Lookup("MAKE_LEVEL");
        if (!v)
        {
            SetVariable("MAKE_LEVEL", "0", Variable::o_environ, true);
        }
        else
        {
            std::strstream str;
            std::string temp;
            str << v->GetValue();
            int n;
            str >> n;
            n++;
            str <<  n;
            str >> temp;
            v->SetValue(temp);
        }
        SetVariable(".FEATURES","second-expansion order-only target-specific", Variable::o_environ, false);
        SetVariable(".DEFAULT_GOAL","", Variable::o_environ, false);
        SetVariable(".INCLUDE_DIRS",includes.GetValue(), Variable::o_command_line, false);
        SetVariable("VPATH",includes.GetValue(), Variable::o_environ, false);
        SetInternalVars();		
        v = VariableContainer::Instance()->Lookup("MAKEFILES");
        if (v)
        {
            v->SetExport(true);
            Include::Instance()->AddFileList(v->GetValue(), true, true);
        }
        Rule *rule = new Rule(".SUFFIXES", ".c .o .cpp .nas .asm", "", new Command("", 0), "", 0, false);
        RuleList *ruleList = new RuleList(".SUFFIXES");
        ruleList->Add(rule, false);
        *RuleContainer::Instance() += ruleList;
        std::string files = specifiedFiles.GetValue();
        if (!files.size())
            files = "makefile";
        Include::Instance()->AddFileList(files, false, false);
        SetupImplicit();
        RuleContainer::Instance()->SecondaryEval();
        done = !Include::Instance()->MakeMakefiles(silent.GetValue());
        if (!done)
            restarts++;
    }
    if (showDatabase.GetValue())
        ShowDatabase();
    int rv = 0;
    if (Eval::GetErrCount())
    {
        rv = 2;
    }
    else
    {
        bool xsilent = silent.GetValue();
        bool xignore = ignoreErrors.GetValue();
        bool xdontrun = displayOnly.GetValue();
        bool xtouch = touch.GetValue();
        xdontrun |= xtouch || query.GetValue();
        xsilent |= xtouch || query.GetValue();
        Maker maker(xsilent, xdontrun, xignore, xtouch, rebuild.GetValue(), newFiles.GetValue(), oldFiles.GetValue());
        for (int i = 1; i < argc; i++)
        {
            maker.AddGoal(argv[i]);
        }
        if (maker.CreateDependencyTree())
        {
            rv = maker.RunCommands(keepGoing.GetValue());
            if (query.GetValue() && rv == 0)
                rv = maker.HasCommands() ? 1 : 0;
        }
        else
        {
            rv = 2;
        }
    }
    if (dir.GetValue().size())
    {
        OS::SetWorkingDir(cwd);
    }
    if (printDir.GetValue())
    {
        std::cout << OS::GetWorkingDir() << std::endl;
    }
    return rv;
}
Ejemplo n.º 10
0
int Maker::RunOne(Depends *depend, Environment &env, bool keepGoing)
{
    int rv = 0;
    if (depend->GetRuleList()->IsBuilt())
        return 0;
    RuleList *rl = depend->GetRuleList();
    Eval::PushruleStack(rl);
    bool stop = false;
    bool cantbuild = false;
    for (Depends::iterator it = depend->begin(); it != depend->end(); ++it)
    {
//		if (!(*it)->GetOrdered())
        {
            if (rv = RunOne(*it, env, keepGoing))
            {
                stop = true;
                if (!keepGoing)
                {
                    Eval::PopruleStack();
                    return rv;
                }
            }			
        }
//		else 
//			cantbuild |= !(*it)->GetRuleList()->IsBuilt();
    }
    if (stop)
    {
        Eval::PopruleStack();
        return -1;
    }
    if (cantbuild || rl->IsBuilt())
    {
        Eval::PopruleStack();
        return 0;
    }
    rl->SetBuilt();
    if (touch)
    {
        rl->Touch(OS::GetCurrentTime());
    }
    bool sil = silent;
    bool ig = ignoreResults;
    if (!sil)
        sil = OnList(depend->GetGoal(), ".SILENT");
    if (!ig)
        ig = OnList(depend->GetGoal(), ".IGNORE");
    Spawner sp(env, ig, sil, displayOnly);
    if (depend->GetRule() && depend->GetRule()->GetCommands())
        rv = sp.Run(*depend->GetRule()->GetCommands(), rl, NULL);
    if (rv)
    {
        std::strstream a;
        a << rv;
        std::string b;
        a >> b;
        if (RuleContainer::Instance()->Lookup(".DELETE_ON_ERROR"))
        {
            OS::RemoveFile(depend->GetGoal());
            std::cout << std::endl;
            Eval::error("commands returned error code " + b + " '" + depend->GetGoal()  + "' removed");
        }
        else
        {
            std::cout << std::endl;
            Eval::error("commands returned error code " + b);
        }
    }
    Eval::PopruleStack();
    return rv;	
}
Ejemplo n.º 11
0
Maker::Depends *Maker::Dependencies(const std::string &goal, const std::string &preferredPath, Time &timeval)
{
    Time goalTime;
    Time dependsTime;
    Depends *rv = Depends::Lookup(goal);
    bool intermediate = OnList(goal, ".INTERMEDIATE");
    bool secondary = OnList(goal, ".SECONDARY");
    bool precious = OnList(goal, ".PRECIOUS");
    if (!rv)
    {
        Time xx;
        RuleList *ruleList = RuleContainer::Instance()->Lookup(goal);
        bool remake = false;
        if (ruleList)
        {
            RuleList::iterator it;
            for (it = ruleList->begin(); it != ruleList->end(); ++it)
            {
                if ((*it)->HasCommands())
                    break;
            }
            if (it == ruleList->end())
            {
                Time xx;
                SearchImplicitRules(goal, preferredPath, true, false, xx);
            }
            std::string foundPath = GetFileTime(goal ,preferredPath, goalTime);
            bool exists = ! !goalTime;
            rv = new Depends(goal, xx, intermediate && !precious && !secondary);
            Rule *executionRule = NULL;
            std::string newerPrereqs;
            for (RuleList::iterator it = ruleList->begin(); it != ruleList->end(); ++it)
            {
                std::string working = (*it)->GetPrerequisites();
                bool remakeThis = false;
                while (working.size())
                {
                    Time current;
                    std::string thisOne = Eval::ExtractFirst(working, " ");
                    Depends *dp = Dependencies(thisOne, foundPath, current);
                    if (current > dependsTime)
                    {
                        dependsTime = current;
                    }
                    if (dp)
                    {
                        *rv += (dp);
                    }
                    if (current > goalTime || rebuildAll)
                    {
                        if (newerPrereqs.size())
                            newerPrereqs += " ";
                        newerPrereqs += thisOne;
                        remakeThis = true;
                    }
                }
                working = (*it)->GetOrderPrerequisites();
                while (working.size())
                {
                    Time current;
                    std::string thisOne = Eval::ExtractFirst(working, " ");
                    Depends *dp = Dependencies(thisOne, preferredPath, current);
                    if (dp)
                    {
                        dp->SetOrdered(true);
                        (*rv) += dp;
                    }
                }
                if ((*it)->HasCommands())
                    if (ruleList->GetDoubleColon() && remakeThis || !ruleList->GetDoubleColon())
                        if (executionRule)
                            Eval::warning("Conflicting command lists for goal '" + goal + "'");
                        else
                            executionRule = *it;
            }
            if (executionRule)
            {
                rv->SetRuleList(ruleList);
                rv->SetRule(executionRule);
                ruleList->SetNewerPrerequisites(newerPrereqs);
            }
            else
            {
                rv->SetRuleList(ruleList);
            }
        }
        else
        {
            if (SearchImplicitRules(goal, preferredPath, true, true, timeval))
                rv = Dependencies(goal, preferredPath, timeval);
        }
    }
    if (rv && !rebuildAll)
    {
        if (goalTime > dependsTime)
        {
            if (!rv->size())
            {
                    delete rv;
                    rv = NULL;
            }
            else
            {
                bool check = true;
                for (Depends::iterator it = rv->begin(); check && it != rv->end(); ++it)
                {
                    check &= (*it)->IsSecondary();
                }
                if (check)
                {
                    delete rv;
                    rv = NULL;
                }
            }
        }
    }
    if (rv)
    {
        rv->SetSecondary(secondary || intermediate);
    }
    if (dependsTime > goalTime)
    {
        if (dependsTime > timeval)
            timeval = dependsTime;
    }
    else
    {
        if (goalTime > timeval)
            timeval = goalTime;
    }
    return rv;
}