added extended error info to text parser API; GameConfigs now display better errors
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401821
This commit is contained in:
@@ -508,14 +508,9 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
|
||||
sm_trie_clear(m_pProps);
|
||||
sm_trie_clear(m_pKeys);
|
||||
|
||||
if ((err=textparsers->ParseFile_SMC(path, this, NULL))
|
||||
if ((err=textparsers->ParseSMCFile(path, this, NULL, error, maxlength))
|
||||
!= SMCError_Okay)
|
||||
{
|
||||
if (error && (err != SMCError_Custom))
|
||||
{
|
||||
const char *str = textparsers->GetSMCErrorString(err);
|
||||
snprintf(error, maxlength, "%s", str);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include <assert.h>
|
||||
#include "TextParsers.h"
|
||||
#include "ShareSys.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include "LibrarySys.h"
|
||||
|
||||
TextParsers g_TextParser;
|
||||
ITextParsers *textparsers = &g_TextParser;
|
||||
@@ -155,6 +157,38 @@ SMCError TextParsers::ParseFile_SMC(const char *file, ITextListener_SMC *smc, SM
|
||||
return result;
|
||||
}
|
||||
|
||||
SMCError TextParsers::ParseSMCFile(const char *file,
|
||||
ITextListener_SMC *smc_listener,
|
||||
SMCStates *states,
|
||||
char *buffer,
|
||||
size_t maxsize)
|
||||
{
|
||||
const char *errstr;
|
||||
FILE *fp = fopen(file, "rt");
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
char error[256] = "unknown";
|
||||
if (states != NULL)
|
||||
{
|
||||
states->line = 0;
|
||||
states->col = 0;
|
||||
}
|
||||
g_LibSys.GetPlatformError(error, sizeof(error));
|
||||
UTIL_Format(buffer, maxsize, "File could not be opened: %s", error);
|
||||
return SMCError_StreamOpen;
|
||||
}
|
||||
|
||||
SMCError result = ParseStream_SMC(fp, FileStreamReader, smc_listener, states);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
errstr = GetSMCErrorString(result);
|
||||
UTIL_Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw parsing of streams with helper functions
|
||||
*/
|
||||
|
||||
@@ -64,6 +64,12 @@ public:
|
||||
ITextListener_SMC *smc_listener,
|
||||
SMCStates *states);
|
||||
|
||||
SMCError ParseSMCFile(const char *file,
|
||||
ITextListener_SMC *smc_listener,
|
||||
SMCStates *states,
|
||||
char *buffer,
|
||||
size_t maxsize);
|
||||
|
||||
unsigned int GetUTF8CharBytes(const char *stream);
|
||||
|
||||
const char *GetSMCErrorString(SMCError err);
|
||||
|
||||
Reference in New Issue
Block a user