From cf698b55a053a5ac5a6c114ad2041669d3d49328 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 18 Feb 2005 13:05:17 +0000 Subject: [PATCH] clean up XML error handling --- stepmania/src/ActorUtil.cpp | 8 ++++++-- stepmania/src/CatalogXml.cpp | 2 +- stepmania/src/Profile.cpp | 9 +++++---- stepmania/src/XmlFile.cpp | 18 ++++++++---------- stepmania/src/XmlFile.h | 18 ++++++++---------- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index 11a6c1a55e..e971b27875 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -306,7 +306,9 @@ Actor* ActorUtil::MakeActor( const RageTextureID &ID ) if( sExt=="xml" ) { XNode xml; - xml.LoadFromFile( ID.filename ); + PARSEINFO pi; + if( !xml.LoadFromFile( ID.filename, &pi ) ) + RageException::Throw( pi.error_string ); CString sDir = Dirname( ID.filename ); return LoadFromActorFile( sDir, &xml ); } @@ -357,7 +359,9 @@ Actor* ActorUtil::MakeActor( const RageTextureID &ID ) if( DoesFileExist(sXml) ) { XNode xml; - xml.LoadFromFile( sXml ); + PARSEINFO pi; + if( !xml.LoadFromFile( sXml, &pi ) ) + RageException::Throw( pi.error_string ); return LoadFromActorFile( sDir, &xml ); } else diff --git a/stepmania/src/CatalogXml.cpp b/stepmania/src/CatalogXml.cpp index c08cd7a08b..dc5c45df3b 100644 --- a/stepmania/src/CatalogXml.cpp +++ b/stepmania/src/CatalogXml.cpp @@ -257,7 +257,7 @@ void SaveCatalogXml() xml.AppendChild( "FooterText", FOOTER_TEXT ); xml.AppendChild( "FooterLink", FOOTER_LINK ); - DISP_OPT opts = optDefault; + DISP_OPT opts; opts.stylesheet = CATALOG_XSL; opts.write_tabs = false; xml.SaveToFile(fn, &opts); diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 71567812ca..98d2d24913 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -661,9 +661,10 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur LOG->Trace( "Loading %s", fn.c_str() ); XNode xml; - if( !xml.LoadFromFile( fn ) ) + PARSEINFO pi; + if( !xml.LoadFromFile( fn, &pi ) ) { - LOG->Warn( "Couldn't open file '%s' for reading.", fn.c_str() ); + LOG->Warn( "Error parsing file '%s': %s", fn.c_str(), pi.error_string.c_str() ); return failed_tampered; } LOG->Trace( "Done." ); @@ -741,7 +742,7 @@ bool Profile::SaveStatsXmlToDir( CString sDir, bool bSignData ) const // Save stats.xml CString fn = sDir + STATS_XML; - DISP_OPT opts = optDefault; + DISP_OPT opts; opts.stylesheet = STATS_XSL; opts.write_tabs = false; bool bSaved = xml->SaveToFile(fn, &opts); @@ -1683,7 +1684,7 @@ public: LunaProfile() { LUA->Register( Register ); } static int GetWeightPounds( T* p, lua_State *L ) { lua_pushnumber(L, p->m_iWeightPounds ); return 1; } - static int SetWeightPounds( T* p, lua_State *L ) { p->m_iWeightPounds = FArg(1); return 0; } + static int SetWeightPounds( T* p, lua_State *L ) { p->m_iWeightPounds = IArg(1); return 0; } static int GetGoalType( T* p, lua_State *L ) { lua_pushnumber(L, p->m_GoalType ); return 1; } static int SetGoalType( T* p, lua_State *L ) { p->m_GoalType = (GoalType)IArg(1); return 0; } static int GetGoalCalories( T* p, lua_State *L ) { lua_pushnumber(L, p->m_iGoalCalories ); return 1; } diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index 38d018e0bb..88c5a603aa 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -11,10 +11,10 @@ static const char chXMLTagOpen = '<'; -static const char chXMLTagClose = '>'; -static const char chXMLTagQuestion = '?'; // used in checking for meta tags: "" -static const char chXMLTagPre = '/'; -static const char chXMLEscape = '\\'; // for value field escape +static const char chXMLTagClose = '>'; +static const char chXMLTagQuestion = '?'; // used in checking for meta tags: "" +static const char chXMLTagPre = '/'; +static const char chXMLEscape = '\\'; // for value field escape static const XENTITY x_EntityTable[] = { @@ -25,8 +25,6 @@ static const XENTITY x_EntityTable[] = { { '>', (">"), 4 } }; -PARSEINFO piDefault; -DISP_OPT optDefault; XENTITYS entityDefault((XENTITY*)x_EntityTable, sizeof(x_EntityTable)/sizeof(x_EntityTable[0]) ); // skip spaces @@ -305,7 +303,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ ) xml++; if( *xml == chXMLTagClose ) { - // wel-formed tag + // well-formed tag ++xml; // UGLY: We want to ignore all XML meta tags. So, since the Node we @@ -477,7 +475,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ ) // Coder Date Desc // bro 2002-10-29 //======================================================== -bool XAttr::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ ) const +bool XAttr::GetXML( RageFileBasic &f, DISP_OPT *opt ) const { return f.Write(m_sName + "='" + (opt->reference_value&&opt->entitys?opt->entitys->Entity2Ref(m_sValue):m_sValue) + "' ") != -1; } @@ -491,7 +489,7 @@ bool XAttr::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ ) const // Coder Date Desc // bro 2002-10-29 //======================================================== -bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ ) const +bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt ) const { // tab if( opt && opt->newline ) @@ -1029,7 +1027,7 @@ bool XNode::LoadFromFile( RageFileBasic &f, PARSEINFO *pi ) return false; } this->Load( s, pi ); - return true; + return !pi->error_occur; } bool XNode::SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index 4827ca2da2..3666b6aaaa 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -108,7 +108,6 @@ struct PARSEINFO PARSEINFO() { trim_value = true; entity_value = true; entitys = &entityDefault; xml = NULL; error_occur = false; error_pointer = NULL; error_code = PIE_PARSE_WELFORMED; escape_value = 0; } }; -extern PARSEINFO piDefault; // display optional environment struct DISP_OPT @@ -130,7 +129,6 @@ struct DISP_OPT tab_base = 0; } }; -extern DISP_OPT optDefault; // XAttr : Attribute Implementation struct XAttr @@ -144,7 +142,7 @@ struct XAttr void GetValue(unsigned &out) const; void GetValue(DateTime &out) const; - bool GetXML( RageFileBasic &f, DISP_OPT *opt = &optDefault ) const; + bool GetXML( RageFileBasic &f, DISP_OPT *opt ) const; }; // XMLNode structure @@ -169,14 +167,14 @@ struct XNode XAttrs m_attrs; // attributes // Load/Save XML - char* Load( const char* pszXml, PARSEINFO *pi = &piDefault ); - char* LoadAttributes( const char* pszAttrs, PARSEINFO *pi = &piDefault ); - bool GetXML( RageFileBasic &f, DISP_OPT *opt = &optDefault ) const; + char* Load( const char* pszXml, PARSEINFO *pi ); + char* LoadAttributes( const char* pszAttrs, PARSEINFO *pi ); + bool GetXML( RageFileBasic &f, DISP_OPT *opt ) const; - bool LoadFromFile( const CString &sFile, PARSEINFO *pi = &piDefault ); - bool LoadFromFile( RageFileBasic &f, PARSEINFO *pi = &piDefault ); - bool SaveToFile( const CString &sFile, DISP_OPT *opt = &optDefault ) const; - bool SaveToFile( RageFileBasic &f, DISP_OPT *opt = &optDefault ) const; + bool LoadFromFile( const CString &sFile, PARSEINFO *pi ); + bool LoadFromFile( RageFileBasic &f, PARSEINFO *pi ); + bool SaveToFile( const CString &sFile, DISP_OPT *opt ) const; + bool SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const; // in own attribute list const XAttr *GetAttr( const char* attrname ) const;