#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 ) )
{
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;
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;
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;
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;
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;
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 )
{
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;
}
#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;
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;
}
%}
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 ']'
;
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;
}
| channel ',' channels_array
;
- channel: T_NUMBER { add_channel( &file_contents, $1 ); }
+ channel: T_NUMBER { add_channel( parsed_file, $1 ); }
;
ranges_array: /* empty */
| range ',' ranges_array
;
- range: T_NUMBER { add_range( &file_contents, $1 ); }
+ range: T_NUMBER { add_range( parsed_file, $1 ); }
;
arefs_array: /* empty */
| aref ',' arefs_array
;
- aref: T_NUMBER { add_aref( &file_contents, $1 ); }
+ aref: T_NUMBER { add_aref( parsed_file, $1 ); }
;
caldacs_array: /* empty */
| '{' caldac '}' ',' caldacs_array
;
- caldac: /* empty */ { add_caldac( &file_contents, caldac ); }
+ caldac: /* empty */ { add_caldac( parsed_file, caldac ); }
| caldac_element
| caldac_element ',' caldac
;