1
1

Fix a problem where internal flex buffers were not getting properly

reset when scanning a second file.

This commit was SVN r3158.
Этот коммит содержится в:
Jeff Squyres 2004-10-15 11:42:54 +00:00
родитель fceb5c122f
Коммит 51b2da657a
3 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -31,6 +31,7 @@ int mca_base_parse_paramfile(const char *paramfile)
}
mca_base_parse_done = false;
mca_base_param_init_buffer(mca_base_yyin);
while (!mca_base_parse_done) {
val = mca_base_yylex();
switch (val) {

Просмотреть файл

@ -20,7 +20,8 @@
#include <stdio.h>
extern int mca_base_yylex(void);
int mca_base_yylex(void);
int mca_base_param_init_buffer(FILE *file);
extern FILE *mca_base_yyin;
extern bool mca_base_parse_done;

Просмотреть файл

@ -62,8 +62,27 @@ static int finish_parsing(void)
return YY_NULL;
}
static int mca_base_yywrap(void)
{
mca_base_parse_done = true;
return 1;
}
/*
* Ensure that we have a valid yybuffer to use. Specifically, if this
* scanner is invoked a second time, finish_parsing() (above) will
* have been executed, and the current buffer will have been freed.
* Flex doesn't recognize this fact because as far as it's concerned,
* its internal state was already initialized, so it thinks it should
* have a valid buffer. Hence, here we ensure to give it a valid
* buffer.
*/
int mca_base_param_init_buffer(FILE *file)
{
YY_BUFFER_STATE buf = yy_create_buffer(file, YY_BUF_SIZE);
yy_switch_to_buffer(buf);
return 0;
}