Exemplo n.º 1
0
// Retourne le numéro du groupe passé en paramètre
int GetNumeroGroupe( const CSString& groupe )
{
	CSString result;
	char buffer[100];
	char buffer2[100];
	int res;

	// *** Get the group number, and add it to group.typ if not already done
	// on recherche si le groupe est présent
	// dans le fichier item_mp_group.typ
	sprintf( buffer, "%s\" Value=\"", groupe.c_str() );
	result = GroupTypContent.splitFrom( buffer );

	// si oui, on retourne son numéro de groupe
	if ( !result.empty() )
		res = result.splitTo( "\"" ).atoi();
	else
	{
		// sinon, on génère un nouveau numéro :
		// on recupère le dernier numéro de groupe (le max)
		result = GroupTypContent.splitTo( "<LOG>" ).right(10);
		result.splitTo( "\"", true );
		result = result.splitTo( "\"" );

		// on ajoute 1 pour avoir un numéro non utilisé
		res = result.atoi() + 1;

		// on ajoute la nouvelle MP :
		// dans le fichier item_mp_group.typ
		sprintf( buffer, "<DEFINITION Label=\"%s\" Value=\"%d\"/>\n<LOG>", groupe.c_str(), res );
		GroupTypContent= GroupTypContent.replace( "<LOG>", buffer );
		GroupTypContent.writeToFile( ITEM_MP_GROUPE_TYP );
	}


	// *** Add the text in wk.uxt (if not done)
	// Exist in wk.uxt ???
	sprintf( buffer, "mpgroup%d\t", res );
	sprintf( buffer2, "mpgroup%d ", res );
	// if not found
	if ( !WKContent.contains(buffer) && !WKContent.contains(buffer2) )
	{
		// add it at end
		sprintf( buffer, "mpgroup%d\t\t\t[%s]\n\r\nmpSource", res, groupe.c_str() );
		WKContent= WKContent.replace( "\r\nmpSource", buffer );
		WKContent.writeToFile( WK_UXT );
	}

	return res;
}
Exemplo n.º 2
0
/*
 * Set the result vector with strings corresponding to the input string:
 * - If inputStr is partially or completely found in the keys, all the matching <key,words> are returned;
 * - If inputStr is partially or completely in the words, all the matching <key, words> are returned.
 * The following tags can modify the behaviour of the search algorithm:
 * - ^mystring returns mystring only if it is at the beginning of a key or word
 * - mystring$ returns mystring only if it is at the end of a key or word
 * All returned words are in UTF8.
 */
