예제 #1
0
bool CCharScanScriptFile::parseFile(const std::string& fileName, CCharScanScript* container)
{
	_FileName= fileName;

	// read the content of the input file
	bool result;
	NLMISC::CSString fileContent;
	result=fileContent.readFromFile(fileName);
	if (result==false)
	{
		nlwarning("Failed to read script file: %s",fileName.c_str());
		return false;
	}

	// split the file into lines and execute them one by one
	NLMISC::CVectorSString lines;
	fileContent.splitLines(lines);
	for (uint32 i=0;i<lines.size();++i)
	{
		// strip comments and leading and trailing blanks
		CSString theLine= lines[i].replace("//","\xff").splitTo('\xff').strip();
		if (theLine.empty())
			continue;

		CCharScanScriptCommandRegistry::getInstance()->execute(*this,theLine,container);
	}
	return true;
}
예제 #2
0
static void readFileList(const NLMISC::CSString& fileListName, CFileDescriptionContainer& result)
{
	// read the file list from disk (the result will be empty if the file list didn't exist)
	NLMISC::CSString fileList;
	fileList.readFromFile(fileListName);

	// split the file list text block into lines
	NLMISC::CVectorSString files;
	fileList.splitLines(files);

	// iterate over the lies in the input file
	for(uint32 i=0;i<files.size();++i)
	{
		// clean lines up, stripping spaces and quotes
		NLMISC::CSString theFile= files[i].strip().unquoteIfQuoted();

		// skip empty lines and comments
		if (theFile.empty() || theFile.left(1)=="#")
			continue;

		// add the file name to the result
		result.addFile(theFile);
	}
}