Esempio n. 1
0
//-----------------------------------------------------------------------------
void ConsoleServer::process_script(TCPSocket /*client*/, const char* msg)
{
	JSONParser parser(msg);
	JSONElement root = parser.root();

	DynamicString script;
	root.key("script").to_string(script);
	device()->lua_environment()->execute_string(script.c_str());
}
Esempio n. 2
0
	static void parse_uniforms(JSONElement root, Array<UniformData>& uniforms, Array<char>& names, Array<char>& dynamic)
	{
		using namespace vector;

		Vector<DynamicString> keys(default_allocator());
		root.key("uniforms").to_keys(keys);

		for (uint32_t i = 0; i < size(keys); i++)
		{
			UniformHandle uh;
			uh.uniform_handle = 0;

			DynamicString type = root.key("uniforms").key(keys[i].c_str()).key("type").to_string();

			UniformData ud;
			ud.name_offset = array::size(names); array::push(names, keys[i].c_str(), keys[i].length()); array::push_back(names, '\0');
			ud.type = string_to_uniform_type(type.c_str());
			ud.data_offset = reserve_dynamic_data(uh, dynamic);

			switch (ud.type)
			{
				case UniformType::FLOAT:
				{
					float data = root.key("uniforms").key(keys[i].c_str()).key("value").to_float();
					reserve_dynamic_data(data, dynamic);
					break;
				}
				case UniformType::VECTOR2:
				{
					Vector2 data = root.key("uniforms").key(keys[i].c_str()).key("value").to_vector2();
					reserve_dynamic_data(data, dynamic);
					break;
				}
				case UniformType::VECTOR3:
				{
					Vector3 data = root.key("uniforms").key(keys[i].c_str()).key("value").to_vector3();
					reserve_dynamic_data(data, dynamic);
					break;
				}
				case UniformType::VECTOR4:
				{
					Vector4 data = root.key("uniforms").key(keys[i].c_str()).key("value").to_vector4();
					reserve_dynamic_data(data, dynamic);
					break;
				}
				default: CE_FATAL("Oops"); break;
			}

			array::push_back(uniforms, ud);
		}
	}
Esempio n. 3
0
int main()
{
    DynamicString ds = "what the f**k", ds1;
    cout << ds << endl;
    cout << ds.size() << endl;
    cout << ds.find("the") << endl;
    cout << (ds.find("the") == DynamicString::npos ? "not found" : "found") << endl;
    cout << (ds.find("them") == DynamicString::npos ? "not found" : "found") << endl;
    getline(cin, ds1);
    cout << ds1 << endl;
    cout << ds1.empty() << endl;

	return 0;
}
Esempio n. 4
0
	void read_line(DynamicString& line)
	{
		const char* s  = &_str[_pos];
		const char* nl = strnl(s);
		_pos += u32(nl - s);
		line.set(s, nl - s);
	}
Esempio n. 5
0
//--------------------------------------------------------------------------
uint32_t JSONElement::size() const
{
	if (m_at == NULL)
	{
		return 0;
	}

	switch(json::type(m_at))
	{
		case JSONType::NIL:
		{
			return 1;
		}
		case JSONType::OBJECT:
		{
			Map<DynamicString, const char*> object(default_allocator());
			json::parse_object(m_at, object);
			return map::size(object);
		}
		case JSONType::ARRAY:
		{
			Array<const char*> array(default_allocator());
			json::parse_array(m_at, array);
			return array::size(array);
		}
		case JSONType::STRING:
		{
			DynamicString string;
			json::parse_string(m_at, string);
			return string.length();
		}
		case JSONType::NUMBER:
		{
			return 1;
		}
		case JSONType::BOOL:
		{
			return 1;
		}
		default:
		{
			CE_FATAL("Oops, unknown value type");
			return 0;
		}
	}
}
Esempio n. 6
0
	void join(const char* path_a, const char* path_b, DynamicString& path)
	{
		CE_ENSURE(NULL != path_a);
		CE_ENSURE(NULL != path_b);
		const u32 la = strlen32(path_a);
		const u32 lb = strlen32(path_b);
		path.reserve(la + lb + 1);
		path += path_a;
		path += PATH_SEPARATOR;
		path += path_b;
	}
