<commit_before>%{
/*
    lib/calib_yacc.y
    code for parsing calibration file, generated by bison

    Copyright (C) 2003 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation, version 2.1
    of the License.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
    USA.
*/

#define _GNU_SOURCE

#include <stdio.h>
#include "libinternal.h"
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "calib_yacc.h"
#include "calib_lex.h"

#define YYERROR_VERBOSE
#define YYPARSE_PARAM parse_arg
#define YYLEX_PARAM priv(YYPARSE_PARAM)->yyscanner

enum polynomial_direction
{
	POLYNOMIAL_TO_PHYS,
	POLYNOMIAL_FROM_PHYS
};

typedef struct
{
	yyscan_t yyscanner;
	comedi_calibration_t *parsed_file;
	comedi_caldac_t caldac;
	int cal_index;
	unsigned num_coefficients;
	comedi_polynomial_t polynomial;
} calib_yyparse_private_t;

YY_DECL;

static inline calib_yyparse_private_t* priv( calib_yyparse_private_t *parse_arg)
{
	return parse_arg;
}

static void free_calibration_setting( comedi_calibration_setting_t *setting )
{
	if( setting->channels );
	{
		free( setting->channels );
		setting->channels = NULL;
		setting->num_channels = 0;
	}
	if( setting->ranges );
	{
		free( setting->ranges );
		setting->ranges = NULL;
		setting->num_ranges = 0;
	}
	setting->num_arefs = 0;
	if( setting->caldacs );
	{
		free( setting->caldacs );
		setting->caldacs = NULL;
		setting->num_caldacs = 0;
	}
	if(setting->soft_calibration.to_phys)
	{
		free(setting->soft_calibration.to_phys);
		setting->soft_calibration.to_phys = NULL;
	}
	if(setting->soft_calibration.from_phys)
	{
		free(setting->soft_calibration.from_phys);
		setting->soft_calibration.from_phys = NULL;
	}
}

static void free_settings( comedi_calibration_t *file_contents )
{
	int i;

	if( file_contents->settings == NULL ) return;

	for( i = 0; i < file_contents->num_settings; i++ )
	{
		free_calibration_setting( &file_contents->settings[ i ] );
	}
	file_contents->settings = NULL;
}

static int add_calibration_setting( comedi_calibration_t *file_contents )
{
	comedi_calibration_setting_t *temp;

	temp = realloc( file_contents->settings,
		( file_contents->num_settings + 1 ) * sizeof( comedi_calibration_setting_t ) );
	if( temp == NULL )
	{
		fprintf(stderr, "%s: realloc failed to allocate memory.\n", __FUNCTION__);
		return -1;
	}
	file_contents->settings = temp;
	memset( &file_contents->settings[ file_contents->num_settings ],
		0, sizeof( comedi_calibration_setting_t ) );

	file_contents->num_settings++;
	return 0;
}

static comedi_calibration_setting_t* current_setting( calib_yyparse_private_t *priv )
{
	int retval;

	while( priv->cal_index >= priv->parsed_file->num_settings )
	{
		retval = add_calibration_setting( priv->parsed_file );
		if( retval < 0 ) return NULL;
	}
	return &priv->parsed_file->settings[ priv->cal_index ];
}

static int add_channel( calib_yyparse_private_t *priv, int channel )
{
	int *temp;
	comedi_calibration_setting_t *setting;

	setting = current_setting( priv );
	if( setting == NULL ) return -1;

	temp = realloc( setting->channels, ( setting->num_channels + 1 ) * sizeof( int ) );
	if( temp == NULL )
	{
		fprintf(stderr, "%s: realloc failed to allocate memory.\n", __FUNCTION__);
		return -1;
	}
	setting->channels = temp;
	setting->channels[ setting->num_channels++ ] = channel;
	return 0;
}

static int add_range( calib_yyparse_private_t *priv, int range )
{
	int *temp;
	comedi_calibration_setting_t *setting;

	setting = current_setting( priv );
	if( setting == NULL ) return -1;

	temp = realloc( setting->ranges, ( setting->num_ranges + 1 ) * sizeof( int ) );<commit_msg>Fixed compile warning under gcc 4.1.2<commit_after>%{
/*
    lib/calib_yacc.y
    code for parsing calibration file, generated by bison

    Copyright (C) 2003 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation, version 2.1
    of the License.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
    USA.
*/

#define _GNU_SOURCE

#include <stdio.h>
#include "libinternal.h"
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "calib_yacc.h"
#include "calib_lex.h"

#define YYERROR_VERBOSE
#define YYPARSE_PARAM parse_arg
#define YYLEX_PARAM priv(YYPARSE_PARAM)->yyscanner

enum polynomial_direction
{
	POLYNOMIAL_TO_PHYS,
	POLYNOMIAL_FROM_PHYS
};

typedef struct
{
	yyscan_t yyscanner;
	comedi_calibration_t *parsed_file;
	comedi_caldac_t caldac;
	int cal_index;
	unsigned num_coefficients;
	comedi_polynomial_t polynomial;
} calib_yyparse_private_t;

YY_DECL;

static inline calib_yyparse_private_t* priv( calib_yyparse_private_t *parse_arg)
{
	return parse_arg;
}

static void free_calibration_setting( comedi_calibration_setting_t *setting )
{
	if( setting->channels );
	{
		free( setting->channels );
		setting->channels = NULL;
		setting->num_channels = 0;
	}
	if( setting->ranges );
	{
		free( setting->ranges );
		setting->ranges = NULL;
		setting->num_ranges = 0;
	}
	setting->num_arefs = 0;
	if( setting->caldacs );
	{
		free( setting->caldacs );
		setting->caldacs = NULL;
		setting->num_caldacs = 0;
	}
	if(setting->soft_calibration.to_phys)
	{
		free(setting->soft_calibration.to_phys);
		setting->soft_calibration.to_phys = NULL;
	}
	if(setting->soft_calibration.from_phys)
	{
		free(setting->soft_calibration.from_phys);
		setting->soft_calibration.from_phys = NULL;
	}
}

static void free_settings( comedi_calibration_t *file_contents )
{
	int i;

	if( file_contents->settings == NULL ) return;

	for( i = 0; i < file_contents->num_settings; i++ )
	{
		free_calibration_setting( &file_contents->settings[ i ] );
	}
	file_contents->settings = NULL;
}

static int add_calibration_setting( comedi_calibration_t *file_contents )
{
	comedi_calibration_setting_t *temp;

	temp = realloc( file_contents->settings,
		( file_contents->num_settings + 1 ) * sizeof( comedi_calibration_setting_t ) );
	if( temp == NULL )
	{
		fprintf(stderr, "%s: realloc failed to allocate memory.\n", __FUNCTION__);
		return -1;
	}
	file_contents->settings = temp;
	memset( &file_contents->settings[ file_contents->num_settings ],
		0, sizeof( comedi_calibration_setting_t ) );

	file_contents->num_settings++;
	return 0;
}

static comedi_calibration_setting_t* current_setting( calib_yyparse_private_t *priv )
{
	int retval;

	while( priv->cal_index >= priv->parsed_file->num_settings )
	{
		retval = add_calibration_setting( priv->parsed_file );
		if( retval < 0 ) return NULL;
	}
	return &priv->parsed_file->settings[ priv->cal_index ];
}

static int add_channel( calib_yyparse_private_t *priv, int channel )
{
	unsigned *temp;
	comedi_calibration_setting_t *setting;

	setting = current_setting( priv );
	if( setting == NULL ) return -1;

	temp = realloc( setting->channels, ( setting->num_channels + 1 ) * sizeof(unsigned) );
	if( temp == NULL )
	{
		fprintf(stderr, "%s: realloc failed to allocate memory.\n", __FUNCTION__);
		return -1;
	}
	setting->channels = temp;
	setting->channels[ setting->num_channels++ ] = channel;
	return 0;
}

static int add_range( calib_yyparse_private_t *priv, int range )
{
	unsigned *temp;
	comedi_calibration_setting_t *setting;

	setting = current_setting( priv );
	if( setting == NULL ) return -1;

	temp = realloc( setting->ranges, ( setting->num_ranges + 1 ) * sizeof(unsigned) );
{'fraction_non_alphanumeric': 0.10691222195646974, 'fraction_numerical': 0.00896914613728773, 'mean_word_length': 4.567909454061252, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6564444', 'n_tokens_mistral': 2974, 'n_tokens_neox': 2863, 'n_words': 737}