From 163c004adaf0baf31479da4785610499295c6f6e Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Wed, 19 Mar 2003 20:08:26 +0000 Subject: [PATCH] make flex stuff as reentrant as i can --- lib/calib.c | 6 ++++-- lib/calib_lex.l | 32 ++++++++++++-------------------- lib/calib_yacc.y | 3 +-- lib/libinternal.h | 1 + 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/calib.c b/lib/calib.c index 81d1622..566fd99 100644 --- a/lib/calib.c +++ b/lib/calib.c @@ -32,13 +32,15 @@ static int check_cal_file( comedi_t *dev, struct calibration_file_contents *pars { if( strcmp( comedi_get_driver_name( dev ), parsed_file->driver_name ) ) { - COMEDILIB_DEBUG( 3, "driver name does not match calibration file\n" ); + COMEDILIB_DEBUG( 3, "driver name does not match '%s' from calibration file\n", + parsed_file->driver_name ); return -1; } if( strcmp( comedi_get_board_name( dev ), parsed_file->board_name ) ) { - COMEDILIB_DEBUG( 3, "board name does not match calibration file\n" ); + COMEDILIB_DEBUG( 3, "board name does not match '%s' from calibration file\n", + parsed_file->board_name ); return -1; } diff --git a/lib/calib_lex.l b/lib/calib_lex.l index 65f7326..ee60a7b 100644 --- a/lib/calib_lex.l +++ b/lib/calib_lex.l @@ -24,13 +24,10 @@ USA. */ +#include #include "libinternal.h" #include "calib_yacc.h" -YYLTYPE yylloc; -char string_buf[ 100 ]; -char *string_buf_ptr; - %} %x COMMENT @@ -38,25 +35,20 @@ char *string_buf_ptr; %% -\n { yylloc.first_line++; } +\n { calib_llocp->first_line++; } -"#" BEGIN(COMMENT); -\n { yylloc.first_line++; BEGIN(INITIAL); } +"#" { BEGIN(COMMENT); } +\n { calib_llocp->first_line++; BEGIN(INITIAL); } . -\" { string_buf_ptr = string_buf; BEGIN(STRING); } -\" { - *string_buf_ptr = 0; - BEGIN(INITIAL); - calib_lvalp->sval = string_buf; - return ( T_STRING ); - } -[^\n\"]+ { - char *yptr = yytext; - - while ( *yptr && ( string_buf_ptr - string_buf ) < sizeof( string_buf ) - 1 ) - *string_buf_ptr++ = *yptr++; - } +\" { BEGIN(STRING); } +[^\"]*\" { + if( strlen( yytext ) > 0 ) + yytext[ strlen( yytext ) - 1 ] = 0; + calib_lvalp->sval = yytext; + BEGIN(INITIAL); + return ( T_STRING ); +} driver_name { return ( T_DRIVER_NAME ); } board_name { return ( T_BOARD_NAME ); } diff --git a/lib/calib_yacc.y b/lib/calib_yacc.y index b42f114..ef235b9 100644 --- a/lib/calib_yacc.y +++ b/lib/calib_yacc.y @@ -37,7 +37,6 @@ typedef struct int cal_index; } calib_yyparse_private_t; -FILE *calib_yyin; YY_DECL; static inline calib_yyparse_private_t* priv( calib_yyparse_private_t *parse_arg) @@ -200,10 +199,10 @@ extern struct calibration_file_contents* parse_calibration_file( FILE *file ) { calib_yyparse_private_t priv; - calib_yyin = file; priv.parsed_file = alloc_calib_parse(); if( priv.parsed_file == NULL ) return priv.parsed_file; priv.cal_index = 0; + calib_yyrestart( file ); if( calib_yyparse( &priv ) ) { cleanup_calibration_parse( priv.parsed_file ); diff --git a/lib/libinternal.h b/lib/libinternal.h index 6b1dffc..224d5e1 100644 --- a/lib/libinternal.h +++ b/lib/libinternal.h @@ -186,6 +186,7 @@ struct calibration_file_contents #define YY_DECL int calib_yylex( YYSTYPE *calib_lvalp, YYLTYPE *calib_llocp ) void calib_yyerror( char *s ); int calib_yyparse( void *parse_arg ); +void calib_yyrestart( FILE *input ); struct calibration_file_contents* parse_calibration_file( FILE *file ); void cleanup_calibration_parse( struct calibration_file_contents *parsed_file ); -- 2.26.2