From 43005abc2fc88014f1221009714f9e57e3c75700 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 6 Jan 2007 07:53:56 +0000 Subject: [PATCH] added API for getting error messages --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40277 --- core/CTextParsers.cpp | 27 ++++++++++++++++++++++++++- core/CTextParsers.h | 10 ++++++---- core/interfaces/ITextParsers.h | 11 ++++++++++- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/core/CTextParsers.cpp b/core/CTextParsers.cpp index b0720bad..c653601e 100644 --- a/core/CTextParsers.cpp +++ b/core/CTextParsers.cpp @@ -6,7 +6,7 @@ #include #include "CTextParsers.h" -CTextParsers g_TextParse; +CTextParsers g_TextParser; static int g_ini_chartable1[255] = {0}; static int g_ws_chartable[255] = {0}; @@ -898,3 +898,28 @@ event_failed: return false; } + +const char *CTextParsers::GetSMCErrorString(SMCParseError err) +{ + static const char *s_errors[] = + { + NULL, + "Stream failed to open", + "Stream returned read error", + NULL, + "Un-quoted section has invalid tokens", + "Section declared without header", + "Section declared with unknown tokens", + "Section ending without a matching section beginning", + "Line contained too many invalid tokens", + "Token buffer overflowed", + "A property was declared outside of a section", + }; + + if (err < SMCParse_Okay || err > SMCParse_InvalidProperty1) + { + return NULL; + } + + return s_errors[err]; +} diff --git a/core/CTextParsers.h b/core/CTextParsers.h index 0c0f48d0..aeaf40da 100644 --- a/core/CTextParsers.h +++ b/core/CTextParsers.h @@ -37,17 +37,19 @@ class CTextParsers : public ITextParsers public: CTextParsers(); public: - virtual bool ParseFile_INI(const char *file, + bool ParseFile_INI(const char *file, ITextListener_INI *ini_listener, unsigned int *line, unsigned int *col); - virtual SMCParseError ParseFile_SMC(const char *file, + SMCParseError ParseFile_SMC(const char *file, ITextListener_SMC *smc_listener, unsigned int *line, unsigned int *col); - virtual unsigned int GetUTF8CharBytes(const char *stream); + unsigned int GetUTF8CharBytes(const char *stream); + + const char *GetSMCErrorString(SMCParseError err); private: SMCParseError ParseString_SMC(const char *stream, ITextListener_SMC *smc, @@ -61,6 +63,6 @@ private: }; -extern CTextParsers g_TextParse; +extern CTextParsers g_TextParser; #endif //_INCLUDE_SOURCEMOD_TEXTPARSERS_H_ diff --git a/core/interfaces/ITextParsers.h b/core/interfaces/ITextParsers.h index 0812cdfc..8a583a82 100644 --- a/core/interfaces/ITextParsers.h +++ b/core/interfaces/ITextParsers.h @@ -149,7 +149,7 @@ namespace SourceMod enum SMCParseError { - SMCParse_Okay, //no error + SMCParse_Okay = 0, //no error SMCParse_StreamOpen, //stream failed to open SMCParse_StreamError, //the stream died... somehow SMCParse_Custom, //a custom handler threw an error @@ -292,6 +292,15 @@ namespace SourceMod ITextListener_SMC *smc_listener, unsigned int *line, unsigned int *col) =0; + + /** + * @brief Converts an SMCParseError to a stirng. + * + * @param err SMCParseError. + * @return String error message, or NULL if none. + */ + virtual const char *GetSMCErrorString(SMCParseError err) =0; + public: /** * @brief Returns the number of bytes that a multi-byte character contains in a UTF-8 stream.