mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 23:19:19 +02:00
Random includes only for mmd files
This commit is contained in:
@@ -4970,6 +4970,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
|
|||||||
+ " end",
|
+ " end",
|
||||||
cParser::buffer_TEXT,
|
cParser::buffer_TEXT,
|
||||||
asBaseDir );
|
asBaseDir );
|
||||||
|
parser.allowRandomIncludes = true;
|
||||||
std::string token;
|
std::string token;
|
||||||
do {
|
do {
|
||||||
token = "";
|
token = "";
|
||||||
|
|||||||
@@ -8671,6 +8671,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
|
|||||||
std::string cabstr("cab" + std::to_string(cabindex) + "definition:");
|
std::string cabstr("cab" + std::to_string(cabindex) + "definition:");
|
||||||
|
|
||||||
cParser parser( asFileName, cParser::buffer_FILE, DynamicObject->asBaseDir );
|
cParser parser( asFileName, cParser::buffer_FILE, DynamicObject->asBaseDir );
|
||||||
|
parser.allowRandomIncludes = true;
|
||||||
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
||||||
// parser.addCommentStyle( "#", "\n" );
|
// parser.addCommentStyle( "#", "\n" );
|
||||||
std::string token;
|
std::string token;
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
|||||||
// launch child parser if include directive found.
|
// launch child parser if include directive found.
|
||||||
// NOTE: parameter collecting uses default set of token separators.
|
// NOTE: parameter collecting uses default set of token separators.
|
||||||
if( expandIncludes && token == "include" ) {
|
if( expandIncludes && token == "include" ) {
|
||||||
std::string includefile = deserialize_random_set(*this); //readToken(ToLower); // nazwa pliku
|
std::string includefile = allowRandomIncludes ? deserialize_random_set(*this) : readToken(ToLower); // nazwa pliku
|
||||||
replace_slashes(includefile);
|
replace_slashes(includefile);
|
||||||
if( ( true == LoadTraction )
|
if( ( true == LoadTraction )
|
||||||
|| ( ( false == contains( includefile, "tr/" ) )
|
|| ( ( false == contains( includefile, "tr/" ) )
|
||||||
@@ -253,6 +253,7 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
|||||||
if (Global.ParserLogIncludes)
|
if (Global.ParserLogIncludes)
|
||||||
WriteLog("including: " + includefile);
|
WriteLog("including: " + includefile);
|
||||||
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ) );
|
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ) );
|
||||||
|
mIncludeParser->allowRandomIncludes = allowRandomIncludes;
|
||||||
mIncludeParser->autoclear( m_autoclear );
|
mIncludeParser->autoclear( m_autoclear );
|
||||||
if( mIncludeParser->mSize <= 0 ) {
|
if( mIncludeParser->mSize <= 0 ) {
|
||||||
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
||||||
@@ -268,7 +269,8 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
|||||||
else if( ( std::strcmp( Break, "\n\r" ) == 0 ) && ( token.compare( 0, 7, "include" ) == 0 ) ) {
|
else if( ( std::strcmp( Break, "\n\r" ) == 0 ) && ( token.compare( 0, 7, "include" ) == 0 ) ) {
|
||||||
// HACK: if the parser reads full lines we expect this line to contain entire include directive, to make parsing easier
|
// HACK: if the parser reads full lines we expect this line to contain entire include directive, to make parsing easier
|
||||||
cParser includeparser( token.substr( 7 ) );
|
cParser includeparser( token.substr( 7 ) );
|
||||||
std::string includefile = deserialize_random_set(includeparser);//includeparser.readToken( ToLower ); // nazwa pliku
|
includeparser.allowRandomIncludes = allowRandomIncludes;
|
||||||
|
std::string includefile = allowRandomIncludes ? deserialize_random_set( includeparser ) : includeparser.readToken( ToLower ); // nazwa pliku
|
||||||
replace_slashes(includefile);
|
replace_slashes(includefile);
|
||||||
if( ( true == LoadTraction )
|
if( ( true == LoadTraction )
|
||||||
|| ( ( false == contains( includefile, "tr/" ) )
|
|| ( ( false == contains( includefile, "tr/" ) )
|
||||||
@@ -276,6 +278,7 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
|||||||
if (Global.ParserLogIncludes)
|
if (Global.ParserLogIncludes)
|
||||||
WriteLog("including: " + includefile);
|
WriteLog("including: " + includefile);
|
||||||
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ) );
|
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ) );
|
||||||
|
mIncludeParser->allowRandomIncludes = allowRandomIncludes;
|
||||||
mIncludeParser->autoclear( m_autoclear );
|
mIncludeParser->autoclear( m_autoclear );
|
||||||
if( mIncludeParser->mSize <= 0 ) {
|
if( mIncludeParser->mSize <= 0 ) {
|
||||||
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
||||||
@@ -382,6 +385,7 @@ void cParser::injectString(const std::string &str)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mIncludeParser = std::make_shared<cParser>( str, buffer_TEXT, "", LoadTraction );
|
mIncludeParser = std::make_shared<cParser>( str, buffer_TEXT, "", LoadTraction );
|
||||||
|
mIncludeParser->allowRandomIncludes = allowRandomIncludes;
|
||||||
mIncludeParser->autoclear( m_autoclear );
|
mIncludeParser->autoclear( m_autoclear );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
parser.h
1
parser.h
@@ -91,6 +91,7 @@ class cParser //: public std::stringstream
|
|||||||
// returns number of currently processed line in main file, -1 if inside include
|
// returns number of currently processed line in main file, -1 if inside include
|
||||||
int LineMain() const;
|
int LineMain() const;
|
||||||
bool expandIncludes = true;
|
bool expandIncludes = true;
|
||||||
|
bool allowRandomIncludes = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// methods:
|
// methods:
|
||||||
|
|||||||
Reference in New Issue
Block a user