//-----------------------------------------------------------------------------
// Copyright © 2006 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/ctools
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// file		intrange.c
//
// program	intrange
//
// purpose	Display the value range, bit size, and signed/unsigned type,
//		for several integer types, to test out the macros:
//			int_bits()
//			int_max()
//			int_min()
//			int_signed()
//
// usage	Shell command
//
// syntax	intrange
//-----------------------------------------------------------------------------
// #define _POSIX_SOURCE
// #define _POSIX_C_SOURCE         200112
// #define _XOPEN_SOURCE           500

#define _GNU_SOURCE

#include <inttypes.h>
#include <stddef.h>
#include <signal.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <wctype.h>

#include <libh/ctools.h>

#define print_type(t)						\
	printf( "%20lld %20llu %ssigned %3u bits %s\n",		\
		(long long) int_min( t ),			\
		(unsigned long long) int_max( t ),		\
		int_is_signed( t ) ? "  " : "un",		\
		type_bits( t ),					\
		#t )

int
main (
    int		argc
    ,
    char * *	argv
)
{
    print_type( char );
    print_type( signed char );
    print_type( unsigned char );
    print_type( signed short );
    print_type( unsigned short );
    print_type( signed int );
    print_type( unsigned int );
    print_type( signed long );
    print_type( unsigned long );
    print_type( signed long long );
    print_type( unsigned long long );

    print_type( int8_t );
    print_type( uint8_t );
    print_type( int16_t );
    print_type( uint16_t );
    print_type( int32_t );
    print_type( uint32_t );
    print_type( int64_t );
    print_type( uint64_t );

    print_type( int_least8_t );
    print_type( uint_least8_t );
    print_type( int_least16_t );
    print_type( uint_least16_t );
    print_type( int_least32_t );
    print_type( uint_least32_t );
    print_type( int_least64_t );
    print_type( uint_least64_t );

    print_type( int_fast8_t );
    print_type( uint_fast8_t );
    print_type( int_fast16_t );
    print_type( uint_fast16_t );
    print_type( int_fast32_t );
    print_type( uint_fast32_t );
    print_type( int_fast64_t );
    print_type( uint_fast64_t );

    print_type( intmax_t );
    print_type( uintmax_t );

    print_type( intptr_t );
    print_type( uintptr_t );

    print_type( ptrdiff_t );
    print_type( size_t );
    print_type( ssize_t );
    print_type( wchar_t );
    print_type( sig_atomic_t );

    print_type( clock_t );

    print_type( wint_t );
    print_type( wctype_t );

    printf( "# these are the sizes for members of struct stat:\n" );
    print_type( dev_t );
    print_type( ino_t );
    print_type( ino64_t );
    print_type( mode_t );
    print_type( nlink_t );
    print_type( uid_t );
//    print_type( uid32_t );
    print_type( gid_t );
//    print_type( gid32_t );
    print_type( off_t );
    print_type( off64_t );
    print_type( blksize_t );
    print_type( blkcnt_t );
    print_type( blkcnt64_t );
    print_type( time_t );


#ifdef __USE_LARGEFILE
    printf( "__USE_LARGEFILE is defined\n" );
#else
    printf( "__USE_LARGEFILE is not defined\n" );
#endif

#ifdef __USE_LARGEFILE64
    printf( "__USE_LARGEFILE64 is defined\n" );
#else
    printf( "__USE_LARGEFILE64 is not defined\n" );
#endif

#ifdef __USE_FILE_OFFSET64
    printf( "__USE_FILE_OFFSET64 is defined\n" );
#else
    printf( "__USE_FILE_OFFSET64 is not defined\n" );
#endif

    return 0;
}

