?RCS: $Id: intsize.U,v 3.0.1.2 1997/02/28 15:55:26 ram Exp $
?RCS:
?RCS: Copyright (c) 1991-1993, Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic License,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 3.0.
?RCS:
?RCS: $Log: intsize.U,v $
?RCS: Revision 3.0.1.2  1997/02/28  15:55:26  ram
?RCS: patch61: avoid prompting the user if the test runs ok
?RCS: patch61: moved code from longsize.U into there
?RCS: patch61: new tests for shortsize as well
?RCS:
?RCS: Revision 3.0.1.1  1994/10/29  16:21:06  ram
?RCS: patch36: added ?F: line for metalint file checking
?RCS:
?RCS: Revision 3.0  1993/08/18  12:08:52  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?MAKE:intsize intmaxsize longsize shortsize: Compile Myread cat run i_stdlib i_stdint rm_try
?MAKE:	-pick add $@ %<
?S:intsize:
?S:	This variable contains the value of the INTSIZE symbol, which
?S:	indicates to the C program how many bytes there are in an int.
?S:.
?S:intmaxsize:
?S:	This variable contains the value of the INTMAXSIZE symbol, which
?S:	indicates to the C program how many bytes there are in an intmax_t.
?S:.
?S:longsize:
?S:	This variable contains the value of the LONGSIZE symbol, which
?S:	indicates to the C program how many bytes there are in a long.
?S:.
?S:shortsize:
?S:	This variable contains the value of the SHORTSIZE symbol which
?S:	indicates to the C program how many bytes there are in a short.
?S:.
?C:INTSIZE:
?C:	This symbol contains the value of sizeof(int) so that the C
?C:	preprocessor can make decisions based on it.
?C:.
?C:LONGSIZE:
?C:	This symbol contains the value of sizeof(long) so that the C
?C:	preprocessor can make decisions based on it.
?C:.
?C:SHORTSIZE:
?C:	This symbol contains the value of sizeof(short) so that the C
?C:	preprocessor can make decisions based on it.
?C:.
?C:INTMAXSIZE:
?C:	This symbol contains the value of sizeof(intmax_t) so that the C
?C:	preprocessor can make decisions based on it.
?C:.
?H:#define INTSIZE $intsize		/**/
?H:#define LONGSIZE $longsize		/**/
?H:#define SHORTSIZE $shortsize		/**/
?H:#define INTMAXSIZE $intmaxsize		/**/
?H:.
?F:!try
: check for lengths of integral types
echo " "
case "$intsize" in
'')
	echo "Checking to see how big your integers are..." >&4
	$cat >try.c <<EOCP
#include <stdio.h>
#$i_stdlib I_STDLIB
#ifdef I_STDLIB
#include <stdlib.h>
#endif
#$i_stdint I_STDINT
#ifdef I_STDINT
#include <stdint.h>
#endif
#include <stdio.h>
int main()
{
@if INTSIZE || intsize
	printf("intsize=%d;\n", (int)sizeof(int));
@end
@if LONGSIZE || longsize
	printf("longsize=%d;\n", (int)sizeof(long));
@end
@if SHORTSIZE || shortsize
	printf("shortsize=%d;\n", (int)sizeof(short));
@end
?X:@if INTMAXSIZE || intmaxsize
	printf("intmaxsize=%d;\n", (int)sizeof(intmax_t));
?X:@end
	exit(0);
}
EOCP
	set try
	if eval $compile_ok && $run ./try > /dev/null; then
		eval `$run ./try`
@if INTSIZE || intsize
		echo "Your integers are $intsize bytes long."
@end
@if LONGSIZE || longsize
		echo "Your long integers are $longsize bytes long."
@end
@if SHORTSIZE || shortsize
		echo "Your short integers are $shortsize bytes long."
@end
?X:@if INTMAXSIZE || intmaxsize
		echo "Your longest integers are $intmaxsize bytes long."
?X:@end
	else
		$cat >&4 <<EOM
!
Help! I can't compile and run the intsize test program: please enlighten me!
(This is probably a misconfiguration in your system or libraries, and
you really ought to fix it.  Still, I'll try anyway.)
!
EOM
@if INTSIZE || intsize
		dflt=4
		rp="What is the size of an integer (in bytes)?"
		. ./myread
		intsize="$ans"
@end
@if LONGSIZE || longsize
		dflt=$intsize
		rp="What is the size of a long integer (in bytes)?"
		. ./myread
		longsize="$ans"
@end
@if SHORTSIZE || shortsize
		dflt=2
		rp="What is the size of a short integer (in bytes)?"
		. ./myread
		shortsize="$ans"
@end
?X:@if INTMAXSIZE || intmaxsize
		dflt=$longsize
		rp="What is the size of a intmax_t integer (in bytes)?"
		. ./myread
		intmaxsize="$ans"
?X:@end
	fi
	;;
esac
$rm_try