Esempio n. 7
0
char * DfnChip::buildChip(int pId){
  DynamicString *ds;
  PcbGroup *pg1;
  PcbGroup *pg2;
  BoxDef bd;
  char *tmp;
    
  pg1 = new PcbGroup(2, HORZ);
  pg2 = new PcbGroup(2, N_HORZ);

  ds = new DynamicString();

  ds->append("Element[0x00000000 \"%s\" \"$1\" \"\" 10000 10000 -3150 -3150 0 100 \"\"](\n", mTab[pId].cid);  
  pg1->setXYDim(mTab[pId].y, mTab[pId].x);
  pg1->setESpace(mTab[pId].e);
  pg1->center();
  pg2->setXYDim(mTab[pId].y, mTab[pId].x);
  pg2->setESpace(mTab[pId].e);
  pg2->center();
  pg1->move(0, mTab[pId].c / 2);
  pg2->move(0, -(mTab[pId].c / 2));
  pg2->setOffset(2);
  pg1->generatePads(ds);
  pg2->generatePads(ds);

  bd.x2 = ((mTab[pId].e + mTab[pId].x)/2) + 2.0;
  bd.x1 = -bd.x2;
  bd.y2 = (mTab[pId].g / 2) + 2.0;
  bd.y1 = -bd.y2;
  bd.bm = NO_MARK;
  pg1->generateBox(ds, &bd);
  ds->append(")\n");

  tmp = ds->str();
  
  delete pg1;
  delete pg2;
  delete ds;
  return tmp;
}
Esempio n. 8
0
	void toString(const Guid& guid, DynamicString& s)
	{
		char str[36+1];
		snPrintF(str, sizeof(str), "%.8x-%.4x-%.4x-%.4x-%.4x%.8x"
			, guid.data1
			, guid.data2
			, guid.data3
			, (uint16_t)((guid.data4 & 0xffff000000000000u) >> 48)
			, (uint16_t)((guid.data4 & 0x0000ffff00000000u) >> 32)
			, (uint32_t)((guid.data4 & 0x00000000ffffffffu) >>  0)
			);
		s.set(str, sizeof(str)-1);
	}
