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:
David Anderson
2007-12-22 19:36:28 +00:00
parent c3456b8804
commit f8f5a6a888
4 changed files with 57 additions and 7 deletions
+34
View File
@@ -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
*/