示例#1
0
////-------------------------
/// FFConfigParser::ParseSets
//-----------------------------
//
//
//	Parameters:
//
//	Returns:
//
qboolean FFConfigParser::ParseSets( const char **pos )
{
	qboolean result = qboolean( pos != NULL );
	string			groupName;

	if ( pos )
	{
		char *token = COM_ParseExt( pos, qtrue );
		if ( token[ 0 ] == '{' )
		{
			for
			(	token = COM_ParseExt( pos, qtrue )
			;	token[ 0 ]
			&&	token[ 0 ] != '}'
			&&	result // fail if any problem
			;	token = COM_ParseExt( pos, qtrue )
			){
				TData &data = mMap[ token ];
				result &= ParseSet( pos, data );
			}
		}
		else
		{
			// expected '{'
			result = qfalse;
		}
	}

	return result;
}
示例#2
0
文件: Map.cpp 项目: Senney/HarvestSun
bool Map::LoadFromFile(std::string fileName)
{
	std::ifstream fs;
	fs.open(fileName.c_str(), std::ifstream::in);

	if (fs.fail())
		return false;

	int i = 0;
	while (!fs.eof())
	{
		std::string curLine;
		getline(fs, curLine);

		if (curLine == "" || curLine.find("//") != std::string::npos)
			continue;

		// Line #1
		if (i == 0) 
		{
			// The first line should be the file size.
			GetMapSize(curLine);
			InitArray(map_size_x, map_size_y);
			if (mapTiles == NULL)
			{
				std::cout << "Could not load map file: Error reading map size." << '\n';
				return false;
			}
			i++;
		}

		std::vector<std::string> parts = GetParts(curLine, ' ');

		if (parts[0] == "define")
		{
			ParseDefine(parts);
		}
		else if (parts[0] == "set")
		{
			ParseSet(parts);
		}
	}

	fs.close();

	return true;
}
示例#3
0
void cRawParser::ParseVariables(cXmlNode& node, bool command, const wxString& path) {
    wxString inc = wxT("");
    ParseStringOption(inc, node, wxT("include"), NULL);
    if (!inc.IsEmpty()) {
        wxFSFileName src;
        if (path.IsEmpty()) {
            src = m_input.GetPath();
        } else {
            src = wxFSFileName(path, true);
        }
        wxFSFileName filename = inc;
        if (!filename.IsAbsolute())
            filename.MakeAbsolute(src.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME));
        LoadVariables(filename, command, (m_bake.Index(wxT(RAWXML_VARIABLES))!=wxNOT_FOUND)?&node:NULL );

        if (m_mode == MODE_BAKE) {
            if (m_bake.Index(wxT(RAWXML_VARIABLES)) == wxNOT_FOUND) {
                wxString newfile;
                if (m_bake.Index(wxT(RAWBAKE_ABSOLUTE)) == wxNOT_FOUND) {
                    filename.MakeRelativeTo(m_bakeroot.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME));
                }
                newfile = filename.GetFullPath();
                node.delProp("include");
                node.addProp("include", newfile.utf8_str());
            } else {
                node.delProp("include");
            }
        }
    }

    cXmlNode child(node.children());
    while (child) {
        DO_CONDITION_COMMENT(child);

        if (child(RAWXML_SET)) {
            ParseSet(child, command);
        } else if (child(RAWXML_UNSET)) {
            ParseUnset(child, command);
        } else if (child(RAWXML_VARIABLES)) {
            ParseVariables(child, command, path);
        } else if (child.is(XML_ELEMENT_NODE)) {
            throw MakeNodeException<RCT3Exception>(wxString::Format(_("Unknown tag '%s' in variables tag"), child.wxname().c_str()), child);
        }
        child.go_next();
    }
}
示例#4
0
文件: regexp.c 项目: sfraize/TemuTerm
struct Expression* ParseAtom(const RegexpTokenType* token_stream, int* pos) {
    int origpos = *pos;
    char c = token_stream[*pos];
    if(IS_LITERAL_TOKEN(c)) {
	/* Atom := string of literal characters/ANY_CHAR/LINE_START/LINE_END */
	struct LiteralStringExpression* result =
	    malloc(sizeof(struct LiteralStringExpression));
	int num_tokens;
	result->base.typecode = LITERAL_STRING_EXPRESSION_TYPE;
	result->base.group_number = NO_GROUP;

	for( ; token_stream[*pos] != 0; (*pos)++) {
	    if (!IS_LITERAL_TOKEN(token_stream[*pos])) {
		break;
	    }
	}
	num_tokens = (*pos) - origpos;
	result->literal_string = malloc((num_tokens + 1) * sizeof(RegexpTokenType));
	result->literal_string[num_tokens] = 0; /* null terminate */
	memmove(result->literal_string, &token_stream[origpos], num_tokens*sizeof(RegexpTokenType));
	return (struct Expression*)result;
    }

