void SeccompFiltersWebProcessEfl::platformInitialize()
{
    // TODO: We should block all the syscalls and whitelist
    // what we need + trap what should be handled by the broker.
    addRule("open", Trap);
    addRule("openat", Trap);
    addRule("creat", Trap);

    // Needed by Eeze on NetworkStateNotifierEfl.
    m_policy.addDirectoryPermission(ASCIILiteral("/sys/bus"), SyscallPolicy::Read);
    m_policy.addDirectoryPermission(ASCIILiteral("/sys/class"), SyscallPolicy::Read);
    m_policy.addDirectoryPermission(ASCIILiteral("/sys/devices"), SyscallPolicy::Read);
    m_policy.addFilePermission(ASCIILiteral("/etc/udev/udev.conf"), SyscallPolicy::Read);

    // Place where the theme and icons are installed.
    char* dataDir = canonicalize_file_name(DATA_DIR);
    if (dataDir) {
        m_policy.addDirectoryPermission(String::fromUTF8(dataDir), SyscallPolicy::Read);
        free(dataDir);
    }

#if USE(GSTREAMER)
    // Video playback requires access to the root of the user cache dir which
    // is not right. We need to check with these directories on gstreamer
    // can be configured.
    char* homeDir = getenv("HOME");
    if (homeDir)
        m_policy.addDirectoryPermission(String::fromUTF8(homeDir) + "/.cache", SyscallPolicy::ReadAndWrite);
#endif

    SeccompBroker::launchProcess(this, m_policy);
}
Beispiel #2
0
/*************************************************************
 *************************************************************
 Initializes a chromosome with random values for the DB parameters
 adding numInitRules random rules
 *************************************************************
 **************************************************************/
