Ejemplo n.º 1
0
bool PolygonStyleBuilder<V>::addPolygon(const Polygon& _polygon, const Properties& _props, const DrawRule& _rule) {

    parseRule(_rule, _props);

    m_builder.addVertex = [this](const glm::vec3& coord,
                                 const glm::vec3& normal,
                                 const glm::vec2& uv) {
        m_meshData.vertices.push_back({ coord, m_params.order, normal, uv, m_params.color, m_params.selectionColor });
    };

    if (m_params.minHeight != m_params.height) {
        Builders::buildPolygonExtrusion(_polygon, m_params.minHeight,
                                        m_params.height, m_builder);
    }

    Builders::buildPolygon(_polygon, m_params.height, m_builder);

    m_meshData.indices.insert(m_meshData.indices.end(),
                              m_builder.indices.begin(),
                              m_builder.indices.end());

    m_meshData.offsets.emplace_back(m_builder.indices.size(),
                                    m_builder.numVertices);
    m_builder.clear();

    return true;
}
Ejemplo n.º 2
0
/* The following routine parses timezone information in POSIX-format. For
 * the requirements, see IEEE Std 1003.1-1988 section 8.1.1.
 * The function returns as soon as it spots an error.
 */
static void
parseTZ(const char *p)
{
	long tz, dst = 60 * 60, sign = 1;
	static char lastTZ[2 * RULE_LEN];
	static char buffer[RULE_LEN];

	if (!p) return;

	if (*p == ':') {
		/*
		 * According to POSIX, this is implementation defined.
		 * Since it depends on the particular operating system, we
		 * can do nothing.
		 */
		return;
	}

	if (!strcmp(lastTZ, p)) return;		/* nothing changed */

	*_tzname[0] = '\0';
	*_tzname[1] = '\0';
	dststart.ds_type = 'U';
	dststart.ds_sec = 2 * 60 * 60;
	dstend.ds_type = 'U';
	dstend.ds_sec = 2 * 60 * 60;

	if (strlen(p) > 2 * RULE_LEN) return;
	strcpy(lastTZ, p);

	if (!(p = parseZoneName(buffer, p))) return;

	if (*p == '-') {
		sign = -1;
		p++;
	} else if (*p == '+') p++;

	if (!(p = parseTime(&tz, p, NULL))) return;
	tz *= sign;
	_timezone = tz;
	strncpy(_tzname[0], buffer, TZ_LEN);

	if (!(_daylight = (*p != '\0'))) return;

	buffer[0] = '\0';
	if (!(p = parseZoneName(buffer, p))) return;
	strncpy(_tzname[1], buffer, TZ_LEN);

	buffer[0] = '\0';
	if (*p && (*p != ','))
		if (!(p = parseTime(&dst, p, NULL))) return;
	_dst_off = dst;			/* dst was initialized to 1 hour */
	if (*p) {
		if (*p != ',') return;
		p++;
		if (strlen(p) > RULE_LEN) return;
		if (!(p = parseRule(buffer, p))) return;
	}
}
Ejemplo n.º 3
0
	bool LparseParser::parseRules() {
		int rt = -1;
		while (input()->skipWhite() && input()->parseInt(rt) && rt != 0 && parseRule(rt)) {
			active_->clear();
		}
		return check(rt == 0, "Rule type expected!")
			&& check(matchEol(*input(), true), "Symbol table expected!")
			&& input()->skipWhite();
	}
Ejemplo n.º 4
0
	void *NclPresentationControlParser::parseRuleBase(
		    DOMElement *parentElement, void *objGrandParent) {

		wclog << "parseRuleBase" << endl;
		void *parentObject;
		DOMNodeList *elementNodeList;
		DOMElement *element;
		DOMNode *node;
		string elementTagName;
		void *elementObject;

		parentObject = createRuleBase(parentElement, objGrandParent);
		if (parentObject == NULL) {
			return NULL;
		}

		elementNodeList = parentElement->getChildNodes();
		for (int i = 0; i < (int)elementNodeList->getLength(); i++) {
			node = elementNodeList->item(i);
			if (node->getNodeType() == DOMNode::ELEMENT_NODE) {
				element = (DOMElement*)node;
				elementTagName = XMLString::transcode(element->getTagName());
				wclog << ">>" << elementTagName.c_str() << ": ";
				wclog << XMLString::transcode(element->getAttribute(XMLString::transcode("id"))) << endl;

				if (XMLString::compareIString(elementTagName.c_str(),
					    "importBase") == 0) {

					elementObject = getImportParser()->parseImportBase(
						    element, parentObject);

					if (elementObject != NULL) {
						addImportBaseToRuleBase(parentObject, elementObject);
					}

				} else if(XMLString::compareIString(elementTagName.c_str(),
					    "rule") == 0) {

					elementObject = parseRule(element, parentObject);
					if (elementObject != NULL) {
						addRuleToRuleBase(parentObject, elementObject);
					}

				} else if(XMLString::compareIString(elementTagName.c_str(),
					    "compositeRule")==0) {

					elementObject = parseCompositeRule(element, parentObject);
					if (elementObject != NULL) {
						addCompositeRuleToRuleBase(parentObject, elementObject);
					}
				}
			}
		}

		return parentObject;
	}
