//=================================================================================================
void DCmdFindID::exec(const DPreprocessor::DS_Command* pContext)
{
	DStaticAssert(D_PREPROCESSOR_NBPARAMS >= 2);
	DAssertMsg(pContext->nbParameters == 2, "Invalid parameter in script file.");
	
	const std::list<DString>& fileList = DCmdFindFile::getFileList();
	const char* pBeginMarkup = pContext->aParameters[0];
	const char* pEndMarkup = pContext->aParameters[1];
	if(!*pEndMarkup)
		pEndMarkup = "\r\n";
	u32 beginMarkupLength = DStrLen(pBeginMarkup);
	u32 endMarkupLength = DStrLen(pEndMarkup);
	
	// Parcours des fichiers
	for(std::list<DString>::const_iterator it = fileList.begin(); it != fileList.end(); it++)
	{
		// Lecture du fichier
		char* pFileBuffer = static_cast<char*>(DLoadFile(it->getCStr()));
		
		// Recherche de la balise de début
		const char* pBegin = DStrStr(pFileBuffer, pBeginMarkup);
		while(pBegin)
		{
			pBegin += beginMarkupLength;
			
			// Recherche de la balise de fin
			const char* pEnd = DStrStr(pBegin, pEndMarkup);
			if(pEnd)
			{
				g_ResultList.resize(g_ResultList.size() + 1);
				DS_Result* pResult = &g_ResultList.back();
				DStrNCpy(pResult->ID.getCStr(), D_STRING_LENGTH, pBegin, pEnd - pBegin);
				pResult->filePath = it->getCStr();
				pResult->position = static_cast<u32>(pBegin - pFileBuffer);
			}
			
			pBegin = DStrStr(pEnd + endMarkupLength, pBeginMarkup);
		}
		
		// Destruction du buffer de fichier
		DUnloadFile(pFileBuffer);
	}
}
Exemple #2
0
BOOL DText::Attach(STRCPTR data, TEXT_FORMAT fmt, UINT width /* = 0U */, BOOL warp /* = FALSE */)
{
	if (m_Data)
		return FALSE;

	if (!CheckText(data, fmt, width, warp))
		return FALSE;

	m_Attach = TRUE;
	m_Warp = warp;
	m_Width = width;
	m_Format = fmt;
	m_Data = data;
	m_Length = DStrLen(m_Data);
	return TRUE;
}
Exemple #3
0
STRPTR DText::AllocData(STRCPTR data, UINT len /* = 0U */)
{
	if (!data) {
		if (!len)
			return NULL;
		return new CHAR[len + 1];
	}

	if (!len)
		len = DStrLen(data);

	STRPTR buf = new CHAR[len + 1];
	DStrCpyN(buf, data, len);
	buf[len] = '\0';
	return buf;
}
Exemple #4
0
BOOL DText::Create(STRCPTR data, TEXT_FORMAT fmt, UINT width /* = 0U */, BOOL warp /* = FALSE */, BOOL pre_alloc /* = FALSE */)
{
	if (m_Data)
		return FALSE;

	if (!CheckText(data, fmt, width, warp))
		return FALSE;

	if (pre_alloc) {
		m_Data = data;
	} else {
		m_Data = AllocData(data);
		if (!m_Data)
			return FALSE;
	}

	m_Attach = FALSE;
	m_Warp = warp;
	m_Width = width;
	m_Format = fmt;
	m_Length = DStrLen(m_Data);
	return TRUE;
}