/****************************************************************************/
/*	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		*/
/*	This software is released under the GNU General Public License, version	*/
/*	3, with the exemptions that 1) the header files installed by this 	 	*/
/*	package can be included in closed-source code and 2) the libraries		*/
/*	built by this package can be statically linked into a closed-source 	*/
/*	binary. See the file LICENSE for the details.							*/
/*	This software is provided "AS IS", without any warranty or guarantee.	*/
/*	By using this software you acknowledge that neither Bendor Research nor	*/
/*	any of its personnel or affiliates can be held liable for any damages,	*/
/*	including, but not limited to, loss of business, loss of money, loss of */
/*	life, loss or reputation, arising out of this software being faulty or	*/
/*	not performing as advertised, even if Bendor Research was aware of such	*/
/*	faults in the software. You use this software at your own risk, any and */
/*	all liabilities that arise out of your using this software are strictly	*/
/*	yours.																	*/
/****************************************************************************/

#ifndef _BLC_STDLIB_H
#define _BLC_STDLIB_H

#include <stdlib.h>

/*
*	Character stream to integer conversion related types
*/

typedef struct s_blc_s2i *BLC_S2IP;

typedef	int	(*BLC_S2IF)( BLC_S2IP, int c );

typedef struct s_blc_s2i {

	BLC_S2IF		func;			// State function
	unsigned int	hval;			// Upper 32 bits of the result
	unsigned int	lval;			// Lower 32 bits of the result
	unsigned char	base;			// Conversion base
	unsigned char	fneg;			// Negative flag
	unsigned char	fovf;			// Overflow flag
	unsigned char	fnum;			// Don't remember FIXME

} BLC_S2I;

/*
*	Charater stream to integer conversion initialisation.
*	See the init functin's comments for details on usage.
*/

void	_blc_StrToInt( BLC_S2I *stat, int base );

/*
*	Character stream to float conversion related types
*/

typedef struct s_blc_s2f *BLC_S2FP;

typedef	int	(*BLC_S2FF)( BLC_S2FP, int c );

typedef struct s_blc_s2f {

	BLC_S2FF	func;				// State function

	union {

		double		numb;			// The final result
		unsigned	accu[ 3 ];		// Temporary 96-bit accumulator

	} data;							// Data

	int		expo;					// Exponent
	short	last;					// Number of discarded valuable digits
	short	flag;					// Varoious flags

} BLC_S2F;

/*
*	Charater stream to float conversion initialisation.
*	See the init functin's comments for details on usage.
*/

void	_blc_StrToFlt( BLC_S2F *stat );

/*
*	Integer to string conversion internal functions
*/

int		_blc_itoa10( char *buff, unsigned long x, int z );
int		_blc_itoa2n( char *buff, unsigned long numb,
					 int base, int uppc, int lead );

#endif

