Moved contents of YY_USER_INIT definition into a separate function which

is now called by YY_USER_INIT (better readability)
This commit is contained in:
Thomas Jensen
1999-08-20 19:51:12 +00:00
parent 29143b73e9
commit f180fca44c

View File

@ -4,7 +4,7 @@
* Date created: March 15, 1999 (Monday, 17:16h) * Date created: March 15, 1999 (Monday, 17:16h)
* Author: Copyright (C) 1999 Thomas Jensen * Author: Copyright (C) 1999 Thomas Jensen
* tsjensen@stud.informatik.uni-erlangen.de * tsjensen@stud.informatik.uni-erlangen.de
* Version: $Id: lexer.l,v 1.15 1999/08/18 15:40:10 tsjensen Exp tsjensen $ * Version: $Id: lexer.l,v 1.16 1999/08/18 18:23:41 tsjensen Exp tsjensen $
* Language: lex (ANSI C) * Language: lex (ANSI C)
* Purpose: flex lexical analyzer for boxes configuration files * Purpose: flex lexical analyzer for boxes configuration files
* *
@ -26,6 +26,12 @@
* Revision History: * Revision History:
* *
* $Log: lexer.l,v $ * $Log: lexer.l,v $
* Revision 1.16 1999/08/18 18:23:41 tsjensen
* Declared yyerrcnt to be static
* Added YY_USER_INIT macro to set the input buffer size to the config file
* size (plus a bit). This is supposed to be a workaround for the REJECT
* problem.
*
* Revision 1.15 1999/08/18 15:40:10 tsjensen * Revision 1.15 1999/08/18 15:40:10 tsjensen
* Added %options never-interactive and caseless * Added %options never-interactive and caseless
* Added code for DELIMITER statements * Added code for DELIMITER statements
@ -103,7 +109,7 @@
static const char rcsid_lexer_l[] = static const char rcsid_lexer_l[] =
"$Id: lexer.l,v 1.15 1999/08/18 15:40:10 tsjensen Exp tsjensen $"; "$Id: lexer.l,v 1.16 1999/08/18 18:23:41 tsjensen Exp tsjensen $";
int yylineno = 1; int yylineno = 1;
@ -114,35 +120,29 @@ static char sesc = '\\';
/* /*
* Since this scanner must use REJECT in order to be able to process the * User-defined initializations for the lexer
* string delimiter commands, it cannot dynamically enlarge its input
* buffer to accomodate larger tokens. Thus, we simply set the buffer size
* to the input file size plus 10 bytes margin-of-error.
*/ */
#define YY_USER_INIT { \ static void inflate_inbuf();
struct stat sinf; \ #define YY_USER_INIT inflate_inbuf()
\
if (stat(yyfilename, &sinf)) { \
perror (PROJECT); \
exit (EXIT_FAILURE); \
} \
yy_delete_buffer (YY_CURRENT_BUFFER); \
YY_CURRENT_BUFFER = yy_create_buffer (yyin, sinf.st_size+10); \
}
%} %}
%option nounput %option nounput
%option noyywrap %option noyywrap
%option never-interactive %option never-interactive
%option caseless %option caseless
%x SAMPLE %x SAMPLE
%x SPEEDMODE %x SPEEDMODE
%x DELWORD %x DELWORD
%s SHAPES %s SHAPES
%s ELASTIC %s ELASTIC
PWORD [a-zA-Z<><5A><EFBFBD><EFBFBD><EFBFBD><EFBFBD>][a-zA-Z0-9\-_<><5F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]* PWORD [a-zA-Z<><5A><EFBFBD><EFBFBD><EFBFBD><EFBFBD>][a-zA-Z0-9\-_<><5F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]*
PWHITE [\n \r\t] PWHITE [\n \r\t]
PBOX Box PBOX Box
@ -152,6 +152,7 @@ SDELIM [\"~\'`!@\%\&\*=:;<>\?/|\.\\]
%% %%
<DELWORD,SHAPES,ELASTIC,INITIAL>[ \r\t] /* ignore whitespace */ <DELWORD,SHAPES,ELASTIC,INITIAL>[ \r\t] /* ignore whitespace */
<DELWORD,SHAPES,ELASTIC,INITIAL>\n ++yylineno; <DELWORD,SHAPES,ELASTIC,INITIAL>\n ++yylineno;
@ -444,6 +445,30 @@ Delimiter|Delim {
%% %%
static void inflate_inbuf()
/*
* User-defined initializations for the lexer.
*
* Since this scanner must use REJECT in order to be able to process the
* string delimiter commands, it cannot dynamically enlarge its input
* buffer to accomodate larger tokens. Thus, we simply set the buffer size
* to the input file size plus 10 bytes margin-of-error.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
{
struct stat sinf;
if (stat(yyfilename, &sinf)) {
perror (PROJECT);
exit (EXIT_FAILURE);
}
yy_delete_buffer (YY_CURRENT_BUFFER);
YY_CURRENT_BUFFER = yy_create_buffer (yyin, sinf.st_size+10);
}
void begin_speedmode() void begin_speedmode()
{ {
#ifdef LEXER_DEBUG #ifdef LEXER_DEBUG