void chromosome::inizialize(frbs& fis) {

	inizializewithoutrule();
		//calcolaErroreC45(fis, inOutTr, numPatterTr,0, (unsigned**)matC45,dimmatC45);

	if (CLASSIFICATION)
	{	if (matWM==0)
		{	inizializeWM(fis);
			generateMatCL(fis);
		}
		if (TYPE==0)
			generateMatR(fis);
		else
			generateIndiciCL(fis);
	}
	else
	{	if (TYPE == 0)
		{	for (int i = 0; i < maxRule; i++)
				addRule(fis);
		}
		else
		{	if (matWM==0)
				inizializeWM(fis);
			generateIndici(dimMatWM,maxRule);
		}
	}
}
void EnoughLeaguePlayersRule::addPlayer(Player *player)
{
    AtomicRule* playerIsInGameRule = new AtomicRule();
    playerIsInGameRule->attributeName->setValue("playerId");
    playerIsInGameRule->parameter->setValue(QString::number(player->id()));
    addRule(playerIsInGameRule);
}
////////////////////////////////////////////
// only for using in MFC
////////////////////////////////////////////
bool
	LSystem::LoadRulesFromText( char *buf)
{
	char left;
	short prob;
	string right;
	unsigned long pos = 0;

	string line, rule;

	line.clear( );
	line = getLineFromText( buf, &pos);
	// check if there is end of file
	if( line.size( ) == 0)
		return false;

	while( line[ 0] != '@')					// while not sign for end of lsystem 
	{
		// is line a rule in right format?
		if( isItRule( &line, &left, &prob, &right) )
			addRule( left, prob, right);
		else
			return false;

		// load new line
		line.clear( );
		line = getLineFromText( buf, &pos);
		// check if there is end of file
		if( line.size( ) == 0)
			return false;
	}

	return true;
}
Beispiel #5
0
rulesDialog::rulesDialog( const QMap<QString, TopologyRule>& testMap, QgisInterface *theQgisIface, QWidget *parent )
    : QDialog( parent ), Ui::rulesDialog()
{
  setupUi( this );

  mQgisIface = theQgisIface;

  //setHorizontalHeaderItems();
  mRulesTable->hideColumn( 4 );
  mRulesTable->hideColumn( 5 );

  mTestConfMap = testMap;
  mRulesTable->setSelectionBehavior( QAbstractItemView::SelectRows );
  mRuleBox->addItems( mTestConfMap.keys() );

  mAddTestButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.svg" ) ) );
  mDeleteTestButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.svg" ) ) );

  connect( mAddTestButton, SIGNAL( clicked() ), this, SLOT( addRule() ) );
  connect( mAddTestButton, SIGNAL( clicked() ), mRulesTable, SLOT( resizeColumnsToContents() ) );
  // attempt to add new test when Ok clicked
  //connect( buttonBox, SIGNAL( accepted() ), this, SLOT( addTest() ) );
  connect( mDeleteTestButton, SIGNAL( clicked() ), this, SLOT( deleteTest() ) );

  connect( mLayer1Box, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( updateRuleItems( const QString& ) ) );
  connect( mRuleBox, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( showControls( const QString& ) ) );

  mRuleBox->setCurrentIndex( 0 );

  //this resets this plugin up if a project is loaded
  connect( mQgisIface, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
  //reset plugin if new project is activated
  projectRead();
}
Beispiel #6
0
	bool LparseParser::parseRule(int rt) {
		if (knownRuleType(rt)) {
			int  bound = -1;
			bool weights = false;
			active_->setType(static_cast<Asp::RuleType>(rt));
			if (rt == Asp::CHOICERULE || rt == Asp::DISJUNCTIVERULE) {
				int heads = input()->parseInt(1, INT_MAX, "Rule has too few heads");
				for (int i = 0; i < heads; ++i) { active_->addHead(parseAtom()); }
			}
			else if (rt == Asp::OPTIMIZERULE) {
				weights = input()->parseInt(0, 0, "Minimize rule: 0 expected!") == 0;
			}
			else {
				active_->addHead(parseAtom());
				weights = rt == Asp::WEIGHTRULE && check(input()->parseInt(bound, 0, INT_MAX), "Weightrule: Positive weight expected!");
			}
			int lits = input()->parseInt(0, INT_MAX, "Number of body literals expected!");
			int neg = input()->parseInt(0, lits, "Illegal negative body size!");
			check(rt != Asp::CONSTRAINTRULE || input()->parseInt(bound, 0, INT_MAX), "Constraint rule: Positive bound expected!");
			if (bound >= 0) { active_->setBound(bound); }
			return parseBody(static_cast<uint32>(lits), static_cast<uint32>(neg), weights) && addRule(*active_);
		}
		else if (rt >= 90 && rt < 93) {
			if (rt == 90) { return input()->parseInt(0, 0, "0 expected") == 0; }
			int a = input()->parseInt(1, INT_MAX, "atom id expected");
			if (rt == 91) { builder_->freeze(a, input()->parseInt(0, 1, "0 or 1 expected") ? value_true : value_false); }
			else { builder_->unfreeze(a); }
			return true;
		}
		else {
			return parseRuleExtension(rt);
		}
	}
PrivacyDlg::PrivacyDlg(JabberAccount* acc, QWidget* parent) : KDialog(parent), acc_(acc)
{
	QWidget * w = new QWidget (this);
	ui_.setupUi(w);
	setMainWidget (w);
	setAttribute(Qt::WA_DeleteOnClose);
	setCaption(i18n("%1: Privacy Lists", (acc->myself()->nickName() ) ) );
	setButtons (KDialog::Close);
	ui_.lv_rules->setFocus (Qt::PopupFocusReason);

	PrivacyManager* manager = acc->client()->privacyManager();
	connect(manager,SIGNAL(listsReceived(QString,QString,QStringList)),SLOT(updateLists(QString,QString,QStringList)));
	connect(manager,SIGNAL(listReceived(PrivacyList)),SLOT(refreshList(PrivacyList)));
	connect(manager,SIGNAL(listError()),SLOT(list_failed()));
	//connect(manager,SIGNAL(listNamesError()),SLOT(listNamesError()));
	//connect(manager,SIGNAL(listReceiveError()),SLOT(listReceiveError()));

	connect(ui_.cb_active,SIGNAL(activated(int)),SLOT(active_selected(int)));
	connect(ui_.cb_default,SIGNAL(activated(int)),SLOT(default_selected(int)));
	connect(ui_.cb_lists,SIGNAL(activated(int)),SLOT(list_selected(int)));
	connect(ui_.cb_lists,SIGNAL(currentIndexChanged(int)),SLOT(list_changed(int)));
	connect(manager,SIGNAL(changeActiveList_success()),SLOT(change_succeeded()));
	connect(manager,SIGNAL(changeActiveList_error()),SLOT(change_failed()));
	connect(manager,SIGNAL(changeDefaultList_success()),SLOT(change_succeeded()));
	connect(manager,SIGNAL(changeDefaultList_error()),SLOT(change_failed()));
	connect(manager,SIGNAL(changeList_success()),SLOT(changeList_succeeded()));
	connect(manager,SIGNAL(changeList_error()),SLOT(changeList_failed()));

	connect(ui_.pb_newList,SIGNAL(clicked()),SLOT(newList()));
	connect(ui_.pb_deleteList,SIGNAL(clicked()),SLOT(removeList()));
	
	connect(ui_.pb_add,SIGNAL(clicked()),SLOT(addRule()));
	connect(ui_.pb_edit,SIGNAL(clicked()),SLOT(editCurrentRule()));
	connect(ui_.pb_remove,SIGNAL(clicked()),SLOT(removeCurrentRule()));
	connect(ui_.pb_up,SIGNAL(clicked()),SLOT(moveCurrentRuleUp()));
	connect(ui_.pb_down,SIGNAL(clicked()),SLOT(moveCurrentRuleDown()));
	connect(ui_.pb_apply,SIGNAL(clicked()),SLOT(applyList()));
	
	ui_.pb_newList->setIcon(KIcon("list-add"));
	ui_.pb_deleteList->setIcon(KIcon("list-remove"));
	ui_.pb_add->setIcon(KIcon("list-add"));
	ui_.pb_remove->setIcon(KIcon("list-remove"));
	ui_.pb_up->setIcon(KIcon("arrow-up"));
	ui_.pb_down->setIcon(KIcon("arrow-down"));
	ui_.pb_edit->setIcon(KIcon("edit-rename"));
	ui_.pb_apply->setIcon(KIcon("dialog-ok-apply"));

	setWidgetsEnabled(false);

	// Disable all buttons
	ui_.pb_deleteList->setEnabled(false);
	setEditRuleEnabled(false);
	ui_.pb_add->setEnabled(false);
	ui_.pb_apply->setEnabled(false);

	// FIXME: Temporarily disabling auto-activate
	ui_.ck_autoActivate->hide();
	
	manager->requestListNames();
}
Beispiel #8
0
QaView::QaView(QWidget* parent)
 : QDockWidget ( i18nc("@title:window","Quality Assurance"), parent)
 , m_browser(new QTreeView(this))
{
    if (!QaModel::isInstantiated())
        QaModel::instance()->loadRules(Project::instance()->qaPath());
    m_qaModel=QaModel::instance();

    setWidget(m_browser);
    m_browser->setModel(m_qaModel);
    m_browser->setRootIsDecorated(false);
    m_browser->setContextMenuPolicy(Qt::ActionsContextMenu);

    QAction* action=new QAction(i18nc("@action:inmenu", "Add"), m_browser);
    connect(action, SIGNAL(triggered()), this, SLOT(addRule()));
    m_browser->addAction(action);

    action=new QAction(i18nc("@action:inmenu", "Remove"), m_browser);
    connect(action, SIGNAL(triggered()), this, SLOT(removeRule()));
    m_browser->addAction(action);
    
    m_browser->setAlternatingRowColors(true);
    
    connect(m_qaModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(rulesChanged()));
}
QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
    : QgsRendererV2Widget( layer, style )
{

  // try to recognize the previous renderer
  // (null renderer means "no previous renderer")
  if ( !renderer || renderer->type() != "RuleRenderer" )
  {
    // we're not going to use it - so let's delete the renderer
    delete renderer;

    // some default options
    QgsSymbolV2* symbol = QgsSymbolV2::defaultSymbol( mLayer->geometryType() );

    mRenderer = new QgsRuleBasedRendererV2( symbol );
  }
  else
  {
    mRenderer = static_cast<QgsRuleBasedRendererV2*>( renderer );
  }

  setupUi( this );

  mModel = new QgsRuleBasedRendererV2Model( mRenderer );
  //new ModelTest( mModel, this ); // for model validity checking
  viewRules->setModel( mModel );

  mRefineMenu = new QMenu( "Refine current rule", btnRefineRule );
  mRefineMenu->addAction( tr( "Add scales to rule" ), this, SLOT( refineRuleScales() ) );
  mRefineMenu->addAction( tr( "Add categories to rule" ), this, SLOT( refineRuleCategories() ) );
  mRefineMenu->addAction( tr( "Add ranges to rule" ), this, SLOT( refineRuleRanges() ) );
  btnRefineRule->setMenu( mRefineMenu );
  contextMenu->addMenu( mRefineMenu );

  btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) );
  btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
  btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );

  connect( viewRules, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( editRule( const QModelIndex & ) ) );

  // support for context menu (now handled generically)
  connect( viewRules, SIGNAL( customContextMenuRequested( const QPoint& ) ),  this, SLOT( contextMenuViewCategories( const QPoint& ) ) );

  connect( viewRules->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( currentRuleChanged( QModelIndex, QModelIndex ) ) );

  connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
  connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
  connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );
  connect( btnCountFeatures, SIGNAL( clicked() ), this, SLOT( countFeatures() ) );

  connect( btnRenderingOrder, SIGNAL( clicked() ), this, SLOT( setRenderingOrder() ) );

  currentRuleChanged();

  // store/restore header section widths
  connect( viewRules->header(), SIGNAL( sectionResized( int, int, int ) ), this, SLOT( saveSectionWidth( int, int, int ) ) );

  restoreSectionWidths();

}
Beispiel #10
0
/* Initialisation d'un L-System a partir d'une chaine de caracteres ou sont stockes les parametres */
Lsystem initLsystem(String strLsystem)
{
    Lsystem lsystem;
    lsystem.name = NULL;
    lsystem.variables = NULL;
    lsystem.constants = NULL;
    lsystem.start = NULL;
    lsystem.rules = NULL;
    lsystem.generations = NULL;
    lsystem.position = NULL;

    char delims[] = "\n";

    lsystem.name = strtok( strLsystem, delims );
    lsystem.angle = atoi(strtok( NULL, delims ));
    lsystem.variables = strtok( NULL, delims );
    lsystem.constants = strtok( NULL, delims );
    lsystem.start = strtok( NULL, delims );
    String result = NULL;
    result = strtok( NULL, delims );
    while( result != NULL ) {
        lsystem.rules=addRule(lsystem.rules,result);
        result = strtok( NULL, delims );
    }
    lsystem.generations = (Generations*)malloc(sizeof(Generations));
    lsystem.generations = newGeneration(lsystem.generations,lsystem);
    lsystem.position = (Position*)malloc(sizeof(Position));
    lsystem.position = newPosition(lsystem.position);
    return lsystem;
}
QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
    : QgsRendererV2Widget( layer, style )
{

  // try to recognize the previous renderer
  // (null renderer means "no previous renderer")
  if ( !renderer || renderer->type() != "RuleRenderer" )
  {
    // we're not going to use it - so let's delete the renderer
    delete renderer;

    // some default options
    QgsSymbolV2* symbol = QgsSymbolV2::defaultSymbol( mLayer->geometryType() );

    mRenderer = new QgsRuleBasedRendererV2( symbol );
  }
  else
  {
    mRenderer = static_cast<QgsRuleBasedRendererV2*>( renderer );
  }

  setupUi( this );

  treeRules->setRenderer( mRenderer );
  mRefineMenu = new QMenu( btnRefineRule );
  mRefineMenu->addAction( tr( "Add scales" ), this, SLOT( refineRuleScales() ) );
  mRefineMenu->addAction( tr( "Add categories" ), this, SLOT( refineRuleCategories() ) );
  mRefineMenu->addAction( tr( "Add ranges" ), this, SLOT( refineRuleRanges() ) );
  btnRefineRule->setMenu( mRefineMenu );

  btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) );
  btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
  btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );
  btnIncreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyUp.png" ) ) );
  btnDecreasePriority->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.png" ) ) );

  connect( treeRules, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( editRule() ) );

  connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
  connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
  connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );
  connect( btnIncreasePriority, SIGNAL( clicked() ), this, SLOT( increasePriority() ) );
  connect( btnDecreasePriority, SIGNAL( clicked() ), this, SLOT( decreasePriority() ) );

  connect( radNoGrouping, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
  connect( radGroupFilter, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );
  connect( radGroupScale, SIGNAL( clicked() ), this, SLOT( setGrouping() ) );

  // Make sure buttons are always in the correct state
  chkUsingFirstRule->setChecked( mRenderer->usingFirstRule() );
  chkEnableSymbolLevels->setChecked( mRenderer->usingSymbolLevels() );
  // If symbol levels are used, forcefully check and gray-out the chkUsingFirstRule checkbox
  if (mRenderer->usingSymbolLevels() ) { forceUsingFirstRule(); }
  connect( chkUsingFirstRule, SIGNAL( clicked() ), this, SLOT( usingFirstRuleChanged() ));
  connect( chkEnableSymbolLevels, SIGNAL( clicked() ), this, SLOT( symbolLevelsEnabledChanged() ) );
  connect( this, SIGNAL( forceChkUsingFirstRule() ), this, SLOT( forceUsingFirstRule() ) );

  treeRules->populateRules();
}
Beispiel #12
0
WCssTextRule *WCssStyleSheet::addRule(const std::string& selector,
				      const WT_USTRING& declarations,
				      const std::string& ruleName)
{
  WCssTextRule *result = new WCssTextRule(selector, declarations);
  addRule(result, ruleName);
  return result;
}
Beispiel #13
0
        KnowledgeBase()
            : vmd::KnowledgeBase(), today(0), yesterday(0)
        {
            addFact("today", boost::bind(&vmd::ex::KnowledgeBase::date, this, _1));

            vmd::Rule& r1 = addRule("Rule 1");
            r1.add(boost::bind(&vmd::ex::KnowledgeBase::haveGoodTemp, this));
            r1.add(boost::bind(&vmd::ex::KnowledgeBase::isAlwaysTrue, this));

            vmd::Rule& r2 = addRule("Rule 2");
            r2.add(boost::bind(&vmd::ex::KnowledgeBase::haveGoodTemp, this));

            vmd::Activity& act1 = addActivity("act1");
            act1.addRule("Rule 1", r1);

            vmd::Activity& act2 = addActivity("act2");
            act2.addRule("Rule 2", r2);
        }
