summaryrefslogtreecommitdiff
path: root/mcon/U/intsize.U
blob: 38c54146313ad7c66f55aaae84560111bdb4aec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
?RCS: $Id$
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS: 
?RCS: You may redistribute only under the terms of the Artistic Licence,
?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 Licence; a copy of which may be found at the root
?RCS: of the source tree for dist 4.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 longsize shortsize: \
	Myread cat rm +cc +optimize +ccflags +ldflags +libs
?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: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:.
?H:#define INTSIZE $intsize		/**/
?H:#define LONGSIZE $longsize		/**/
?H:#define SHORTSIZE $shortsize		/**/
?H:.
?F:!intsize.out !intsize
: check for lengths of integral types
echo " "
case "$intsize" in
'')
	echo "Checking to see how big your integers are..." >&4
	$cat >intsize.c <<'EOCP'
#include <stdio.h>
int main()
{
@if INTSIZE || intsize
	printf("intsize=%d;\n", sizeof(int));
@end
@if LONGSIZE || longsize
	printf("longsize=%d;\n", sizeof(long));
@end
@if SHORTSIZE || shortsize
	printf("shortsize=%d;\n", sizeof(short));
@end
	fflush(stdout);
	exit(0);
}
EOCP
#	If $libs contains -lsfio, and sfio is mis-configured, then it
#	sometimes (apparently) runs and exits with a 0 status, but with no
#	output!.  Thus we check with test -s whether we actually got any
#	output.  I think it has to do with sfio's use of _exit vs. exit,
#	but I don't know for sure.  --Andy Dougherty  1/27/97.
	if $cc $optimize $ccflags $ldflags -o intsize intsize.c $libs >/dev/null 2>&1 &&
	./intsize > intsize.out 2>/dev/null && test -s intsize.out ; then
		eval `$cat intsize.out`
@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
	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
	fi
	;;
esac
$rm -f intsize intsize.[co] intsize.out