    switch (c) {
    case SPECIAL_SET_PREFIX: {
	/* Atom := SPECIAL_SET_PREFIX <letter>, just invoke its regexp */
	(*pos)++;
	if (predefined_char_classes[token_stream[*pos]].token_string != NULL) {
	    int pre_pos = 0;
	    struct Expression* result =
		ParseExpression(predefined_char_classes[token_stream[*pos]].token_string, &pre_pos);
	    (*pos)++;
	    return result;
	}
	switch(token_stream[*pos]) {
	case 'B':   /* Between \w and \w OR between \W and \W */
	case 'b': { /* Between \w and \W OR between \W and \w */
	    int temp_pos = 0;
	    struct ZeroWidthExpression* left =
		malloc(sizeof(struct ZeroWidthExpression));
	    struct ZeroWidthExpression* right =
		malloc(sizeof(struct ZeroWidthExpression));
	    struct UnionExpression* result =
		malloc(sizeof(struct UnionExpression));

	    left->base.typecode = ZERO_WIDTH_EXPRESSION_TYPE;
	    left->base.group_number = NO_GROUP;
	    temp_pos=0; ParseSet(predefined_char_classes['w'].token_string,
				 &temp_pos, left->preceding_set);
	    if (token_stream[*pos] == 'b') {
		temp_pos=0; ParseSet(predefined_char_classes['W'].token_string,
				     &temp_pos, left->following_set);
	    } else {
		temp_pos=0; ParseSet(predefined_char_classes['w'].token_string,
				     &temp_pos, left->following_set);
	    }

	    right->base.typecode = ZERO_WIDTH_EXPRESSION_TYPE;
	    right->base.group_number = NO_GROUP;
	    temp_pos=0; ParseSet(predefined_char_classes['W'].token_string,
				 &temp_pos, right->preceding_set);
	    if (token_stream[*pos] == 'b') {
		temp_pos=0; ParseSet(predefined_char_classes['w'].token_string,
				     &temp_pos, right->following_set);
	    } else {
		temp_pos=0; ParseSet(predefined_char_classes['W'].token_string,
				     &temp_pos, right->following_set);
	    }

	    result->base.typecode = UNION_EXPRESSION_TYPE;
	    result->base.group_number = NO_GROUP;
	    result->left_expression = (struct Expression*)left;
	    result->right_expression = (struct Expression*)right;
	    (*pos)++;
	    return (struct Expression*)result;
	}
	}
	goto parse_error;
    }
    case ANY_CHAR: {
	struct CharSetExpression* result =
	    malloc(sizeof(struct CharSetExpression));
	result->base.typecode = CHARSET_EXPRESSION_TYPE;
	result->base.group_number = NO_GROUP;
	SetAllCharSet(result->set);
	(*pos)++;
	return (struct Expression*)result;
    }
    case LINE_START: {
	struct ZeroWidthExpression* result =
	    malloc(sizeof(struct ZeroWidthExpression));
	result->base.typecode = ZERO_WIDTH_EXPRESSION_TYPE;
	result->base.group_number = NO_GROUP;
	ZeroOutCharSet(result->preceding_set);
	BitArrayInsert(result->preceding_set, BEFORE_STRING_CHAR);
	SetAllCharSet(result->following_set);
	(*pos)++;
	return (struct Expression*)result;
    }
    case LINE_END: {
	struct ZeroWidthExpression* result =
	    malloc(sizeof(struct ZeroWidthExpression));
	result->base.typecode = ZERO_WIDTH_EXPRESSION_TYPE;
	result->base.group_number = NO_GROUP;
	SetAllCharSet(result->preceding_set);
	ZeroOutCharSet(result->following_set);
	BitArrayInsert(result->following_set, AFTER_STRING_CHAR);
	(*pos)++;
	return (struct Expression*)result;
    }
    case SET_OPEN: {
	/* Atom := character set */
	struct CharSetExpression* result =
	    malloc(sizeof(struct CharSetExpression));
	result->base.typecode = CHARSET_EXPRESSION_TYPE;
	result->base.group_number = NO_GROUP;
	if (ParseSet(token_stream, pos, result->set) == 0) {
	    destroy_expression((struct Expression*)result);
	    goto parse_error;
	}
	return (struct Expression*)result;
    }
    case GROUP_OPEN: {
        /* Atom := GROUP_OPEN Expression GROUP_CLOSE */
	int open_pos = *pos;
	int group_num = 0;
	struct Expression* expr =
	    ((*pos)++, ParseExpression(token_stream, pos));
	int i;
	if (expr == NULL || token_stream[*pos] != GROUP_CLOSE) {
	    destroy_expression(expr);
	    goto parse_error;
	}
	/* Find group number by counting preceding (s */
	for(i=0; i<open_pos; i++) {
	    if (token_stream[i] == GROUP_OPEN) {
		group_num++;
	    }
	}
	expr->group_number = group_num;
	(*pos)++;
	return expr;
    }
    default:
	/* Unexpected char, parse error */
	goto parse_error;
    }
parse_error:
    *pos = origpos;
    return NULL;
}