Kaydet (Commit) 6bbca348 authored tarafından Luboš Luňák's avatar Luboš Luňák

make debug output print tags as strings rather than id numbers

üst eb31865c
...@@ -162,7 +162,7 @@ public: ...@@ -162,7 +162,7 @@ public:
*/ */
void handleUnexpectedTag(); void handleUnexpectedTag();
protected: protected:
Tag checkTag( int token, bool optional, const char* txt ); Tag checkTag( int token, bool optional );
std::vector< Tag > tags; std::vector< Tag > tags;
unsigned int pos; unsigned int pos;
}; };
......
...@@ -31,10 +31,19 @@ ...@@ -31,10 +31,19 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <oox/token/namespacemap.hxx>
#include <oox/token/tokenmap.hxx>
#include <oox/token/tokens.hxx> #include <oox/token/tokens.hxx>
#include <oox/token/namespaces.hxx> #include <oox/token/namespaces.hxx>
#include <rtl/string.hxx>
// *sigh*
#define STR( str ) OUString( RTL_CONSTASCII_USTRINGPARAM( str ))
#define CSTR( str ) ( rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr())
using namespace com::sun::star; using namespace com::sun::star;
using rtl::OUString;
namespace oox namespace oox
{ {
...@@ -67,6 +76,40 @@ AttributeListBuilder::AttributeListBuilder( const uno::Reference< xml::sax::XFas ...@@ -67,6 +76,40 @@ AttributeListBuilder::AttributeListBuilder( const uno::Reference< xml::sax::XFas
attrs[ pFastAttr[ i ].Token ] = pFastAttr[ i ].Value; attrs[ pFastAttr[ i ].Token ] = pFastAttr[ i ].Value;
} }
} }
static OUString tokenToString( int token )
{
OUString tokenname = StaticTokenMap::get().getUnicodeTokenName( token & TOKEN_MASK );
if( tokenname.isEmpty())
tokenname = STR( "???" );
int nmsp = ( token & NMSP_MASK & ~( TAG_OPENING | TAG_CLOSING ));
#if 0 // this is awfully long
OUString namespacename = StaticNamespaceMap::get().count( nmsp ) != 0
? StaticNamespaceMap::get()[ nmsp ] : STR( "???" );
#else
OUString namespacename;
// only few are needed actually
switch( nmsp )
{
case NMSP_officeMath:
namespacename = STR( "m" );
break;
case NMSP_doc:
namespacename = STR( "w" );
break;
default:
namespacename = STR( "?" );
break;
}
#endif
if( token == OPENING( token ))
return STR( "<" ) + namespacename + STR( ":" ) + tokenname + STR ( ">" );
if( token == CLOSING( token ))
return STR( "</" ) + namespacename + STR( ":" ) + tokenname + STR ( ">" );
// just the name itself, not specified whether opening or closing
return namespacename + STR( ":" ) + tokenname;
}
} // namespace } // namespace
bool XmlStream::AttributeList::hasAttribute( int token ) const bool XmlStream::AttributeList::hasAttribute( int token ) const
...@@ -93,8 +136,7 @@ bool XmlStream::AttributeList::attribute( int token, bool def ) const ...@@ -93,8 +136,7 @@ bool XmlStream::AttributeList::attribute( int token, bool def ) const
if( find->second.equalsIgnoreAsciiCaseAscii( "false" ) || find->second.equalsIgnoreAsciiCaseAscii( "off" ) if( find->second.equalsIgnoreAsciiCaseAscii( "false" ) || find->second.equalsIgnoreAsciiCaseAscii( "off" )
|| find->second.equalsIgnoreAsciiCaseAscii( "f" ) || find->second.equalsIgnoreAsciiCaseAscii( "0" )) || find->second.equalsIgnoreAsciiCaseAscii( "f" ) || find->second.equalsIgnoreAsciiCaseAscii( "0" ))
return false; return false;
fprintf( stderr, "Cannot convert \'%s\' to bool.\n", fprintf( stderr, "Cannot convert \'%s\' to bool.\n", CSTR( find->second ));
rtl::OUStringToOString( find->second, RTL_TEXTENCODING_UTF8 ).getStr());
} }
return def; return def;
} }
...@@ -107,8 +149,7 @@ sal_Unicode XmlStream::AttributeList::attribute( int token, sal_Unicode def ) co ...@@ -107,8 +149,7 @@ sal_Unicode XmlStream::AttributeList::attribute( int token, sal_Unicode def ) co
if( find->second.getLength() >= 1 ) if( find->second.getLength() >= 1 )
{ {
if( find->second.getLength() != 1 ) if( find->second.getLength() != 1 )
fprintf( stderr, "Cannot convert \'%s\' to sal_Unicode, stripping.\n", fprintf( stderr, "Cannot convert \'%s\' to sal_Unicode, stripping.\n", CSTR( find->second ));
rtl::OUStringToOString( find->second, RTL_TEXTENCODING_UTF8 ).getStr());
return find->second[ 0 ]; return find->second[ 0 ];
} }
} }
...@@ -162,20 +203,20 @@ void XmlStream::moveToNextTag() ...@@ -162,20 +203,20 @@ void XmlStream::moveToNextTag()
XmlStream::Tag XmlStream::ensureOpeningTag( int token ) XmlStream::Tag XmlStream::ensureOpeningTag( int token )
{ {
return checkTag( OPENING( token ), false, "opening" ); return checkTag( OPENING( token ), false );
} }
XmlStream::Tag XmlStream::checkOpeningTag( int token ) XmlStream::Tag XmlStream::checkOpeningTag( int token )
{ {
return checkTag( OPENING( token ), true, "opening" ); return checkTag( OPENING( token ), true );
} }
void XmlStream::ensureClosingTag( int token ) void XmlStream::ensureClosingTag( int token )
{ {
checkTag( CLOSING( token ), false, "closing" ); checkTag( CLOSING( token ), false );
} }
XmlStream::Tag XmlStream::checkTag( int token, bool optional, const char* txt ) XmlStream::Tag XmlStream::checkTag( int token, bool optional )
{ {
// either it's the following tag, or find it // either it's the following tag, or find it
int savedPos = pos; int savedPos = pos;
...@@ -190,7 +231,7 @@ XmlStream::Tag XmlStream::checkTag( int token, bool optional, const char* txt ) ...@@ -190,7 +231,7 @@ XmlStream::Tag XmlStream::checkTag( int token, bool optional, const char* txt )
pos = savedPos; pos = savedPos;
return Tag(); return Tag();
} }
fprintf( stderr, "Expected %s tag %d not found.\n", txt, token ); fprintf( stderr, "Expected tag %s not found.\n", CSTR( tokenToString( token )));
return Tag(); return Tag();
} }
...@@ -205,17 +246,17 @@ bool XmlStream::recoverAndFindTag( int token ) ...@@ -205,17 +246,17 @@ bool XmlStream::recoverAndFindTag( int token )
{ {
if( currentToken() == OPENING( currentToken())) if( currentToken() == OPENING( currentToken()))
{ {
fprintf( stderr, "Skipping opening tag %d\n", currentToken()); fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken())));
++depth; ++depth;
} }
else if( currentToken() == CLOSING( currentToken())) else if( currentToken() == CLOSING( currentToken()))
{ // TODO debug output without the OPENING/CLOSING bits set { // TODO debug output without the OPENING/CLOSING bits set
fprintf( stderr, "Skipping closing tag %d\n", currentToken()); fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken())));
--depth; --depth;
} }
else else
{ {
fprintf( stderr, "Malformed token %d\n", currentToken()); fprintf( stderr, "Malformed token %d (%s)\n", currentToken(), CSTR( tokenToString( currentToken())));
abort(); abort();
} }
continue; continue;
...@@ -226,7 +267,7 @@ bool XmlStream::recoverAndFindTag( int token ) ...@@ -226,7 +267,7 @@ bool XmlStream::recoverAndFindTag( int token )
return false; // that would be leaving current element, so not found return false; // that would be leaving current element, so not found
if( currentToken() == OPENING( currentToken())) if( currentToken() == OPENING( currentToken()))
{ {
fprintf( stderr, "Skipping opening tag %d\n", currentToken()); fprintf( stderr, "Skipping tag %s\n", CSTR( tokenToString( currentToken())));
++depth; ++depth;
} }
else else
...@@ -247,7 +288,7 @@ void XmlStream::skipElement( int token ) ...@@ -247,7 +288,7 @@ void XmlStream::skipElement( int token )
moveToNextTag(); // and skip it too moveToNextTag(); // and skip it too
return; return;
} }
fprintf( stderr, "Expected end of element %d not found.\n", token ); fprintf( stderr, "Expected end of element %s not found.\n", CSTR( tokenToString( token )));
} }
void XmlStream::handleUnexpectedTag() void XmlStream::handleUnexpectedTag()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment