core/TextParsers.cpp
changeset 1815 b0de032adc8f
parent 1730 62dd251bb1cd
child 1947 e73a1e51833b
     1.1 --- a/core/TextParsers.cpp	Sat Dec 22 19:35:54 2007 +0000
     1.2 +++ b/core/TextParsers.cpp	Sat Dec 22 19:36:28 2007 +0000
     1.3 @@ -37,6 +37,8 @@
     1.4  #include <assert.h>
     1.5  #include "TextParsers.h"
     1.6  #include "ShareSys.h"
     1.7 +#include "sm_stringutil.h"
     1.8 +#include "LibrarySys.h"
     1.9  
    1.10  TextParsers g_TextParser;
    1.11  ITextParsers *textparsers = &g_TextParser;
    1.12 @@ -155,6 +157,38 @@
    1.13  	return result;
    1.14  }
    1.15  
    1.16 +SMCError TextParsers::ParseSMCFile(const char *file,
    1.17 +								   ITextListener_SMC *smc_listener,
    1.18 +								   SMCStates *states,
    1.19 +								   char *buffer,
    1.20 +								   size_t maxsize)
    1.21 +{
    1.22 +	const char *errstr;
    1.23 +	FILE *fp = fopen(file, "rt");
    1.24 +
    1.25 +	if (fp == NULL)
    1.26 +	{
    1.27 +		char error[256] = "unknown";
    1.28 +		if (states != NULL)
    1.29 +		{
    1.30 +			states->line = 0;
    1.31 +			states->col = 0;
    1.32 +		}
    1.33 +		g_LibSys.GetPlatformError(error, sizeof(error));
    1.34 +		UTIL_Format(buffer, maxsize, "File could not be opened: %s", error);
    1.35 +		return SMCError_StreamOpen;
    1.36 +	}
    1.37 +
    1.38 +	SMCError result = ParseStream_SMC(fp, FileStreamReader, smc_listener, states);
    1.39 +
    1.40 +	fclose(fp);
    1.41 +
    1.42 +	errstr = GetSMCErrorString(result);
    1.43 +	UTIL_Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error");
    1.44 +
    1.45 +	return result;
    1.46 +}
    1.47 +
    1.48  /** 
    1.49   * Raw parsing of streams with helper functions
    1.50   */