Beispiel #14
0
void VRSnappingEngine::setPreset(PRESET preset) {
    clear();

    Line t0(Pnt3f(0,0,0), Vec3f(0,0,0));
    Line o0(Pnt3f(0,0,-1), Vec3f(0,1,0));

    switch(preset) {
        case SIMPLE_ALIGNMENT:
            addRule(POINT, POINT, t0, o0, 1, 1, 0);
            addRule(LINE, POINT, Line(Pnt3f(), Vec3f(1,0,0)), o0, 1, 1, 0);
            addRule(LINE, POINT, Line(Pnt3f(), Vec3f(0,1,0)), o0, 1, 1, 0);
            addRule(LINE, POINT, Line(Pnt3f(), Vec3f(0,0,1)), o0, 1, 1, 0);
            break;
        case SNAP_BACK:
            addRule(POINT, POINT, t0, o0, 1, 1, 0);
            break;
    }
}
Beispiel #15
0
void CLuaSocketRestrictions::addRules(RestrictType type, const std::string& configstr)
{
	int i=0;
	char ch;
	std::string rule;

	while((ch=configstr[i++])) {
		if ((isspace(ch)) && (!rule.empty())) {
			addRule(type, rule);
			rule = "";
		} else {
			rule += ch;
		}
	}
	if (!rule.empty()) {
		addRule(type, rule);
	}
}
void SeccompFiltersWebProcessEfl::platformInitialize()
{
    // TODO: We should block all the syscalls and whitelist
    // what we need + trap what should be handled by the broker.
    addRule("open", Trap);
    addRule("openat", Trap);
    addRule("creat", Trap);

    // Needed by Eeze on NetworkStateNotifierEfl.
    m_policy.addDirectoryPermission(ASCIILiteral("/sys/bus"), SyscallPolicy::Read);
    m_policy.addDirectoryPermission(ASCIILiteral("/sys/class"), SyscallPolicy::Read);
    m_policy.addDirectoryPermission(ASCIILiteral("/sys/devices"), SyscallPolicy::Read);
    m_policy.addFilePermission(ASCIILiteral("/etc/udev/udev.conf"), SyscallPolicy::Read);

#ifdef SOURCE_DIR
    // Developers using build-webkit --efl expect some libraries to be loaded
    // from the build root directory and they also need access to layout test
    // files. The constant is defined only when jhbuild is detected, which is
    // an indication of a development build.
    char* sourceDir = canonicalize_file_name(SOURCE_DIR);
    if (sourceDir) {
        m_policy.addDirectoryPermission(String::fromUTF8(sourceDir), SyscallPolicy::ReadAndWrite);
        free(sourceDir);
    }
#endif

    // Place where the theme and icons are installed.
    char* dataDir = canonicalize_file_name(DATA_DIR);
    if (dataDir) {
        m_policy.addDirectoryPermission(String::fromUTF8(dataDir), SyscallPolicy::Read);
        free(dataDir);
    }

#if USE(GSTREAMER)
    // Video playback requires access to the root of the user cache dir which
    // is not right. We need to check with these directories on gstreamer
    // can be configured.
    char* homeDir = getenv("HOME");
    if (homeDir)
        m_policy.addDirectoryPermission(String::fromUTF8(homeDir) + "/.cache", SyscallPolicy::ReadAndWrite);
#endif

    SeccompBroker::launchProcess(this, m_policy);
}
Beispiel #17
0
bool RuleSet::parseEntries(QString s, int year,
			   QTime t1, QTime t2,
			   double costs, double len, double after)
{
  // special rule: on() is the same as on(monday..sunday)
  if(s.isEmpty())
    s = "monday..sunday";

  while(s.length()) {
    int pos = s.indexOf(',');
    QString token;
    if(pos == -1) {
      token = s;
      s = "";
    } else {
      token = s.left(pos);
      s = s.right(s.length()-pos-1);
    }

    // we've a token, now check if it defines a
    // range
    RULE r;
    if(token.contains("..")) {
      QString left, right;
      left = token.left(token.indexOf(".."));
      right = token.right(token.length()-2-left.length());
      RULE lr, rr;
      if(parseEntry(lr, left, year) && parseEntry(rr, right, year)) {
	if(lr.type == rr.type) {
	  r.type = lr.type;
	  switch(lr.type) {
	  case 1:
	    r.date.from = lr.date.from;
	    r.date.until = rr.date.from;
	    break;
	  case 2:
	    r.weekday.from = lr.weekday.from;
	    r.weekday.until = rr.weekday.from;
	  }
	} else
	  return false;
      }
    } else
      if(!parseEntry(r, token, year))
	return false;

    r.costs = costs;
    r.len = len;
    r.after = after;
    r.from = t1;
    r.until = t2;
    addRule(r);
  }

  return true;
}
Beispiel #18
0
//#include "HtmlHighlighterh"
PhpHighlighter::PhpHighlighter(QTextDocument *parent) : Highlighter(parent)
{
    // Les mots clé.
    keywordFormat.setForeground(Qt::darkBlue);
    keywordFormat.setFontWeight(QFont::Bold);
    addRule(PhpData::keywordRegex, keywordFormat);

    // Pour les déclarations de variable.
    idFormat.setForeground(Qt::darkRed);
    idFormat.setFontWeight(QFont::Bold);
    addRule(PhpData::idRegex, idFormat);

    // Les mots clé de déclaration.
    keywordConstantFormat.setFontWeight(QFont::Bold);
    keywordConstantFormat.setForeground(Qt::darkMagenta);
    addRule(PhpData::keywordConstantRegex, keywordConstantFormat);

    // Les nombres.
    numberFormat.setFontWeight(QFont::Bold);
    numberFormat.setForeground(Qt::darkYellow);
    addRule(PhpData::numberRegex, numberFormat);

    // Commentaire sur une seule ligne.
    singleLineCommentFormat.setForeground(Qt::gray);
    addRule(PhpData::singleLineCommentRegex, singleLineCommentFormat);

    // Commentaires multilignes.
    multilineCommentFormat.setForeground(Qt::gray);
    addMultilineRule(PhpData::multilineCommentStartRegex,
                     PhpData::multilineCommentEndRegex,
                     multilineCommentFormat,
                     IN_COMMENT_STATE);

    // Les simples et doubles quotes.
    quotationFormat.setForeground(Qt::darkGreen);
    addRule(PhpData::quotationRegex, quotationFormat);

    // Les déclarations de fonction
    functionFormat.setForeground(Qt::blue);
    addRule(PhpData::functionRegex, functionFormat);

    // Coloration balise php
    startPhpFormat.setForeground(Qt::red);
    addRule(PhpData::startPhpRegex, startPhpFormat);

    endPhpFormat.setForeground(Qt::red);
    addRule(PhpData::endPhpRegex, endPhpFormat);
}
Beispiel #19
0
WCssTemplateRule *WCssStyleSheet::addRule(const std::string& selector,
					  const WCssDecorationStyle& style,
					  const std::string& ruleName)
{
  WCssTemplateRule *result = new WCssTemplateRule(selector);
  result->templateWidget()->setDecorationStyle(style);

  addRule(result, ruleName);
  return result;
}
static std::unique_ptr<RuleSet> makeRuleSet(const Vector<RuleFeature>& rules)
{
    size_t size = rules.size();
    if (!size)
        return nullptr;
    auto ruleSet = std::make_unique<RuleSet>();
    for (size_t i = 0; i < size; ++i)
        ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState);
    ruleSet->shrinkToFit();
    return ruleSet;
}
Beispiel #21
0
int main()
{
  addRule(rules, "URL aaaa 2 4.3 test-url");
  addRule(rules, "URL bbbb other-url");
  addRule(rules, "ARC bbbb cccc");

  test(aaa);
  test(bbb);
  test(ccc);
  test(ddd);

  loadRulesJsonFile(rules, "rules.json");

  test(aaa);
  test(bbb);
  test(ccc);
  test(ddd);

  return 0;
}
Beispiel #22
0
int CategoryManager::addRules(const RuleSet& ruleSet)
{
    int count = 0;
    for (int i = 0; i < ruleSet.maxNumRules(); ++i) {
        const Rule *rule = ruleSet.getRuleById(i);
        if (rule) {
            count += addRule(*rule);
        }
    }
    return count;
}
Beispiel #23
0
void CLuaSocketRestrictions::addRule(RestrictType type, const std::string& rule)
{
	size_t delimpos = rule.find(":");
	if (delimpos==std::string::npos) {
		LOG_L(L_ERROR, "Invalid %d rule: %s, rule has to be hostname:port", type, rule.c_str());
		return;
	}
	const std::string strport = rule.substr(delimpos+1, delimpos-rule.length());
	const int port = atoi(strport.c_str());
	addRule(type, rule.substr(0, delimpos), port, true);
}
Beispiel #24
0
void CLuaSocketRestrictions::addIP(const char* hostname, const char* ip)
{
	for(int i=0; i<ALL_RULES; i++) {
		TStrIntMap::iterator it;
		for(it = restrictions[i].begin(); it != restrictions[i].end(); ++it) {
			const TSocketRule &rule = *it;
			if ((rule.hostname == hostname)  && (getRule((RestrictType)i, ip, rule.port) == NULL)) { //add rule with ip, when not exisitng
				addRule((RestrictType)i, ip, rule.port, rule.allowed);
			}
		}
	}
}
Beispiel #25
0
 void RuleBlock::loadRules(const std::string& text, const Engine* engine, bool append) {
     if (not append) unloadRules();
     std::vector<std::string> textRules = fl::Op::split(text, "\n");
     for (std::size_t i = 0; i < textRules.size(); ++i){
         Rule* rule = new Rule(textRules.at(i));
         try{
             rule->load(engine);
         }catch(...){
             //ignore
         }
         addRule(rule);
     }
 }