Esempio n. 9
0
bool LocalizableStringManager::ProduceLanguageFile( const BazisLib::String &fp )
{
	File file(fp, FileModes::CreateOrTruncateRW);
	if (!file.Valid())
	{
		_tprintf(_T("ERROR: cannot open %s for writing\n"), fp.c_str());
		return false;
	}
#ifdef UNICODE
	unsigned short unicodeHeader = 0xFEFF;
	file.Write(&unicodeHeader, sizeof(unicodeHeader));
#endif
	//1033 == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)
	file.WriteLine(DynamicString(_T("; Generated by BazisLib STRGEN.EXE, http://bazislib.sysprogs.org/\r\n; Syntax: <ID> <spaces or tabs> <value>\r\n; <value> should be in C/C++ format (\\r, \\n, \\t, \\\", etc.) \r\n; Strings starting with '; ' will be ignored\r\n; WARNING! This file should always be UNICODE!\r\n")));
	file.WriteLine(DynamicString(_T("[settings]\r\nLanguage       English\r\nLANGID         1033\r\nLanguageEng    English\r\nTranslator     SysProgs\r\nE-Mail         [email protected]\r\n"))); 
	file.WriteLine(DynamicString(_T("[strings]"))); 

	unsigned maxIdLen = 0;

	for each(const std::map<BazisLib::String, StringRecord>::value_type &pair in m_Strings)
		if (pair.first.length() > maxIdLen)
			maxIdLen = pair.first.length();

	DynamicString definitionLine;
	DynamicString maxSpacing;
	maxSpacing.insert(0, maxIdLen, ' ');

	for each(const std::map<BazisLib::String, StringRecord>::value_type &pair in m_Strings)
	{
		const TCHAR *pSpacing = maxSpacing.c_str() + pair.first.length();
		definitionLine.Format(_T("%s%s   %s"), pair.first.c_str(), pSpacing, pair.second.Value.c_str());
		file.WriteLine(definitionLine);
	}

	return true;
}
Esempio n. 10
0
char * QfpChip::buildChip(int pId){
  DynamicString *ds;
  PcbGroup *pg1;
  PcbGroup *pg2;
  PcbGroup *pg3;
  PcbGroup *pg4;
  BoxDef bd;
  char *tmp;
  int pincnt;
  int e;
  
  e = (int)(mTab[pId].e * 100);
  pincnt = (int)(mTab[pId].d * 100);
  pincnt = pincnt / e;
  pincnt++;

  pg1 = new PcbGroup(pincnt, N_HORZ);
  pg2 = new PcbGroup(pincnt, HORZ);
  pg3 = new PcbGroup(pincnt, N_VERT);
  pg4 = new PcbGroup(pincnt, VERT);

  ds = new DynamicString();

  ds->append("Element[0x00000000 \"%s\" \"$1\" \"\" 10000 10000 -3150 -3150 0 100 \"\"](\n", mTab[pId].cid);  

  pg1->setXYDim(mTab[pId].y, mTab[pId].x);
  pg1->setESpace(mTab[pId].e);
  pg1->center();
  pg1->move(0, mTab[pId].c / 2);
  pg1->setOffset(pincnt*2);  
  pg1->generatePads(ds);
  

  pg2->setXYDim(mTab[pId].y, mTab[pId].x);
  pg2->setESpace(mTab[pId].e);
  pg2->center();
  pg2->move(0, -(mTab[pId].c / 2));
  pg2->generatePads(ds);


  pg3->setXYDim(mTab[pId].y, mTab[pId].x);
  pg3->setESpace(mTab[pId].e);
  pg3->center();
  pg3->move(-(mTab[pId].c / 2), 0);
  pg3->setOffset(pincnt*3);
  pg3->generatePads(ds);


  pg4->setXYDim(mTab[pId].y, mTab[pId].x);
  pg4->setESpace(mTab[pId].e); 
  pg4->center();
  pg4->move(mTab[pId].c / 2,0);
  pg4->setOffset(pincnt);
  pg4->generatePads(ds);
  bd.x2 = (mTab[pId].g / 2) - 0.5;
  bd.x1 = -bd.x2;
  bd.y2 = bd.x2;
  bd.y1 = bd.x1;
  bd.bm = TOP_LEFT;
  pg4->generateBox(ds, &bd);
  ds->append(")\n");

  tmp = ds->str();
  
  delete pg1;
  delete pg2;
  delete ds;
  return tmp;
}
Esempio n. 11
0
bool LocalizableStringManager::ParseSourceFile( const BazisLib::String &fp )
{
	ManagedPointer<TextANSIFileReader> pRdr = new TextANSIFileReader(new ACFile(fp, FileModes::OpenReadOnly));
	if (!pRdr->Valid())
	{
		_tprintf(_T("ERROR: cannot open %s\n"), fp.c_str());
		return false;
	}
	_tprintf(_T("  %s\n"), Path::GetFileName(fp).c_str());

	bool insideCCommentBlock = false;
	bool insideStringConstant = false;

	unsigned lineNum = 0;

	DynamicString currentDialogID;

	while (!pRdr->IsEOF())
	{
		size_t LocalizationTokenStart = -1;
		enum
		{
			ltUnknown = 0,
			ltTR,
			ltDIALOG,
			ltDLGITEM,
		} localizationTokenType;

		lineNum++;
		DynamicStringA line = pRdr->ReadLine();

		if (line[0] == '#')
			break;
			
		unsigned backslashCount = 0;
		char prevChar = 0, ch = 0;

		size_t lastStringStart = -1, lastStringLen = 0;

		for (size_t i = 0; i < line.length(); i++, prevChar = ch)
		{
			//Even amount of backslashes followed by quotation mark toggles string constant flag (outside comment block)
			//The "/*" and "*/" sequences outside string block change the comment flag.
			//The "//" sequence skips everything till the end of the string
			//At the end of each line inside the string block there should be a backslash
			ch = line[i];

			bool isLastChar = (i == (line.length() - 1));

			if (insideCCommentBlock)
			{
				if ((ch == '/') && (prevChar == '*'))
					insideCCommentBlock = false;
			}
			else	//Outside comment block - detect string literals
			{
				if (ch == '\\')
					backslashCount++;
				else 
				{
					if (((ch == '\"') || (ch == '\'')) && !(backslashCount % 2))
					{
						if (!insideStringConstant)
							lastStringStart = i + 1, lastStringLen = 0;
						else
							lastStringLen = i - lastStringStart;

						insideStringConstant = !insideStringConstant;
					}
					backslashCount = 0;
				}

				if (!insideStringConstant)	//Outside comment and string blocks - check for comment start
				{
					if ((ch == '*') && (prevChar == '/'))
						insideCCommentBlock = true;
					if ((ch == '/') && (prevChar == '/'))
						break;
				}
				else	//Inside string block
				{
					if (isLastChar && (ch != '\\'))
					{
						_tprintf(_T("%s(%d) : error: Unterminated string"), GetFullPath(fp).c_str(), lineNum);
						return false;
					}
				}
			}

			//Here, both insideCCommentBlock and insideStringConstant reflect the real file context. So, let's find "_TR()" and LOCALIZE_DIALOG()/LOCALIZE_DLGITEM()
			if (!insideCCommentBlock && !insideStringConstant)
			{
				if (!IsValidCTokenChar(prevChar))
				{
					size_t newTokenStart = -1;
					size_t remaining = line.length() - i;
					if ((remaining > 4) && (line.substr(i, 3) == "_TR") && !IsValidCTokenChar(line[i + 3]))
						newTokenStart = i + 3, localizationTokenType = ltTR;
					else if ((remaining > 16) && (line.substr(i, 15) == "LOCALIZE_DIALOG") && !IsValidCTokenChar(line[i + 15]))
						newTokenStart = i + 15, localizationTokenType = ltDIALOG;
					else if ((remaining > 17) && (line.substr(i, 16) == "LOCALIZE_DLGITEM") && !IsValidCTokenChar(line[i + 16]))
						newTokenStart = i + 16, localizationTokenType = ltDLGITEM;

					if (newTokenStart != -1)
					{
						if (LocalizationTokenStart != -1)
						{
							_tprintf(_T("%s(%d) : error: Localization token used recursively"), GetFullPath(fp).c_str(), lineNum);
							return false;
						}
						LocalizationTokenStart = newTokenStart;
						
						lastStringStart = -1;
						lastStringLen = 0;
					}

				}
				if (ch == '}')
					currentDialogID.clear();

				if ((ch == ')') && (LocalizationTokenStart != -1))
				{
					size_t tokenParamsStart = line.find_first_not_of(" \t()", LocalizationTokenStart);
					TempStringA tokenParams = line.substr(tokenParamsStart, i - LocalizationTokenStart);
					if (tokenParams.empty())
					{
						_tprintf(_T("%s(%d) : error: Empty localization macro"), GetFullPath(fp).c_str(), lineNum);
						return false;
					}
					if (localizationTokenType == ltTR)
					{
						if ((lastStringStart == -1) || !lastStringLen)
						{
							_tprintf(_T("%s(%d) : error: Invalid _TR() statement - default string not found"), GetFullPath(fp).c_str(), lineNum);
							return false;
						}
						DynamicString lastString = ANSIStringToString(line.substr(lastStringStart, lastStringLen));

						size_t idEnd = tokenParams.find_first_of(" ,");
						DynamicString id = ANSIStringToString(tokenParams.substr(0, (idEnd == -1) ? 0 : idEnd));
						if (id.empty())
						{
							_tprintf(_T("%s(%d) : error: Invalid _TR() statement - cannot determine string ID"), GetFullPath(fp).c_str(), lineNum);
							return false;
						}

						const DynamicString &existingValue = m_Strings[id].Value;
						if (!existingValue.empty() && (existingValue != lastString))
							_tprintf(_T("%s(%d) : warning: %s redefined with different value\n"), GetFullPath(fp).c_str(), lineNum, id.c_str());

						m_Strings[id].Value = lastString;
					}
					else
					{
						_FixedSetOfCharsSplitString<2, TempStringA> params(tokenParams, ", \t");
						if (params.count() < 2)
						{
							_tprintf(_T("%s(%d) : error: Invalid LOCALIZE_xxx() statement - less than 2 arguments\n"), GetFullPath(fp).c_str(), lineNum);
							return false;
						}

						DynamicString stringId = ANSIStringToString(params[0]);
						if (stringId.empty())
						{
							_tprintf(_T("%s(%d) : error: Invalid LOCALIZE_xxx() statement - empty string ID\n"), GetFullPath(fp).c_str(), lineNum);
							return false;
						}

						if (localizationTokenType == ltDIALOG)
						{
							DynamicString dlgID = ANSIStringToString(params[1]);
							if (m_Dialogs.find(dlgID) == m_Dialogs.end())
							{
								_tprintf(_T("%s(%d) : error: Cannot find dialog %s\n"), GetFullPath(fp).c_str(), lineNum, dlgID.c_str());
								return false;
							}
							m_Dialogs[dlgID].Localized = true;
							m_Dialogs[dlgID].LocalizationFileAndLine.Format(_T("%s(%d)"), GetFullPath(fp).c_str(), lineNum);
							m_Strings[stringId].Value = m_Dialogs[dlgID].Caption;
							currentDialogID = dlgID;
						}
						else if (localizationTokenType == ltDLGITEM)
						{
							if (currentDialogID.empty())
							{
								_tprintf(_T("%s(%d) : error: LOCALIZE_DLGITEM() used outside LOCALIZE_DIALOG() block\n"), GetFullPath(fp).c_str(), lineNum);
								return false;
							}
							DynamicString itemID = ANSIStringToString(params[1]);
							std::map<BazisLib::String, DialogMember>::iterator it = m_Dialogs[currentDialogID].DialogMembers.find(itemID);
							if ((stringId == _T("0")) || !stringId.icompare(_T("NULL")))
							{
								it->second.Skipped = true;
								continue;
							}
							if (it == m_Dialogs[currentDialogID].DialogMembers.end())
							{
								_tprintf(_T("%s(%d) : error: %s is not defined in %s\n"), GetFullPath(fp).c_str(), lineNum, itemID.c_str(), currentDialogID.c_str());
								return false;
							}
							m_Strings[stringId].Value = it->second.Name;
							it->second.Localized = true;
						}

					}
					LocalizationTokenStart = -1;
				}
			}
		}

	}
	return true;
}
Esempio n. 12
0
bool LocalizableStringManager::ParseResourceFile( const BazisLib::String &fp )
{
	ManagedPointer<TextANSIFileReader> pRdr = new TextANSIFileReader(new ACFile(fp, FileModes::OpenReadOnly));
	if (!pRdr->Valid())
	{
		_tprintf(_T("ERROR: cannot open %s\n"), fp.c_str());
		return false;
	}
	_tprintf(_T("  %s\n"), DynamicString(Path::GetFileName((fp))).c_str());

	DynamicString dialogName;
	bool insideDialogDescription = false;
	size_t spacingBeforeDlgitem = -1;

	unsigned lineNum = 0;

	while (!pRdr->IsEOF())
	{
		lineNum++;
		DynamicStringA line = pRdr->ReadLine();
		_FixedCharacterSplitString<2, TempStringA> tokens(line, ' ');
		if (!tokens.count())
			continue;
		if (!tokens[0].icompare("BEGIN"))
			insideDialogDescription = true;
		else if (!tokens[0].icompare("END"))
			dialogName.clear(), insideDialogDescription = false;
		else if (!tokens[1].icompare("DIALOGEX"))
		{
			dialogName = ANSIStringToString(tokens[0]), insideDialogDescription = false;
			m_Dialogs[dialogName].FileAndLine.Format(_T("%s(%d)"), GetFullPath(fp).c_str(), lineNum);
		}
		else if (!line.substr(0, 8).icompare("CAPTION ") && !dialogName.empty() && !insideDialogDescription)
		{
			TempStringA dlgCaption = line.substr(9);
			size_t lastQuote = dlgCaption.find_last_of('\"');
			if (lastQuote != -1)
				dlgCaption = dlgCaption.substr(0, lastQuote);

			DynamicString translatedCaption = ANSIStringToString(dlgCaption);
			for (size_t idx = 0; idx < (translatedCaption.length() - 1); idx++)
			{
				if ((translatedCaption[idx] == '\"') && (translatedCaption[idx + 1] == '\"'))
					translatedCaption.erase(idx, 1);
			}
			m_Dialogs[dialogName].Caption = FormatStringASCString(translatedCaption);
		}
		else if (insideDialogDescription && !dialogName.empty())
		{
			if (spacingBeforeDlgitem == -1)
				spacingBeforeDlgitem = line.find_first_not_of(" \t");
			if (spacingBeforeDlgitem == -1)
				continue;

			if ((line.length() <= spacingBeforeDlgitem) || (line[spacingBeforeDlgitem] == ' ') || (line[spacingBeforeDlgitem] == '\t'))
				continue;

			_FixedSetOfCharsSplitString<1, TempStringA> tokens2(line.substr(spacingBeforeDlgitem), " \t");
			if (tokens2.count() < 1)
				continue;

			if (!tokens2[0].length())
				continue;

			size_t nameStart = tokens2.GetRemainderOffset();
			if (nameStart == -1)
				continue;

			nameStart = line.find_first_not_of(" \t", nameStart + spacingBeforeDlgitem);

			if ((nameStart == -1) || (line[nameStart] != '\"'))
				continue;

			nameStart++;

			char prevChar = 0;
			size_t nameEnd;
			for (nameEnd = nameStart; nameEnd < line.length(); nameEnd++)
			{
				if (line[nameEnd] == '\"')
				{
					if (((nameEnd + 1) < line.length()) && (line[nameEnd + 1] == '\"'))
					{
						nameEnd++;
						continue;
					}
					else
						break;
				}
			}

			DynamicStringA itemText = line.substr(nameStart, nameEnd - nameStart);

			for (size_t idx = 0; (idx + 1) < itemText.length(); idx++)
			{
				if ((itemText[idx] == '\"') && (itemText[idx + 1] == '\"'))
					itemText.erase(idx, 1);
			}


			size_t IDOffset = line.find_first_not_of(" \t,", nameEnd + 1);
			if (IDOffset == -1)
				continue;
			size_t IDEnd = line.find_first_of(" \t,", IDOffset);

			TempStringA itemID = line.substr(IDOffset, (IDEnd == -1) ? -1 : IDEnd - IDOffset);

			m_Dialogs[dialogName].DialogMembers[ANSIStringToString(itemID)].Name = FormatStringASCString(ANSIStringToString(itemText));
			
		}
	}
	return true;
}
Esempio n. 13
0
void StringId64::to_string(DynamicString& s)
{
	char buf[16+1];
	snprintf(buf, sizeof(buf), "%.16" PRIx64, _id);
	s.set(buf, sizeof(buf)-1);
}
Esempio n. 14
0
void StringId32::to_string(DynamicString& s)
{
	char buf[8+1];
	snprintf(buf, sizeof(buf), "%.8x", _id);
	s.set(buf, sizeof(buf)-1);
}