summaryrefslogtreecommitdiff
path: root/mcon/U/i_varhdr.U
blob: 6d53d248fc2d586f40d95e3ca95d44d04b1c081e (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
?RCS: $Id: i_varhdr.U 167 2013-05-08 17:58:00Z rmanfredi $
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, 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 4.0.
?RCS:
?RCS: $Log: i_varhdr.U,v $
?RCS: Revision 3.0.1.3  1997/02/28  15:54:42  ram
?RCS: patch61: varargs script now starts with leading "startsh"
?RCS:
?RCS: Revision 3.0.1.2  1994/10/29  16:21:02  ram
?RCS: patch36: added ?F: line for metalint file checking
?RCS:
?RCS: Revision 3.0.1.1  1994/05/13  15:26:05  ram
?RCS: patch27: this unit now supersedes old i_stdarg.U and i_varargs.U
?RCS: patch27: modified to avoid spurious Whoa warnings (ADO)
?RCS:
?RCS: Revision 3.0  1993/08/18  12:08:49  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?MAKE:i_stdarg i_varargs i_varhdr: cat +cc +ccflags rm test Setvar \
	Findhdr Warn startsh _o
?MAKE:	-pick add $@ %<
?S:i_stdarg:
?S:	This variable conditionally defines the I_STDARG symbol, which
?S:	indicates to the C program that <stdarg.h> exists and should
?S:	be included.
?S:.
?S:i_varargs:
?S:	This variable conditionally defines I_VARARGS, which indicates
?S:	to the C program that it should include <varargs.h>.
?S:.
?S:i_varhdr:
?S:	Contains the name of the header to be included to get va_dcl definition.
?S:	Typically one of varargs.h or stdarg.h.
?S:.
?C:I_STDARG:
?C:	This symbol, if defined, indicates that <stdarg.h> exists and should
?C:	be included.
?C:.
?C:I_VARARGS:
?C:	This symbol, if defined, indicates to the C program that it should
?C:	include <varargs.h>.
?C:.
?H:#$i_stdarg I_STDARG		/**/
?H:#$i_varargs I_VARARGS	/**/
?H:.
?W:%<:va_dcl
?F:!varargs
?T:valstd
?LINT:set i_stdarg i_varargs
?X:
?X: Don't use setvar because the varags test below might override these.
?X: Actually, the messages here are just informative. We don't wish to set
?X: i_varargs or i_stdarg to their final value before knowing which of the
?X: two we'll include.
?X:
: see if stdarg is available
echo " "
if $test `./findhdr stdarg.h`; then
	echo "<stdarg.h> found." >&4
	valstd="$define"
else
	echo "<stdarg.h> NOT found." >&4
	valstd="$undef"
fi

: see if varags is available
echo " "
if $test `./findhdr varargs.h`; then
	echo "<varargs.h> found." >&4
else
	echo "<varargs.h> NOT found, but that's ok (I hope)." >&4
fi

?X:
?X: if you have stdarg.h, you need to support prototypes to actually use it;
?X: but if stdarg.h exists and the compiler doesn't support prototypes (for some
?X: bizarre reason), we'll fall back to varargs.h anyway so it's not so bad.
?X:
: set up the varargs testing programs
$cat > varargs.c <<EOP
#ifdef I_STDARG
#include <stdarg.h>
#endif
#ifdef I_VARARGS
#include <varargs.h>
#endif

#ifdef I_STDARG
int f(char *p, ...)
#else
int f(va_alist)
va_dcl
#endif
{
	va_list ap;
#ifndef I_STDARG
	char *p;
#endif
#ifdef I_STDARG
	va_start(ap,p);
#else
	va_start(ap);
	p = va_arg(ap, char *);
#endif
	va_end(ap);
	return 0;
}
EOP
$cat > varargs <<EOP
$startsh
if $cc -c $ccflags -D\$1 varargs.c; then
	echo "true"
else
	echo "false"
fi
$rm -f varargs$_o
EOP
chmod +x varargs

: now check which varargs header should be included
echo " "
i_varhdr=''
case "$valstd" in
"$define")
	if `./varargs I_STDARG`; then
		val='stdarg.h'
	elif `./varargs I_VARARGS`; then
		val='varargs.h'
	fi
	;;
*)
	if `./varargs I_VARARGS`; then
		val='varargs.h'
	fi
	;;
esac
case "$val" in
'')
	./warn "I could not find the definition for va_dcl... You have problems..." 4>&4
	val="$undef"; set i_stdarg; eval $setvar
	val="$undef"; set i_varargs; eval $setvar
	;;
*) 
	set i_varhdr
	eval $setvar
	case "$i_varhdr" in
	stdarg.h)
		val="$define"; set i_stdarg; eval $setvar
		val="$undef"; set i_varargs; eval $setvar
		;;
	varargs.h)
		val="$undef"; set i_stdarg; eval $setvar
		val="$define"; set i_varargs; eval $setvar
		;;
	esac
	echo "We'll include <$i_varhdr> to get va_dcl definition." >&4;;
esac
$rm -f varargs*