From 8939955f2f7abdf5b063d630f5a4d21c21a5ee0c Mon Sep 17 00:00:00 2001 From: Cirilo Bernardo Date: Sun, 3 Jan 2016 09:18:16 +1100 Subject: [PATCH] Relax VRML2 naming rules (perhaps temporarily) to accept the '-' character in DEF names --- plugins/3d/vrml/CMakeLists.txt | 2 ++ plugins/3d/vrml/v2/vrml2_node.cpp | 5 ++++- plugins/3d/vrml/v2/wrlproc.cpp | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/3d/vrml/CMakeLists.txt b/plugins/3d/vrml/CMakeLists.txt index 91d7dc4dc6..9f496cc03c 100644 --- a/plugins/3d/vrml/CMakeLists.txt +++ b/plugins/3d/vrml/CMakeLists.txt @@ -1,5 +1,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/v2 ) +#add_definitions( -DDEBUG_VRML2=3 ) + add_library( s3d_plugin_vrml MODULE vrml.cpp v2/wrlproc.cpp diff --git a/plugins/3d/vrml/v2/vrml2_node.cpp b/plugins/3d/vrml/v2/vrml2_node.cpp index 2e2ecccdf8..7b9b2b3515 100644 --- a/plugins/3d/vrml/v2/vrml2_node.cpp +++ b/plugins/3d/vrml/v2/vrml2_node.cpp @@ -235,7 +235,10 @@ bool WRL2NODE::SetName( const std::string& aName ) return false; } - #define BAD_CHARS1 "\"\'#+,-.\\[]{}\x00\x01\x02\x03\x04\x05\x06\x09\x0A\x0B\x0C\x0D\x0E\x0F" + // XXX: NOTE: in VRML2 the '-' is invalid; however there are some bad models which contain '-' in + // a name and many VRML parsers seem to accept them. In VRML1 the '-' is allowed. + // #define BAD_CHARS1 "\"\'#+,-.\\[]{}\x00\x01\x02\x03\x04\x05\x06\x09\x0A\x0B\x0C\x0D\x0E\x0F" + #define BAD_CHARS1 "\"\'#+,.\\[]{}\x00\x01\x02\x03\x04\x05\x06\x09\x0A\x0B\x0C\x0D\x0E\x0F" #define BAD_CHARS2 "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" if( std::string::npos != aName.find_first_of( BAD_CHARS1 ) diff --git a/plugins/3d/vrml/v2/wrlproc.cpp b/plugins/3d/vrml/v2/wrlproc.cpp index 3e3e0be7ff..51cb40eb96 100644 --- a/plugins/3d/vrml/v2/wrlproc.cpp +++ b/plugins/3d/vrml/v2/wrlproc.cpp @@ -111,7 +111,11 @@ bool WRLPROC::Open( const std::string& aFileName ) // square brackets [] // curly braces {} // backslash - m_badchars = "'\"#,.+-[]\\{}"; + // XXX: NOTE: badchars should include '-' but due to my bad model naming scheme + // in the VRML model generator, I have allowed '-'. Other VRML parsers seem to + // accept '-'. + //m_badchars = "'\"#,.+-[]\\{}"; + m_badchars = "'\"#,.+[]\\{}"; return true; } @@ -332,6 +336,18 @@ bool WRLPROC::ReadName( std::string& aName ) return false; } + if( aName.empty() && m_buf[m_linepos] >= '0' && m_buf[m_linepos] <= '9' ) + { + std::ostringstream ostr; + ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n"; + ostr << " * [INFO] failed on file '" << m_filename << "'\n"; + ostr << " * [INFO] line " << m_fileline << ", column " << m_linepos; + ostr << " -- name must not start with a digit"; + m_error = ostr.str(); + + return false; + } + aName.append( 1, m_buf[m_linepos++] ); }