コード例 #1
0
ファイル: FurnaceRecipe.cpp プロジェクト: 1285done/cuberite
void cFurnaceRecipe::AddRecipeFromLine(const AString & a_Line, unsigned int a_LineNum)
{
	AString Line(a_Line);
	Line.erase(std::remove_if(Line.begin(), Line.end(), isspace), Line.end());

	int CookTime = 200;
	std::unique_ptr<cItem> InputItem = cpp14::make_unique<cItem>();
	std::unique_ptr<cItem> OutputItem = cpp14::make_unique<cItem>();

	const AStringVector & Sides = StringSplit(Line, "=");
	if (Sides.size() != 2)
	{
		LOGWARNING("furnace.txt: line %d: A single '=' was expected, got " SIZE_T_FMT, a_LineNum, Sides.size() - 1);
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	const AStringVector & InputSplit = StringSplit(Sides[0], "@");
	if (!ParseItem(InputSplit[0], *InputItem))
	{
		LOGWARNING("furnace.txt: line %d: Cannot parse input item \"%s\".", a_LineNum, InputSplit[0].c_str());
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	if (InputSplit.size() > 1)
	{
		if (!StringToInteger<int>(InputSplit[1], CookTime))
		{
			LOGWARNING("furnace.txt: line %d: Cannot parse cook time \"%s\".", a_LineNum, InputSplit[1].c_str());
			LOGINFO("Offending line: \"%s\"", a_Line.c_str());
			return;
		}
	}

	if (!ParseItem(Sides[1], *OutputItem))
	{
		LOGWARNING("furnace.txt: line %d: Cannot parse output item \"%s\".", a_LineNum, Sides[1].c_str());
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	cRecipe Recipe;
	Recipe.In = InputItem.release();
	Recipe.Out = OutputItem.release();
	Recipe.CookTime = CookTime;
	m_pState->Recipes.push_back(Recipe);
}
コード例 #2
0
ファイル: MicroCode.cpp プロジェクト: tempbottle/TestSet
// 解析微代码
// pszMicroCode [IN]  微代码字符串
// pszAddr      [IN]  代码地址
// pszNextAddr  [IN]  下一条微代码的地址
// Item         [OUT] 微代码数据
bool CMicroCode::ParseMicroCode(const char *pszMicroCode, 
                                const char *pszAddr, 
                                const char *pszNextAddr,
                                MICROCODE_ITEM &Item)
{

    if ((NULL == pszMicroCode) || (NULL == pszAddr) || (NULL == pszNextAddr))
    {
        return false;
    }
    
    if (0 == strcmp("0xFFF", pszAddr))
    {
        TRACE("ALU:%s\n", pszAddr);
    }

    Item.Addr.wAddr = CStrConver::StrToHex(pszAddr);
    Item.NextAddr.wAddr = CStrConver::StrToHex(pszNextAddr);

    VECTOR_STR vecParam;
    CStrConver::TokenizeData(pszMicroCode, ",", vecParam);

    for (unsigned int i = 0; i < vecParam.size(); i++)
    {
        ParseItem(vecParam[i].c_str(), Item);
    }

    return true;
}
コード例 #3
0
ファイル: SessionRParser.hpp プロジェクト: igitur/rstudio
   std::set<ParseItem> getUnresolvedSymbols() const
   {
      std::set<ParseItem> unresolvedSymbols;
      
      for (SymbolPositions::const_iterator it = referencedSymbols_.begin();
           it != referencedSymbols_.end();
           ++it)
      {
         const std::string& symbol = it->first;
         BOOST_FOREACH(const Position& position, it->second)
         {
            DEBUG("-- Checking for symbol '" << symbol << "' " << position.toString());
            if (!symbolHasDefinitionInTree(symbol, position))
            {
               DEBUG("--- No definition for symbol '" << symbol << "'");
               unresolvedSymbols.insert(
                        ParseItem(symbol, position, this));
            }
            else
            {
               DEBUG("--- Found definition for symbol '" << symbol << "'");
            }
         }
      }

      return unresolvedSymbols;
   }
コード例 #4
0
channels_container_t Atom10Parser::Parse (const QDomDocument& doc,
        const IDType_t& feedId) const
{
    channels_container_t channels;
    Channel_ptr chan (new Channel (feedId));
    channels.push_back (chan);

    QDomElement root = doc.documentElement ();
    chan->Title_ = root.firstChildElement ("title").text ().trimmed ();
    if (chan->Title_.isEmpty ())
        chan->Title_ = QObject::tr ("(No title)");
    chan->LastBuild_ = FromRFC3339 (root.firstChildElement ("updated").text ());
    chan->Link_ = GetLink (root);
    chan->Description_ = root.firstChildElement ("subtitle").text ();
    chan->Author_ = GetAuthor (root);
    if (chan->Author_.isEmpty ())
    {
        QDomElement author = root.firstChildElement ("author");
        chan->Author_ = author.firstChildElement ("name").text () +
                        " (" +
                        author.firstChildElement ("email").text () +
                        ")";
    }
    chan->Language_ = "<>";

    QDomElement entry = root.firstChildElement ("entry");
    while (!entry.isNull ())
    {
        chan->Items_.push_back (Item_ptr (ParseItem (entry, chan->ChannelID_)));
        entry = entry.nextSiblingElement ("entry");
    }

    return channels;
}
コード例 #5
0
ファイル: Protocol125.cpp プロジェクト: FX-Master/MCServer
int cProtocol125::ParseWindowClick(void)
{
	HANDLE_PACKET_READ(ReadChar,    char,  WindowID);
	HANDLE_PACKET_READ(ReadBEShort, short, SlotNum);
	HANDLE_PACKET_READ(ReadBool,    bool,  IsRightClick);
	HANDLE_PACKET_READ(ReadBEShort, short, TransactionID);
	HANDLE_PACKET_READ(ReadBool,    bool,  IsShiftPressed);
	cItem HeldItem;
	int res = ParseItem(HeldItem);
	if (res < 0)
	{
		return res;
	}
	
	// Convert IsShiftPressed, IsRightClick, SlotNum and HeldItem into eClickAction used in the newer protocols:
	eClickAction Action;
	if (IsRightClick)
	{
		if (IsShiftPressed)
		{
			Action = caShiftRightClick;
		}
		else
		{
			if (SlotNum == -999)
			{
				Action = (HeldItem.IsEmpty()) ? caRightClickOutsideHoldNothing : caRightClickOutside;
			}
			else
			{
				Action = caRightClick;
			}
		}
	}
	else
	{
		// IsLeftClick
		if (IsShiftPressed)
		{
			Action = caShiftLeftClick;
		}
		else
		{
			if (SlotNum == -999)
			{
				Action = (HeldItem.IsEmpty()) ? caLeftClickOutsideHoldNothing : caRightClickOutside;
			}
			else
			{
				Action = caLeftClick;
			}
		}
	}
	m_Client->HandleWindowClick(WindowID, SlotNum, Action, HeldItem);
	return PARSE_OK;
}
コード例 #6
0
ファイル: Protocol15x.cpp プロジェクト: Dam63/MCServer
int cProtocol150::ParseWindowClick(void)
{
	HANDLE_PACKET_READ(ReadChar,    char,  WindowID);
	HANDLE_PACKET_READ(ReadBEShort, short, SlotNum);
	HANDLE_PACKET_READ(ReadByte,    Byte,  Button);
	HANDLE_PACKET_READ(ReadBEShort, short, TransactionID);
	HANDLE_PACKET_READ(ReadByte,    Byte,  Mode);
	cItem HeldItem;
	int res = ParseItem(HeldItem);
	if (res < 0)
	{
		return res;
	}
	
	// Convert Button, Mode, SlotNum and HeldItem into eClickAction:
	eClickAction Action = caUnknown;
	switch ((Mode << 8) | Button)
	{
		case 0x0000: Action = (SlotNum != -999) ? caLeftClick  : caLeftClickOutside;  break;
		case 0x0001: Action = (SlotNum != -999) ? caRightClick : caRightClickOutside; break;
		case 0x0100: Action = caShiftLeftClick;  break;
		case 0x0101: Action = caShiftRightClick; break;
		case 0x0200: Action = caNumber1;         break;
		case 0x0201: Action = caNumber2;         break;
		case 0x0202: Action = caNumber3;         break;
		case 0x0203: Action = caNumber4;         break;
		case 0x0204: Action = caNumber5;         break;
		case 0x0205: Action = caNumber6;         break;
		case 0x0206: Action = caNumber7;         break;
		case 0x0207: Action = caNumber8;         break;
		case 0x0208: Action = caNumber9;         break;
		case 0x0300: Action = caMiddleClick;     break;
		case 0x0400: Action = (SlotNum == -999) ? caLeftClickOutsideHoldNothing  : caDropKey;           break;
		case 0x0401: Action = (SlotNum == -999) ? caRightClickOutsideHoldNothing : caCtrlDropKey;       break;
		case 0x0500: Action = (SlotNum == -999) ? caLeftPaintBegin               : caUnknown;           break;
		case 0x0501: Action = (SlotNum != -999) ? caLeftPaintProgress            : caUnknown;           break;
		case 0x0502: Action = (SlotNum == -999) ? caLeftPaintEnd                 : caUnknown;           break;
		case 0x0504: Action = (SlotNum == -999) ? caRightPaintBegin              : caUnknown;           break;
		case 0x0505: Action = (SlotNum != -999) ? caRightPaintProgress           : caUnknown;           break;
		case 0x0506: Action = (SlotNum == -999) ? caRightPaintEnd                : caUnknown;           break;
		case 0x0600: Action = caDblClick; break;
	}
	
	if (Action == caUnknown)
	{
		LOGWARNING("Received an unknown click action combination: Mode = %d, Button = %d, Slot = %d, HeldItem = %s. Ignoring packet.",
			Mode, Button, SlotNum, ItemToFullString(HeldItem).c_str()
		);
		ASSERT(!"Unknown click action");
		return PARSE_OK;
	}
	
	m_Client->HandleWindowClick(WindowID, SlotNum, Action, HeldItem);
	return PARSE_OK;
}
コード例 #7
0
ファイル: Protocol125.cpp プロジェクト: FX-Master/MCServer
int cProtocol125::ParseCreativeInventoryAction(void)
{
	HANDLE_PACKET_READ(ReadBEShort, short, SlotNum);
	cItem HeldItem;
	int res = ParseItem(HeldItem);
	if (res < 0)
	{
		return res;
	}
	m_Client->HandleCreativeInventory(SlotNum, HeldItem);
	return PARSE_OK;
}
コード例 #8
0
ファイル: Protocol125.cpp プロジェクト: FX-Master/MCServer
int cProtocol125::ParseBlockPlace(void)
{
	HANDLE_PACKET_READ(ReadBEInt, int,  PosX);
	HANDLE_PACKET_READ(ReadByte,  Byte, PosY);
	HANDLE_PACKET_READ(ReadBEInt, int,  PosZ);
	HANDLE_PACKET_READ(ReadChar,  char, BlockFace);

	cItem HeldItem;
	int res = ParseItem(HeldItem);
	if (res < 0)
	{
		return res;
	}

	// 1.2.5 didn't have any cursor position, so use 8, 8, 8, so that halfslabs and stairs work correctly and the special value is recognizable.
	m_Client->HandleRightClick(PosX, PosY, PosZ, static_cast<eBlockFace>(BlockFace), 8, 8, 8, HeldItem);
	return PARSE_OK;
}
コード例 #9
0
void ReportDescParserBase::Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset) {
    uint16_t cntdn = (uint16_t)len;
    uint8_t *p = (uint8_t*)pbuf;


    totalSize = 0;

    while (cntdn) {
        //USB_HOST_SERIAL.println("");
        //PrintHex<uint16_t>(offset + len - cntdn);
        //USB_HOST_SERIAL.print(":");

        ParseItem(&p, &cntdn);

        //if (ParseItem(&p, &cntdn))
        //	return;
    }
    //USBTRACE2("Total:", totalSize);
}
コード例 #10
0
ファイル: Protocol132.cpp プロジェクト: wang108/MCServer
int cProtocol132::ParseBlockPlace(void)
{
	HANDLE_PACKET_READ(ReadBEInt, int,  PosX);
	HANDLE_PACKET_READ(ReadByte,  Byte, PosY);
	HANDLE_PACKET_READ(ReadBEInt, int,  PosZ);
	HANDLE_PACKET_READ(ReadChar,  char, BlockFace);

	cItem HeldItem;
	int res = ParseItem(HeldItem);
	if (res < 0)
	{
		return res;
	}
	
	HANDLE_PACKET_READ(ReadChar, char, CursorX);
	HANDLE_PACKET_READ(ReadChar, char, CursorY);
	HANDLE_PACKET_READ(ReadChar, char, CursorZ);

	m_Client->HandleRightClick(PosX, PosY, PosZ, static_cast<eBlockFace>(BlockFace), CursorX, CursorY, CursorZ, HeldItem);
	return PARSE_OK;
}
コード例 #11
0
bool CCMatchBuffDescMgr::ReadXml(const char* szFileName)
{
	m_nChecksum = CCGetCCZFileChecksum(szFileName);

	CCXmlDocument xmlIniData;

	xmlIniData.Create();

	if (!xmlIniData.LoadFromFile(szFileName))
	{
		m_nChecksum = 0;
		xmlIniData.Destroy();
		return false;
	}

	CCXmlElement rootElement, chrElement, attrElement;
	char szTagName[256];

	rootElement = xmlIniData.GetDocumentElement();
	int iCount = rootElement.GetChildNodeCount();

	for (int i = 0; i < iCount; i++)
	{
		chrElement = rootElement.GetChildNode(i);
		chrElement.GetTagName(szTagName);
		if (szTagName[0] == '#') continue;

		if (!stricmp(szTagName, MICTOK_BUFF))
		{
			if( !ParseItem(chrElement) ) {
				Clear();
				return false;
			}
		}
	}

	xmlIniData.Destroy();
	return true;
}
コード例 #12
0
ファイル: rss20parser.cpp プロジェクト: grio/leechcraft
			channels_container_t RSS20Parser::Parse (const QDomDocument& doc,
					const IDType_t& feedId) const
			{
				channels_container_t channels;
				QDomElement root = doc.documentElement ();
				QDomElement channel = root.firstChildElement ("channel");
				while (!channel.isNull ())
				{
					Channel_ptr chan (new Channel (feedId));
					chan->Title_ = channel.firstChildElement ("title").text ().trimmed ();
					chan->Description_ = channel.firstChildElement ("description").text ();
					chan->Link_ = GetLink (channel);
					chan->LastBuild_ = RFC822TimeToQDateTime (channel.firstChildElement ("lastBuildDate").text ());
					chan->Language_ = channel.firstChildElement ("language").text ();
					chan->Author_ = GetAuthor (channel);
					if (chan->Author_.isEmpty ())
						chan->Author_ = channel.firstChildElement ("managingEditor").text ();
					if (chan->Author_.isEmpty ())
						chan->Author_ = channel.firstChildElement ("webMaster").text ();
					chan->PixmapURL_ = channel.firstChildElement ("image").attribute ("url");
			
					QDomElement item = channel.firstChildElement ("item");
					while (!item.isNull ())
					{
						chan->Items_.push_back (Item_ptr (ParseItem (item, chan->ChannelID_)));
						item = item.nextSiblingElement ("item");
					}
					if (!chan->LastBuild_.isValid () || chan->LastBuild_.isNull ())
					{
						if (chan->Items_.size ())
							chan->LastBuild_ = chan->Items_.at (0)->PubDate_;
						else
							chan->LastBuild_ = QDateTime::currentDateTime ();
					}
					channels.push_back (chan);
					channel = channel.nextSiblingElement ("channel");
				}
				return channels;
			}
コード例 #13
0
ファイル: FurnaceRecipe.cpp プロジェクト: 1285done/cuberite
void cFurnaceRecipe::AddFuelFromLine(const AString & a_Line, unsigned int a_LineNum)
{
	AString Line(a_Line);
	Line.erase(Line.begin());  // Remove the beginning "!"
	Line.erase(std::remove_if(Line.begin(), Line.end(), isspace), Line.end());

	std::unique_ptr<cItem> Item = cpp14::make_unique<cItem>();
	int BurnTime;

	const AStringVector & Sides = StringSplit(Line, "=");
	if (Sides.size() != 2)
	{
		LOGWARNING("furnace.txt: line %d: A single '=' was expected, got " SIZE_T_FMT, a_LineNum, Sides.size() - 1);
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	if (!ParseItem(Sides[0], *Item))
	{
		LOGWARNING("furnace.txt: line %d: Cannot parse item \"%s\".", a_LineNum, Sides[0].c_str());
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	if (!StringToInteger<int>(Sides[1], BurnTime))
	{
		LOGWARNING("furnace.txt: line %d: Cannot parse burn time.", a_LineNum);
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	// Add to fuel list:
	cFuel Fuel;
	Fuel.In = Item.release();
	Fuel.BurnTime = BurnTime;
	m_pState->Fuel.push_back(Fuel);
}
コード例 #14
0
void PodcastParser::ParseChannel(QXmlStreamReader* reader, Podcast* ret) const {
  while (!reader->atEnd()) {
    QXmlStreamReader::TokenType type = reader->readNext();
    switch (type) {
    case QXmlStreamReader::StartElement: {
      const QStringRef name = reader->name();
      if (name == "title") {
        ret->set_title(reader->readElementText());
      } else if (name == "link" && reader->namespaceUri().isEmpty()) {
        ret->set_link(QUrl::fromEncoded(reader->readElementText().toAscii()));
      } else if (name == "description") {
        ret->set_description(reader->readElementText());
      } else if (name == "owner" && reader->namespaceUri() == kItunesNamespace) {
        ParseItunesOwner(reader, ret);
      } else if (name == "image") {
        ParseImage(reader, ret);
      } else if (name == "copyright") {
        ret->set_copyright(reader->readElementText());
      } else if (name == "link" && reader->namespaceUri() == kAtomNamespace &&
                 ret->url().isEmpty() && reader->attributes().value("rel") == "self") {
        ret->set_url(QUrl::fromEncoded(reader->readElementText().toAscii()));
      } else if (name == "item") {
        ParseItem(reader, ret);
      } else {
        Utilities::ConsumeCurrentElement(reader);
      }
      break;
    }

    case QXmlStreamReader::EndElement:
      return;

    default:
      break;
    }
  }
}
コード例 #15
0
	channels_container_t RSS091Parser::Parse (const QDomDocument& doc,
			const IDType_t& feedId) const
	{
		channels_container_t channels;
		QDomElement root = doc.documentElement ();
		QDomElement channel = root.firstChildElement ("channel");
		while (!channel.isNull ())
		{
			Channel_ptr chan (new Channel (feedId));

			chan->Title_ = channel.firstChildElement ("title").text ().trimmed ();
			chan->Description_ = channel.firstChildElement ("description").text ();
			chan->Link_ = channel.firstChildElement ("link").text ();

			auto& itemsList = chan->Items_;
			itemsList.reserve (20);

			QDomElement item = channel.firstChildElement ("item");
			while (!item.isNull ())
			{
				itemsList.push_back (Item_ptr (ParseItem (item, chan->ChannelID_)));
				item = item.nextSiblingElement ("item");
			}
			if (!chan->LastBuild_.isValid () || chan->LastBuild_.isNull ())
			{
				if (!itemsList.empty ())
					chan->LastBuild_ = itemsList.at (0)->PubDate_;
				else
					chan->LastBuild_ = QDateTime::currentDateTime ();
			}

			channels.push_back (chan);
			channel = channel.nextSiblingElement ("channel");
		}
		return channels;
	}
コード例 #16
0
ファイル: XmlFile.cpp プロジェクト: jithuin/infogeezer
BOOL CXmlFile::ParseRootItem(const CString& sRootItemName, CXmlDocumentWrapper* pDoc)
{
	ASSERT (pDoc);
	
	m_xiRoot.Reset();
	
	CString sRootItem(sRootItemName), sItem;
	sRootItem.TrimLeft();
	sRootItem.TrimRight();
	
	// save off the header string
	// Valik - Change IXMLDOMNode* to IXMLDOMNodePtr to prevent an ambiguous symbol error (C2872) in VC 7.1
	CXmlNodeWrapper node(pDoc->AsNode());
	
	if (0 != node.Name().CompareNoCase(sRootItem))
		return FALSE;
	
	m_sHeader = pDoc->GetHeader();
	
	// parse rest of file
	ParseItem(m_xiRoot, &node);
	
	return TRUE;
}
コード例 #17
0
ファイル: Parser.cpp プロジェクト: Romag/LI_EU4_Converter
ItemSet Parse(std::istream& in)
{
  ItemSet items;

  std::string currentItem;
  int openBraces = 0;
  while (!in.eof() && !in.fail())
  {
    std::string currentLine;
    std::getline(in, currentLine);

    auto commentPos = currentLine.find('#');
    if (commentPos != std::string::npos)
      currentLine.erase(commentPos); // remove any comment

    if (!currentItem.empty())
      currentItem.push_back('\n');  // preserve new-lines within an item
    currentItem += currentLine;
    openBraces += std::count(currentLine.begin(), currentLine.end(), '{');
    openBraces -= std::count(currentLine.begin(), currentLine.end(), '}');
    if (openBraces <= 0)
    {
      auto lastCharPos = currentItem.find_last_not_of(" \t");
      if (lastCharPos != std::string::npos && currentItem[lastCharPos] != '=')
      {
        auto parsedItem = ParseItem(currentItem);
        if (parsedItem)
          items.push_back(std::move(parsedItem));
        currentItem.clear();
        openBraces = 0;
      }
    }
  }

  return items;
}
コード例 #18
0
void ItemMover::OnGamePacketRecv(BYTE* packet, bool* block) {
	switch (packet[0])
	{
	case 0x9c:
		{
			// We get this packet after placing an item in a container or on the ground
			if (FirstInit) {
				BYTE action = packet[1];
				unsigned int itemId = *(unsigned int*)&packet[4];
				Lock();
				if (itemId == ActivePacket.itemId) {
					//PrintText(1, "Placed item id %d", itemId);
					ActivePacket.itemId = 0;
					ActivePacket.x = 0;
					ActivePacket.y = 0;
					ActivePacket.startTicks = 0;
					ActivePacket.destination = 0;
				}
				Unlock();
			}

			if ((*BH::MiscToggles2)["Advanced Item Display"].state) {
				bool success = true;
				ItemInfo item = {};
				ParseItem((unsigned char*)packet, &item, &success);
				//PrintText(1, "Item packet: %s, %s, %X, %d, %d", item.name.c_str(), item.code, item.attrs->flags, item.sockets, GetDefense(&item));
				if ((item.action == ITEM_ACTION_NEW_GROUND || item.action == ITEM_ACTION_OLD_GROUND) && success) {
					//PrintText(1, "Item on ground: %s, %s, %s, %X", item.name.c_str(), item.code, item.attrs->category.c_str(), item.attrs->flags);
					for (vector<Rule*>::iterator it = IgnoreRuleList.begin(); it != IgnoreRuleList.end(); it++) {
						if ((*it)->Evaluate(NULL, &item)) {
							*block = true;
							//PrintText(1, "Blocking item: %s, %s, %d", item.name.c_str(), item.code, item.amount);
							break;
						}
					}
				}
			}
			break;
		}
	case 0x9d:
		{
			// We get this packet after picking up an item
			if (FirstInit) {
				BYTE action = packet[1];
				unsigned int itemId = *(unsigned int*)&packet[4];
				Lock();
				if (itemId == ActivePacket.itemId) {
					//PrintText(2, "Picked up item id %d", itemId);
					if (ActivePacket.destination == STORAGE_NULL) {
						PutItemOnGround();
					} else {
						PutItemInContainer();
					}
				}
				Unlock();
			}
			break;
		}
	default:
		break;
	}
	return;
}
コード例 #19
0
int XbelTree::parseTSTITTU(QDomElement* root, unsigned char type)
{
    QDomNode n = root->firstChild();
    GLOBALSTRUCT *ts = new GLOBALSTRUCT;
    int result;
    for(int i=0; i<_mq_maskasize; i++)
        ts->maska[i] = 0;
    while(!n.isNull()) {
        QDomElement e = n.toElement(); // try to convert the node to an element.
        if( (!e.isNull())&&(!e.attribute("name").isNull()) ) {
            QString name = e.attribute("name");
            if( !keywords.contains(name) ) {
                emit(MessageToStatusBar(QString::fromUtf8("не найдено %1").arg(name)));
                Q_ASSERT(0);
            }
            switch(keywords[name]){
            case _address:
                if( (result = ParseItem(&e, "address")) == -1 )
                    Q_ASSERT(0);
                else
                    ts->mbus = result;
                break;
            case _comport:
                if( (result = ParseItem(&e, "comport")) == -1 )
                    Q_ASSERT(0);
                else
                    ts->com = result;
                break;
            case _registers:
                if( (result = ParseItem(&e, "registers")) == -1 )
                    Q_ASSERT(0);
                else
                    ts->regs = result;
                break;
            case _cycle:
                if( (result = ParseItem(&e, "cycle")) == -1 )
                    Q_ASSERT(0);
                else
                    ts->cycle = result;
                break;
            case _proto:
                result = ParseProto(e.attribute("href"));
                if( result == -1 )
                    Q_ASSERT(0);
                else
                    ts->proto = result;
                break;
            case _begin_TU:
                if( (result = ParseItem(&e, "begin_TU")) == -1 )
                    Q_ASSERT(0);
                else
                    ts->begin = result;
                break;
            case _end_TU:
                if( (result = ParseItem(&e, "end_TU")) == -1 )
                    Q_ASSERT(0);
                else
                    ts->end = result;
                break;
            case _maska:
                result = MaskaParse(ts, &e);
                break;
            case _mqpassword:
                result = MQPasswordParse(ts, &e);
                break;
            case _potential: case _current: case _powerA: case _powerQ: case _powerS:
                result = MQMaskaParse(ts, &e);
                break;
            }
        }
        n = n.nextSibling();
    }
    ts->type = type;
    stack.push(ts);
    qDebug() << "TS-TIT" << type;
    return 0;
}
コード例 #20
0
ファイル: bbSlit.cpp プロジェクト: BackupTheBerlios/bblean
//=============================================================================
bool get_style(StyleItem *si, const char *key)
{
    const char *s, *p;
    COLORREF c; int w;
    char fullkey[80], *r;

    memset(si, 0, sizeof *si);
    r = strchr(strcpy(fullkey, key), 0);
    s = stylePath();

    strcpy(r, ".appearance:");
    p = ReadString(s, fullkey, NULL);
    if (p) {
        si->bordered = IsInString(p, "border");
    } else {
        strcpy(r, ":");
        p = ReadString(s, fullkey, NULL);
        if (NULL == p)
            return false;
        si->bordered = true;
    }
    ParseItem(p, si);

    if (B_SOLID != si->type || si->interlaced)
        strcpy(r, ".color1:");
    else
        strcpy(r, ".backgroundColor:");
    c = ReadColor(s, fullkey, NULL);
    if ((COLORREF)-1 == c) {
        strcpy(r, ".color:");
        c = ReadColor(s, fullkey, NULL);
        if ((COLORREF)-1 == c)
            return false;
    }

    si->Color = si->ColorTo = c;
    if (B_SOLID != si->type || si->interlaced) {
        strcpy(r, ".color2:");
        c = ReadColor(s, fullkey, NULL);
        if ((COLORREF)-1 == c) {
            strcpy(r, ".colorTo:");
            c = ReadColor(s, fullkey, NULL);
        }
        if ((COLORREF)-1 != c)
            si->ColorTo = c;
    }

    if (si->bordered) {
        strcpy(r, ".borderColor:");
        c = ReadColor(s, fullkey, NULL);
        if ((COLORREF)-1 != c)
            si->borderColor = c;
        else
            si->borderColor = ReadColor(s, "borderColor:", "black");

        strcpy(r, ".borderWidth:");
        w = ReadInt(s, fullkey, -100);
        if (-100 != w)
            si->borderWidth = w;
        else
            si->borderWidth = ReadInt(s, "borderWidth:", 1);
    }

    strcpy(r, ".marginWidth:");
    w = ReadInt(s, fullkey, -100);
    if (-100 != w)
        si->marginWidth = w;
    else
        si->marginWidth = ReadInt(s, "bevelWidth:", 2);
    return true;
}
コード例 #21
0
ファイル: xmlfileex.cpp プロジェクト: jithuin/infogeezer
BOOL CXmlFileEx::Decrypt(LPCTSTR szPassword)
{
	if (!IsEncrypted())
		return TRUE; // nothing to do
    
	// we don't try to decrypt if no encryption capabilities
	if (!CanEncrypt())
	{
		m_nFileError = XFL_NOENCRYPTIONDLL;
		return FALSE;
	}
	
	// use existing password if required
	if (!szPassword)
		szPassword = m_sPassword;

	CXmlItem* pXI = GetEncryptedBlock();
    
	if (pXI && !pXI->GetSibling())
	{
		// else keep getting password till success or user cancels
		while (TRUE)
		{
			CString sPassword(szPassword);
			
			if (sPassword.IsEmpty())
			{
				CString sExplanation(s_sPasswordExplanation);

				if (sExplanation.Find(_T("%s")) != -1)
					sExplanation.Format(s_sPasswordExplanation, GetFileName());
				
				if (!CPasswordDialog::RetrievePassword(FALSE, sPassword, sExplanation))
				{
					// RB - Set m_nFileError to avoid "The selected task list could not be opened..." message when cancelling
					m_nFileError = XFL_CANCELLED;
					return FALSE;
				}
			}
			
			CString sFile;
			
			if (Decrypt(pXI->GetValue(), sFile, sPassword))
			{
				m_sPassword = sPassword;
				
				sFile.TrimLeft();
				sFile.TrimRight();
				sFile = _T("<ROOT>") + sFile + _T("</ROOT>");
				
				// delete the cdata item
				m_xiRoot.DeleteItem(pXI);
				
				try
				{
					CXmlDocumentWrapper doc;
					
					// reparse decrypted xml
					if (doc.LoadXML(sFile))
					{
						CXmlNodeWrapper node(doc.AsNode());
						
						return ParseItem(m_xiRoot, &node);
					}
				}
				catch (...)
				{
					m_nFileError = XFL_BADMSXML;
				}
				
				return FALSE;
			}
			// RB - Added code to format the error message before calling AfxMessage
			else
			{
				CEnString sMessage(s_sDecryptFailed, GetFileName());

				if (IDNO == AfxMessageBox(sMessage, MB_YESNO))
				{
					m_nFileError = XFL_CANCELLED;
					return FALSE;
				}
				// else user will try again
			}
		}
	}
    
	// else
	m_nFileError = XFL_UNKNOWNENCRYPTION;
	return FALSE;
}
コード例 #22
0
void GetStyleSettings()
{
	// Get the path to the current style file from Blackbox...
	strcpy(stylepath, stylePath());

	// ...and some additional parameters
	bevelWidth = ReadInt(stylepath, "bevelWidth:", 2);
	borderWidth = ReadInt(stylepath, "borderWidth:", 1);

	// Get the applicable color settings from the current style...
	backColor = ReadColor(stylepath, "toolbar.color:", "#000000");
	backColorTo = ReadColor(stylepath, "toolbar.colorTo:", "#FFFFFF");
	
	borderColor = ReadColor(stylepath, "borderColor:", "#000000");

	// ...gradient type, bevel etc. from toolbar:(using a StyleItem)...
	char tempstyle[MAX_LINE_LENGTH];
	strcpy(tempstyle, ReadString(stylepath, "toolbar:", "Flat Gradient Vertical"));
	if (myStyleItem) delete myStyleItem;
	myStyleItem = new StyleItem;
	ParseItem(tempstyle, myStyleItem);

	
	
 if(StrStrI(windowStyle, "label") != NULL  && strlen(windowStyle) < 6)
	{
		// ...gradient type, bevel etc. from toolbar.label:(using a StyleItem)...
		char tempstyle2[MAX_LINE_LENGTH];
		strcpy(tempstyle2, ReadString(stylepath, "toolbar.label:", "parentrelative"));
		if (!IsInString("", tempstyle2)&&!IsInString(tempstyle2, "parentrelative"))
		{
			if (myStyleItem2) delete myStyleItem2;	//if everything is found in toolbar.label: then make a new StyleItem
			myStyleItem2 = new StyleItem;			
			ParseItem(tempstyle2, myStyleItem2);
			
			if (!IsInString("", ReadString(stylepath, "toolbar.label.color:", "")))
				backColor2 = ReadColor(stylepath, "toolbar.label.color:", "#000000");
			else
    			backColor2 = ReadColor(stylepath, "toolbar.color:", "#FFFFFF");

			if (!IsInString("", ReadString(stylepath, "toolbar.label.colorTo:", "")))
				backColorTo2 = ReadColor(stylepath, "toolbar.label.colorTo:", "#000000");
			else
				backColorTo2 = ReadColor(stylepath, "toolbar.colorTo:", "#000000");
			
			fontColor = ReadColor(stylepath, "toolbar.label.textColor:", "#FFFFFF");
		}
		else
		{
			if (myStyleItem2) delete myStyleItem2;	//else use the the toolbar: settings
			myStyleItem2 = new StyleItem;
			ParseItem(tempstyle, myStyleItem2);	//use original tempstyle if "parentrelative"
			backColor2 = backColor;			//have to do this if parent relative found, it seems bb4win uses
			backColorTo2 = backColorTo;		//the toolbar.color if parent relative is found for toolbar.label
			fontColor = ReadColor(stylepath, "toolbar.textColor:", "#FFFFFF");
		}
	} 
	else if(StrStrI(windowStyle, "windowlabel") != NULL)
	{
		// ...gradient type, bevel etc. from toolbar.windowLabel:(using a StyleItem)...
		char tempstyle2[MAX_LINE_LENGTH];
		strcpy(tempstyle2, ReadString(stylepath, "toolbar.windowLabel:", "parentrelative"));
		if (!IsInString("", tempstyle2)&&!IsInString(tempstyle2, "parentrelative"))
		{
			if (myStyleItem2) delete myStyleItem2;	//if everything is found in toolbar.windowLabel: then make a new StyleItem
			myStyleItem2 = new StyleItem;			
			ParseItem(tempstyle2, myStyleItem2);
			
			if (!IsInString("", ReadString(stylepath, "toolbar.windowLabel.color:", "")))
				backColor2 = ReadColor(stylepath, "toolbar.windowLabel.color:", "#000000");
			else
    			backColor2 = ReadColor(stylepath, "toolbar.color:", "#FFFFFF");

			if (!IsInString("", ReadString(stylepath, "toolbar.windowLabel.colorTo:", "")))
				backColorTo2 = ReadColor(stylepath, "toolbar.windowLabel.colorTo:", "#000000");
			else
				backColorTo2 = ReadColor(stylepath, "toolbar.colorTo:", "#000000");
			
			fontColor = ReadColor(stylepath, "toolbar.windowLabel.textColor:", "#FFFFFF");
		}
	}
	else if(StrStrI(windowStyle, "toolbar") != NULL)
	{
		if (myStyleItem2) delete myStyleItem2;	//else use the the toolbar: settings
			myStyleItem2 = new StyleItem;
			ParseItem(tempstyle, myStyleItem2);	//use original tempstyle if "parentrelative"
			backColor2 = ReadColor(stylepath, "toolbar.color:", "#FFFFFF");		//have to do this if parent relative found, it seems bb4win uses
			backColorTo2 = ReadColor(stylepath, "toolbar.colorTo:", "#000000");	//the toolbar.color if parent relative is found for toolbar.windowLabel
			fontColor = ReadColor(stylepath, "toolbar.textColor:", "#FFFFFF");
	}
		else if(StrStrI(windowStyle, "buttonpr") != NULL)
	{
		// ...gradient type, bevel etc. from toolbar.windowLabel:(using a StyleItem)...
		char tempstyle2[MAX_LINE_LENGTH];
		strcpy(tempstyle2, ReadString(stylepath, "toolbar.button.pressed:", "parentrelative"));
		if (!IsInString("", tempstyle2)&&!IsInString(tempstyle2, "parentrelative"))
		{
			if (myStyleItem2) delete myStyleItem2;	//if everything is found in toolbar.windowLabel: then make a new StyleItem
			myStyleItem2 = new StyleItem;			
			ParseItem(tempstyle2, myStyleItem2);
			
			if (!IsInString("", ReadString(stylepath, "toolbar.button.pressed.color:", "")))
				backColor2 = ReadColor(stylepath, "toolbar.button.pressed.color:", "#000000");
			else
    			backColor2 = ReadColor(stylepath, "toolbar.color:", "#FFFFFF");

			if (!IsInString("", ReadString(stylepath, "toolbar.button.pressed.colorTo:", "")))
				backColorTo2 = ReadColor(stylepath, "toolbar.button.pressed.colorTo:", "#000000");
			else
				backColorTo2 = ReadColor(stylepath, "toolbar.colorTo:", "#000000");
			
			fontColor = ReadColor(stylepath, "toolbar.button.pressed.picColor:", "#FFFFFF");
		}
		else
		{
			if (myStyleItem2) delete myStyleItem2;	//else use the the toolbar: settings
			myStyleItem2 = new StyleItem;
			ParseItem(tempstyle, myStyleItem2);	//use original tempstyle if "parentrelative"
			backColor2 = backColor;			//have to do this if parent relative found, it seems bb4win uses
			backColorTo2 = backColorTo;		//the toolbar.color if parent relative is found for toolbar.clock
			fontColor = ReadColor(stylepath, "toolbar.textColor:", "#FFFFFF");
		}
	}
	else if(StrStrI(windowStyle, "buttonnp") != NULL)
	{
		// ...gradient type, bevel etc. from toolbar.windowLabel:(using a StyleItem)...
		char tempstyle2[MAX_LINE_LENGTH];
		strcpy(tempstyle2, ReadString(stylepath, "toolbar.button:", "parentrelative"));
		if (!IsInString("", tempstyle2)&&!IsInString(tempstyle2, "parentrelative"))
		{
			if (myStyleItem2) delete myStyleItem2;	//if everything is found in toolbar.windowLabel: then make a new StyleItem
			myStyleItem2 = new StyleItem;			
			ParseItem(tempstyle2, myStyleItem2);
			
			if (!IsInString("", ReadString(stylepath, "toolbar.button.color:", "")))
				backColor2 = ReadColor(stylepath, "toolbar.button.color:", "#000000");
			else
    			backColor2 = ReadColor(stylepath, "toolbar.color:", "#FFFFFF");

			if (!IsInString("", ReadString(stylepath, "toolbar.button.colorTo:", "")))
				backColorTo2 = ReadColor(stylepath, "toolbar.button.colorTo:", "#000000");
			else
				backColorTo2 = ReadColor(stylepath, "toolbar.colorTo:", "#000000");
			
			fontColor = ReadColor(stylepath, "toolbar.button.picColor:", "#FFFFFF");
		}
		else
		{
			if (myStyleItem2) delete myStyleItem2;	//else use the the toolbar: settings
			myStyleItem2 = new StyleItem;
			ParseItem(tempstyle, myStyleItem2);	//use original tempstyle if "parentrelative"
			backColor2 = backColor;			//have to do this if parent relative found, it seems bb4win uses
			backColorTo2 = backColorTo;		//the toolbar.color if parent relative is found for toolbar.clock
			fontColor = ReadColor(stylepath, "toolbar.textColor:", "#FFFFFF");
		}
	}
	else
	{
		// ...gradient type, bevel etc. from toolbar.clock:(using a StyleItem)...
		char tempstyle2[MAX_LINE_LENGTH];
		strcpy(tempstyle2, ReadString(stylepath, "toolbar.clock:", "parentrelative"));
		if (!IsInString("", tempstyle2)&&!IsInString(tempstyle2, "parentrelative"))
		{
			if (myStyleItem2) delete myStyleItem2;	//if everything is found in toolbar.clock: then make a new StyleItem
			myStyleItem2 = new StyleItem;			
			ParseItem(tempstyle2, myStyleItem2);
			
			if (!IsInString("", ReadString(stylepath, "toolbar.clock.color:", "")))
				backColor2 = ReadColor(stylepath, "toolbar.clock.color:", "#000000");
			else
    			backColor2 = ReadColor(stylepath, "toolbar.color:", "#FFFFFF");

			if (!IsInString("", ReadString(stylepath, "toolbar.clock.colorTo:", "")))
				backColorTo2 = ReadColor(stylepath, "toolbar.clock.colorTo:", "#000000");
			else
				backColorTo2 = ReadColor(stylepath, "toolbar.colorTo:", "#000000");
			
			fontColor = ReadColor(stylepath, "toolbar.clock.textColor:", "#FFFFFF");
		}
		else
		{
			if (myStyleItem2) delete myStyleItem2;	//else use the the toolbar: settings
			myStyleItem2 = new StyleItem;
			ParseItem(tempstyle, myStyleItem2);	//use original tempstyle if "parentrelative"
			backColor2 = backColor;			//have to do this if parent relative found, it seems bb4win uses
			backColorTo2 = backColorTo;		//the toolbar.color if parent relative is found for toolbar.clock
			fontColor = ReadColor(stylepath, "toolbar.textColor:", "#FFFFFF");
		}
	}

	// ...font settings...
	strcpy(fontFace, ReadString(stylepath, "toolbar.font:", ""));
	if (!_stricmp(fontFace, "")) strcpy(fontFace, ReadString(stylepath, "*font:", "Tahoma"));
	
}
コード例 #23
0
ファイル: Level.cpp プロジェクト: realn/exptor3D
const bool	CLevel::LoadItemList( std::fstream& stream )
{
	Log.Log( "GLEVEL( " + file + " ): £adowanie listy przedmiotów.");

	std::string str;
	std::vector<std::string> params;
	ITEM_TYPE type;
	int x, y;

	while( stream )
	{
		str = GetLine( stream );

		if( str == "END ITEMLIST" )
			return true;

		str = ClearWhiteSpace( str );	

		params.clear();
		if( ParseItem( str, x, y, type, params ) )
		{
			CItem* item = nullptr;
			switch (type)
			{
				break;
			case ITEM_TYPE::AMMO:
				item = new CItemAmmo( ParseWeapon( params[0] ) , StrToUInt( params[1] ) );
				break;

			case ITEM_TYPE::HEALTH:
				item = new CItemHealth( StrToFloat( params[0] ) );
				break;

			case ITEM_TYPE::ARMOR:
				item = new CItemArmor( StrToFloat( params[0] ) );
				break;

			case ITEM_TYPE::WEAPON:
				item = new CItemWeapon( ParseWeapon( params[0] ), StrToUInt( params[1] ) );
				break;

			case ITEM_TYPE::UNKNOWN:
			default:
				Log.Error("GLEVEL( " + file + " ): B³¹d parsowania przedmiotu, nieznany typ z parsowania ci¹gu: " + str + ".");
				break;
			}

			if(item != nullptr)
			{
				item->Pos = GetBlockPos( x, y );
				AddEntity( item );
				Items.push_back( item );
			}
		}
		else
		{
			Log.Error("GLEVEL( " + file + " ): B³¹d parsowania przedmiotu dla ci¹gu: " + str + ".");
		}
	}

	Log.Error( "GLEVEL( " + file + " ): Brak koñca listy przedmiotów!" );
	return false;
}
コード例 #24
0
ファイル: ContentParser.cpp プロジェクト: Bia10/clrn
bool CContentParser::ParseSite(const std::string& sURL, boost::property_tree::ptree& xmlResult)
{
    bool bNotEmpty = false;
    xmlResult.clear();
    boost::property_tree::ptree& xmlRoot = xmlResult.put("data", "");

    std::size_t nPageCount = 1;
    std::size_t nEmptyPages = 0;
    while(1)
    {
        try
        {
            const std::string sPage = (boost::format(sURL) % nPageCount++).str();

            std::cout << (boost::format("Processing page: [%s]...") % sPage).str();

            CDownloader Dwnldr;
            Dwnldr.Open(sPage);

            std::string sBuffer;
            Dwnldr.Read(sBuffer);

            const std::string::size_type encoding = sBuffer.find("charset=");
            if (encoding != std::string::npos)
            {
                const std::string::size_type encodingEnd = sBuffer.find("\"", encoding);
                if (encodingEnd != std::string::npos)
                {
                    const std::string encodingValue(sBuffer.substr(encoding + 8, encodingEnd - encoding - 8));

                    if (boost::algorithm::iequals(encodingValue, "utf-8"))
                    {
                        const std::wstring out = boost::locale::conv::utf_to_utf<wchar_t, char>(sBuffer);
                        sBuffer = boost::locale::conv::from_utf<wchar_t>(out, "cp1251");
                    }
                }
            }

            std::vector< std::string > vecItems;
            ParsePage(sBuffer, vecItems);

            std::cout << (boost::format("\titems parsed: [%s]") % vecItems.size()).str() << std::endl;

            if (vecItems.empty())
                ++nEmptyPages;
            else
                nEmptyPages = 0;

            if (nEmptyPages > 5)
                break;

            bNotEmpty = true;

            std::vector< std::string >::iterator it = vecItems.begin();
            const std::vector< std::string >::iterator itEnd = vecItems.end();

            BOOST_FOREACH(std::string& sCurrent, vecItems)
            {
                xmlRoot.push_back(std::pair< std::string, boost::property_tree::ptree > ("item", boost::property_tree::ptree()));
                boost::property_tree::ptree& xmlItem = xmlRoot.back().second;
                ParseItem(sCurrent, xmlItem);
            }
        }
        catch (std::exception& e)
        {
            std::cout << e.what() << std::endl;
        }
    }
    return bNotEmpty;
}
コード例 #25
0
ファイル: BrewingRecipes.cpp プロジェクト: 1285done/cuberite
void cBrewingRecipes::AddRecipeFromLine(const AString & a_Line, unsigned int a_LineNum)
{
	AString Line(a_Line);
	Line.erase(std::remove_if(Line.begin(), Line.end(), isspace), Line.end());

	short InputDamage;
	short OutputDamage;

	std::unique_ptr<cItem> InputItem = cpp14::make_unique<cItem>();
	std::unique_ptr<cItem> IngredientItem = cpp14::make_unique<cItem>();
	std::unique_ptr<cItem> OutputItem = cpp14::make_unique<cItem>();

	const AStringVector & InputAndIngredient = StringSplit(Line, "+");

	if (InputAndIngredient.size() != 2)
	{
		LOGWARNING("brewing.txt: line %d: A line with '+' was expected", a_LineNum);
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	const AStringVector & IngredientAndOutput = StringSplit(InputAndIngredient[1].c_str(), "=");
	if (IngredientAndOutput.size() != 2)
	{
		LOGWARNING("brewing.txt: line %d: A line with '=' was expected", a_LineNum);
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	if (!ParseItem(IngredientAndOutput[0], *IngredientItem))
	{
		LOGWARNING("brewing.txt: Parsing of the item didn't worked.");
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	if (!StringToInteger<short>(InputAndIngredient[0], InputDamage))
	{
		LOGWARNING("brewing.txt: line %d: Cannot parse the damage value for the input item\"%s\".", a_LineNum, InputAndIngredient[0].c_str());
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	if (!StringToInteger<short>(IngredientAndOutput[1], OutputDamage))
	{
		LOGWARNING("brewing.txt: line %d: Cannot parse the damage value for the output item\"%s\".", a_LineNum, IngredientAndOutput[1].c_str());
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	// The items has always the same type
	InputItem->m_ItemType = E_ITEM_POTION;
	InputItem->m_ItemDamage = InputDamage;

	OutputItem->m_ItemType = E_ITEM_POTION;
	OutputItem->m_ItemDamage = OutputDamage;

	std::unique_ptr<cRecipe> Recipe = cpp14::make_unique<cRecipe>();
	Recipe->Input = std::move(InputItem);
	Recipe->Output = std::move(OutputItem);
	Recipe->Ingredient = std::move(IngredientItem);
	m_pState->Recipes.push_back(std::move(Recipe));
}
コード例 #26
0
	void XmlSettingsDialog::ParseEntity (const QDomElement& entity, QWidget *baseWidget)
	{
		QDomElement item = entity.firstChildElement ("item");
		while (!item.isNull ())
		{
			ParseItem (item, baseWidget);
			item = item.nextSiblingElement ("item");
		}

		auto gbox = entity.firstChildElement ("groupbox");
		while (!gbox.isNull ())
		{
			const auto box = new QGroupBox (GetLabel (gbox));
			box->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Preferred);
			const auto groupLayout = new QGridLayout ();
			groupLayout->setContentsMargins (2, 2, 2, 2);
			box->setLayout (groupLayout);

			ParseEntity (gbox, box);

			const auto lay = qobject_cast<QGridLayout*> (baseWidget->layout ());
			lay->addWidget (box, lay->rowCount (), 0, 1, 2);

			gbox = gbox.nextSiblingElement ("groupbox");
		}

		auto scroll = entity.firstChildElement ("scrollarea");
		while (!scroll.isNull ())
		{
			const auto area = new QScrollArea ();
			if (scroll.hasAttribute ("horizontalScroll"))
			{
				const auto& attr = scroll.attribute ("horizontalScroll");
				if (attr == "on")
					area->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
				else if (attr == "off")
					area->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
			}
			if (scroll.hasAttribute ("verticalScroll"))
			{
				const auto& attr = scroll.attribute ("verticalScroll");
				if (attr == "on")
					area->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
				else if (attr == "off")
					area->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
			}

			area->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);

			const auto areaWidget = new QFrame;
			areaWidget->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
			const auto areaLayout = new QGridLayout;
			areaWidget->setLayout (areaLayout);
			ParseEntity (scroll, areaWidget);
			area->setWidget (areaWidget);
			area->setWidgetResizable (true);
			areaWidget->show ();

			const auto lay = qobject_cast<QGridLayout*> (baseWidget->layout ());
			const auto thisRow = lay->rowCount ();
			lay->addWidget (area, thisRow, 0, 1, 2);
			lay->setRowStretch (thisRow, 1);

			scroll = scroll.nextSiblingElement ("scrollarea");
		}

		auto tab = entity.firstChildElement ("tab");
		if (!tab.isNull ())
		{
			const auto tabs = new QTabWidget;
			const auto lay = qobject_cast<QGridLayout*> (baseWidget->layout ());
			lay->addWidget (tabs, lay->rowCount (), 0, 1, 2);
			while (!tab.isNull ())
			{
				const auto page = new QWidget;
				const auto widgetLay = new QGridLayout;
				widgetLay->setContentsMargins (0, 0, 0, 0);
				page->setLayout (widgetLay);
				tabs->addTab (page, GetLabel (tab));
				ParseEntity (tab, page);
				tab = tab.nextSiblingElement ("tab");

				widgetLay->addItem (new QSpacerItem (0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding),
						widgetLay->rowCount (), 0, 1, 1);
			}
		}
	}
コード例 #27
0
/*
================
sdDeclRadialMenu::Parse
================
*/
bool sdDeclRadialMenu::Parse( const char *text, const int textLength ) {
	idToken token;
	idParser src;

	src.SetFlags( DECL_LEXER_FLAGS );
//	src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
//	src.AddIncludes( GetFileLevelIncludeDependencies() );
	//sdDeclParseHelper declHelper( this, text, textLength, src );
	sdDeclParseHelper declHelper( this, text, textLength, src );

	src.SkipUntilString( "{", &token );

	bool hadError = false;

	while( true ) {
		if( !src.ReadToken( &token )) {
			src.Error( "sdDeclRadialMenu::Parse: unexpected end of file." );
			hadError = true;
			break;
		}
		if( !token.Cmp( "}" )) {
			break;
		}

		if( !token.Icmp( "keys" )) {
			if( !ParseKeys( src, keys )) {
				src.Error( "sdDeclRadialMenu::Parse: failed to parse keys" );
				hadError = true;
				break;
			}
			continue;
		}

		if( !token.Icmp( "title" )) {
			if( !src.ReadToken( &token )) {
				src.Error( "sdDeclRadialMenu::Parse: failed to title" );
				hadError = true;
				break;
			}
			title = declHolder.FindLocStr( token.c_str() );
			continue;
		}

		if( !token.Icmp( "page" )) {
			if( !ParsePage( src )) {
				src.Error( "sdDeclRadialMenu::Parse: failed to parse page" );
				hadError = true;
				break;
			}
			continue;
		}
		if( !token.Icmp( "item" )) {
			if( !ParseItem( src )) {
				src.Error( "sdDeclRadialMenu::Parse: failed to parse item" );
				hadError = true;
				break;
			}
			continue;
		}
	}
	
	return !hadError;
}
コード例 #28
0
ファイル: CraftingRecipes.cpp プロジェクト: DjKiDD/MCServer
void cCraftingRecipes::AddRecipeLine(int a_LineNum, const AString & a_RecipeLine)
{
	// Remove any spaces within the line:
	AString RecipeLine(a_RecipeLine);
	RecipeLine.erase(std::remove_if(RecipeLine.begin(), RecipeLine.end(), isspace), RecipeLine.end());

	AStringVector Sides = StringSplit(RecipeLine, "=");
	if (Sides.size() != 2)
	{
		LOGWARNING("crafting.txt: line %d: A single '=' was expected, got %d", a_LineNum, (int)Sides.size() - 1);
		LOGINFO("Offending line: \"%s\"", a_RecipeLine.c_str());
		return;
	}
	
	std::unique_ptr<cCraftingRecipes::cRecipe> Recipe(new cCraftingRecipes::cRecipe);
	
	// Parse the result:
	AStringVector ResultSplit = StringSplit(Sides[0], ",");
	if (ResultSplit.empty())
	{
		LOGWARNING("crafting.txt: line %d: Result is empty, ignoring the recipe.", a_LineNum);
		LOGINFO("Offending line: \"%s\"", a_RecipeLine.c_str());
		return;
	}
	if (!ParseItem(ResultSplit[0], Recipe->m_Result))
	{
		LOGWARNING("crafting.txt: line %d: Cannot parse result item, ignoring the recipe.", a_LineNum);
		LOGINFO("Offending line: \"%s\"", a_RecipeLine.c_str());
		return;
	}
	if (ResultSplit.size() > 1)
	{
		if (!StringToInteger<char>(ResultSplit[1].c_str(), Recipe->m_Result.m_ItemCount))
		{
			LOGWARNING("crafting.txt: line %d: Cannot parse result count, ignoring the recipe.", a_LineNum);
			LOGINFO("Offending line: \"%s\"", a_RecipeLine.c_str());
			return;
		}
	}
	else
	{
		Recipe->m_Result.m_ItemCount = 1;
	}
	
	// Parse each ingredient:
	AStringVector Ingredients = StringSplit(Sides[1], "|");
	int Num = 1;
	for (AStringVector::const_iterator itr = Ingredients.begin(); itr != Ingredients.end(); ++itr, ++Num)
	{
		if (!ParseIngredient(*itr, Recipe.get()))
		{
			LOGWARNING("crafting.txt: line %d: Cannot parse ingredient #%d, ignoring the recipe.", a_LineNum, Num);
			LOGINFO("Offending line: \"%s\"", a_RecipeLine.c_str());
			return;
		}
	}  // for itr - Ingredients[]
	
	NormalizeIngredients(Recipe.get());
	
	m_Recipes.push_back(Recipe.release());
}
コード例 #29
0
ファイル: CraftingRecipes.cpp プロジェクト: DjKiDD/MCServer
bool cCraftingRecipes::ParseIngredient(const AString & a_String, cRecipe * a_Recipe)
{
	// a_String is in this format: "ItemType^damage, X:Y, X:Y, X:Y..."
	AStringVector Split = StringSplit(a_String, ",");
	if (Split.size() < 2)
	{
		// Not enough split items
		return false;
	}
	cItem Item;
	if (!ParseItem(Split[0], Item))
	{
		return false;
	}
	Item.m_ItemCount = 1;
	
	cCraftingRecipes::cRecipeSlots TempSlots;
	for (AStringVector::const_iterator itr = Split.begin() + 1; itr != Split.end(); ++itr)
	{
		// Parse the coords in the split item:
		AStringVector Coords = StringSplit(*itr, ":");
		if ((Coords.size() == 1) && (TrimString(Coords[0]) == "*"))
		{
			cCraftingRecipes::cRecipeSlot Slot;
			Slot.m_Item = Item;
			Slot.x = -1;
			Slot.y = -1;
			TempSlots.push_back(Slot);
			continue;
		}
		if (Coords.size() != 2)
		{
			return false;
		}
		Coords[0] = TrimString(Coords[0]);
		Coords[1] = TrimString(Coords[1]);
		if (Coords[0].empty() || Coords[1].empty())
		{
			return false;
		}
		cCraftingRecipes::cRecipeSlot Slot;
		Slot.m_Item = Item;
		switch (Coords[0][0])
		{
			case '1': Slot.x = 0;  break;
			case '2': Slot.x = 1;  break;
			case '3': Slot.x = 2;  break;
			case '*': Slot.x = -1; break;
			default:
			{
				return false;
			}
		}
		switch (Coords[1][0])
		{
			case '1': Slot.y = 0;  break;
			case '2': Slot.y = 1;  break;
			case '3': Slot.y = 2;  break;
			case '*': Slot.y = -1; break;
			default:
			{
				return false;
			}
		}
		TempSlots.push_back(Slot);
	}  // for itr - Split[]
	
	// Append the ingredients:
	a_Recipe->m_Ingredients.insert(a_Recipe->m_Ingredients.end(), TempSlots.begin(), TempSlots.end());
	return true;
}
コード例 #30
0
bool CCMatchBuffDescMgr::ReadXml(CCZFileSystem* pFileSystem, const char* szFileName)
{
	CCXmlDocument xmlIniData;
	xmlIniData.Create();

	char *buffer;
	CCZFile mzf;

	if(pFileSystem) 
	{
		if(!mzf.Open(szFileName,pFileSystem)) 
		{
			if(!mzf.Open(szFileName)) 
			{
				xmlIniData.Destroy();
				return false;
			}
		}
	} 
	else 
	{
		if(!mzf.Open(szFileName))
		{
			xmlIniData.Destroy();
			return false;
		}
	}

	buffer = new char[mzf.GetLength()+1];
	buffer[mzf.GetLength()] = 0;
	memset( buffer, 0, mzf.GetLength()+1 );

	mzf.Read(buffer,mzf.GetLength());

	m_nChecksum = CCGetMemoryChecksum(buffer,mzf.GetLength());

	if(!xmlIniData.LoadFromMemory(buffer))
	{
		m_nChecksum = 0;
		xmlIniData.Destroy();
		return false;
	}
	delete[] buffer;
	mzf.Close();

	//	<------------------


	CCXmlElement rootElement, chrElement, attrElement;
	char szTagName[256];

	rootElement = xmlIniData.GetDocumentElement();
	int iCount = rootElement.GetChildNodeCount();

	for (int i = 0; i < iCount; i++)
	{
		chrElement = rootElement.GetChildNode(i);
		chrElement.GetTagName(szTagName);
		if (szTagName[0] == '#') continue;

		if (!stricmp(szTagName, MICTOK_BUFF))
		{
			if( !ParseItem(chrElement) ) {
				Clear();
				return false;
			}
		}
	}

	xmlIniData.Destroy();
	return true;
}