// The following routine builds a timestamp value from a date string in the format <dd>/<mm>/<yyyy>
// If the text doesn't match the expected format then ~0u is returned
static uint32 buildTimestampFromDateStr(const NLMISC::CSString& dateStr)
{
	// setup a new time structure, extracting the day, month and year values from the argument string
	struct tm tmstruct;
	NLMISC::CSString txt= dateStr.strip();
	tmstruct.tm_mday	= txt.splitTo('/',true,true).atoi();
	tmstruct.tm_mon		= txt.splitTo('/',true,true).atoi() -1;
	tmstruct.tm_year	= txt.atoi();
	if (tmstruct.tm_year<100)
		tmstruct.tm_year= ((tmstruct.tm_year+30)%100)+1970;

	// make sure the day month and year are valid
	DROP_IF(tmstruct.tm_year<1970 || tmstruct.tm_year>=2100,"FILE_LIST_BUILDER 'Since' invalid year: "+dateStr,return ~0u);
	DROP_IF(tmstruct.tm_mon<0 || tmstruct.tm_mon>=12,"FILE_LIST_BUILDER 'Since' invalid month: "+dateStr,return ~0u);
	DROP_IF(tmstruct.tm_mday<1 || tmstruct.tm_mday>31,"FILE_LIST_BUILDER 'Since' invalid day: "+dateStr,return ~0u);

	// complete initialisation of tm struct (and map year into range from 1970 up
	tmstruct.tm_year	-= 1900;
	tmstruct.tm_wday	= 0;
	tmstruct.tm_yday	= 0;
	tmstruct.tm_isdst	= 0;

	// build a time_t value for the start of the day
	tmstruct.tm_sec		= 0;
	tmstruct.tm_min		= 0;
	tmstruct.tm_hour	= 0;
	
	return (uint32)mktime( &tmstruct );
}
Example #2
0
bool CStateManager::beginState(const NLMISC::CSString& stateName)
{
	// make sure the state is valid
	if (_ValidStates.find(stateName.strip())==_ValidStates.end())
	{
		nlwarning("Cannot start state as it is not in valid state list: %s",stateName.c_str());
		return false;
	}

	// make sure the state isn't already active
	for (uint32 i=0;i<_States.size();++i)
	{
		if (_States[i]==stateName)
		{
			nlwarning("Cannot start state as it is already active: %s",stateName.c_str());
			return false;
		}
	}

	// set the state as active
	_States.push_back(stateName);

	// write the states to a file
	NLMISC::CSString stateTxt;
	stateTxt.join(_States,"\n");
	stateTxt.writeToFile(StateFileName);

	// execute the begin_state script
	CScriptManager::getInstance()->runScript("begin_"+stateName);

	return true;
}
Example #3
0
void CStateManager::addValidState(const NLMISC::CSString& stateName)
{
	if (stateName.countWords()!=1)
	{
		nlwarning("Invalid state name: %s",stateName.c_str());
		return;
	}
	_ValidStates.insert(stateName.strip());
}
Example #4
0
	NLMISC::CSString extractNamedParameter(const NLMISC::CSString& argName,NLMISC::CSString rawArgs)
	{
		while (!rawArgs.empty())
		{
			NLMISC::CSString keyword;
			NLMISC::CSString args;
			keyword= rawArgs.firstWord(true);
			rawArgs=rawArgs.strip();
			if (rawArgs[0]=='(')
			{
				args=rawArgs.matchDelimiters(true).stripBlockDelimiters();
			}

			if (keyword==argName)
			{
				return args;
			}
		}

		return NLMISC::CSString();
	}