Exemplo n.º 1
0
static inline double toDoubleType(const CharType* data, size_t length, bool* ok, size_t& parsedLength)
{
    size_t leadingSpacesLength = 0;
    while (leadingSpacesLength < length && isASCIISpace(data[leadingSpacesLength]))
        ++leadingSpacesLength;

    double number = parseDouble(data + leadingSpacesLength, length - leadingSpacesLength, parsedLength);
    if (!parsedLength) {
        if (ok)
            *ok = false;
        return 0.0;
    }

    parsedLength += leadingSpacesLength;
    if (ok)
        *ok = policy == AllowTrailingJunk || parsedLength == length;
    return number;
}
Exemplo n.º 2
0
AstNode* Parser::parseUnary() {
    if (isUnaryOp(currentToken())) {
        TokenKind op = currentToken();
        consumeToken();
        return new UnaryOpNode(_currentTokenIndex, op, parseUnary());
    } else if (currentToken() == tIDENT && lookaheadToken(1) == tLPAREN) {
        AstNode* expr = parseCall();
        return expr;
    } else if (currentToken() == tIDENT) {
        AstVar* var = _currentScope->lookupVariable(currentTokenValue());
        if (var == 0) {
            error("undeclared variable: %s", currentTokenValue().c_str());
        }
        LoadNode* result = new LoadNode(_currentTokenIndex, var);
        consumeToken();
        return result;
    } else if (currentToken() == tDOUBLE) {
        DoubleLiteralNode* result =
            new DoubleLiteralNode(_currentTokenIndex,
                                  parseDouble(currentTokenValue()));
        consumeToken();
        return result;
    } else if (currentToken() == tINT) {
        IntLiteralNode* result =
            new IntLiteralNode(_currentTokenIndex,
                               parseInt(currentTokenValue()));
        consumeToken();
        return result;
    } else if (currentToken() == tSTRING) {
        StringLiteralNode* result =
            new StringLiteralNode(_currentTokenIndex,
                                  currentTokenValue());
        consumeToken();
        return result;
    } else if (currentToken() == tLPAREN) {
        consumeToken();
        AstNode* expr = parseExpression();
        ensureToken(tRPAREN);
        return expr;
    } else {
        error("Unexpected token: %s", tokenStr(currentToken()));
        return 0;
    }
}
Exemplo n.º 3
0
double Node::dn() const
{
    if (!m_dn)
    {
        m_dn = new double(0);
        if (m_line2)
        {
            ErrorCode error = NoError;
            *m_dn = parseDouble(m_line2, 33, 10, error);
            if (error != NoError)
            {
                m_lastError = error;
                *m_dn = 0;
            }
        }
    }

    return *m_dn;
}
Exemplo n.º 4
0
double Node::d2n() const
{
    if (!m_d2n)
    {
        m_d2n = new double(0);
        if (m_line2)
        {
            ErrorCode error = NoError;
            *m_d2n = parseDouble(m_line2, 44, 8, error, true);
            if (error != NoError)
            {
                m_lastError = error;
                *m_d2n = 0;
            }
        }
    }

    return *m_d2n;
}
Exemplo n.º 5
0
double Node::omega() const
{
    if (!m_omega)
    {
        m_omega = new double(0);
        if (m_line3)
        {
            ErrorCode error = NoError;
            *m_omega = parseDouble(m_line3, 34, 8, error);
            if (error != NoError)
            {
                m_lastError = error;
                *m_omega = 0;
            }
        }
    }

    return *m_omega;
}
Exemplo n.º 6
0
double Node::M() const
{
    if (!m_M)
    {
        m_M = new double(0);
        if (m_line3)
        {
            ErrorCode error = NoError;
            *m_M = parseDouble(m_line3, 43, 8, error);
            if (error != NoError)
            {
                m_lastError = error;
                *m_M = 0;
            }
        }
    }

    return *m_M;
}
Exemplo n.º 7
0
double Node::bstar() const
{
    if (!m_bstar)
    {
        m_bstar = new double(0);
        if (m_line2)
        {
            ErrorCode error = NoError;
            *m_bstar = parseDouble(m_line2, 53, 8, error, true);
            if (error != NoError)
            {
                m_lastError = error;
                *m_bstar = 0;
            }
        }
    }

    return *m_bstar;
}
Exemplo n.º 8
0
double Node::e() const
{
    if (!m_e)
    {
        m_e = new double(0);
        if (m_line3)
        {
            ErrorCode error = NoError;
            *m_e = parseDouble(m_line3, 26, 8, error, true);
            if (error != NoError)
            {
                m_lastError = error;
                *m_e = 0;
            }
        }
    }

    return *m_e;
}
Exemplo n.º 9
0
double Node::n() const
{
    if (!m_n)
    {
        m_n = new double(0);
        if (m_line3)
        {
            ErrorCode error = NoError;
            *m_n = parseDouble(m_line3, 52, 11, error);
            if (error != NoError)
            {
                m_lastError = error;
                *m_n = 0;
            }
        }
    }

    return *m_n;
}
Exemplo n.º 10
0
double Node::i() const
{
    if (!m_i)
    {
        m_i = new double(0);
        if (m_line3)
        {
            ErrorCode error = NoError;
            *m_i = parseDouble(m_line3, 8, 8, error);
            if (error != NoError)
            {
                m_lastError = error;
                *m_i = 0;
            }
        }
    }

    return *m_i;
}
Exemplo n.º 11
0
Expression parseArguments(int argc, char** argv) {
    if (argc == 1) {
        help(argv[0]);
        exit(0);
    } else if (argc != 4) {
        printf("ERROR: Should be 3 arguments.\n\n");
        help(argv[0]);
        exit(1);
    }

    Expression expression;
    try {
        expression.value = static_cast<double>(parseDouble(argv[1]));
        expression.UnitInput = static_cast<LengthUnit>(parseUnit(argv[2]));
        expression.UnitOutput = static_cast<LengthUnit>(parseUnit(argv[3]));
    }
    catch(...) {
        printf("Wrong format!");
        exit(2);
    }

    return expression;
}
Exemplo n.º 12
0
void SGFReader::parseKM(Game& game, std::string line)
{
    game.m_komi = parseDouble(line);
}
Exemplo n.º 13
0
void ComplexXMLParser10x::parseRadarCollectionFromXML(
        const XMLElem radarCollectionXML,
        RadarCollection* radarCollection) const
{
    XMLElem tmpElem = getFirstAndOnly(radarCollectionXML, "TxFrequency");
    parseDouble(getFirstAndOnly(tmpElem, "Min"),
                radarCollection->txFrequencyMin);
    parseDouble(getFirstAndOnly(tmpElem, "Max"),
                radarCollection->txFrequencyMax);

    tmpElem = getOptional(radarCollectionXML, "RefFreqIndex");
    if (tmpElem)
    {
        //optional
        parseInt(tmpElem, radarCollection->refFrequencyIndex);
    }

    tmpElem = getOptional(radarCollectionXML, "Waveform");
    if (tmpElem)
    {
        //optional
        parseWaveformFromXML(tmpElem, radarCollection->waveform);
    }

    tmpElem = getFirstAndOnly(radarCollectionXML, "TxPolarization");
    radarCollection->txPolarization = six::toType<PolarizationSequenceType>(
            tmpElem->getCharacterData());

    tmpElem = getOptional(radarCollectionXML, "TxSequence");
    if (tmpElem)
    {
        //optional
        parseTxSequenceFromXML(tmpElem, radarCollection->txSequence);
    }

    tmpElem = getFirstAndOnly(radarCollectionXML, "RcvChannels");

    std::vector<XMLElem> channelsXML;
    tmpElem->getElementsByTagName("ChanParameters", channelsXML);
    if (channelsXML.empty())
    {
        throw except::Exception(Ctxt(
                "Expected at least one ChanParameters element"));
    }

    for (std::vector<XMLElem>::const_iterator it = channelsXML.begin();
         it != channelsXML.end();
         ++it)
    {
        radarCollection->rcvChannels.resize(
                radarCollection->rcvChannels.size() + 1);
        mem::ScopedCloneablePtr<ChannelParameters>& chanParams =
                radarCollection->rcvChannels.back();
        chanParams.reset(new ChannelParameters());

        XMLElem childXML = getFirstAndOnly(*it, "TxRcvPolarization");
        chanParams->txRcvPolarization = six::toType<DualPolarizationType>(
                childXML->getCharacterData());

        childXML = getOptional(*it, "RcvAPCIndex");
        if (childXML)
        {
            parseInt(childXML, chanParams->rcvAPCIndex);
        }
    }

    XMLElem areaXML = getOptional(radarCollectionXML, "Area");
    if (areaXML)
    {
        //optional
        parseAreaFromXML(areaXML, true, false, radarCollection->area);
    }

    common().parseParameters(radarCollectionXML, "Parameter",
                    radarCollection->parameters);
}
Exemplo n.º 14
0
 static inline double parse(const char* value)
 {
   return parseDouble(value);
 }
