* Provide an abstraction of YY_INPUT so that we have a single definition which we can use in multiple lexers which can read from both in-memory buffers as well as PhysicsFS files
* Utilise this new version of YY_INPUT in script_parser and script_lexer git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5008 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
2bc35a5714
commit
701f65469c
|
@ -13,11 +13,12 @@ CLEANFILES = resource_lexer.lex.c strres_lexer.lex.c resource_parser.tab.c strre
|
|||
|
||||
noinst_LIBRARIES = libframework.a
|
||||
noinst_HEADERS = configfile.h cursors.h debug.h frame.h frameint.h \
|
||||
frameresource.h input.h listmacs.h math-help.h printf_ext.h resly.h \
|
||||
strlfuncs.h strnlen1.h strres.h strresly.h treap.h treapint.h trig.h \
|
||||
types.h tagfile.h i18n.h file.h physfs_ext.h
|
||||
frameresource.h input.h lexer_input.h listmacs.h math-help.h \
|
||||
printf_ext.h resly.h strlfuncs.h strnlen1.h strres.h strresly.h treap.h \
|
||||
treapint.h trig.h types.h tagfile.h i18n.h file.h physfs_ext.h
|
||||
|
||||
libframework_a_SOURCES = SDL_framerate.c configfile.c cursors.c cursors16.c \
|
||||
cursors32.c debug.c frame.c frameresource.c input.c printf_ext.c \
|
||||
resource_lexer.lex.c resource_parser.tab.c strnlen1.c strres.c \
|
||||
strres_lexer.lex.c strres_parser.tab.c treap.c trig.c tagfile.c i18n.c
|
||||
cursors32.c debug.c frame.c frameresource.c input.c lexer_input.c \
|
||||
printf_ext.c resource_lexer.lex.c resource_parser.tab.c strnlen1.c \
|
||||
strres.c strres_lexer.lex.c strres_parser.tab.c treap.c trig.c \
|
||||
tagfile.c i18n.c
|
||||
|
|
|
@ -10,6 +10,7 @@ SRC=configfile.c \
|
|||
frameresource.c \
|
||||
input.c \
|
||||
i18n.c \
|
||||
lexer_input.c \
|
||||
printf_ext.c \
|
||||
resource_parser.tab.c \
|
||||
resource_lexer.lex.c \
|
||||
|
|
|
@ -201,6 +201,10 @@
|
|||
RelativePath=".\input.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lexer_input.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\printf_ext.c"
|
||||
>
|
||||
|
@ -309,6 +313,10 @@
|
|||
RelativePath=".\input.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lexer_input.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\listmacs.h"
|
||||
>
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
#include "frame.h"
|
||||
#include "lexer_input.h"
|
||||
|
||||
int lexer_input(lexerinput_t* input, char* buf, size_t max_size, int nullvalue)
|
||||
{
|
||||
switch (input->type)
|
||||
{
|
||||
case LEXINPUT_PHYSFS:
|
||||
if (PHYSFS_eof(input->input.physfsfile))
|
||||
{
|
||||
buf[0] = EOF;
|
||||
return nullvalue;
|
||||
}
|
||||
else
|
||||
{
|
||||
int result = PHYSFS_read(input->input.physfsfile, buf, 1, max_size);
|
||||
if (result == -1)
|
||||
{
|
||||
buf[0] = EOF;
|
||||
return nullvalue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
|
||||
case LEXINPUT_BUFFER:
|
||||
if (input->input.buffer.begin != input->input.buffer.end)
|
||||
{
|
||||
buf[0] = *input->input.buffer.begin++;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf[0] = EOF;
|
||||
return nullvalue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ASSERT(!"Invalid input type!", "Invalid input type used for lexer (numeric value: %u)", (unsigned int)input->type);
|
||||
return nullvalue;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef __INCLUDED_LIB_FRAMEWORK_LEXER_INPUT_H__
|
||||
#define __INCLUDED_LIB_FRAMEWORK_LEXER_INPUT_H__
|
||||
|
||||
#include <physfs.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
PHYSFS_file* physfsfile;
|
||||
struct
|
||||
{
|
||||
const char* begin;
|
||||
const char* end;
|
||||
} buffer;
|
||||
} input;
|
||||
|
||||
enum
|
||||
{
|
||||
LEXINPUT_PHYSFS,
|
||||
LEXINPUT_BUFFER,
|
||||
} type;
|
||||
} lexerinput_t;
|
||||
|
||||
#ifdef YY_EXTRA_TYPE
|
||||
# undef YY_EXTRA_TYPE
|
||||
#endif
|
||||
|
||||
#define YY_EXTRA_TYPE lexerinput_t *
|
||||
|
||||
extern int lexer_input(lexerinput_t* input, char* buf, size_t max_size, int nullvalue);
|
||||
|
||||
#define YY_INPUT(buf, result, max_size) \
|
||||
do \
|
||||
{ \
|
||||
result = lexer_input(yyextra, buf, max_size, YY_NULL); \
|
||||
} while(0)
|
||||
|
||||
#endif // __INCLUDED_LIB_FRAMEWORK_LEXER_INPUT_H__
|
|
@ -47,21 +47,7 @@ static UDWORD currText=0;
|
|||
// Note if we are in a comment
|
||||
static BOOL inComment = false;
|
||||
|
||||
/* Handle to the input file */
|
||||
#define YY_EXTRA_TYPE PHYSFS_file *
|
||||
|
||||
#define YY_INPUT(buf,result,max_size) \
|
||||
if (PHYSFS_eof(yyextra)) \
|
||||
{ \
|
||||
buf[0] = EOF; result = YY_NULL; \
|
||||
} \
|
||||
else { \
|
||||
result = PHYSFS_read(yyextra, buf, 1, max_size); \
|
||||
if (result == -1) \
|
||||
{ \
|
||||
buf[0] = EOF; result = YY_NULL; \
|
||||
} \
|
||||
}
|
||||
#include "lib/framework/lexer_input.h"
|
||||
|
||||
#ifndef yyextra
|
||||
# define yyextra yyget_extra()
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include "lib/sound/audio.h"
|
||||
|
||||
#include "scriptvals.h"
|
||||
#include "lib/framework/lexer_input.h"
|
||||
#include "scriptvals_parser.tab.h"
|
||||
#include "scriptvals_lexer.lex.h"
|
||||
#include "src/scripttabs.h"
|
||||
#include "src/objects.h"
|
||||
|
@ -830,7 +832,12 @@ BOOL scrvLookUpArray(const char *pIdent, UDWORD *pIndex)
|
|||
// Load a script value file
|
||||
BOOL scrvLoad(PHYSFS_file* fileHandle)
|
||||
{
|
||||
scrv_set_extra(fileHandle);
|
||||
lexerinput_t input;
|
||||
|
||||
input.type = LEXINPUT_PHYSFS;
|
||||
input.input.physfsfile = fileHandle;
|
||||
|
||||
scrv_set_extra(&input);
|
||||
|
||||
if (scrv_parse() != 0)
|
||||
{
|
||||
|
|
|
@ -354,6 +354,19 @@
|
|||
<Option target="DBGWindows" />
|
||||
<Option target="NDBGWindows" />
|
||||
</Unit>
|
||||
<Unit filename="lib/framework/lexer_input.c">
|
||||
<Option compilerVar="CC" />
|
||||
<Option target="DBGUnix" />
|
||||
<Option target="NDBGUnix" />
|
||||
<Option target="DBGWindows" />
|
||||
<Option target="NDBGWindows" />
|
||||
</Unit>
|
||||
<Unit filename="lib/framework/lexer_input.h">
|
||||
<Option target="DBGUnix" />
|
||||
<Option target="NDBGUnix" />
|
||||
<Option target="DBGWindows" />
|
||||
<Option target="NDBGWindows" />
|
||||
</Unit>
|
||||
<Unit filename="lib/framework/listmacs.h">
|
||||
<Option target="DBGUnix" />
|
||||
<Option target="NDBGUnix" />
|
||||
|
|
Loading…
Reference in New Issue