mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-17 23:39:18 +02:00
build 200630. parser include support enhancement
This commit is contained in:
@@ -9099,7 +9099,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
|
||||
*/
|
||||
while( fizparser.ok() ) {
|
||||
|
||||
inputline = fizparser.getToken<std::string>( false, "\n" );
|
||||
inputline = fizparser.getToken<std::string>( false, "\n\r" );
|
||||
|
||||
bool comment = ( ( inputline.find('#') != std::string::npos )
|
||||
|| ( inputline.compare( 0, 2, "//" ) == 0 ) );
|
||||
|
||||
@@ -194,7 +194,7 @@ drivermouse_input::recall_bindings() {
|
||||
}
|
||||
|
||||
// NOTE: to simplify things we expect one entry per line, and whole entry in one line
|
||||
while( true == bindingparser.getTokens( 1, true, "\n" ) ) {
|
||||
while( true == bindingparser.getTokens( 1, true, "\n\r" ) ) {
|
||||
|
||||
std::string bindingentry;
|
||||
bindingparser >> bindingentry;
|
||||
|
||||
@@ -174,7 +174,7 @@ gamepad_input::recall_bindings() {
|
||||
{ "value_invert", input_type::value_invert } };
|
||||
|
||||
// NOTE: to simplify things we expect one entry per line, and whole entry in one line
|
||||
while( true == bindingparser.getTokens( 1, true, "\n" ) ) {
|
||||
while( true == bindingparser.getTokens( 1, true, "\n\r" ) ) {
|
||||
|
||||
std::string bindingentry;
|
||||
bindingparser >> bindingentry;
|
||||
|
||||
@@ -63,7 +63,7 @@ keyboard_input::recall_bindings() {
|
||||
};
|
||||
|
||||
// NOTE: to simplify things we expect one entry per line, and whole entry in one line
|
||||
while( true == bindingparser.getTokens( 1, true, "\n" ) ) {
|
||||
while( true == bindingparser.getTokens( 1, true, "\n\r" ) ) {
|
||||
|
||||
std::string bindingentry;
|
||||
bindingparser >> bindingentry;
|
||||
|
||||
42
parser.cpp
42
parser.cpp
@@ -230,23 +230,14 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
||||
token.insert( pos, "none" ); // zabezpieczenie przed brakiem parametru
|
||||
}
|
||||
}
|
||||
|
||||
// launch child parser if include directive found.
|
||||
// NOTE: parameter collecting uses default set of token separators.
|
||||
if( token == "include" ) {
|
||||
// launch child parser if include directive found.
|
||||
// NOTE: parameter collecting uses default set of token separators.
|
||||
std::string includefile = readToken(ToLower); // nazwa pliku
|
||||
if( ( true == LoadTraction )
|
||||
|| ( ( includefile.find( "tr/" ) == std::string::npos )
|
||||
&& ( includefile.find( "tra/" ) == std::string::npos ) ) ) {
|
||||
// get parameter list for the child parser
|
||||
std::vector<std::string> includeparameters;
|
||||
std::string parameter = readToken( false ); // w parametrach nie zmniejszamy
|
||||
while( ( parameter.empty() == false )
|
||||
&& ( parameter != "end" ) ) {
|
||||
includeparameters.emplace_back( parameter );
|
||||
parameter = readToken( false );
|
||||
}
|
||||
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, includeparameters );
|
||||
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ) );
|
||||
mIncludeParser->autoclear( m_autoclear );
|
||||
if( mIncludeParser->mSize <= 0 ) {
|
||||
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
||||
@@ -259,10 +250,37 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
||||
}
|
||||
token = readToken(ToLower, Break);
|
||||
}
|
||||
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
|
||||
cParser includeparser( token.substr( 7 ) );
|
||||
std::string includefile = includeparser.readToken( ToLower ); // nazwa pliku
|
||||
if( ( true == LoadTraction )
|
||||
|| ( ( includefile.find( "tr/" ) == std::string::npos )
|
||||
&& ( includefile.find( "tra/" ) == std::string::npos ) ) ) {
|
||||
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ) );
|
||||
mIncludeParser->autoclear( m_autoclear );
|
||||
if( mIncludeParser->mSize <= 0 ) {
|
||||
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
||||
}
|
||||
}
|
||||
token = readToken( ToLower, Break );
|
||||
}
|
||||
// all done
|
||||
return token;
|
||||
}
|
||||
|
||||
std::vector<std::string> cParser::readParameters( cParser &Input ) {
|
||||
|
||||
std::vector<std::string> includeparameters;
|
||||
std::string parameter = Input.readToken( false ); // w parametrach nie zmniejszamy
|
||||
while( ( parameter.empty() == false )
|
||||
&& ( parameter != "end" ) ) {
|
||||
includeparameters.emplace_back( parameter );
|
||||
parameter = Input.readToken( false );
|
||||
}
|
||||
return includeparameters;
|
||||
}
|
||||
|
||||
std::string cParser::readQuotes(char const Quote) { // read the stream until specified char or stream end
|
||||
std::string token = "";
|
||||
char c { 0 };
|
||||
|
||||
1
parser.h
1
parser.h
@@ -89,6 +89,7 @@ class cParser //: public std::stringstream
|
||||
private:
|
||||
// methods:
|
||||
std::string readToken(bool ToLower = true, const char *Break = "\n\r\t ;");
|
||||
std::vector<std::string> readParameters( cParser &Input );
|
||||
std::string readQuotes( char const Quote = '\"' );
|
||||
void skipComment( std::string const &Endmark );
|
||||
bool findQuotes( std::string &String );
|
||||
|
||||
2
uart.cpp
2
uart.cpp
@@ -105,7 +105,7 @@ uart_input::recall_bindings() {
|
||||
{ "value", input_type_t::value } };
|
||||
|
||||
// NOTE: to simplify things we expect one entry per line, and whole entry in one line
|
||||
while( true == bindingparser.getTokens( 1, true, "\n" ) ) {
|
||||
while( true == bindingparser.getTokens( 1, true, "\n\r" ) ) {
|
||||
|
||||
std::string bindingentry;
|
||||
bindingparser >> bindingentry;
|
||||
|
||||
Reference in New Issue
Block a user