Exemplo n.º 15
0
static int m3u_parser_line(struct list_mgt *mgt,unsigned char *line,struct list_item*item)
{
    unsigned char *p=line;
    int enditem=0;
    const char* ptr = NULL;
    int isLetvFlag = 0;
    while(*p==' ' && p!='\0' && p-line<1024) p++;
    if(*p!='#' && strlen(p)>0&&mgt->is_variant==0)
    {
        item->file=p;
        enditem=1;
    } else if(av_strstart(line,EXT_LETV_VER, &ptr)) {
        av_log(NULL,AV_LOG_INFO,"Get letv version: %s\n",ptr+1);
        mgt->flags|=IGNORE_SEQUENCE_FLAG;
    } else if(is_TAG(p,EXT_X_ENDLIST)) {
        item->flags|=ENDLIST_FLAG;
        enditem=1;
    } else if(is_TAG(p,EXTINF)) {
        double duration=0.00;
        parseDouble(p+8,&duration);
        av_log(NULL,AV_LOG_INFO,"Get item duration:%.4lf\n",duration);
        //sscanf(p+8,"%d",&duration);//skip strlen("#EXTINF:")
        if(duration>0) {
            item->flags|=DURATION_FLAG;
            item->duration=duration;
        }
    } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
        mgt->target_duration = atoi(ptr);
        av_log(NULL, AV_LOG_INFO, "get target duration:%ld\n",mgt->target_duration);
    } else if(is_TAG(p,EXT_X_ALLOW_CACHE)) {
        item->flags|=ALLOW_CACHE_FLAG;
    } else if(is_TAG(p,EXT_X_MEDIA_SEQUENCE)&&!(mgt->flags&IGNORE_SEQUENCE_FLAG)) {
        int seq = -1;
        int ret=0;
        int slen = strlen("#EXT-X-MEDIA-SEQUENCE:");
        ret=sscanf(p+slen,"%d",&seq); //skip strlen("#EXT-X-MEDIA-SEQUENCE:");
        if(ret>0&&seq>=0&&seq>=mgt->next_seq) {
            if(mgt->start_seq<0) {
                mgt->start_seq=seq;
                if(seq>0) {
                    mgt->flags |=REAL_STREAMING_FLAG;

                }
            }
            item->seq=seq;
            mgt->next_seq=seq+1;

        } else {
            item->seq = seq;
            item->flags|=INVALID_ITEM_FLAG;
        }
    }

    else if(av_strstart(p,"#EXT-X-STREAM-INF:",&ptr)) {
        struct variant_info info = {{0}};
        ff_parse_key_value(p, (ff_parse_key_val_cb) handle_variant_args,
                           &info);
        mgt->bandwidth = atoi(info.bandwidth);
        av_log(NULL, AV_LOG_INFO, "get a stream info,bandwidth:%d\n",mgt->bandwidth);
        mgt->is_variant = 1;
        return -(TRICK_LOGIC_BASE+1);
    }

    else if(av_strstart(p,"#EXT-X-KEY:",&ptr)) {

        struct key_info info = {{0}};
        uint8_t iv[16] = "";
        ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_key_args,
                           &info);
#if 0
        av_log(NULL,AV_LOG_INFO,"==========start dump a aes key===========\n");
        av_log(NULL,AV_LOG_INFO,"==========key location : %s\n",info.uri);
        av_log(NULL,AV_LOG_INFO,"==========key iv : %s\n",info.iv);
        av_log(NULL,AV_LOG_INFO,"==========key method : %s\n",info.method);
        av_log(NULL,AV_LOG_INFO,"==========end dump a aes key===========\n");