void CWordsDictionary::lookup( const CSString& inputStr, CVectorSString& resultVec ) const
{
	// Prepare search string
	if ( inputStr.empty() )
		return;

	CSString searchStr = inputStr;
	bool findAtBeginning = false, findAtEnd = false;
	if ( searchStr[0] == '^' )
	{
		searchStr = searchStr.substr( 1 );
		findAtBeginning = true;
	}
	if ( searchStr[searchStr.size()-1] == '$' )
	{
		searchStr = searchStr.rightCrop( 1 );
		findAtEnd = true;
	}

	// Search
	const vector<string> &vec = reinterpret_cast<const vector<string>&>(_Keys);
//	for ( CVectorSString::const_iterator ivs=_Keys.begin(); ivs!=_Keys.end(); ++ivs )
	for ( vector<string>::const_iterator ivs=vec.begin(); ivs!=vec.end(); ++ivs )
	{
		const CSString& key = *ivs;
		string::size_type p;
		if ( (p = key.findNS( searchStr.c_str() )) != string::npos )
		{
			if ( ((!findAtBeginning) || (p==0)) && ((!findAtEnd) || (p==key.size()-searchStr.size())) )
				resultVec.push_back( makeResult( key, _Words[ivs-vec.begin()] ) );
		}
	}
	for ( CVectorSString::const_iterator ivs=_Words.begin(); ivs!=_Words.end(); ++ivs )
	{
		const CSString& word = *ivs;
		string::size_type p;
		if ( (p = word.findNS( searchStr.c_str() )) != string::npos )
		{
			if ( ((!findAtBeginning) || (p==0)) && ((!findAtEnd) || (p==word.size()-searchStr.size())) )
				resultVec.push_back( makeResult( _Keys[ivs-_Words.begin()], word ) );
		}
	}
}
Exemplo n.º 3
0
static void checkShutdownRequest()
{
	// a little system to prevent us from eating too much CPU on systems that have a cstly 'fileExists()'
	static uint32 count=0;
	if ((++count)<10)	return;
	count=0;

	// if there's no ctrl file to be found then giveup
	if (!NLMISC::CFile::fileExists(ShutdownRequestFileName)) return;

	// if a shutdown ctrl file exists then read it's contents (if the file doesn't exist this returns an empty string)
	CSString fileContents;
	fileContents.readFromFile(ShutdownRequestFileName.c_str());

	// see if the file exists
	if (!fileContents.empty())
	{
		NLMISC::CFile::deleteFile(ShutdownRequestFileName);
		fileContents= fileContents.strip().splitToOneOfSeparators(" \t\n\r\x1a");
		// get rid of any unwanted junk surrounding the file contents
		nlinfo("Treating shutdown request from ctrl file %s: %s",ShutdownRequestFileName.c_str(),("#.State="+fileContents).c_str());
		NLMISC::ICommand::execute("getViewAES #.State="+fileContents, *NLMISC::InfoLog);
	}
}
Exemplo n.º 4
0
// Génère l'item parent pour une MP
void CreateParentSItem( int numMP, 
					    const CSString& nomMP,
						const CSString& groupe,
						bool dropOrSell,
						const CSString& icon,
						const CSString& overlay )
{
	CSString output;
	CSString outputFileName;

	// nom du fichier de sortie
	outputFileName = toString( "%s_parent\\_m%04d.sitem", MP_DIRECTORY.c_str(), numMP );

	// entete xml
	output = "<?xml version=\"1.0\"?>\n<FORM Version=\"0.0\" State=\"modified\">\n";
	
	// basics
	output += "  <STRUCT>\n    <STRUCT Name=\"basics\">\n";
	output += "      <ATOM Name=\"Drop or Sell\" Value=\"";

	if ( !dropOrSell )
		// il s'agit d'un item de mission, non vendable
		output += "false\"/>\n";
	else
		// sinon, on peut le vendre
		output += "true\"/>\n";

	output += "      <ATOM Name=\"Bulk\" Value=\"0.5\"/>\n    </STRUCT>\n";

	// mp
	output += "    <STRUCT Name=\"mp\">\n";
	output += "      <ATOM Name=\"Family\" Value=\"";
	output += nomMP;
	output += "\"/>\n      <ATOM Name=\"Group\" Value=\"";
	output += groupe;
	output += "\"/>\n    </STRUCT>\n";

	// 3d
	output += "    <STRUCT Name=\"3d\">\n";
	
	if ( !icon.empty() )
	{
		output += "      <ATOM Name=\"icon\" Value=\"";
		output += icon;
		output += "\"/>\n";
	}

	if ( !overlay.empty() )
	{
		output += "      <ATOM Name=\"text overlay\" Value=\"";
		output += overlay;
		output += "\"/>\n";
	}

	output += "    </STRUCT>\n  </STRUCT>\n";

	// fin du fichier
	output += "  <STRUCT/>\n  <STRUCT/>\n  <STRUCT/>\n  <STRUCT/>\n</FORM>\n";

	// écriture finale
	output.writeToFile( outputFileName );

}
Exemplo n.º 5
0
// Nouvelle MP à traiter
void NewMP( CSString& ligne )
{
	CSString nomMP, groupe, loc, icon, overlay, special, stat, specialAttributes;
	MPCraftStats craftStats;
	CExtraInfo	extraInfo;
	int numMP;
	bool specialOnly = false;
	CSortedStringSet specialNames;

	// nouveau nom de famille
	nomMP = ligne.splitTo( ";", true );
	if ( nomMP.empty() )
	{
		// cette ligne ne contient pas d'info
		return;
	}
	
	// récupération des infos
	groupe = ligne.splitTo( ";", true );
	craftStats.Craft = ligne.splitTo( ";", true );
	specialAttributes= ligne.splitTo( ";" , true );
	parseSpecialAttributes(specialAttributes, craftStats, extraInfo);
	ligne.splitTo( ";" , true );
	loc = ligne.splitTo( ";" , true );
	icon = ligne.splitTo( ";", true );
	ligne.splitTo( ";", true );
	ligne.splitTo( ";", true );
	ligne.splitTo( ";", true );

	stat = ligne.splitTo( ";", true );
	if ( !stat.firstWord().empty() )
		craftStats.bestStatA = stat.atoi();
	else
		craftStats.bestStatA = -1;

	stat = ligne.splitTo( ";", true );
	if ( !stat.firstWord().empty() )
		craftStats.worstStatA1 = stat.atoi();
	else
		craftStats.worstStatA1 = -1;

	stat = ligne.splitTo( ";", true );
	if ( !stat.firstWord().empty() )
		craftStats.worstStatA2 = stat.atoi();
	else
		craftStats.worstStatA2 = -1;

	stat = ligne.splitTo( ";", true );
	if ( !stat.firstWord().empty() )
		craftStats.bestStatB = stat.atoi();
	else
		craftStats.bestStatB = -1;

	stat = ligne.splitTo( ";", true );
	if ( !stat.firstWord().empty() )
		craftStats.worstStatB1 = stat.atoi();
	else
		craftStats.worstStatB1 = -1;

	stat = ligne.splitTo( ";", true );
	if ( !stat.firstWord().empty() )
		craftStats.worstStatB2 = stat.atoi();
	else
		craftStats.worstStatB2 = -1;

	stat = ligne.splitTo( ";", true );
	craftStats.color = stat.firstWord().atoi();

	stat = ligne.splitTo( ";", true );
	specialOnly = stat.firstWord().contains( "x" );
	
	// cas particuliers
	while ( !ligne.empty() )
	{
		if ( !ligne.contains( ";" ) ) 
		{
			special = ligne;
			if ( !special.firstWord().empty() )
				specialNames.insert( special );
			ligne = "";
		}
		else
		{
			special = ligne.splitTo( ";", true );
			if ( !special.empty() )
				specialNames.insert( special );
		}
	}


	currentDocItem.push( DtRMFamily, nomMP );
	currentDocItem.push( DtGroup, groupe );
	
	// récupréation du numéro de MP
	numMP = GetNumeroMP( nomMP );
	printf( "    Processing Family %d : %s\n", numMP, nomMP.c_str() );

	GetNumeroGroupe( groupe );


	// Add the MPFamily into the list
	if(numMP>=(sint)MPFamilies.size())
		MPFamilies.resize(numMP+1);
	MPFamilies[numMP].Name= nomMP;
	MPFamilies[numMP].Icon= icon;

	
	// MP trouvées dans les déposits ou dans la goo
	if ( loc.left(1) != "C" )
	{
		if ( !specialOnly )
		{
			// Génération des items
			GenerateDepositItems( numMP, nomMP, craftStats, loc );
		}
		
		// on enregistre les items se trouvant dans les deposits
		if ( loc.left(1) == "D" )
		{
			CSString output;
			output.writeToFile( toString( "%s%s_%d.mp", DEPOSIT_MPS.c_str(), nomMP.toLower().replace( " ", "_" ).c_str(), numMP ) );
		}

		overlay = nomMP.firstWord().toUpper().left(6);
	}
	// MP trouvées sur les creature
	else
	{
		GenerateCreatureItems( numMP, nomMP, craftStats );
	}


	// items spéciaux
	CSString codeSpecial, nouveauCode;
	int variation = 1;
	CSortedStringSet::const_iterator it = specialNames.begin();

	while ( it != specialNames.end() )
	{
		CSString name = (*it);
		
		nouveauCode = name.left(2).toLower();

		if ( nouveauCode == codeSpecial )
			variation++;
		else
			variation = 1;

		GenerateSpecialItem( numMP, nomMP, craftStats, loc, name, variation );
		codeSpecial = nouveauCode;
		it++;
	}
		
		
	// Création de la fiche parente pour la MP
	CreateParentSItem( numMP, nomMP, groupe, extraInfo.DropOrSell, icon, overlay );

	currentDocItem.reset( DtRMFamily );
	currentDocItem.reset( DtGroup );
	currentDocItem.reset( DtProp );
	currentDocItem.reset( DtCreature );
}
Exemplo n.º 6
0
//void executeScriptBuf(char *txt)
void executeScriptBuf(const string &text)
{
	CSString buf = text;
	CVectorSString	lines;

	vector<string>	tmpLines;
	NLMISC::explode(std::string(buf.c_str()), std::string("\n"), tmpLines, true);
	lines.resize(tmpLines.size());
	for (uint i=0; i<tmpLines.size();i++)
	{
		lines[i]= tmpLines[i];
	}

	for (uint i=0; i<lines.size(); ++i)
	{
		CSString line = lines[i];
		line = line.strip();
		if (line.empty() || line.find("//") == 0)
		{
			// comment or empty line, skip
			continue;
		}
		CSString command = line.strtok(" \t");
		line = line.strip();

		
		if (command == "DFNPATH")
		{
			//CPath::getPathContent(args,true,false,true,files);
			CPath::addSearchPath(line, true, false); // for the dfn files
		}
		else if (command == "PATH")
		{
			files.clear();
			CPath::getPathContent(line, true,false,true,files);
			CPath::addSearchPath(line, true, false); // for the dfn files
		}
		else if (command == "OUTPUT")
		{
			setOutputFile(line);
		}
		else if (command == "FIELD")
		{
			addField(line);
		}
		else if (command == "SOURCE")
		{
			addSource(line);
		}
		else if (command == "SCANFILES")
		{
			scanFiles(line);
		}
		else if (command == "SCRIPT")
		{
			executeScriptFile(line);
		}
		else
		{
			fprintf(stderr,"Unknown command: '%s' '%s'\n", command.c_str(), line.c_str());
		}
	}

	
}
Exemplo n.º 7
0
void buildFileVector(std::vector<std::string> &filenames, const std::string &filespec)
{
	uint i,j;
	// split up the filespec into chains
	CSString filters = filespec;
	filters.strip();
	std::vector<std::string> in, out;

	while (!filters.empty())
	{
		CSString filter = filters.strtok(" \t");
		if (filter.empty())
			continue;

		switch (filter[0])
		{
		case '+':
			in.push_back(filter.leftCrop(1)); break;
			break;
		case '-':
			out.push_back(filter.leftCrop(1)); break;
			break;
		default:
			fprintf(stderr,"Error in '%s' : filter must start with '+' or '-'\n",
				filter.c_str());
			getchar(); 
			exit(1);
		}
	}

/*	for (i=0;i<filespec.size();)
	{
		for (j=i;j<filespec.size() && filespec[j]!=' ' && filespec[j]!='\t';j++) {}
		switch(filespec[i])
		{
		case '+': 
			in.push_back(filespec.substr(i+1,j-i-1)); break;
		case '-': 
			out.push_back(filespec.substr(i+1,j-i-1)); break;
		default: 
			fprintf(stderr,"Filter must start with '+' or '-'\n",&(filespec[i])); getchar(); exit(1);
		}
		i=j;
		while (i<filespec.size() && (filespec[i]==' ' || filespec[i]=='\t')) i++; // skip white space
	}
*/
	// use the filespec as a filter while we build the sheet file vector
	for (i=0;i<files.size();i++)
	{
		bool ok=true;

		// make sure the filename includes all of the include strings
		for (j=0;j<in.size() && ok;j++)
		{
			if (!testWildCard(CFile::getFilename(files[i]), in[j]))
			{
				ok=false;
			}
		}

		// make sure the filename includes none of the exclude strings
		for (j=0;j<out.size() && ok;j++)
		{
			if (testWildCard(CFile::getFilename(files[i]), out[j]))
			{
				ok=false;
			}
		}

		// if the filename matched all of the above criteria then add it to the list
		if (ok)
		{
			printf("Added: %s\n",CFile::getFilename(files[i]).c_str());
			filenames.push_back(files[i]);
		}
	}
	printf("Found: %zu matching files (from %zu)\n",filenames.size(),files.size());

}