Commit | Line | Data |
---|---|---|
0f00356b JH |
1 | ?RCS: $Id: i_varhdr.U,v 3.0.1.3 1997/02/28 15:54:42 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
4 | ?RCS: | |
5 | ?RCS: You may redistribute only under the terms of the Artistic Licence, | |
6 | ?RCS: as specified in the README file that comes with the distribution. | |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
8 | ?RCS: that same Artistic Licence; a copy of which may be found at the root | |
9 | ?RCS: of the source tree for dist 3.0. | |
10 | ?RCS: | |
11 | ?RCS: $Log: i_varhdr.U,v $ | |
12 | ?RCS: Revision 3.0.1.3 1997/02/28 15:54:42 ram | |
13 | ?RCS: patch61: varargs script now starts with leading "startsh" | |
14 | ?RCS: | |
15 | ?RCS: Revision 3.0.1.2 1994/10/29 16:21:02 ram | |
16 | ?RCS: patch36: added ?F: line for metalint file checking | |
17 | ?RCS: | |
18 | ?RCS: Revision 3.0.1.1 1994/05/13 15:26:05 ram | |
19 | ?RCS: patch27: this unit now supersedes old i_stdarg.U and i_varargs.U | |
20 | ?RCS: patch27: modified to avoid spurious Whoa warnings (ADO) | |
21 | ?RCS: | |
22 | ?RCS: Revision 3.0 1993/08/18 12:08:49 ram | |
23 | ?RCS: Baseline for dist 3.0 netwide release. | |
24 | ?RCS: | |
25 | ?MAKE:i_stdarg i_varargs i_varhdr: cat +cc +ccflags rm test Setvar \ | |
26 | Findhdr startsh _o run | |
27 | ?MAKE: -pick add $@ %< | |
28 | ?S:i_stdarg: | |
29 | ?S: This variable conditionally defines the I_STDARG symbol, which | |
30 | ?S: indicates to the C program that <stdarg.h> exists and should | |
31 | ?S: be included. | |
32 | ?S:. | |
33 | ?S:i_varargs: | |
34 | ?S: This variable conditionally defines I_VARARGS, which indicates | |
35 | ?S: to the C program that it should include <varargs.h>. | |
36 | ?S:. | |
37 | ?S:i_varhdr: | |
38 | ?S: Contains the name of the header to be included to get va_dcl definition. | |
39 | ?S: Typically one of varargs.h or stdarg.h. | |
40 | ?S:. | |
41 | ?C:I_STDARG: | |
42 | ?C: This symbol, if defined, indicates that <stdarg.h> exists and should | |
43 | ?C: be included. | |
44 | ?C:. | |
45 | ?C:I_VARARGS: | |
46 | ?C: This symbol, if defined, indicates to the C program that it should | |
47 | ?C: include <varargs.h>. | |
48 | ?C:. | |
49 | ?H:#$i_stdarg I_STDARG /**/ | |
50 | ?H:#$i_varargs I_VARARGS /**/ | |
51 | ?H:. | |
52 | ?W:%<:va_dcl | |
53 | ?T:valstd | |
54 | ?F:!varargs | |
55 | ?LINT:set i_stdarg i_varargs | |
56 | ?X: | |
57 | ?X: Don't use setvar because the varags test below might override these. | |
58 | ?X: Actually, the messages here are just informative. We don't wish to set | |
59 | ?X: i_varargs or i_stdarg to their final value before knowing which of the | |
60 | ?X: two we'll include. | |
61 | ?X: | |
62 | : see if stdarg is available | |
63 | echo " " | |
64 | if $test `./findhdr stdarg.h`; then | |
65 | echo "<stdarg.h> found." >&4 | |
66 | valstd="$define" | |
67 | else | |
68 | echo "<stdarg.h> NOT found." >&4 | |
69 | valstd="$undef" | |
70 | fi | |
71 | ||
72 | : see if varags is available | |
73 | echo " " | |
74 | if $test `./findhdr varargs.h`; then | |
75 | echo "<varargs.h> found." >&4 | |
76 | else | |
77 | echo "<varargs.h> NOT found, but that's ok (I hope)." >&4 | |
78 | fi | |
79 | ||
80 | ?X: | |
81 | ?X: if you have stdarg.h, you need to support prototypes to actually use it; | |
82 | ?X: but if stdarg.h exists and the compiler doesn't support prototypes (for some | |
83 | ?X: bizarre reason), we'll fall back to varargs.h anyway so it's not so bad. | |
84 | ?X: | |
85 | : set up the varargs testing programs | |
86 | $cat > varargs.c <<EOP | |
87 | #ifdef I_STDARG | |
88 | #include <stdarg.h> | |
89 | #endif | |
90 | #ifdef I_VARARGS | |
91 | #include <varargs.h> | |
92 | #endif | |
93 | ||
94 | #ifdef I_STDARG | |
95 | int f(char *p, ...) | |
96 | #else | |
97 | int f(va_alist) | |
98 | va_dcl | |
99 | #endif | |
100 | { | |
101 | va_list ap; | |
102 | #ifndef I_STDARG | |
103 | char *p; | |
104 | #endif | |
105 | #ifdef I_STDARG | |
106 | va_start(ap,p); | |
107 | #else | |
108 | va_start(ap); | |
109 | p = va_arg(ap, char *); | |
110 | #endif | |
111 | va_end(ap); | |
47f8a159 | 112 | return 0; |
0f00356b JH |
113 | } |
114 | EOP | |
115 | $cat > varargs <<EOP | |
116 | $startsh | |
117 | if $cc -c $ccflags -D\$1 varargs.c >/dev/null 2>&1; then | |
118 | echo "true" | |
119 | else | |
120 | echo "false" | |
121 | fi | |
122 | $rm -f varargs$_o | |
123 | EOP | |
124 | chmod +x varargs | |
125 | ||
126 | : now check which varargs header should be included | |
127 | echo " " | |
128 | i_varhdr='' | |
129 | case "$valstd" in | |
130 | "$define") | |
131 | if `./varargs I_STDARG`; then | |
132 | val='stdarg.h' | |
133 | elif `./varargs I_VARARGS`; then | |
134 | val='varargs.h' | |
135 | fi | |
136 | ;; | |
137 | *) | |
138 | if `./varargs I_VARARGS`; then | |
139 | val='varargs.h' | |
140 | fi | |
141 | ;; | |
142 | esac | |
143 | case "$val" in | |
144 | '') | |
145 | echo "I could not find the definition for va_dcl... You have problems..." >&4 | |
146 | val="$undef"; set i_stdarg; eval $setvar | |
147 | val="$undef"; set i_varargs; eval $setvar | |
148 | ;; | |
149 | *) | |
150 | set i_varhdr | |
151 | eval $setvar | |
152 | case "$i_varhdr" in | |
153 | stdarg.h) | |
154 | val="$define"; set i_stdarg; eval $setvar | |
155 | val="$undef"; set i_varargs; eval $setvar | |
156 | ;; | |
157 | varargs.h) | |
158 | val="$undef"; set i_stdarg; eval $setvar | |
159 | val="$define"; set i_varargs; eval $setvar | |
160 | ;; | |
161 | esac | |
162 | echo "We'll include <$i_varhdr> to get va_dcl definition." >&4;; | |
163 | esac | |
164 | $rm -f varargs* | |
165 |