Beispiel #26
0
void LexicalAnalyser::readRules (ifstream& rulesFile)
{
	string regex, token;
	while (true)
	{
		rulesFile >> regex;
		if ( rulesFile.eof())
			break;
		rulesFile >> token;
		addRule (regex, token);
		if ( rulesFile.eof())
			break;
  	}
}
QgsRuleBasedLabelingWidget::QgsRuleBasedLabelingWidget( QgsVectorLayer* layer, QgsMapCanvas* canvas, QWidget* parent )
    : QgsPanelWidget( parent )
    , mLayer( layer )
    , mCanvas( canvas )
    , mRootRule( nullptr )
    , mModel( nullptr )
{
  setupUi( this );

  btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.svg" ) ) );
  btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
  btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.svg" ) ) );

  mCopyAction = new QAction( tr( "Copy" ), this );
  mCopyAction->setShortcut( QKeySequence( QKeySequence::Copy ) );
  mPasteAction = new QAction( tr( "Paste" ), this );
  mPasteAction->setShortcut( QKeySequence( QKeySequence::Paste ) );
  mDeleteAction = new QAction( tr( "Remove Rule" ), this );
  mDeleteAction->setShortcut( QKeySequence( QKeySequence::Delete ) );

  viewRules->addAction( mDeleteAction );
  viewRules->addAction( mCopyAction );
  viewRules->addAction( mPasteAction );

  connect( viewRules, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( editRule( const QModelIndex & ) ) );

  connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
  connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
  connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );
  connect( mCopyAction, SIGNAL( triggered( bool ) ), this, SLOT( copy() ) );
  connect( mPasteAction, SIGNAL( triggered( bool ) ), this, SLOT( paste() ) );
  connect( mDeleteAction, SIGNAL( triggered( bool ) ), this, SLOT( removeRule() ) );

  if ( mLayer->labeling() && mLayer->labeling()->type() == "rule-based" )
  {
    const QgsRuleBasedLabeling* rl = static_cast<const QgsRuleBasedLabeling*>( mLayer->labeling() );
    mRootRule = rl->rootRule()->clone();
  }
  else
  {
    mRootRule = new QgsRuleBasedLabeling::Rule( nullptr );
  }

  mModel = new QgsRuleBasedLabelingModel( mRootRule );
  viewRules->setModel( mModel );

  connect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SIGNAL( widgetChanged() ) );
  connect( mModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SIGNAL( widgetChanged() ) );
  connect( mModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SIGNAL( widgetChanged() ) );
}
TEST_F(AspAlicaEngineWithDomain, ReusePlanFromPlantypeWithoutCycle_PlanBase)
{
    ae = new alica::AlicaEngine(new supplementary::AgentIDManager(new supplementary::AgentIDFactory()),
                                "ReusePlanWithoutCycle", "ReusePlanFromPlantypeWithoutCycle", ".", false);
    ae->setIAlicaClock(new alica_dummy_proxy::AlicaSystemClock());
    ae->setCommunicator(new alica_dummy_proxy::AlicaDummyCommunication(ae));
    // "1" stands for the ASPSolver in this test suite only!
    std::vector<char const *> args{"clingo", "-W", "no-atom-undefined", nullptr};
    auto solver = new ::reasoner::ASPSolver(args);
    auto solverWrapper = new alica::reasoner::ASPSolverWrapper(ae, args);
    solverWrapper->init(solver);

    solverWrapper->getSolver()->loadFileFromConfig("assistanceBackgroundKnowledgeFile");
    ae->addSolver(1, solverWrapper);
    EXPECT_TRUE(ae->init(bc, cc, uc, crc)) << "Unable to initialise the ALICA Engine!";

    alica::reasoner::ASPSolverWrapper *aspSolver =
        dynamic_cast<alica::reasoner::ASPSolverWrapper *>(ae->getSolver(1)); // "1" for ASPSolver

    alica::Plan *plan = ae->getPlanBase()->getMasterPlan();

    string queryString1 = "brokenPlanBase(donatello)";
    auto constraint = make_shared<::reasoner::ASPCommonsTerm>();
    constraint->addRule(queryString1);
    constraint->setType(::reasoner::ASPQueryType::Facts);
    constraint->setProgramSection("assistanceTestFacts");

    ((::reasoner::ASPSolver *)(aspSolver->getSolver()))->ground({{"assistanceBackground", {}}}, nullptr);

    shared_ptr<::reasoner::ASPFactsQuery> queryObject1 =
        make_shared<::reasoner::ASPFactsQuery>(((::reasoner::ASPSolver *)(aspSolver->getSolver())), constraint);
    ((alica::reasoner::ASPSolverWrapper *)(aspSolver->getSolver()))->registerQuery(queryObject1);

    // start time measurement for grounding
    std::chrono::_V2::system_clock::time_point groundingStart = std::chrono::high_resolution_clock::now();
    if (!((alica::reasoner::ASPSolverWrapper *)(aspSolver->getSolver()))->validatePlan(plan))
    {
        cout << "ASPAlicaTest: No Model found!" << endl;
    }
    else
    {
        ((alica::reasoner::ASPSolverWrapper *)(aspSolver->getSolver()))->printStats();
    }
    std::chrono::_V2::system_clock::time_point end = std::chrono::high_resolution_clock::now();
    cout << "Measured Grounding Time: "
         << std::chrono::duration_cast<chrono::milliseconds>(end - groundingStart).count() << " ms" << endl;

    EXPECT_FALSE(queryObject1->factsExistForAllModels()) << "The plan base of agent donatello should not be broken.";
    cout << queryObject1->toString() << endl;
}
Beispiel #29
0
void Engine::parseRule(std::string line) throw(std::string)
{
    EvaluationRule* rule = new EvaluationRule(line);

    while (line.length() > 0 && line.find_first_not_of(' ') != std::string::npos)
    {
        std::size_t keyWordEnd = line.find(" ");
        if (line.substr(0, keyWordEnd).compare("and") == 0)
        {
            rule->pushOperatorList(AND);
        }
        else if (line.substr(0, keyWordEnd).compare("or") == 0)
        {
            rule->pushOperatorList(OR);
        }
        else if (line.substr(0, keyWordEnd).compare("then") == 0)
        {
            rule->pushOperatorList(EQUAL);
        }
        else if (line.substr(0, keyWordEnd).compare("if") != 0) // No valid keyword
        {
            throw parseError;
        }
        // the rest looks now like : VARIABLENAME is TERM ......
        std::size_t variableNameEnd = line.find(" ", keyWordEnd + 1);
        std::size_t fillWordEnd = line.find(" ", variableNameEnd + 1);
        std::size_t termNameEnd = line.find(" ", fillWordEnd + 1);
        std::string variableName = line.substr(keyWordEnd + 1, variableNameEnd - keyWordEnd - 1);
        std::string termName = line.substr(fillWordEnd + 1, termNameEnd - fillWordEnd - 1);

        // Now find variable and term
        Variable* var = getVariableToName(variableName);
        if (var == NULL) throw parseError;
        Term* term = var->getTermToName(termName);
        if (term == NULL) throw parseError;
        rule->pushOperandList(term);

        if (line == line.substr(termNameEnd + 1))
        {
            line = "";
        }
        else
        {
            line = line.substr(termNameEnd + 1);
        }
    }

    addRule(rule);
}
Beispiel #30
0
PrivacyDlg::PrivacyDlg(const QString& account_name, PrivacyManager* manager, QWidget* parent) : QDialog(parent), manager_(manager)
{
	ui_.setupUi(this);
	setAttribute(Qt::WA_DeleteOnClose);
	setWindowTitle(tr("%1: Privacy Lists").arg(account_name));
	setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint);

	connect(manager_,SIGNAL(listsReceived(const QString&, const QString&, const QStringList&)),SLOT(updateLists(const QString&, const QString&, const QStringList&)));
	connect(manager_,SIGNAL(listReceived(const PrivacyList&)),SLOT(refreshList(const PrivacyList&)));
	connect(manager_,SIGNAL(listError()),SLOT(list_failed()));
	//connect(manager_,SIGNAL(listNamesError()),SLOT(listNamesError()));
	//connect(manager_,SIGNAL(listReceiveError()),SLOT(listReceiveError()));

	connect(ui_.cb_active,SIGNAL(activated(int)),SLOT(active_selected(int)));
	connect(ui_.cb_default,SIGNAL(activated(int)),SLOT(default_selected(int)));
	connect(ui_.cb_lists,SIGNAL(activated(int)),SLOT(list_selected(int)));
	connect(ui_.cb_lists,SIGNAL(currentIndexChanged(int)),SLOT(list_changed(int)));
	connect(manager_,SIGNAL(changeActiveList_success(QString)),SLOT(changeActiveList_succeeded(QString)));
	connect(manager_,SIGNAL(changeActiveList_error()),SLOT(change_failed()));
	connect(manager_,SIGNAL(changeDefaultList_success(QString)),SLOT(changeDefaultList_succeeded(QString)));
	connect(manager_,SIGNAL(changeDefaultList_error()),SLOT(change_failed()));
	connect(manager_,SIGNAL(changeList_success(QString)),SLOT(changeList_succeeded(QString)));
	connect(manager_,SIGNAL(changeList_error()),SLOT(changeList_failed()));

	connect(ui_.pb_newList,SIGNAL(clicked()),SLOT(newList()));
	connect(ui_.pb_deleteList,SIGNAL(clicked()),SLOT(removeList()));
	connect(ui_.pb_renameList,SIGNAL(clicked()),SLOT(renameList()));

	connect(ui_.pb_add,SIGNAL(clicked()),SLOT(addRule()));
	connect(ui_.pb_edit,SIGNAL(clicked()),SLOT(editCurrentRule()));
	connect(ui_.pb_remove,SIGNAL(clicked()),SLOT(removeCurrentRule()));
	connect(ui_.pb_up,SIGNAL(clicked()),SLOT(moveCurrentRuleUp()));
	connect(ui_.pb_down,SIGNAL(clicked()),SLOT(moveCurrentRuleDown()));
	connect(ui_.pb_apply,SIGNAL(clicked()),SLOT(applyList()));

	connect(ui_.buttonBox->button(QDialogButtonBox::Close),SIGNAL(clicked()),SLOT(close()));
	setWidgetsEnabled(false);

	// Disable all buttons
	ui_.pb_deleteList->setEnabled(false);
	setEditRuleEnabled(false);
	ui_.pb_add->setEnabled(false);
	ui_.pb_apply->setEnabled(false);

	// FIXME: Temporarily disabling auto-activate
	ui_.ck_autoActivate->hide();

	manager_->requestListNames();
}