a couple not so important tweaks to calibration file parsing, before

I leave it
This commit is contained in:
Frank Mori Hess 2003-03-05 16:55:14 +00:00
parent fac040f462
commit 6dcb08e06b
3 changed files with 48 additions and 37 deletions

View file

@ -28,7 +28,7 @@
#include <comedilib.h>
#include <libinternal.h>
static int check_cal_file( comedi_t *dev, const struct calibration_file_contents *parsed_file )
static int check_cal_file( comedi_t *dev, struct calibration_file_contents *parsed_file )
{
if( strcmp( comedi_get_driver_name( dev ), parsed_file->driver_name ) )
{
@ -45,7 +45,7 @@ static int check_cal_file( comedi_t *dev, const struct calibration_file_contents
return 0;
}
static inline int valid_channel( const struct calibration_file_contents *parsed_file,
static inline int valid_channel( struct calibration_file_contents *parsed_file,
unsigned int cal_index, unsigned int channel )
{
int num_channels, i;
@ -61,7 +61,7 @@ static inline int valid_channel( const struct calibration_file_contents *parsed_
return 0;
}
static inline int valid_range( const struct calibration_file_contents *parsed_file,
static inline int valid_range( struct calibration_file_contents *parsed_file,
unsigned int cal_index, unsigned int range )
{
int num_ranges, i;
@ -77,7 +77,7 @@ static inline int valid_range( const struct calibration_file_contents *parsed_fi
return 0;
}
static inline int valid_aref( const struct calibration_file_contents *parsed_file,
static inline int valid_aref( struct calibration_file_contents *parsed_file,
unsigned int cal_index, unsigned int aref )
{
int num_arefs, i;
@ -93,7 +93,7 @@ static inline int valid_aref( const struct calibration_file_contents *parsed_fil
return 0;
}
static int find_calibration( const struct calibration_file_contents *parsed_file,
static int find_calibration( struct calibration_file_contents *parsed_file,
unsigned int subdev, unsigned int channel, unsigned int range, unsigned int aref )
{
int num_cals, i;
@ -113,7 +113,7 @@ static int find_calibration( const struct calibration_file_contents *parsed_file
return i;
}
static int set_calibration( comedi_t *dev, const struct calibration_file_contents *parsed_file,
static int set_calibration( comedi_t *dev, struct calibration_file_contents *parsed_file,
unsigned int cal_index )
{
int i, retval, num_caldacs;
@ -143,7 +143,7 @@ int comedi_apply_calibration( comedi_t *dev, unsigned int subdev, unsigned int c
int retval;
int cal_index;
FILE *cal_file;
const struct calibration_file_contents *parsed_file;
struct calibration_file_contents *parsed_file;
if( cal_file_path )
{
@ -172,21 +172,21 @@ int comedi_apply_calibration( comedi_t *dev, unsigned int subdev, unsigned int c
retval = check_cal_file( dev, parsed_file );
if( retval < 0 )
{
cleanup_calibration_parse();
cleanup_calibration_parse( parsed_file );
return retval;
}
cal_index = find_calibration( parsed_file, subdev, channel, range, aref );
if( cal_index < 0 )
{
cleanup_calibration_parse();
cleanup_calibration_parse( parsed_file );
return cal_index;
}
retval = set_calibration( dev, parsed_file, cal_index );
if( retval < 0 );
{
cleanup_calibration_parse();
cleanup_calibration_parse( parsed_file );
return retval;
}

View file

@ -28,7 +28,7 @@
#define YYERROR_VERBOSE
struct calibration_file_contents file_contents;
struct calibration_file_contents *parsed_file;
static struct caldac_setting caldac;
static int cal_index;
FILE *calib_yyin;
@ -157,33 +157,44 @@ static int add_caldac( struct calibration_file_contents *file_contents,
return 0;
}
static void init_calib_parse( void )
static struct calibration_file_contents* alloc_calib_parse( void )
{
memset( &file_contents, 0, sizeof( file_contents ) );
cal_index = 0;
struct calibration_file_contents *file_contents;
file_contents = malloc( sizeof( *file_contents ) );
if( file_contents == NULL ) return file_contents;
memset( file_contents, 0, sizeof( *file_contents ) );
return file_contents;
}
extern void cleanup_calibration_parse( void )
extern void cleanup_calibration_parse( struct calibration_file_contents *file_contents )
{
if( file_contents.driver_name )
if( file_contents->driver_name )
{
free( file_contents.driver_name );
file_contents.driver_name = NULL;
free( file_contents->driver_name );
file_contents->driver_name = NULL;
}
if( file_contents.board_name )
if( file_contents->board_name )
{
free( file_contents.board_name );
file_contents.board_name = NULL;
free( file_contents->board_name );
file_contents->board_name = NULL;
}
free_calibrations( &file_contents );
free_calibrations( file_contents );
free( file_contents );
file_contents = NULL;
}
extern const struct calibration_file_contents* parse_calibration_file( FILE *file )
extern struct calibration_file_contents* parse_calibration_file( FILE *file )
{
calib_yyin = file;
init_calib_parse();
if( calib_yyparse() ) return NULL;
return &file_contents;
parsed_file = alloc_calib_parse();
if( parsed_file == NULL ) return parsed_file;
cal_index = 0;
if( calib_yyparse() )
{
cleanup_calibration_parse( parsed_file );
return NULL;
}
return parsed_file;
}
%}
@ -218,13 +229,13 @@ extern const struct calibration_file_contents* parse_calibration_file( FILE *fil
hash_element: T_DRIVER_NAME T_ASSIGN T_STRING
{
if( file_contents.driver_name != NULL ) YYABORT;
file_contents.driver_name = strdup( $3 );
if( parsed_file->driver_name != NULL ) YYABORT;
parsed_file->driver_name = strdup( $3 );
}
| T_BOARD_NAME T_ASSIGN T_STRING
{
if( file_contents.board_name != NULL ) YYABORT;
file_contents.board_name = strdup( $3 );
if( parsed_file->board_name != NULL ) YYABORT;
parsed_file->board_name = strdup( $3 );
}
| T_CALIBRATIONS T_ASSIGN '[' calibrations_array ']'
;
@ -242,7 +253,7 @@ extern const struct calibration_file_contents* parse_calibration_file( FILE *fil
calibration_setting_element: T_SUBDEVICE T_ASSIGN T_NUMBER
{
struct calibration_setting *setting;
setting = current_setting( &file_contents );
setting = current_setting( parsed_file );
if( setting == NULL ) YYABORT;
setting->subdevice = $3;
}
@ -257,7 +268,7 @@ extern const struct calibration_file_contents* parse_calibration_file( FILE *fil
| channel ',' channels_array
;
channel: T_NUMBER { add_channel( &file_contents, $1 ); }
channel: T_NUMBER { add_channel( parsed_file, $1 ); }
;
ranges_array: /* empty */
@ -265,7 +276,7 @@ extern const struct calibration_file_contents* parse_calibration_file( FILE *fil
| range ',' ranges_array
;
range: T_NUMBER { add_range( &file_contents, $1 ); }
range: T_NUMBER { add_range( parsed_file, $1 ); }
;
arefs_array: /* empty */
@ -273,7 +284,7 @@ extern const struct calibration_file_contents* parse_calibration_file( FILE *fil
| aref ',' arefs_array
;
aref: T_NUMBER { add_aref( &file_contents, $1 ); }
aref: T_NUMBER { add_aref( parsed_file, $1 ); }
;
caldacs_array: /* empty */
@ -281,7 +292,7 @@ extern const struct calibration_file_contents* parse_calibration_file( FILE *fil
| '{' caldac '}' ',' caldacs_array
;
caldac: /* empty */ { add_caldac( &file_contents, caldac ); }
caldac: /* empty */ { add_caldac( parsed_file, caldac ); }
| caldac_element
| caldac_element ',' caldac
;

View file

@ -186,8 +186,8 @@ struct calibration_file_contents
int calib_yylex( void );
void calib_yyerror( char *s );
int calib_yyparse( void );
const struct calibration_file_contents* parse_calibration_file( FILE *file );
void cleanup_calibration_parse( void );
struct calibration_file_contents* parse_calibration_file( FILE *file );
void cleanup_calibration_parse( struct calibration_file_contents *parsed_file );
#endif