/****************************************************************************/
/*	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 externally 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 _CTYPE_H
#define	_CTYPE_H

#ifndef BLC_CTYPE_INLINE

	int		toupper( int c )	__attribute__ ((const));
	int		tolower( int c )	__attribute__ ((const));
	int		isalnum( int c )	__attribute__ ((const));
	int		isalpha( int c )	__attribute__ ((const));
	int		isascii( int c )	__attribute__ ((const));
	int		isblank( int c )	__attribute__ ((const));
	int		iscntrl( int c )	__attribute__ ((const));
	int		isdigit( int c )	__attribute__ ((const));
	int		isgraph( int c )	__attribute__ ((const));
	int		islower( int c )	__attribute__ ((const));
	int		isprint( int c )	__attribute__ ((const));
	int		ispunct( int c )	__attribute__ ((const));
	int		isspace( int c )	__attribute__ ((const));
	int		isupper( int c )	__attribute__ ((const));
	int		isxdigit( int c )	__attribute__ ((const));

#else

	#undef _static

	#if ! defined __GNUC_STDC_INLINE__ && ! defined __GNUC_GNU_INLINE__
		#if defined __STRICT_ANSI__ && __STRICT_ANSI__
			#define __GNUC_STDC_INLINE__ 1
		#else
			#define __GNUC_GNU_INLINE__ 1
		#endif
	#endif
	#if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
		#define _static	static
	#else
		#define	_static extern
	#endif

	extern const unsigned char _blc_ctype[];
	_static int		toupper( int c );
	_static int		tolower( int c );
	_static int		isalnum( int c );
	_static int		isalpha( int c );
	_static int		isascii( int c );
	_static int		isblank( int c );
	_static int		iscntrl( int c );
	_static int		isdigit( int c );
	_static int		isgraph( int c );
	_static int		islower( int c );
	_static int		isprint( int c );
	_static int		ispunct( int c );
	_static int		isspace( int c );
	_static int		isupper( int c );
	_static int		isxdigit( int c );

	_static __inline__ int		isalnum( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 7 );
	}

	_static __inline__ int		isalpha( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 3 );
	}

	_static __inline__ int		isascii( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( 1 );
	}

	_static __inline__ int		isblank( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 8 );
	}

	_static __inline__ int		iscntrl( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 128 );
	}

	_static __inline__ int		isdigit( int c )
	{
		if ( (unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 4 );
	}

	_static __inline__ int		isgraph( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] && ! ( _blc_ctype[ c ] & 136 ) );
	}

	_static __inline__ int		islower( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 2 );
	}

	_static __inline__ int		isprint( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] && ( ( _blc_ctype[ c ] & 128 ) ^ 128 ) );
	}

	_static __inline__ int		ispunct( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 64 );
	}

	_static __inline__ int		isspace( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 16 );
	}

	_static __inline__ int		isupper( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 1 );
	}

	_static __inline__ int		isxdigit( int c )
	{
		if ( ( unsigned int) c > 127 )

			return( 0 );
		else
			return( _blc_ctype[ c ] & 32 );
	}

	_static __inline__ int		tolower( int c )
	{
		return( ( c >= 'A' && c <= 'Z' ) ? c + ( 'a' - 'A' ) : c );
	}

	_static __inline__ int		toupper( int c )
	{
		return( ( c >= 'a' && c <= 'z' ) ? c - ( 'a' - 'A' ) : c );
	}

	#undef _static

#endif

#endif