Ejemplo n.º 5
0
// Public entry point to parsing.
ParseResult Parser::parse(ParseNamedDefinition* start) {
  if (start->numArguments() != 0) {
    parseError(SourceLocation()) << "Start rule must have no arguments";
    return ParseResult();
  }
  parseError_ = false;
  resultStack_.clear();
  parseRule(start);
  return resultStack_.getBack();
}
Ejemplo n.º 6
0
/*
 * Process input from a stream.
 */
static void processInput(FILE *stream, FILE *outstream)
{
	char buffer[BUFSIZ];
	while(readLine(buffer, stream))
	{
		if(parseRule(buffer))
		{
			generateCode(outstream);
		}
	}
}
bool XMLFPParser::loopRules(const xml_node& rules_root,
		MamdaniFuzzyObject* object) {

	for (xml_node rule = rules_root.child(RULE_TAG); rule; rule = rule.next_sibling(RULE_TAG)){
		if(!parseRule(rule, object)){
			LERROR << "Error during parse rule for object: " << object->getName();
			return false;
		}
	}
	return true;
}
/*!
 *  syntax ::= ( rule )+
 */
std::vector<RuleNode*> Parser::parseSyntax()
{
    std::vector<RuleNode*> v;

    // parsed but an error occurred
    if (!error_info_.empty()) {
        return v;
    }

    // parsed and ok
    if (!nodes_.empty()) {
        for (auto& n: nodes_) {
            v.push_back(n.get());
        }
        return v;
    }

    // not parsed, let's start
    v.push_back(parseRule());
    while (token_ == Lexer::Token::identifier) {
        v.push_back(parseRule());
    }

    if (token_ != Lexer::Token::eof) {
        errorNode("too much token");
    }

    // an error occurred while parsing
    if (!error_info_.empty()) {
        for (auto& n: v) {
            delete n;
        }
        v.clear();
    }

    for (auto& n: v) {
        nodes_.push_back(std::shared_ptr<RuleNode>(n));
    }

    return v;
}
Ejemplo n.º 9
0
void PolylineStyle::buildLine(const Line& _line, const DrawRule& _rule, const Properties& _props, VboMesh& _mesh, Tile& _tile) const {
    std::vector<PolylineVertex> vertices;

    Parameters params = parseRule(_rule);
    GLuint abgr = params.color;

    if (Tangram::getDebugFlag(Tangram::DebugFlags::proxy_colors)) {
        abgr = abgr << (_tile.getID().z % 6);
    }

    GLfloat layer = _props.getNumeric("sort_key") + params.order;
    float halfWidth = params.width * .5f;

    PolyLineBuilder builder {
        [&](const glm::vec3& coord, const glm::vec2& normal, const glm::vec2& uv) {
            vertices.push_back({ coord, uv, normal, halfWidth, abgr, layer });
        },
        [&](size_t sizeHint){ vertices.reserve(sizeHint); },
        params.cap,
        params.join
    };

    Builders::buildPolyLine(_line, builder);

    if (params.outlineOn) {

        GLuint abgrOutline = params.outlineColor;
        halfWidth += params.outlineWidth * .5f;

        if (params.outlineCap != params.cap || params.outlineJoin != params.join) {
            // need to re-triangulate with different cap and/or join
            builder.cap = params.outlineCap;
            builder.join = params.outlineJoin;
            Builders::buildPolyLine(_line, builder);
        } else {
            // re-use indices from original line
            size_t oldSize = builder.indices.size();
            size_t offset = vertices.size();
            builder.indices.reserve(2 * oldSize);

            for(size_t i = 0; i < oldSize; i++) {
                builder.indices.push_back(offset + builder.indices[i]);
            }
            for (size_t i = 0; i < offset; i++) {
                const auto& v = vertices[i];
                vertices.push_back({ v.pos, v.texcoord, v.enorm, halfWidth, abgrOutline, layer - 1.f });
            }
        }
    }

    auto& mesh = static_cast<PolylineStyle::Mesh&>(_mesh);
    mesh.addVertices(std::move(vertices), std::move(builder.indices));
}
Ejemplo n.º 10
0
PassRefPtrWillBeRawPtr<CSSValue> CSSParser::parseFontFaceDescriptor(CSSPropertyID propertyID, const String& propertyValue, const CSSParserContext& context)
{
    StringBuilder builder;
    builder.appendLiteral("@font-face { ");
    builder.append(getPropertyNameString(propertyID));
    builder.appendLiteral(" : ");
    builder.append(propertyValue);
    builder.appendLiteral("; }");
    RefPtrWillBeRawPtr<StyleRuleBase> rule = parseRule(context, nullptr, builder.toString());
    if (!rule || !rule->isFontFaceRule())
        return nullptr;
    return toStyleRuleFontFace(rule.get())->properties().getPropertyCSSValue(propertyID);
}
Ejemplo n.º 11
0
QVector<Rule> CSSParser::parseRules(){
#ifdef CSS_DEBUG
    qDebug() << Q_FUNC_INFO;
#endif /* CSS_DEBUG */
    QVector<Rule> rules;
    while(!eof()){
        consumeWhitespaceOrNewline();
        rules.append(parseRule());
        consumeWhitespaceOrNewline();
    }
    //QVector is implicit sharing
    return rules;
}
Ejemplo n.º 12
0
void Parser::parseProgram() {
    int id;
    while(true) {
        in >> id;
        switch(id) {
        case 0:
            return;
            
        case 1:
            parseRule();
            break;
            
        default:
            cerr << "Parsing error." << endl;
            return;
        }
    }
}
Ejemplo n.º 13
0
bool_t passwordGeneratorInitialize(passwordGenerator_t * self,
				   const char * rule,
				   const dictionary_t * dictionary) {
	uint_t i;
	self->ruleSegmentAccumulativeSizes = NULL;
	CHECK(parseRule(self, rule, dictionary));

	self->maxPasswordLength = 0;
	self->size = 0;

	for (i = 0; i < self->numRuleSegments; ++i) {
		const ruleSegment_t * ruleSegment = self->ruleSegments + i;
		ulong_t currMaxLength = ruleSegmentGetMaxLength(ruleSegment);
		if (self->maxPasswordLength < currMaxLength) {
			self->maxPasswordLength = currMaxLength;
		}
		self->size += ruleSegmentGetSize(ruleSegment);
	}

	if (self->numRuleSegments > 0) {
		self->ruleSegmentAccumulativeSizes = (ulong_t *) malloc(self->numRuleSegments * sizeof(ulong_t));
		CHECK(NULL != self->ruleSegmentAccumulativeSizes);

		self->ruleSegmentAccumulativeSizes[0] = ruleSegmentGetSize(self->ruleSegments + 0);

		for (i = 1; i < self->numRuleSegments; ++i) {
			self->ruleSegmentAccumulativeSizes[i] =
					self->ruleSegmentAccumulativeSizes[i - 1] +
					ruleSegmentGetSize(self->ruleSegments + i);
		}
	}

	return TRUE;

LBL_ERROR:
	passwordGeneratorFinalize(self);
	return FALSE;
}
Ejemplo n.º 14
0
void PolylineStyleBuilder<V>::addFeature(const Feature& _feat, const DrawRule& _rule) {

    if (_feat.geometryType == GeometryType::points) { return; }
    if (!checkRule(_rule)) { return; }

    Parameters params = parseRule(_rule, _feat.props);

    if (params.fill.width[0] <= 0.0f && params.fill.width[1] <= 0.0f ) { return; }

    if (_feat.geometryType == GeometryType::lines) {
        // Line geometries are never clipped to tiles, so keep all segments
        params.keepTileEdges = true;

        for (auto& line : _feat.lines) {
            addMesh(line, params);
        }
    } else {
        for (auto& polygon : _feat.polygons) {
            for (const auto& line : polygon) {
                addMesh(line, params);
            }
        }
    }
}
Ejemplo n.º 15
0
int RewriteRule::parse( char * &pRule, const RewriteMapList * pMaps )
{
    char * pCur;
    char * pLineEnd;
    LinkedObj * pLast = m_conds.head();
    assert( pLast->next() == NULL );
    while( *pRule )
    {
        while( isspace( *pRule ) )
            ++pRule;
        if ( !*pRule )
            break;
        pCur = pRule;
        pLineEnd = strchr( pCur, '\n' );
        if ( !pLineEnd )
        {
            pLineEnd = pCur + strlen( pCur );
            pRule = pLineEnd;
        }
        else
        {
            pRule = pLineEnd + 1;
            *pLineEnd = 0;
        }
        s_pCurLine = pCur;
        if ( *pCur != '#' )
        {
            if (( strncasecmp( pCur, "RewriteCond", 11 ) == 0 )&&
                ( isspace( *(pCur + 11)) ))
            {
                RewriteCond * pCond = new RewriteCond();
                if ( !pCond )
                {
                    ERR_NO_MEM( "new RewriteCond()" );
                    return -1;
                }
                
                if ( pCond->parse( pCur+12, pLineEnd, pMaps ) )
                {
                    delete pCond;
                    HttpLog::parse_error( s_pCurLine,  "invalid rewrite condition" );
                    return -1;
                }
                pLast->addNext( pCond );
                pLast = pCond;
            }
            else if (( strncasecmp( pCur, "RewriteRule", 11 ) == 0 )&&
                     ( isspace( *(pCur + 11)) ))
            {
                int ret = parseRule( pCur+12, pLineEnd, pMaps );
                pCur = pLineEnd+1;
                return ret;
            }
            else
            {
                HttpLog::parse_error( s_pCurLine,  "invalid rewrite directive " );
                return -1;
            }
        }
    }

    return -1;
}
Ejemplo n.º 16
0
void Engine::parseInput() throw (std::string) 
{
    // TODO: Add more error checking (if strings and numbers really exist)
    std::string line;
    std::getline(*inputFile, line);
    ParseStateEnum parseState = Invalid;
    InputVariable* actInputVar = NULL;
    OutputVariable* actOutputVar = NULL;

    while (!inputFile->eof())
    {
        if (line.find("#") == std::string::npos) // No comment
        {
            std::size_t delimiterPos = line.find(":");
            std::string token = line.substr(0, delimiterPos);
            if (token.compare("Engine") == 0)
            {
                std::size_t endPos = line.find(" ", delimiterPos + 2);
                name = line.substr(delimiterPos + 2, endPos - delimiterPos - 2);
                projectName = name;
                name = name + "App";
            }
            else if (token.compare("InputVariable") == 0)
            {
                parseState = Input;
                std::size_t endPos = line.find(" ", delimiterPos + 2);
                actInputVar = addInputVariable(line.substr(delimiterPos + 2, endPos - delimiterPos - 2));
            }
            else if (token.compare("OutputVariable") == 0)
            {
                parseState = Output;
                std::size_t endPos = line.find(" ", delimiterPos + 2);
                actOutputVar = addOutputVariable(line.substr(delimiterPos + 2, endPos - delimiterPos - 2));
            }
            else if (token.compare("RuleBlock") == 0)
            {
                parseState = Rule;
            }
            else if (token.compare("  enabled") == 0)
            {
                switch(parseState) 
                {
                    case Invalid:
                        throw parseError;
                        break;
                    default:
                        std::cout << "Warning: The enabled option is not supported" << std::endl;
                        break;
                }
            }
            else if (token.compare("  range") == 0)
            {
                std::size_t endFirstNumber = line.find(" ", delimiterPos + 2);
                std::size_t endSecondNumber = line.find(" ", endFirstNumber + 1);
                if (line.length() == endFirstNumber) throw parseError;
                switch(parseState) // range: scalar scalar
                {
                    case Input:
                        actInputVar->setRange(strtod(line.substr(delimiterPos + 2, endFirstNumber - delimiterPos - 2).c_str(), NULL),
                        strtod(line.substr(endFirstNumber + 1, endSecondNumber - endFirstNumber - 1).c_str(), NULL));
                        break;
                    case Output:
                        actOutputVar->setRange(strtod(line.substr(delimiterPos + 2, endFirstNumber - delimiterPos - 2).c_str(), NULL),
                        strtod(line.substr(endFirstNumber + 1, endSecondNumber - endFirstNumber - 1).c_str(), NULL));
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  term") == 0)
            {
                switch(parseState) 
                {
                    case Input:
                        try
                        {
                            parseTerm(actInputVar, line.substr(delimiterPos + 2), true);
                        }
                        catch (std::string error)
                        {
                            throw error;
                        }
                        break;
                    case Output:
                        try
                        {
                            parseTerm(actOutputVar, line.substr(delimiterPos + 2), false);
                        }
                        catch (std::string error)
                        {
                            throw error;
                        }
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  accumulation") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The accumulation option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  defuzzifier") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The defuzzifier option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  default") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The default option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  lock-previous") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The lock-previous option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  lock-range") == 0)
            {
                switch(parseState) 
                {
                    case Output:
                        std::cout << "Warning: The lock-range option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  conjunction") == 0)
            {
                switch(parseState) 
                {
                    case Rule:
                        std::cout << "Warning: The conjunction option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  disjunction") == 0)
            {
                switch(parseState) 
                {
                    case Rule:
                        std::cout << "Warning: The disjunction option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  activation") == 0)
            {
                switch(parseState) 
                {
                    case Rule:
                        std::cout << "Warning: The activation option is not supported" << std::endl;
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else if (token.compare("  rule") == 0)
            {
                switch(parseState) 
                {
                    case Rule:
                        try
                        {
                            parseRule(line.substr(delimiterPos + 2));
                        }
                        catch (std::string error)
                        {
                            throw error;
                        }
                        break;
                    default:
                        throw parseError;
                        break;
                }
            }
            else // Not a valid symbol
            {
                throw parseError;
            }
        }
        std::getline(*inputFile, line);
    }
}
int CommandListener::FirewallCmd::runCommand(SocketClient *cli, int argc,
        char **argv) {
    if (argc < 2) {
        cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing command", false);
        return 0;
    }

    if (!strcmp(argv[1], "enable")) {
        int res = sFirewallCtrl->enableFirewall();
        return sendGenericOkFail(cli, res);
    }
    if (!strcmp(argv[1], "disable")) {
        int res = sFirewallCtrl->disableFirewall();
        return sendGenericOkFail(cli, res);
    }
    if (!strcmp(argv[1], "is_enabled")) {
        int res = sFirewallCtrl->isFirewallEnabled();
        return sendGenericOkFail(cli, res);
    }

    if (!strcmp(argv[1], "set_interface_rule")) {
        if (argc != 4) {
            cli->sendMsg(ResponseCode::CommandSyntaxError,
                         "Usage: firewall set_interface_rule <rmnet0> <allow|deny>", false);
            return 0;
        }

        const char* iface = argv[2];
        FirewallRule rule = parseRule(argv[3]);

        int res = sFirewallCtrl->setInterfaceRule(iface, rule);
        return sendGenericOkFail(cli, res);
    }

    if (!strcmp(argv[1], "set_egress_source_rule")) {
        if (argc != 4) {
            cli->sendMsg(ResponseCode::CommandSyntaxError,
                         "Usage: firewall set_egress_source_rule <192.168.0.1> <allow|deny>",
                         false);
            return 0;
        }

        const char* addr = argv[2];
        FirewallRule rule = parseRule(argv[3]);

        int res = sFirewallCtrl->setEgressSourceRule(addr, rule);
        return sendGenericOkFail(cli, res);
    }

    if (!strcmp(argv[1], "set_egress_dest_rule")) {
        if (argc != 5) {
            cli->sendMsg(ResponseCode::CommandSyntaxError,
                         "Usage: firewall set_egress_dest_rule <192.168.0.1> <80> <allow|deny>",
                         false);
            return 0;
        }

        const char* addr = argv[2];
        int port = atoi(argv[3]);
        FirewallRule rule = parseRule(argv[4]);

        int res = 0;
        res |= sFirewallCtrl->setEgressDestRule(addr, PROTOCOL_TCP, port, rule);
        res |= sFirewallCtrl->setEgressDestRule(addr, PROTOCOL_UDP, port, rule);
        return sendGenericOkFail(cli, res);
    }

    if (!strcmp(argv[1], "set_uid_rule")) {
        if (argc != 4) {
            cli->sendMsg(ResponseCode::CommandSyntaxError,
                         "Usage: firewall set_uid_rule <1000> <allow|deny>",
                         false);
            return 0;
        }

        int uid = atoi(argv[2]);
        FirewallRule rule = parseRule(argv[3]);

        int res = sFirewallCtrl->setUidRule(uid, rule);
        return sendGenericOkFail(cli, res);
    }

    cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown command", false);
    return 0;
}