#endif
        struct encrypt_key_priv_t* key_priv_info = av_mallocz(sizeof(struct encrypt_key_priv_t));

        if(NULL == key_priv_info) {
            av_log(NULL,AV_LOG_ERROR,"no memory for key_info\n");
            return -1;
        }

        if(NULL!=mgt->key_tmp) {
            av_log(NULL,AV_LOG_INFO,"released old key info\n");
            av_free(mgt->key_tmp);
            mgt->key_tmp = NULL;
        }

        enum KeyType key_type = KEY_NONE;
        if (!strcmp(info.method, "AES-128")) {
            key_type = KEY_AES_128;

        }
        if (!strncmp(info.iv, "0x", 2) || !strncmp(info.iv, "0X", 2)) {
            ff_hex_to_data(iv, info.iv + 2);
            mgt->has_iv = 1;
        } else {
            mgt->has_iv = 0;
        }
        if(key_type ==KEY_AES_128) {
            key_priv_info->key_type = key_type;
            if(mgt->has_iv>0) {
                memcpy(key_priv_info->iv,iv,sizeof(key_priv_info->iv));
            }

            memcpy(key_priv_info->key_from, "s", 1);
            memcpy(key_priv_info->key_from+1, info.uri, MAX_URL_SIZE-1);

            av_log(NULL,AV_LOG_INFO,"aes key location,before:%s,after:%s\n",info.uri,key_priv_info->key_from);
            key_priv_info->is_have_key_file = 0;
            mgt->key_tmp = key_priv_info;
            mgt->flags |= KEY_FLAG;
            return -(TRICK_LOGIC_BASE+0);

        } else {
            av_log(NULL,AV_LOG_INFO,"just only support aes key\n");
            av_free(key_priv_info);
            key_priv_info = NULL;
        }


    }
    else {

        if(mgt->is_variant>0) {
            if(av_strstart(p,"http",&ptr)) {
                if (!new_variant(mgt, mgt->bandwidth, p, NULL)) {
                    free_variant_list(mgt);
                    return -1;
                }

            } else {
                if (!new_variant(mgt, mgt->bandwidth, p, mgt->prefix)) {
                    free_variant_list(mgt);
                    return -1;
                }
            }
            mgt->is_variant = 0;
            mgt->bandwidth  = 0;

            return -(TRICK_LOGIC_BASE+2);

        }

        return 0;
    }
    return enditem;
}
Exemplo n.º 16
0
void TomlParser::load()
{
    bool formatStrMode = false, rawStrMode = false, escMode = false
    bool endOfStrMode = false, endOfLine = false;
    string currLine = "";
    string currStr = "";
    TomlHash currHash = null;
    TomlKey currKey = null;
    int lineNumber = 1;
    char currChar;
    for(; !stream.eof(); lineNumber++)//this is the line loop
    {
        lineloopstart:
        endOfLine = false;
        if(formatStrMode || rawStrMode)
        {
            throw new TomlError(
                "Multiline strings not supported. Use \"\\n\" instead.",
                lineNumber);
        }
        rawStrMode = false;
        formatStrMode = false;
        getline(stream, currLine);
        clipSpaces(currLine);
        for(int i=1; i<currLine.length(); i++)//this goes over each character
        {
            currChar = currLine[i];
            if(endOfLine)
            {
                throw new TomlError(
                    "What are you trying to do with these random characters?",
                    lineNumber);
            }
            else if(formatStrMode)
            {
                //parse string
            }
            else if(rawStrMode)
            {
                if(currChar=='\'')
                {
                    rawStrMode = false;
                    endOfLine = true;
                }
                else
                {
                    currStr.append(1,currChar);
                }
            }
            else if(endOfStrMode)
            {
                goto eos;
            }
            else
            {
                switch(currChar)
                {
                    case '#':
                        goto lineloopstart;
                    case '"':
                        formatStrMode = true;
                        break;
                    case '\'':
                        rawStrMode = true;
                        break;
                    case '[':
                        string hashName = "";
                        while(currChar != ']')
                        {
                            hashName.append(1,currChar);
                            i++;
                            currChar = currLine[i];
                        }
                        currHash = new TomlHash(hashName, currHash);
                        endOfLine = true;
                        break;
                    default://it's a key
                    eos:
                        if(endOfStrMode)
                        {
                            currKey.type = "STRING";
                            currKey.value = currStr;
                            break;
                        }
                        string name = "";
                        while(currChar != '=')
                        {
                            name.append(&currChar);
                            i++;
                            currChar = currLine.at(i);
                        }
                        i++;//we go past the =
                        currChar = currLine.at(i);
                        string valueStr = currLine.substr(i + 1);
                        try
                        {
                            long value = parseInteger(valueStr);
                            currKey = new TomlKey(name, valueStr, "INTEGER",
                                currHash);
                        }
                        catch(int i)
                        {
                            try//This is the only way
                            {
                                bool value = parseBoolean(valueStr);
                                currKey = new TomlKey(name, valueStr, "BOOL",
                                    currHash);
                                catch(int i)
                                {
                                    try
                                    {
                                        double value = parseDouble(
                                            line.substr(valueStr));
                                        currKey.value = valueStr;
                                        currKey = new TomlKey(name, valueStr,
                                            "FLOAT", currHash);
                                        catch(int i)
                                        {
                                            //ignore it
                                        }
                                    }
                                }
                            }
                        }//end try-catch
                }//end switch
            }//end else
        }//end inner for
Exemplo n.º 17
0
int32_t
MessagePattern::parsePluralOrSelectStyle(UMessagePatternArgType argType,
                                         int32_t index, int32_t nestingLevel,
                                         UParseError *parseError, UErrorCode &errorCode) {
    if(U_FAILURE(errorCode)) {
        return 0;
    }
    int32_t start=index;
    UBool isEmpty=TRUE;
    UBool hasOther=FALSE;
    for(;;) {
        // First, collect the selector looking for a small set of terminators.
        // It would be a little faster to consider the syntax of each possible
        // token right here, but that makes the code too complicated.
        index=skipWhiteSpace(index);
        UBool eos=index==msg.length();
        if(eos || msg.charAt(index)==u_rightCurlyBrace) {
            if(eos==inMessageFormatPattern(nestingLevel)) {
                setParseError(parseError, start);  // Bad plural/select pattern syntax.
                errorCode=U_PATTERN_SYNTAX_ERROR;
                return 0;
            }
            if(!hasOther) {
                setParseError(parseError, 0);  // Missing 'other' keyword in plural/select pattern.
                errorCode=U_DEFAULT_KEYWORD_MISSING;
                return 0;
            }
            return index;
        }
        int32_t selectorIndex=index;
        if(UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(argType) && msg.charAt(selectorIndex)==u_equal) {
            // explicit-value plural selector: =double
            index=skipDouble(index+1);
            int32_t length=index-selectorIndex;
            if(length==1) {
                setParseError(parseError, start);  // Bad plural/select pattern syntax.
                errorCode=U_PATTERN_SYNTAX_ERROR;
                return 0;
            }
            if(length>Part::MAX_LENGTH) {
                setParseError(parseError, selectorIndex);  // Argument selector too long.
                errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
                return 0;
            }
            addPart(UMSGPAT_PART_TYPE_ARG_SELECTOR, selectorIndex, length, 0, errorCode);
            parseDouble(selectorIndex+1, index, FALSE,
                        parseError, errorCode);  // adds ARG_INT or ARG_DOUBLE
        } else {
            index=skipIdentifier(index);
            int32_t length=index-selectorIndex;
            if(length==0) {
                setParseError(parseError, start);  // Bad plural/select pattern syntax.
                errorCode=U_PATTERN_SYNTAX_ERROR;
                return 0;
            }
            // Note: The ':' in "offset:" is just beyond the skipIdentifier() range.
            if( UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(argType) && length==6 && index<msg.length() &&
                0==msg.compare(selectorIndex, 7, kOffsetColon, 0, 7)
            ) {
                // plural offset, not a selector
                if(!isEmpty) {
                    // Plural argument 'offset:' (if present) must precede key-message pairs.
                    setParseError(parseError, start);
                    errorCode=U_PATTERN_SYNTAX_ERROR;
                    return 0;
                }
                // allow whitespace between offset: and its value
                int32_t valueIndex=skipWhiteSpace(index+1);  // The ':' is at index.
                index=skipDouble(valueIndex);
                if(index==valueIndex) {
                    setParseError(parseError, start);  // Missing value for plural 'offset:'.
                    errorCode=U_PATTERN_SYNTAX_ERROR;
                    return 0;
                }
                if((index-valueIndex)>Part::MAX_LENGTH) {
                    setParseError(parseError, valueIndex);  // Plural offset value too long.
                    errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
                    return 0;
                }
                parseDouble(valueIndex, index, FALSE,
                            parseError, errorCode);  // adds ARG_INT or ARG_DOUBLE
                if(U_FAILURE(errorCode)) {
                    return 0;
                }
                isEmpty=FALSE;
                continue;  // no message fragment after the offset
            } else {
                // normal selector word
                if(length>Part::MAX_LENGTH) {
                    setParseError(parseError, selectorIndex);  // Argument selector too long.
                    errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
                    return 0;
                }
                addPart(UMSGPAT_PART_TYPE_ARG_SELECTOR, selectorIndex, length, 0, errorCode);
                if(0==msg.compare(selectorIndex, length, kOther, 0, 5)) {
                    hasOther=TRUE;
                }
            }
        }
        if(U_FAILURE(errorCode)) {
            return 0;
        }

        // parse the message fragment following the selector
        index=skipWhiteSpace(index);
        if(index==msg.length() || msg.charAt(index)!=u_leftCurlyBrace) {
            setParseError(parseError, selectorIndex);  // No message fragment after plural/select selector.
            errorCode=U_PATTERN_SYNTAX_ERROR;
            return 0;
        }
        index=parseMessage(index, 1, nestingLevel+1, argType, parseError, errorCode);
        if(U_FAILURE(errorCode)) {
            return 0;
        }
        isEmpty=FALSE;
    }
}
Exemplo n.º 18
0
static void processConfigFile(char *fname)
{
	FILE *rcFile = NULL;
	char buf[1024];
	char *tmp, *tmp2;
	
	if (fname) rcFile = fopen(fname,"r");
	if (!rcFile) rcFile = fopen("sp.rc", "r");
	if (!rcFile) rcFile = fopen("sp.ini","r");
	if(!rcFile) return;

	while(fgets(buf, 1023, rcFile)) {
		char *x = buf;
		char *key, *value;
	
		if(buf[0] == '#') continue;
	
		key = nextToken(&x, "=\t\n\r");
		if(key == NULL) continue;
	
		value = nextToken(&x, "\n\n\r");
		if(value == NULL) continue;
	
		tmp = lowercase(key);
		key = strip(tmp);
		free(tmp);

		if(!strcmp(key, "hashkilobytes")) {
			configvalues.hashkilobytes = parseInteger(value);
		} else if(!strcmp(key, "hashentries")) {
			configvalues.hashentries = parseInteger(value);
		} else if(!strcmp(key, "resign")) {
			configvalues.resign = - ((int) (parseDouble(value) * 100));
		} else if(!strcmp(key, "verbose")) {
			configvalues.verbose = parseInteger(value);
		} else if(!strcmp(key, "logfile")) {
			configvalues.logfilename = strip(value);
		} else if(!strcmp(key, "record")) {
			configvalues.record = 1;
		} else if(!strcmp(key, "gamefile")) {
			configvalues.gamefilename = strip(value);
		} else if(!strcmp(key, "random")) {
			configvalues.random = parseInteger(value);
		} else if(!strcmp(key, "searcher")) {
			tmp = strip(value);
			tmp2 = lowercase(tmp);
			free(tmp);
			if (!strcmp(tmp2,"random")) {
				configvalues.engine = RANDOM_ENGINE;
			} else if (!strcmp(tmp2,"negascout")) {
				configvalues.engine = NEGASCOUT_ENGINE;
			} else if (!strcmp(tmp2,"onestep")) {
				configvalues.engine = ONESTEP_ENGINE;
			} else if (!strcmp(tmp2,"complete")) {
				configvalues.engine = COMPLETENEGAMAX_ENGINE;
			} else if (!strcmp(tmp2,"fixeddepth")) {
				configvalues.engine = MULTISTEP_ENGINE;
			}
			free(tmp2);
		} else if(!strcmp(key, "evaluation")) {
			tmp = strip(value);
			tmp2 = lowercase(tmp);
			free(tmp);
			if (!strcmp(tmp2,"standard")) {
				configvalues.evaltype = POSITIONPIECE_EVAL;
			} else if (!strcmp(tmp2,"relative")) {
				configvalues.evaltype = RELATIVEPOSITIONPIECE_EVAL;
			}
			free(tmp2);
		} else if(!strcmp(key, "computername")) {
			configvalues.computername = strip(value);
		} else if(!strcmp(key, "bookfile")) {
			configvalues.bookfilename = strip(value);
		} else if(!strcmp(key, "valuefile")) {
			configvalues.valuefilename = strip(value);
		} else if(!strcmp(key, "nobook")) {
			configvalues.usebook = 0;
		} else if(!strcmp(key, "novaluefile")) {
			configvalues.usevaluefile = 0;
		} else if(!strcmp(key, "noresign")) {
			configvalues.resign = MINVALUE - 1;
		} else if(!strcmp(key, "maxdepth")) {
			configvalues.maxdepth = parseInteger(value);
  		} else if(!strcmp(key, "epdmindepth")) {
			configvalues.epdmindepth = parseInteger(value);
		} else if(!strcmp(key, "drawvalue")) {
			configvalues.drawvalue = parseInteger(value);
		} else if(!strcmp(key, "timeaggression")) {
			configvalues.timeaggression = parseInteger(value);
		}

		free(key);
	}
	fclose(rcFile);
}
Exemplo n.º 19
0
utilStatus utilCmdLine_parse( utilCmdLine self, int argc, char * argv[] ) {
   utilStatus status = UTIL_STATUS_NO_ERROR;
   utilCmdLineImpl * This = utilCmdLine_safeCast( self, &status );
   if( status == UTIL_STATUS_NO_ERROR ) {
      int i;
      for( i = 1; i < argc; ++i ) {
         bool notFound = true;
         unsigned j;
         for( j = 0; notFound && j < This->count; ++j ) {
            CmdLineDef * def = This->defs + j;
            if( 0 == strncmp( argv[i], def->key, def->len )) {
               const char * value = argv[i] + def->len;

               notFound = false;
               switch( def->type ) {
               case CmdLineType_BOOLEAN:
                  if( 0 == strcasecmp( value, "T" )) {
                     def->value.t = true;
                  }
                  else if( 0 == strcasecmp( value, "true" )) {
                     def->value.t = true;
                  }
                  else if( 0 == strcasecmp( value, "1" )) {
                     def->value.t = true;
                  }
                  else if( 0 == strcasecmp( value, "F" )) {
                     def->value.t = false;
                  }
                  else if( 0 == strcasecmp( value, "false" )) {
                     def->value.t = false;
                  }
                  else if( 0 == strcasecmp( value, "0" )) {
                     def->value.t = false;
                  }
                  else {
                     status = UTIL_STATUS_TYPE_MISMATCH;
                  }
               break;
               case CmdLineType_CHAR:
                  if( strlen( value ) > 1 ) {
                     status = UTIL_STATUS_TYPE_MISMATCH;
                  }
                  else {
                     def->value.b = (byte)value[0];
                  }
               break;
               case CmdLineType_BYTE:
                  def->value.b = (byte)parseInt( value, 0, 0xFF, &status );
               break;
               case CmdLineType_SHORT:
                  def->value.s = (short)parseInt( value, -0x8000, 0x7FFF, &status );
               break;
               case CmdLineType_USHORT:
                  def->value.s = (short)parseInt( value, 0, 0xFFFF, &status );
               break;
               case CmdLineType_INT:
                  def->value.i = parseInt( value, INT_MIN, INT_MAX, &status );
               break;
               case CmdLineType_UINT:
                  def->value.i = (int)parseUInt( value, &status );
               break;
               case CmdLineType_FLOAT:
                  def->value.f = parseFloat( value, &status );
               break;
               case CmdLineType_DOUBLE:
                  def->value.d = parseDouble( value, &status );
               break;
               case CmdLineType_STRING:
                  if( strlen( value ) >= utilCmdLine_VALUE_LEN ) {
                     status = UTIL_STATUS_OUT_OF_RANGE;
                  }
                  else {
                     strncpy( def->value.sz, value, utilCmdLine_VALUE_LEN );
                     def->value.sz[utilCmdLine_VALUE_LEN-1] = '\0';
                  }
               break;
               }
            }
         }
         if( notFound ) {
            fprintf( stderr, "Ignored argument: %s\n", argv[i] );
            status = UTIL_STATUS_NOT_FOUND;
         }
      }
   }
   return status;
}
Exemplo n.º 20
0
static bool parseColorIntOrPercentage(const CharacterType*& string, const CharacterType* end, const char terminator, CSSPrimitiveValue::UnitType& expect, int& value)
{
    const CharacterType* current = string;
    double localValue = 0;
    bool negative = false;
    while (current != end && isHTMLSpace<CharacterType>(*current))
        current++;
    if (current != end && *current == '-') {
        negative = true;
        current++;
    }
    if (current == end || !isASCIIDigit(*current))
        return false;
    while (current != end && isASCIIDigit(*current)) {
        double newValue = localValue * 10 + *current++ - '0';
        if (newValue >= 255) {
            // Clamp values at 255.
            localValue = 255;
            while (current != end && isASCIIDigit(*current))
                ++current;
            break;
        }
        localValue = newValue;
    }

    if (current == end)
        return false;

    if (expect == CSSPrimitiveValue::CSS_NUMBER && (*current == '.' || *current == '%'))
        return false;

    if (*current == '.') {
        // We already parsed the integral part, try to parse
        // the fraction part of the percentage value.
        double percentage = 0;
        int numCharactersParsed = parseDouble(current, end, '%', percentage);
        if (!numCharactersParsed)
            return false;
        current += numCharactersParsed;
        if (*current != '%')
            return false;
        localValue += percentage;
    }

    if (expect == CSSPrimitiveValue::CSS_PERCENTAGE && *current != '%')
        return false;

    if (*current == '%') {
        expect = CSSPrimitiveValue::CSS_PERCENTAGE;
        localValue = localValue / 100.0 * 256.0;
        // Clamp values at 255 for percentages over 100%
        if (localValue > 255)
            localValue = 255;
        current++;
    } else {
        expect = CSSPrimitiveValue::CSS_NUMBER;
    }

    while (current != end && isHTMLSpace<CharacterType>(*current))
        current++;
    if (current == end || *current++ != terminator)
        return false;
    // Clamp negative values at zero.
    value = negative ? 0 : static_cast<int>(localValue);
    string = current;
    return true;
}
Exemplo n.º 21
0
Arquivo: Rjson.cpp Projeto: XoDeR/RE
		uint32_t parseUint(const char* json)
		{
			return (uint32_t)parseDouble(json);
		}
Exemplo n.º 22
0
int32_t
MessagePattern::parseChoiceStyle(int32_t index, int32_t nestingLevel,
                                 UParseError *parseError, UErrorCode &errorCode) {
    if(U_FAILURE(errorCode)) {
        return 0;
    }
    int32_t start=index;
    index=skipWhiteSpace(index);
    if(index==msg.length() || msg.charAt(index)==u_rightCurlyBrace) {
        setParseError(parseError, 0);  // Missing choice argument pattern.
        errorCode=U_PATTERN_SYNTAX_ERROR;
        return 0;
    }
    for(;;) {
        // The choice argument style contains |-separated (number, separator, message) triples.
        // Parse the number.
        int32_t numberIndex=index;
        index=skipDouble(index);
        int32_t length=index-numberIndex;
        if(length==0) {
            setParseError(parseError, start);  // Bad choice pattern syntax.
            errorCode=U_PATTERN_SYNTAX_ERROR;
            return 0;
        }
        if(length>Part::MAX_LENGTH) {
            setParseError(parseError, numberIndex);  // Choice number too long.
            errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
            return 0;
        }
        parseDouble(numberIndex, index, TRUE, parseError, errorCode);  // adds ARG_INT or ARG_DOUBLE
        if(U_FAILURE(errorCode)) {
            return 0;
        }
        // Parse the separator.
        index=skipWhiteSpace(index);
        if(index==msg.length()) {
            setParseError(parseError, start);  // Bad choice pattern syntax.
            errorCode=U_PATTERN_SYNTAX_ERROR;
            return 0;
        }
        UChar c=msg.charAt(index);
        if(!(c==u_pound || c==u_lessThan || c==u_lessOrEqual)) {  // U+2264 is <=
            setParseError(parseError, start);  // Expected choice separator (#<\u2264) instead of c.
            errorCode=U_PATTERN_SYNTAX_ERROR;
            return 0;
        }
        addPart(UMSGPAT_PART_TYPE_ARG_SELECTOR, index, 1, 0, errorCode);
        // Parse the message fragment.
        index=parseMessage(++index, 0, nestingLevel+1, UMSGPAT_ARG_TYPE_CHOICE, parseError, errorCode);
        if(U_FAILURE(errorCode)) {
            return 0;
        }
        // parseMessage(..., CHOICE) returns the index of the terminator, or msg.length().
        if(index==msg.length()) {
            return index;
        }
        if(msg.charAt(index)==u_rightCurlyBrace) {
            if(!inMessageFormatPattern(nestingLevel)) {
                setParseError(parseError, start);  // Bad choice pattern syntax.
                errorCode=U_PATTERN_SYNTAX_ERROR;
                return 0;
            }
            return index;
        }  // else the terminator is '|'
        index=skipWhiteSpace(index+1);
    }
}
Exemplo n.º 23
0
void ProcessEvent(unsigned int me, simtime_t now, int event_type, event_content_type *event_content, unsigned int size, void * ptr) {
	int w;

	event_content_type new_event_content;

	new_event_content.cell = -1;
	new_event_content.second_cell = -1;
	new_event_content.channel = -1;
	new_event_content.call_term_time = -1;
	
	simtime_t handoff_time;
	simtime_t timestamp=0;
	
	lp_state_type * pointer;
	pointer = (lp_state_type*)ptr;

	switch(event_type) {
		
		case INIT:
		
			pointer = (lp_state_type *)malloc(sizeof(lp_state_type));
			if (pointer == NULL){
				printf("ERROR in malloc!\n");
				exit(EXIT_FAILURE);
			}

		
			SetState(pointer);
			
//			pointer->channels = NULL;
			pointer->contatore_canali = CHANNELS_PER_CELL;
			pointer->cont_chiamate_entranti = -1;
			pointer->cont_chiamate_complete = 0;
			pointer->cont_handoff_uscita = 0;
			pointer->cont_bloccate_in_partenza = 0;
			pointer->cont_bloccate_in_handoff  = 0;
			pointer->handoffs_entranti = 0;
//			power_management = true;
//			variable_ta = true;
//			fading_recheck = true;

			// INIT is not considered as an event
			pointer->contatore_eventi = 0;
//			pointer->time = now;


			// Load the predefined values
//			variable_ta = true;
			complete_calls = COMPLETE_CALLS;
			ta = TA;
			ta_durata = TA_DURATA;
			ta_cambio = TA_CAMBIO;
			channels_per_cell = CHANNELS_PER_CELL;
			power_management = true;

			// Read runtime parameters
			char **arguments = (char **)event_content;
			for(w = 0; w < size; w += 2) {

				if(strcmp(arguments[w],"complete-calls") == 0) {
					complete_calls = parseInt(arguments[w + 1]);
				} else if(strcmp(arguments[w],"ta") == 0) {
					ta = parseDouble(arguments[w + 1]);
				} else if(strcmp(arguments[w],"ta-durata") == 0) {
					ta_durata = parseDouble(arguments[w + 1]);
				} else if(strcmp(arguments[w],"ta-cambio") == 0) {
					ta_cambio = parseDouble(arguments[w + 1]);
				} else if(strcmp(arguments[w],"channels-per-cell") == 0) {
					channels_per_cell = parseInt(arguments[w + 1]);
				} else if(strcmp(arguments[w],"complete-time") == 0) {
					complete_time = parseInt(arguments[w + 1]);
				} else if(strcmp(arguments[w],"no-power-management") == 0) {
					w -= 1;
					power_management = false;
				} else if(strcmp(arguments[w],"power-management") == 0) {
					w -= 1;
					power_management = true;
				} else if(strcmp(arguments[w],"variable-ta") == 0) {
					w -= 1;
					variable_ta = true;
				} else if(strcmp(arguments[w],"fading-recheck") == 0) {
					fading_recheck = true;
				} else if(strcmp(arguments[w],"complete-time") == 0) {
					complete_time = parseInt(arguments[w + 1]);
				}
			}
			ref_ta = ta;

			// Show current configuration, only once
			if(me == 0) {
				printf("CURRENT CONFIGURATION:\nCOMPLETE CALLS: %d\nTA: %f\nTA_DURATA: %f\nTA_CAMBIO: %f\nCHANNELS_PER_CELL: %d\nCOMPLETE_TIME: %d\n",
					complete_calls, ta, ta_durata, ta_cambio, channels_per_cell, complete_time);
				printf("POWER MANAGMENT: %d\nFADING RECHECK: %d\nVARIABLE TA: %d\n",
					power_management, fading_recheck, variable_ta);
				fflush(stdout);
			}

			pointer->contatore_canali = channels_per_cell;

			for (w = 0; w < pointer->contatore_canali / (sizeof(int) * 8) + 1; w++)
				pointer->channel_state[w] = 0;
			
			pointer->buff_topology = (_PCS_routing*)malloc(sizeof(_PCS_routing));
			if(pointer->buff_topology == NULL){
				printf("Chiamata a malloc errata sulla topologia della rete!\n");
				exit(EXIT_FAILURE);
			}
	
			set_my_topology(me, pointer->buff_topology);

			timestamp = (simtime_t) (20 * Random());	
			ScheduleNewEvent(me, timestamp, START_CALL, NULL, 0);
			
			if (fading_recheck) {
				timestamp = now + (simtime_t) (FADING_RECHECK_FREQUENCY); 
				ScheduleNewEvent(me, timestamp, FADING_RECHECK, NULL, 0);
			}

			break;

	
		case START_CALL:
			pointer->time = now;
			

			//make_copy(pointer->cont_chiamate_entranti, pointer->cont_chiamate_entranti+1);
			pointer->cont_chiamate_entranti++;
			//make_copy(pointer->contatore_eventi, pointer->contatore_eventi+1);
			pointer->contatore_eventi++;
			
			if (pointer->contatore_canali == 0) {
				//make_copy(pointer->cont_bloccate_in_partenza, pointer->cont_bloccate_in_partenza+1);
				pointer->cont_bloccate_in_partenza++;
			} else {
						
				pointer->contatore_canali--;
				//make_copy(pointer->contatore_canali, pointer->contatore_canali-1);
				
				#ifdef ACCURATE_SIMULATION
				new_event_content.channel = allocation(me, pointer);
				#endif
				
				// Determine call duration
				switch (DISTRIBUZIONE_DURATA) {
	
					case UNIFORME:
						new_event_content.call_term_time = now+
			       			(simtime_t) (ta_durata * Random());

						break;

					case ESPONENZIALE:
						new_event_content.call_term_time = now +
 						(simtime_t)( Expent(ta_durata ));

						break;

					default:
								
 						new_event_content.call_term_time = now+
						(simtime_t) (5 * Random() );	
						}
			
				// Determine whether the call will be handed-off or not
				switch (DISTRIBUZIONE_CAMBIOCELLA) {

					case UNIFORME:
						
						handoff_time  = now+ 
			       			(simtime_t) ((ta_cambio) * Random() );
						break;

					case ESPONENZIALE:
						handoff_time = now+ 
			       			(simtime_t)( Expent( ta_cambio ));
						break;

					default:
						handoff_time = now+ 
			       			(simtime_t) (5 * Random() );
					
				}
			
				if( new_event_content.call_term_time <=  handoff_time) {
				    ScheduleNewEvent(me,new_event_content.call_term_time,END_CALL,&new_event_content,sizeof(new_event_content));

				} else {
					new_event_content.cell = __FindReceiver(me,pointer);
							
					new_event_content.second_cell = -1;
			
					ScheduleNewEvent(me,handoff_time,HANDOFF_LEAVE,&new_event_content,sizeof(new_event_content));

//					#ifdef PRE_SCHEDULING
					new_event_content.call_term_time = new_event_content.call_term_time;
					ScheduleNewEvent(new_event_content.cell,handoff_time,HANDOFF_RECV,&new_event_content,sizeof(new_event_content));
//					#endif
				}
			} // if (pointer->contatore_canali == 0) 


			if (variable_ta)
				ta = recompute_ta(ref_ta, now);

			// Determine the time at which the call will end						
			switch (DISTRIBUZIONE) {   

				case UNIFORME:
					timestamp= now+ 
			   		(simtime_t) (ta * Random() );
					break;
	
				case ESPONENZIALE:
					timestamp= now+ 
			   		(simtime_t)( Expent( ta ));
					break;

				default:
					timestamp= now+	
			   		(simtime_t) (5 * Random());		
						
			}

			ScheduleNewEvent(me, timestamp, START_CALL, NULL, 0);

			break;

		case END_CALL:
		
			pointer->time = now;
//			make_copy(pointer->contatore_eventi, pointer->contatore_eventi+1);
			pointer->contatore_eventi++;
			//make_copy(pointer->contatore_canali, pointer->contatore_canali+1);
			pointer->contatore_canali++;
			//make_copy(pointer->cont_chiamate_complete, pointer->cont_chiamate_complete+1);
			pointer->cont_chiamate_complete++;
			#ifdef ACCURATE_SIMULATION
			deallocation(me, pointer, event_content->channel);
			#endif
			
			break;

		case HANDOFF_LEAVE:

			pointer->time = now;
			//make_copy(pointer->contatore_eventi, pointer->contatore_eventi+1);
			pointer->contatore_eventi++;
			//make_copy(pointer->contatore_canali, pointer->contatore_canali+1);
			pointer->contatore_canali++;
			//make_copy(pointer->cont_handoff_uscita, pointer->cont_handoff_uscita+1);
			pointer->cont_handoff_uscita++;
			#ifdef ACCURATE_SIMULATION
			deallocation(me, pointer, event_content->channel);
			#endif
			
//			#ifndef PRE_SCHEDULING
//			new_event_content.call_term_time =  event_content->call_term_time + 0.00005;
//			ScheduleNewEvent(event_content->cell, now + 0.00003 , HANDOFF_RECV, &new_event_content, sizeof(new_event_content));
//			#endif
			break;

        	case HANDOFF_RECV:
			pointer->time = now;
			//handoff_counter++;
			//make_copy(pointer->handoffs_entranti, pointer->handoffs_entranti+1);
			pointer->handoffs_entranti++;
			//make_copy(pointer->cont_chiamate_entranti, pointer->cont_chiamate_entranti+1);
			//make_copy(pointer->contatore_eventi, pointer->contatore_eventi+1);
			pointer->contatore_eventi++;
			pointer->cont_chiamate_entranti++;
			
			if (pointer->contatore_canali == 0) 
				//make_copy(pointer->cont_bloccate_in_handoff, pointer->cont_bloccate_in_handoff+1);
				pointer->cont_bloccate_in_handoff++;
			else {
				//make_copy(pointer->contatore_canali, pointer->contatore_canali-1);
				pointer->contatore_canali--;
				
				#ifdef ACCURATE_SIMULATION
				new_event_content.channel = allocation(me, pointer);
				#endif
				
				new_event_content.call_term_time = event_content->call_term_time; 
				
				switch (DISTRIBUZIONE_CAMBIOCELLA) {
					case UNIFORME:
						handoff_time  = now+ 
			    			(simtime_t) ((ta_cambio) * Random());
			
						break;
					case ESPONENZIALE:
						handoff_time = now+ 
			    			(simtime_t)( Expent( ta_cambio ));
			
						break;
					default:
						handoff_time = now+ 
			    			(simtime_t) (5 * Random());
				}
				
				
				if (Random() < 0.5) handoff_time *= 10;
				
				if( new_event_content.call_term_time <=  handoff_time ) {
					ScheduleNewEvent(me , new_event_content.call_term_time, END_CALL, &new_event_content, sizeof(new_event_content));


				} else {
					new_event_content.cell = __FindReceiver(me,ptr);
					
					#ifdef  NO_UNCERTAINTY
						new_event_content.second_cell = -1;
					#endif
					ScheduleNewEvent(me , new_event_content.call_term_time, HANDOFF_LEAVE, &new_event_content, sizeof(new_event_content));

				}
			}
			

			break;


		case FADING_RECHECK:

//			pointer->time = now;
			if (pointer->check_fading == true) {
				//make_copy(pointer->check_fading, false);
				pointer->check_fading = false;
			} else {
				//make_copy(pointer->check_fading, true);
				pointer->check_fading = true;
			}

			timestamp = now + (simtime_t) (FADING_RECHECK_FREQUENCY);
			ScheduleNewEvent(me, timestamp, FADING_RECHECK, NULL, 0);
				
			break;

      		default: 
			fprintf(stderr, " pointer simulation: error - inconsistent event (me = %d - event type = %d)\n", me, event_type);
			break;
	} // switch(event->type) 
}
Exemplo n.º 24
0
void parseVariant(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, const char *szFieldName)
{
    proto_item *ti = proto_tree_add_text(tree, tvb, *pOffset, -1, "%s: Variant", szFieldName);
    proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_variant);
    gint    iOffset = *pOffset;
    guint8  EncodingMask;
    gint32  ArrayDimensions = 0;

    EncodingMask = tvb_get_guint8(tvb, iOffset);
    proto_tree_add_item(subtree, hf_opcua_variant_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
    iOffset++;

    if (EncodingMask & VARIANT_ARRAYMASK)
    {
        /* type is encoded in bits 0-5 */
        switch(EncodingMask & 0x3f)
        {
        case OpcUaType_Null: break;
        case OpcUaType_Boolean: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Boolean, parseBoolean); break;
        case OpcUaType_SByte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_SByte, parseSByte); break;
        case OpcUaType_Byte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Byte, parseByte); break;
        case OpcUaType_Int16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int16, parseInt16); break;
        case OpcUaType_UInt16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt16, parseUInt16); break;
        case OpcUaType_Int32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int32, parseInt32); break;
        case OpcUaType_UInt32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt32, parseUInt32); break;
        case OpcUaType_Int64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int64, parseInt64); break;
        case OpcUaType_UInt64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt64, parseUInt64); break;
        case OpcUaType_Float: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Float, parseFloat); break;
        case OpcUaType_Double: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Double, parseDouble); break;
        case OpcUaType_String: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_String, parseString); break;
        case OpcUaType_DateTime: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_DateTime, parseDateTime); break;
        case OpcUaType_Guid: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Guid, parseGuid); break;
        case OpcUaType_ByteString: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_ByteString, parseByteString); break;
        case OpcUaType_XmlElement: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_XmlElement, parseXmlElement); break;
        case OpcUaType_NodeId: parseArrayComplex(subtree, tvb, &iOffset, "NodeId", parseNodeId); break;
        case OpcUaType_ExpandedNodeId: parseArrayComplex(subtree, tvb, &iOffset, "ExpandedNodeId", parseExpandedNodeId); break;
        case OpcUaType_StatusCode: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_StatusCode, parseStatusCode); break;
        case OpcUaType_DiagnosticInfo: parseArrayComplex(subtree, tvb, &iOffset, "DiagnosticInfo", parseDiagnosticInfo); break;
        case OpcUaType_QualifiedName: parseArrayComplex(subtree, tvb, &iOffset, "QualifiedName", parseQualifiedName); break;
        case OpcUaType_LocalizedText: parseArrayComplex(subtree, tvb, &iOffset, "LocalizedText", parseLocalizedText); break;
        case OpcUaType_ExtensionObject: parseArrayComplex(subtree, tvb, &iOffset, "ExtensionObject", parseExtensionObject); break;
        case OpcUaType_DataValue: parseArrayComplex(subtree, tvb, &iOffset, "DataValue", parseDataValue); break;
        case OpcUaType_Variant: parseArrayComplex(subtree, tvb, &iOffset, "Variant", parseVariant); break;
        }

        if (EncodingMask & VARIANT_ARRAYDIMENSIONS)
        {
            proto_item *ti_2 = proto_tree_add_text(subtree, tvb, iOffset, -1, "ArrayDimensions");
            proto_tree *subtree_2 = proto_item_add_subtree(ti_2, ett_opcua_array);
            int i;

            /* read array length */
            ArrayDimensions = tvb_get_letohl(tvb, iOffset);
            proto_tree_add_item(subtree_2, hf_opcua_ArraySize, tvb, iOffset, 4, ENC_LITTLE_ENDIAN);

            if (ArrayDimensions > MAX_ARRAY_LEN)
            {
                proto_item *pi;
                pi = proto_tree_add_text(subtree_2, tvb, iOffset, 4, "ArrayDimensions length %d too large to process", ArrayDimensions);
                PROTO_ITEM_SET_GENERATED(pi);
                return;
            }

            iOffset += 4;
            for (i=0; i<ArrayDimensions; i++)
            {
                parseInt32(subtree_2, tvb, &iOffset, hf_opcua_Int32);
            }
            proto_item_set_end(ti_2, tvb, iOffset);
        }
    }
    else
    {
        /* type is encoded in bits 0-5 */
        switch(EncodingMask & 0x3f)
        {
        case OpcUaType_Null: break;
        case OpcUaType_Boolean: parseBoolean(subtree, tvb, &iOffset, hf_opcua_Boolean); break;
        case OpcUaType_SByte: parseSByte(subtree, tvb, &iOffset, hf_opcua_SByte); break;
        case OpcUaType_Byte: parseByte(subtree, tvb, &iOffset, hf_opcua_Byte); break;
        case OpcUaType_Int16: parseInt16(subtree, tvb, &iOffset, hf_opcua_Int16); break;
        case OpcUaType_UInt16: parseUInt16(subtree, tvb, &iOffset, hf_opcua_UInt16); break;
        case OpcUaType_Int32: parseInt32(subtree, tvb, &iOffset, hf_opcua_Int32); break;
        case OpcUaType_UInt32: parseUInt32(subtree, tvb, &iOffset, hf_opcua_UInt32); break;
        case OpcUaType_Int64: parseInt64(subtree, tvb, &iOffset, hf_opcua_Int64); break;
        case OpcUaType_UInt64: parseUInt64(subtree, tvb, &iOffset, hf_opcua_UInt64); break;
        case OpcUaType_Float: parseFloat(subtree, tvb, &iOffset, hf_opcua_Float); break;
        case OpcUaType_Double: parseDouble(subtree, tvb, &iOffset, hf_opcua_Double); break;
        case OpcUaType_String: parseString(subtree, tvb, &iOffset, hf_opcua_String); break;
        case OpcUaType_DateTime: parseDateTime(subtree, tvb, &iOffset, hf_opcua_DateTime); break;
        case OpcUaType_Guid: parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid); break;
        case OpcUaType_ByteString: parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString); break;
        case OpcUaType_XmlElement: parseXmlElement(subtree, tvb, &iOffset, hf_opcua_XmlElement); break;
        case OpcUaType_NodeId: parseNodeId(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_ExpandedNodeId: parseExpandedNodeId(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_StatusCode: parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode); break;
        case OpcUaType_DiagnosticInfo: parseDiagnosticInfo(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_QualifiedName: parseQualifiedName(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_LocalizedText: parseLocalizedText(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_ExtensionObject: parseExtensionObject(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_DataValue: parseDataValue(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_Variant: parseVariant(subtree, tvb, &iOffset, "Value"); break;
        }
    }

    proto_item_set_end(ti, tvb, iOffset);
    *pOffset = iOffset;
}
Exemplo n.º 25
0
Arquivo: Rjson.cpp Projeto: XoDeR/RE
		float parseFloat(const char* json)
		{
			return (float)parseDouble(json);
		}
Exemplo n.º 26
0
VariableValue* PHPVariableParser::parseValue(PHPVariable* var)
{
  PHPArrayValue* arrayValue;
  PHPObjectValue* objectValue;
  PHPScalarValue* scalarValue;
  int index;

  switch(m_raw.at(m_index).latin1())
  {
    case 'b':
      scalarValue = new PHPScalarValue(var);
      scalarValue->setType(PHPScalarValue::Boolean);

      //var->setValue(scalarValue);
      m_indexedVarList.append(scalarValue);
      scalarValue->set(parseBool());
      return scalarValue;
      //break;
    case 's':
      scalarValue = new PHPScalarValue(var);
      scalarValue->setType(PHPScalarValue::String);
      //var->setValue(scalarValue);
      m_indexedVarList.append(scalarValue);
      scalarValue->set(QString("\"") + parseString() + QString("\""));
      return scalarValue;
      //break;
    case 'a':
      arrayValue = new PHPArrayValue(var);
      arrayValue->setScalar(false);
      //var->setValue(arrayValue);
      m_indexedVarList.append(arrayValue);
      arrayValue->setList(parseArray(var));
      return arrayValue;
      //break;
    case 'O':
      objectValue = new PHPObjectValue(var);
      objectValue->setScalar(false);
      //var->setValue(objectValue);
      m_indexedVarList.append(objectValue);
      objectValue->setClassType(parseClassType());
      objectValue->setList(parseObjectMembers(var));
      return objectValue;
      //break;
    case 'i':
      scalarValue = new PHPScalarValue(var);
      //var->setValue(scalarValue);
      m_indexedVarList.append(scalarValue);

      scalarValue->setType(PHPScalarValue::Integer);
      scalarValue->set(parseInt());
      return scalarValue;
      //break;
    case 'r':
      index = parseSoftReference();
      var->setValueShared(true);
      //var->setValue(m_indexedVarList.at(index-2));
      return m_indexedVarList.at(index-1);
      //break;
    case 'R':
      index = parseReference();
      var->setValueShared(true);
      var->setReference(true);
      return m_indexedVarList.at(index-1);
      //var->setValue(m_indexedVarList.at(index-2));
      break;
    case 'N':
      scalarValue = new PHPScalarValue(var);
      //var->setValue(scalarValue);
      m_indexedVarList.append(scalarValue);

      scalarValue->setType(PHPScalarValue::Undefined);
      scalarValue->set("null");
      m_index+=2; //eats the 'N;'
      return scalarValue;
      //break;
    case 'd':
    scalarValue = new PHPScalarValue(var);
      //var->setValue(scalarValue);
      m_indexedVarList.append(scalarValue);

      scalarValue->setType(PHPScalarValue::Double);
      scalarValue->set(parseDouble());
      return scalarValue;
    case 'z':
      scalarValue = new PHPScalarValue(var);
      m_indexedVarList.append(scalarValue);
      scalarValue->setType(PHPScalarValue::Resource);
      scalarValue->set(parseResource());
      return scalarValue;
    case '?':
      scalarValue = new PHPScalarValue(var);
      m_indexedVarList.append(scalarValue);
      scalarValue->setType(PHPScalarValue::Undefined);
      scalarValue->set("?");
      m_index += 2;
      return scalarValue;
    default:
      kdDebug() << "+++++ Bug on PHPVariableParser! > " << m_index << endl;
      kdDebug() << m_raw.mid(0, 200) << endl;
      return 0;
  }
}
Exemplo n.º 27
0
void testCriteria1(int argc, char *agr[]){
	Criteria *ci1, *ci2;
	CombinedCriteria *cc1, *cc2;
	CompositeCriteria *cp1;
	int error;
	int i, j, outlen, chk;
	float *vals;
	CombinedCriteria *outIntList;
	CompositeCriteria *outDomain;
	
	//Test -1 < x  < 2.1
	ci1 = newCriteria(GT_LT, 'x', -1.0, 2.1, FALSE, FALSE);
	vals = (float*)malloc(sizeof(float));
	vals[0] = parseDouble(agr[1], 0, strlen(agr[1]), &error);	
	if(error != NMATH_NO_ERROR)
		return;
	
	chk = ci1->fcheck(ci1, vals, 1);
	if(chk)
		printf("Value %lf is IN (-1.0, 2.1) \n", vals[0]);
	else
		printf("Value %lf is NOT in (-1.0, 2.1) \n", vals[0]);
	
	free(vals);
	vals = NULL;
		
	//Test CombinedInterval  -1 < x  < 2.1 AND 0 < y
	vals = (float*)malloc(sizeof(float) * 4);
	vals[0] = -0.7f;
	vals[1] = 2.2f;
	vals[2] = -0.9f;
	vals[3] = 1.2f;
	
	outIntList = newCombinedInterval();
	
	ci1->type = GT_LT;
	ci1->variable = 'x';
	ci1->leftVal = -1.0;
	ci1->rightVal = 2.1;
	ci1->flag = ci1->flag & 0xfc;
	
	ci2 = newCriteria(GT_LT, 'y', 0.0, 2.1, FALSE, TRUE);
	
	cc1 = newCombinedInterval();
	cc1->list = (Criteria**)malloc(sizeof(Criteria*) * 2);
	cc1->list[0] = ci1;
	cc1->list[1] = ci2;
	cc1->loggedSize = 2;
	cc1->size = 2;
	
	outlen = -1;
	cc1->fgetInterval(cc1, vals, 2, (void*)outIntList);
	if(outlen >= 0){
		printf("\nOut of space\n");
	}else{
		printf("\nOut(");
		for(i=0; i<outIntList->size; i++){
			printf("(%lf , %lf)", outIntList->list[i]->leftVal, outIntList->list[i]->rightVal);
		}
		printf(")\n");
		
		for(i=0; i<outIntList->size; i++){
			free(outIntList->list[i]);
		}
		free(outIntList->list);
	}
	
	
	free(cc1->list);
	free(cc1);
	free(vals);
	free(outIntList);
	
	//Test CompositeCriteria   x  < -1 OR x > 0
	vals = (float*)malloc(sizeof(float) * 2);
	vals[0] = -1.7f;
	vals[1] = 1.3f;
	
	ci1->type = GT_LT;
	ci1->variable = 'x';
	ci1->leftVal = -1.0;
	ci1->rightVal = -1;
	ci1->flag = (ci1->flag | 0x02) & 0xfe;
	
	ci2->type = GT_LT;
	ci2->variable = 'x';
	ci2->leftVal = 0.0;
	ci2->rightVal = 2.1;
	ci1->flag = (ci1->flag & (0xff << 2 )) | 0x01;
	
	cc1 = newCombinedInterval();
	cc1->list = (Criteria**)malloc(sizeof(Criteria*));
	cc1->list[0] = ci1;
	cc1->loggedSize = 1;
	cc1->size = 1;
	
	cc2 = newCombinedInterval();
	cc2->list = (Criteria**)malloc(sizeof(Criteria*));
	cc2->list[0] = ci2;
	cc2->loggedSize = 1;
	cc2->size = 1;
	
	cp1 = newCompositeInterval();
	cp1->list = (CombinedCriteria**)malloc(sizeof(CombinedCriteria*)*2);
	cp1->list[0] = cc1;
	cp1->list[1] = cc2;
	cp1->loggedSize = 2;
	cp1->size = 2;
	
	outDomain = newCompositeInterval();
	
	cp1->fgetInterval(cp1, vals, 1, (void*)outDomain);
	
	printf("\n");
	for(i=0; i<outDomain->size; i++){
		printf("Out(");
		for(j=0; j<outDomain->list[i]->size; j++)
			printf("(%lf , %lf)", outDomain->list[i]->list[j]->leftVal, outDomain->list[i]->list[j]->rightVal);
		printf(")\n");
	}
		
	for(i=0; i<outDomain->size; i++){
		free(outDomain->list[i]);
	}
	free(outDomain->list);
	
	free(ci1);
	free(ci2);
	free(cc1->list);
	free(cc1);
	free(cc2->list);
	free(cc2);
	free(cp1->list);
	free(cp1);
	free(outDomain);
}