Esempio n. 1
0
bool XMLParser::skipComments() {
	if (_char == '<') {
		_char = _stream->readByte();

		if (_char != '!') {
			_stream->seek(-1, SEEK_CUR);
			_char = '<';
			return false;
		}

		if (_stream->readByte() != '-' || _stream->readByte() != '-')
			return parserError("Malformed comment syntax.");

		_char = _stream->readByte();

		while (_char) {
			if (_char == '-') {
				if (_stream->readByte() == '-') {

					if (_stream->readByte() != '>')
						return parserError("Malformed comment (double-hyphen inside comment body).");

					_char = _stream->readByte();
					return true;
				}
			}

			_char = _stream->readByte();
		}

		return parserError("Comment has no closure.");
	}

	return false;
}
bool VirtualKeyboardParser::parserCallback_area(ParserNode *node) {
	String &shape = node->values["shape"];
	String &target = node->values["target"];
	String &coords = node->values["coords"];

	if (target.equalsIgnoreCase("display_area")) {
		if (!shape.equalsIgnoreCase("rect"))
			return parserError("display_area must be a rect area");
		_mode->displayArea = Rect();
		return parseRect(_mode->displayArea, coords);
	} else if (shape.equalsIgnoreCase("rect")) {
		Polygon *poly = _mode->imageMap.createArea(target);
		if (!poly)
			return parserError(Common::String::format("Cannot define area '%s' again", target.c_str()));
		else
			return parseRectAsPolygon(*poly, coords);
	} else if (shape.equalsIgnoreCase("poly")) {
		Polygon *poly = _mode->imageMap.createArea(target);
		if (!poly)
			return parserError(Common::String::format("Cannot define area '%s' again", target.c_str()));
		else
			return parsePolygon(*poly, coords);
	}
	return parserError("Area shape '" + shape + "' not known");
}
Esempio n. 3
0
bool ThemeParser::parserCallback_dialog(ParserNode *node) {
	Common::String var = "Dialog." + node->values["name"];
	bool enabled = true;
	int inset = 0;

	if (resolutionCheck(node->values["resolution"]) == false) {
		node->ignore = true;
		return true;
	}

	if (node->values.contains("enabled")) {
		if (!Common::parseBool(node->values["enabled"], enabled))
			return parserError("Invalid value for Dialog enabling (expecting true/false)");
	}

	if (node->values.contains("inset")) {
		if (!parseIntegerKey(node->values["inset"], 1, &inset))
			return false;
	}

	_theme->getEvaluator()->addDialog(var, node->values["overlays"], enabled, inset);

	if (node->values.contains("shading")) {
		int shading = 0;
		if (node->values["shading"] == "dim")
			shading = 1;
		else if (node->values["shading"] == "luminance")
			shading = 2;
		else return parserError("Invalid value for Dialog background shading.");

		_theme->getEvaluator()->setVar(var + ".Shading", shading);
	}

	return true;
}
Esempio n. 4
0
bool ThemeParser::parserCallback_drawdata(ParserNode *node) {
	bool cached = false;

	if (resolutionCheck(node->values["resolution"]) == false) {
		node->ignore = true;
		return true;
	}

	if (node->values.contains("cache")) {
		if (node->values["cache"] == "true")
			cached = true;
		else if (node->values["cache"] == "false")
			cached = false;
		else return parserError("'Parsed' value must be either true or false.");
	}

	if (_theme->addDrawData(node->values["id"], cached) == false)
		return parserError("Error adding Draw Data set: Invalid DrawData name.");

	if (_defaultStepLocal) {
		delete _defaultStepLocal;
		_defaultStepLocal = 0;
	}

	return true;
}
Esempio n. 5
0
bool ThemeParser::parserCallback_widget(ParserNode *node) {
	Common::String var;

	if (getParentNode(node)->name == "globals") {

		if (resolutionCheck(node->values["resolution"]) == false) {
			node->ignore = true;
			return true;
		}

		var = "Globals." + node->values["name"] + ".";
		if (!parseCommonLayoutProps(node, var))
			return parserError("Error parsing Layout properties of '%s'.", var.c_str());

	} else {
		// FIXME: Shouldn't we distinguish the name/id and the label of a widget?
		var = node->values["name"];
		int width = -1;
		int height = -1;
		bool enabled = true;

		if (node->values.contains("enabled")) {
			if (node->values["enabled"] == "false")
				enabled = false;
			else if (node->values["enabled"] != "true")
				return parserError("Invalid value for Widget enabling (expecting true/false)");
		}

		if (node->values.contains("width")) {
			if (_theme->getEvaluator()->hasVar(node->values["width"]) == true)
				width = _theme->getEvaluator()->getVar(node->values["width"]);

			else if (!parseIntegerKey(node->values["width"].c_str(), 1, &width))
				return parserError("Corrupted width value in key for %s", var.c_str());
		}

		if (node->values.contains("height")) {
			if (_theme->getEvaluator()->hasVar(node->values["height"]) == true)
				height = _theme->getEvaluator()->getVar(node->values["height"]);

			else if (!parseIntegerKey(node->values["height"].c_str(), 1, &height))
				return parserError("Corrupted height value in key for %s", var.c_str());
		}

		Graphics::TextAlign alignH = Graphics::kTextAlignLeft;

		if (node->values.contains("textalign")) {
			if((alignH = parseTextHAlign(node->values["textalign"])) == Graphics::kTextAlignInvalid)
				return parserError("Invalid value for text alignment.");
		}

		_theme->getEvaluator()->addWidget(var, width, height, node->values["type"], enabled, alignH);
	}

	return true;
}
Esempio n. 6
0
bool XMLParser::parseActiveKey(bool closed) {
	bool ignore = false;
	assert(_activeKey.empty() == false);

	ParserNode *key = _activeKey.top();

	if (key->name == "xml" && key->header == true) {
		assert(closed);
		return parseXMLHeader(key) && closeKey();
	}

	XMLKeyLayout *layout = (_activeKey.size() == 1) ? _XMLkeys : getParentNode(key)->layout;

	if (layout->children.contains(key->name)) {
		key->layout = layout->children[key->name];

		Common::StringMap localMap = key->values;
		int keyCount = localMap.size();

		for (Common::List<XMLKeyLayout::XMLKeyProperty>::const_iterator i = key->layout->properties.begin(); i != key->layout->properties.end(); ++i) {
			if (i->required && !localMap.contains(i->name))
				return parserError("Missing required property '%s' inside key '%s'", i->name.c_str(), key->name.c_str());
			else if (localMap.contains(i->name))
				keyCount--;
		}

		if (keyCount > 0)
			return parserError("Unhandled property inside key '%s'.", key->name.c_str());

	} else {
		return parserError("Unexpected key in the active scope ('%s').", key->name.c_str());
	}

	// check if any of the parents must be ignored.
	// if a parent is ignored, all children are too.
	for (int i = _activeKey.size() - 1; i >= 0; --i) {
		if (_activeKey[i]->ignore)
			ignore = true;
	}

	if (ignore == false && keyCallback(key) == false) {
		// HACK:  People may be stupid and overlook the fact that
		// when keyCallback() fails, a parserError() must be set.
		// We set it manually in that case.
		if (_state != kParserError)
			parserError("Unhandled exception when parsing '%s' key.", key->name.c_str());

		return false;
	}

	if (closed)
		return closeKey();

	return true;
}
bool VirtualKeyboardParser::closedKeyCallback(ParserNode *node) {
	if (node->name.equalsIgnoreCase("keyboard")) {
		_kbdParsed = true;
		if (!_keyboard->_initialMode)
			return parserError("Initial mode of keyboard pack not defined");
	} else if (node->name.equalsIgnoreCase("mode")) {
		if (!_layoutParsed) {
			return parserError("'" + _mode->resolution + "' layout missing from '" + _mode->name + "' mode");
		}
	}
	return true;
}
bool VirtualKeyboardParser::parseRect(Rect &rect, const String& coords) {
    int x1, y1, x2, y2;
    if (!parseIntegerKey(coords, 4, &x1, &y1, &x2, &y2))
        return parserError("Invalid coords for rect area");
    rect.left = x1;
    rect.top = y1;
    rect.right = x2;
    rect.bottom = y2;
    if (!rect.isValidRect())
        return parserError("Rect area is not a valid rectangle");
    return true;
}
bool VirtualKeyboardParser::parserCallback_layout(ParserNode *node) {
	assert(!_mode->resolution.empty());

	String res = node->values["resolution"];

	if (res != _mode->resolution) {
		node->ignore = true;
		return true;
	}

	_mode->bitmapName = node->values["bitmap"];

	SeekableReadStream *file = _keyboard->_fileArchive->createReadStreamForMember(_mode->bitmapName);
	if (!file)
		return parserError("Bitmap '" + _mode->bitmapName + "' not found");

	const Graphics::PixelFormat format = g_system->getOverlayFormat();

	{
		Graphics::BitmapDecoder bmp;
		if (!bmp.loadStream(*file))
			return parserError("Error loading bitmap '" + _mode->bitmapName + "'");

		_mode->image = bmp.getSurface()->convertTo(format);
	}

	delete file;

	int r, g, b;
	if (node->values.contains("transparent_color")) {
		if (!parseIntegerKey(node->values["transparent_color"], 3, &r, &g, &b))
			return parserError("Could not parse color value");
	} else {
		// default to purple
		r = 255;
		g = 0;
		b = 255;
	}
	_mode->transparentColor = format.RGBToColor(r, g, b);

	if (node->values.contains("display_font_color")) {
		if (!parseIntegerKey(node->values["display_font_color"], 3, &r, &g, &b))
			return parserError("Could not parse color value");
	} else {
		r = g = b = 0; // default to black
	}
	_mode->displayFontColor = format.RGBToColor(r, g, b);

	_layoutParsed = true;

	return true;
}
Esempio n. 10
0
bool XMLParser::parseXMLHeader(ParserNode *node) {
	assert(node->header);

	if (_activeKey.size() != 1)
		return parserError("XML Header is expected in the global scope.");

	if (!node->values.contains("version"))
		return parserError("Missing XML version in XML header.");

	if (node->values["version"] != "1.0")
		return parserError("Unsupported XML version.");

	return true;
}
Esempio n. 11
0
bool ThemeParser::parserCallback_layout(ParserNode *node) {
	int spacing = -1;

	if (node->values.contains("spacing")) {
		if (!parseIntegerKey(node->values["spacing"].c_str(), 1, &spacing))
			return false;
	}

	if (node->values["type"] == "vertical")
		_theme->getEvaluator()->addLayout(GUI::ThemeLayout::kLayoutVertical, spacing, node->values["center"] == "true");
	else if (node->values["type"] == "horizontal")
		_theme->getEvaluator()->addLayout(GUI::ThemeLayout::kLayoutHorizontal, spacing, node->values["center"] == "true");
	else
		return parserError("Invalid layout type. Only 'horizontal' and 'vertical' layouts allowed.");


	if (node->values.contains("padding")) {
		int paddingL, paddingR, paddingT, paddingB;

		if (!parseIntegerKey(node->values["padding"].c_str(), 4, &paddingL, &paddingR, &paddingT, &paddingB))
			return false;

		_theme->getEvaluator()->addPadding(paddingL, paddingR, paddingT, paddingB);
	}

	return true;
}
Esempio n. 12
0
bool AnimationResource::parserCallback_animation(ParserNode *node) {
    if (!parseIntegerKey(node->values["fps"], 1, &_FPS) || (_FPS < MIN_FPS) || (_FPS > MAX_FPS)) {
        return parserError("Illegal or missing fps attribute in <animation> tag in \"%s\". Assuming default (\"%d\").",
                           getFileName().c_str(), DEFAULT_FPS);
    }

    // Loop type value
    const char *loopTypeString = node->values["type"].c_str();

    if (strcmp(loopTypeString, "oneshot") == 0) {
        _animationType = Animation::AT_ONESHOT;
    } else if (strcmp(loopTypeString, "loop") == 0) {
        _animationType = Animation::AT_LOOP;
    } else if (strcmp(loopTypeString, "jojo") == 0) {
        _animationType = Animation::AT_JOJO;
    } else {
        warning("Illegal type value (\"%s\") in <animation> tag in \"%s\". Assuming default (\"loop\").",
                loopTypeString, getFileName().c_str());
        _animationType = Animation::AT_LOOP;
    }

    // Calculate the milliseconds required per frame
    // FIXME: Double check variable naming. Based on the constant, it may be microseconds
    _millisPerFrame = 1000000 / _FPS;

    return true;
}
bool VirtualKeyboardParser::parsePolygon(Polygon &poly, const String& coords) {
    StringTokenizer tok(coords, ", ");
    for (String st = tok.nextToken(); !st.empty(); st = tok.nextToken()) {
        int x, y;
        if (sscanf(st.c_str(), "%d", &x) != 1)
            return parserError("Invalid coords for polygon area");
        st = tok.nextToken();
        if (sscanf(st.c_str(), "%d", &y) != 1)
            return parserError("Invalid coords for polygon area");
        poly.addPoint(x, y);
    }
    if (poly.getPointCount() < 3)
        return parserError("Invalid coords for polygon area");

    return true;
}
Esempio n. 14
0
//Note: could possibly use Waffles arff parser
//http://waffles.sourceforge.net/docs/matrices.html
StructuredSampleCollection readArff(std::istream& in){
  unsigned lineNum = 0;
  
  std::string relationName;
  std::vector<std::string> contvarNames;
  std::vector<std::string> catvarNames;
  //std::vector<std::string> binvarNames;
  
  std::vector<Array<std::string> > catvarCatNames;
  //std::vector<Array<std::string> > binvarCatNames;
  
  std::vector<featurety_t> featureTypes; //Used to determine the order of the arff arguments.
  
  std::string line;
  while (1)
  {
    lineNum++;
    if(!std::getline(in, line)){
      parserError(lineNum) << "Blank or absent @DATA section." << std::endl;
      exit(1);
    }
    
    //Filter comments, blank lines
    if(line.length() == 0 || line[0] == '%') continue;
    std::istringstream lineStream(line);

    //Read from the line
    std::string token;
    lineStream >> token;

    tolower(token);
    if(token == "@relation"){
      lineStream >> relationName;
    }
    else if(token == "@attribute"){
bool VirtualKeyboardParser::parserCallback_keyboard(ParserNode *node) {
    if (_kbdParsed)
        return parserError("Only a single keyboard element is allowed");

    // if not full parse then we're done
    if (_parseMode == kParseCheckResolutions)
        return true;

    _initialModeName = node->values["initial_mode"];

    if (node->values.contains("h_align")) {
        String h = node->values["h_align"];
        if (h.equalsIgnoreCase("left"))
            _keyboard->_hAlignment = VirtualKeyboard::kAlignLeft;
        else if (h.equalsIgnoreCase("centre") || h.equalsIgnoreCase("center"))
            _keyboard->_hAlignment = VirtualKeyboard::kAlignCentre;
        else if (h.equalsIgnoreCase("right"))
            _keyboard->_hAlignment = VirtualKeyboard::kAlignRight;
    }

    if (node->values.contains("v_align")) {
        String v = node->values["v_align"];
        if (v.equalsIgnoreCase("top"))
            _keyboard->_vAlignment = VirtualKeyboard::kAlignTop;
        else if (v.equalsIgnoreCase("middle") || v.equalsIgnoreCase("center"))
            _keyboard->_vAlignment = VirtualKeyboard::kAlignMiddle;
        else if (v.equalsIgnoreCase("bottom"))
            _keyboard->_vAlignment = VirtualKeyboard::kAlignBottom;
    }

    return true;
}
Esempio n. 16
0
bool ThemeParser::parserCallback_text_color(ParserNode *node) {
	int red, green, blue;

	TextColor colorId = parseTextColorId(node->values["id"]);
	if (colorId == kTextColorMAX)
		return parserError("Error text color is not defined.");

	if (_palette.contains(node->values["color"]))
		getPaletteColor(node->values["color"], red, green, blue);
	else if (!parseIntegerKey(node->values["color"], 3, &red, &green, &blue))
		return parserError("Error parsing color value for text color definition.");

	if (!_theme->addTextColor(colorId, red, green, blue))
		return parserError("Error while adding text color information.");

	return true;
}
Esempio n. 17
0
void TCParser::_parserError(tcrec_error error, const char *info)
{
	TCInfo *err = new TCInfo(tcinfo_error, error, info);
	
	parserError(err);
	
	err->release();
}
Esempio n. 18
0
bool ThemeParser::parserCallback_text(ParserNode *node) {
	Graphics::TextAlign alignH;
	GUI::ThemeEngine::TextAlignVertical alignV;

	if ((alignH = parseTextHAlign(node->values["horizontal_align"])) == Graphics::kTextAlignInvalid)
		return parserError("Invalid value for text alignment.");

	if ((alignV = parseTextVAlign(node->values["vertical_align"])) == GUI::ThemeEngine::kTextAlignVInvalid)
		return parserError("Invalid value for text alignment.");

	Common::String id = getParentNode(node)->values["id"];
	TextData textDataId = parseTextDataId(node->values["font"]);

	if (!_theme->addTextData(id, textDataId, alignH, alignV))
		return parserError("Error adding Text Data for '%s'.", id.c_str());

	return true;
}
Esempio n. 19
0
bool ThemeParser::parserCallback_color(ParserNode *node) {
	Common::String name = node->values["name"];

	if (_palette.contains(name))
		return parserError("Color '%s' has already been defined.", name.c_str());

	int red, green, blue;

	if (parseIntegerKey(node->values["rgb"].c_str(), 3, &red, &green, &blue) == false ||
		red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255)
		return parserError("Error parsing RGB values for palette color '%s'", name.c_str());\

	_palette[name].r = red;
	_palette[name].g = green;
	_palette[name].b = blue;

	return true;
}
Esempio n. 20
0
bool ThemeParser::parserCallback_cursor(ParserNode *node) {
	if (resolutionCheck(node->values["resolution"]) == false) {
		node->ignore = true;
		return true;
	}

	int spotx, spoty, scale;

	if (!parseIntegerKey(node->values["hotspot"].c_str(), 2, &spotx, &spoty))
		return parserError("Error parsing cursor Hot Spot coordinates.");

	if (!parseIntegerKey(node->values["scale"].c_str(), 1, &scale))
		return parserError("Error parsing cursor scale.");

	if (!_theme->createCursor(node->values["file"], spotx, spoty, scale))
		return parserError("Error creating Bitmap Cursor.");

	return true;
}
Esempio n. 21
0
bool ThemeParser::parserCallback_font(ParserNode *node) {
	int red, green, blue;

	if (resolutionCheck(node->values["resolution"]) == false) {
		node->ignore = true;
		return true;
	}

	if (_palette.contains(node->values["color"]))
		getPaletteColor(node->values["color"], red, green, blue);
	else if (!parseIntegerKey(node->values["color"].c_str(), 3, &red, &green, &blue))
		return parserError("Error parsing color value for font definition.");

	TextData textDataId = parseTextDataId(node->values["id"]);
	if (!_theme->addFont(textDataId, node->values["file"], red, green, blue))
		return parserError("Error loading Font in theme engine.");

	return true;
}
Esempio n. 22
0
bool ThemeParser::parserCallback_bitmap(ParserNode *node) {
	if (resolutionCheck(node->values["resolution"]) == false) {
		node->ignore = true;
		return true;
	}

	if (!_theme->addBitmap(node->values["filename"]))
		return parserError("Error loading Bitmap file '%s'", node->values["filename"].c_str());

	return true;
}
Esempio n. 23
0
bool ThemeParser::parserCallback_font(ParserNode *node) {
	if (resolutionCheck(node->values["resolution"]) == false) {
		node->ignore = true;
		return true;
	}

	TextData textDataId = parseTextDataId(node->values["id"]);
	if (!_theme->addFont(textDataId, node->values["file"]))
		return parserError("Error loading Font in theme engine.");

	return true;
}
Esempio n. 24
0
prio_t
Map_Prio (const String & s)
{
  if (s == "system")
    return PRIO_SYSTEM;
  if (s == "urgent")
    return PRIO_URGENT;
  if (s == "normal")
    return PRIO_NORMAL;
  if (s == "low")
    return PRIO_LOW;
  parserError (_("unkown Priority %s"), s ());
}
Esempio n. 25
0
bool ThemeParser::parserCallback_space(ParserNode *node) {
	int size = -1;

	if (node->values.contains("size")) {
		if (_theme->getEvaluator()->hasVar(node->values["size"]))
			size = _theme->getEvaluator()->getVar(node->values["size"]);

		else if (!parseIntegerKey(node->values["size"].c_str(), 1, &size))
			return parserError("Invalid value for Spacing size.");
	}

	_theme->getEvaluator()->addSpace(size);
	return true;
}
Esempio n. 26
0
bool FontResource::parserCallback_character(ParserNode *node) {
	// Get the attributes of the character
	int charCode, top, left, right, bottom;

	if (!parseIntegerKey(node->values["code"], 1, &charCode) || (charCode < 0) || (charCode >= 256)) {
		return parserError("Illegal or missing code attribute in <character> tag in \"%s\".", getFileName().c_str());
	}

	if (!parseIntegerKey(node->values["top"], 1, &top) || (top < 0)) {
		return parserError("Illegal or missing top attribute in <character> tag in \"%s\".", getFileName().c_str());
	}
	if (!parseIntegerKey(node->values["left"], 1, &left) || (left < 0)) {
		return parserError("Illegal or missing left attribute in <character> tag in \"%s\".", getFileName().c_str());
	}
	if (!parseIntegerKey(node->values["right"], 1, &right) || (right < 0)) {
		return parserError("Illegal or missing right attribute in <character> tag in \"%s\".", getFileName().c_str());
	}
	if (!parseIntegerKey(node->values["bottom"], 1, &bottom) || (bottom < 0)) {
		return parserError("Illegal or missing bottom attribute in <character> tag in \"%s\".", getFileName().c_str());
	}

	this->_characterRects[charCode] = Common::Rect(left, top, right, bottom);
	return true;
}
Esempio n. 27
0
bool ThemeParser::parserCallback_defaults(ParserNode *node) {
	ParserNode *parentNode = getParentNode(node);
	Graphics::DrawStep *step = 0;

	if (parentNode->name == "render_info") {
		step = _defaultStepGlobal;
	} else if (parentNode->name == "drawdata") {
		if (_defaultStepLocal == 0)
			_defaultStepLocal = new Graphics::DrawStep(*_defaultStepGlobal);

		step = _defaultStepLocal;
	} else {
		return parserError("<default> key out of scope. Must be inside <drawdata> or <render_info> keys.");
	}

	return parseDrawStep(node, step, false);
}
Esempio n. 28
0
bool ThemeParser::parserCallback_drawstep(ParserNode *node) {
	Graphics::DrawStep *drawstep = newDrawStep();

	Common::String functionName = node->values["func"];

	drawstep->drawingCall = getDrawingFunctionCallback(functionName);

	if (drawstep->drawingCall == 0)
		return parserError("%s is not a valid drawing function name", functionName.c_str());

	if (!parseDrawStep(node, drawstep, true))
		return false;

	_theme->addDrawStep(getParentNode(node)->values["id"], *drawstep);
	delete drawstep;

	return true;
}
Esempio n. 29
0
bool ThemeParser::parserCallback_def(ParserNode *node) {
	if (resolutionCheck(node->values["resolution"]) == false) {
		node->ignore = true;
		return true;
	}

	Common::String var = "Globals." + node->values["var"];
	int value;

	if (_theme->getEvaluator()->hasVar(node->values["value"]) == true)
		value = _theme->getEvaluator()->getVar(node->values["value"]);

	else if (!parseIntegerKey(node->values["value"].c_str(), 1, &value))
		return parserError("Invalid definition for '%s'.", var.c_str());

	_theme->getEvaluator()->setVar(var, value);
	return true;
}
Esempio n. 30
0
int parseFiles(int argc, char *argv[], graph * map, company ** cmp) {
	int i = 0;
	int ret = 0;
	if (argc < 3)
		return parserError(NULL, NULL, INVALID_ARGUMENTS, NULL);
	if ((ret = openAndReadCityFile(argv[1], map)) != EXIT_SUCCESS
	)
		return ret;
	for (i = 0; i < argc - 2; i++) {
		cmp[i] = NULL;
	}
	for (i = 2; i < argc; ++i) {
		if ((ret = openAndReadCompanyFile(argv[i], cmp, i - 2, map))
				!= EXIT_SUCCESS
				)
			return ret;
	}
	return EXIT_SUCCESS;
}