Commit | Line | Data |
---|---|---|
c6667804 | 1 | ?RCS: $Id$ |
d8875586 MBT |
2 | ?RCS: |
3 | ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi | |
cf39bd7e | 4 | ?RCS: |
c6667804 | 5 | ?RCS: You may redistribute only under the terms of the Artistic License, |
d8875586 MBT |
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 | |
c6667804 | 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
d8875586 MBT |
9 | ?RCS: of the source tree for dist 4.0. |
10 | ?RCS: | |
11 | ?RCS: Original Author: Tye McQueen <tye@metronet.com> | |
12 | ?RCS: | |
13 | ?RCS: $Log: d_stdstdio.U,v $ | |
14 | ?RCS: Revision 3.0.1.3 1997/02/28 15:46:32 ram | |
15 | ?RCS: patch61: merged with perl5's unit | |
16 | ?RCS: | |
17 | ?RCS: Revision 3.0.1.2 1995/07/25 14:06:54 ram | |
18 | ?RCS: patch56: typo fix on ?C: line for FILE_bufsiz | |
19 | ?RCS: patch56: fixed unbalanced parenthesis (ADO) | |
20 | ?RCS: patch56: check whether FILE_cnt and FILE_ptr can be assigned to (ADO) | |
21 | ?RCS: | |
22 | ?RCS: Revision 3.0.1.1 1995/05/12 12:12:11 ram | |
23 | ?RCS: patch54: complete rewrite by Tye McQueen to fit modern systems | |
24 | ?RCS: | |
25 | ?RCS: Revision 3.0 1993/08/18 12:07:31 ram | |
26 | ?RCS: Baseline for dist 3.0 netwide release. | |
27 | ?RCS: | |
28 | ?MAKE:d_stdstdio d_stdiobase stdio_ptr stdio_cnt stdio_base \ | |
29 | stdio_bufsiz d_stdio_cnt_lval d_stdio_ptr_lval stdio_filbuf: cat \ | |
611f4b83 | 30 | +cc +ccflags contains +ldflags +libs rm_try \ |
d8875586 MBT |
31 | Setvar Findhdr Oldconfig |
32 | ?MAKE: -pick add $@ %< | |
33 | ?S:d_stdstdio: | |
34 | ?S: This variable conditionally defines USE_STDIO_PTR if this system | |
35 | ?S: has a FILE structure declaring usable _ptr and _cnt fields (or | |
36 | ?S: equivalent) in stdio.h. | |
37 | ?S:. | |
38 | ?S:stdio_ptr: | |
39 | ?S: This variable defines how, given a FILE pointer, fp, to access the | |
40 | ?S: _ptr field (or equivalent) of stdio.h's FILE structure. This will | |
41 | ?S: be used to define the macro FILE_ptr(fp). | |
42 | ?S:. | |
43 | ?S:d_stdio_ptr_lval: | |
44 | ?S: This variable conditionally defines STDIO_PTR_LVALUE if the | |
45 | ?S: FILE_ptr macro can be used as an lvalue. | |
46 | ?S:. | |
47 | ?S:stdio_cnt: | |
48 | ?S: This variable defines how, given a FILE pointer, fp, to access the | |
49 | ?S: _cnt field (or equivalent) of stdio.h's FILE structure. This will | |
50 | ?S: be used to define the macro FILE_cnt(fp). | |
51 | ?S:. | |
52 | ?S:d_stdio_cnt_lval: | |
53 | ?S: This variable conditionally defines STDIO_CNT_LVALUE if the | |
54 | ?S: FILE_cnt macro can be used as an lvalue. | |
55 | ?S:. | |
56 | ?S:stdio_filbuf: | |
57 | ?S: This variable defines how, given a FILE pointer, fp, to tell | |
58 | ?S: stdio to refill it's internal buffers (?). This will | |
59 | ?S: be used to define the macro FILE_filbuf(fp). | |
60 | ?S:. | |
61 | ?S:d_stdiobase: | |
62 | ?S: This variable conditionally defines USE_STDIO_BASE if this system | |
63 | ?S: has a FILE structure declaring a usable _base field (or equivalent) | |
64 | ?S: in stdio.h. | |
65 | ?S:. | |
66 | ?S:stdio_base: | |
67 | ?S: This variable defines how, given a FILE pointer, fp, to access the | |
68 | ?S: _base field (or equivalent) of stdio.h's FILE structure. This will | |
69 | ?S: be used to define the macro FILE_base(fp). | |
70 | ?S:. | |
71 | ?S:stdio_bufsiz: | |
72 | ?S: This variable defines how, given a FILE pointer, fp, to determine | |
73 | ?S: the number of bytes store in the I/O buffer pointer to by the | |
74 | ?S: _base field (or equivalent) of stdio.h's FILE structure. This will | |
75 | ?S: be used to define the macro FILE_bufsiz(fp). | |
76 | ?S:. | |
77 | ?C:USE_STDIO_PTR ~ d_stdstdio (USE_STD_STDIO STDSTDIO): | |
78 | ?C: This symbol is defined if the _ptr and _cnt fields (or similar) | |
79 | ?C: of the stdio FILE structure can be used to access the stdio buffer | |
80 | ?C: for a file handle. If this is defined, then the FILE_ptr(fp) | |
81 | ?C: and FILE_cnt(fp) macros will also be defined and should be used | |
82 | ?C: to access these fields. | |
83 | ?C:. | |
84 | ?C:FILE_ptr: | |
85 | ?C: This macro is used to access the _ptr field (or equivalent) of the | |
86 | ?C: FILE structure pointed to by its argument. This macro will always be | |
87 | ?C: defined if USE_STDIO_PTR is defined. | |
88 | ?C:. | |
89 | ?C:STDIO_PTR_LVALUE: | |
90 | ?C: This symbol is defined if the FILE_ptr macro can be used as an | |
91 | ?C: lvalue. | |
92 | ?C:. | |
93 | ?C:FILE_cnt: | |
94 | ?C: This macro is used to access the _cnt field (or equivalent) of the | |
95 | ?C: FILE structure pointed to by its argument. This macro will always be | |
96 | ?C: defined if USE_STDIO_PTR is defined. | |
97 | ?C:. | |
98 | ?C:STDIO_CNT_LVALUE: | |
99 | ?C: This symbol is defined if the FILE_cnt macro can be used as an | |
100 | ?C: lvalue. | |
101 | ?C:. | |
102 | ?C:FILE_filbuf: | |
103 | ?C: This macro is used to access the internal stdio _filbuf function | |
104 | ?C: (or equivalent), if STDIO_CNT_LVALUE and STDIO_PTR_LVALUE | |
105 | ?C: are defined. It is typically either _filbuf or __filbuf. | |
106 | ?C: This macro will only be defined if both STDIO_CNT_LVALUE and | |
107 | ?C: STDIO_PTR_LVALUE are defined. | |
108 | ?C:. | |
109 | ?H:?d_stdstdio:#$d_stdstdio USE_STDIO_PTR /**/ | |
110 | ?H:?d_stdstdio:#ifdef USE_STDIO_PTR | |
111 | ?H:#define FILE_ptr(fp) $stdio_ptr | |
112 | ?H:#$d_stdio_ptr_lval STDIO_PTR_LVALUE /**/ | |
113 | ?H:#define FILE_cnt(fp) $stdio_cnt | |
114 | ?H:#$d_stdio_cnt_lval STDIO_CNT_LVALUE /**/ | |
115 | ?H:?d_stdstdio:#if defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE) | |
116 | ?H:#define FILE_filbuf(fp) $stdio_filbuf /**/ | |
117 | ?H:?d_stdstdio:#endif | |
118 | ?H:?d_stdstdio:#endif | |
119 | ?H:. | |
120 | ?W:d_stdstdio:FILE_ptr FILE_cnt FILE_filbuf | |
121 | ?C:USE_STDIO_BASE ~ d_stdiobase: | |
122 | ?C: This symbol is defined if the _base field (or similar) of the | |
123 | ?C: stdio FILE structure can be used to access the stdio buffer for | |
124 | ?C: a file handle. If this is defined, then the FILE_base(fp) macro | |
125 | ?C: will also be defined and should be used to access this field. | |
126 | ?C: Also, the FILE_bufsiz(fp) macro will be defined and should be used | |
127 | ?C: to determine the number of bytes in the buffer. USE_STDIO_BASE | |
128 | ?C: will never be defined unless USE_STDIO_PTR is. | |
129 | ?C:. | |
130 | ?C:FILE_base: | |
131 | ?C: This macro is used to access the _base field (or equivalent) of the | |
132 | ?C: FILE structure pointed to by its argument. This macro will always be | |
133 | ?C: defined if USE_STDIO_BASE is defined. | |
134 | ?C:. | |
135 | ?C:FILE_bufsiz: | |
136 | ?C: This macro is used to determine the number of bytes in the I/O | |
137 | ?C: buffer pointed to by _base field (or equivalent) of the FILE | |
138 | ?C: structure pointed to its argument. This macro will always be defined | |
139 | ?C: if USE_STDIO_BASE is defined. | |
140 | ?C:. | |
141 | ?H:?d_stdiobase:#$d_stdiobase USE_STDIO_BASE /**/ | |
142 | ?H:?d_stdiobase:#ifdef USE_STDIO_BASE | |
143 | ?H:#define FILE_base(fp) $stdio_base | |
144 | ?H:#define FILE_bufsiz(fp) $stdio_bufsiz | |
145 | ?H:?d_stdiobase:#endif | |
146 | ?H:. | |
147 | ?W:d_stdiobase:FILE_base FILE_bufsiz | |
148 | ?LINT:set d_stdstdio d_stdiobase | |
149 | ?T:ptr_lval cnt_lval filbuf xxx | |
150 | ?F:!try | |
151 | : see if _ptr and _cnt from stdio act std | |
152 | echo " " | |
153 | if $contains '_IO_fpos_t' `./findhdr stdio.h` >/dev/null 2>&1 ; then | |
154 | echo "(Looks like you have stdio.h from Linux.)" | |
155 | case "$stdio_ptr" in | |
156 | '') stdio_ptr='((fp)->_IO_read_ptr)' | |
157 | ptr_lval=$define | |
158 | ;; | |
159 | *) ptr_lval=$d_stdio_ptr_lval;; | |
160 | esac | |
161 | case "$stdio_cnt" in | |
162 | '') stdio_cnt='((fp)->_IO_read_end - (fp)->_IO_read_ptr)' | |
163 | cnt_lval=$undef | |
164 | ;; | |
165 | *) cnt_lval=$d_stdio_cnt_lval;; | |
166 | esac | |
167 | case "$stdio_base" in | |
168 | '') stdio_base='((fp)->_IO_read_base)';; | |
169 | esac | |
170 | case "$stdio_bufsiz" in | |
171 | '') stdio_bufsiz='((fp)->_IO_read_end - (fp)->_IO_read_base)';; | |
172 | esac | |
173 | else | |
174 | case "$stdio_ptr" in | |
175 | '') stdio_ptr='((fp)->_ptr)' | |
176 | ptr_lval=$define | |
177 | ;; | |
178 | *) ptr_lval=$d_stdio_ptr_lval;; | |
179 | esac | |
180 | case "$stdio_cnt" in | |
181 | '') stdio_cnt='((fp)->_cnt)' | |
182 | cnt_lval=$define | |
183 | ;; | |
184 | *) cnt_lval=$d_stdio_cnt_lval;; | |
185 | esac | |
186 | case "$stdio_base" in | |
187 | '') stdio_base='((fp)->_base)';; | |
188 | esac | |
189 | case "$stdio_bufsiz" in | |
190 | '') stdio_bufsiz='((fp)->_cnt + (fp)->_ptr - (fp)->_base)';; | |
191 | esac | |
192 | fi | |
193 | : test whether _ptr and _cnt really work | |
194 | echo "Checking how std your stdio is..." >&4 | |
195 | $cat >try.c <<EOP | |
196 | #include <stdio.h> | |
197 | #define FILE_ptr(fp) $stdio_ptr | |
198 | #define FILE_cnt(fp) $stdio_cnt | |
199 | int main() { | |
200 | FILE *fp = fopen("try.c", "r"); | |
201 | char c = getc(fp); | |
202 | if ( | |
203 | 18 <= FILE_cnt(fp) && | |
204 | strncmp(FILE_ptr(fp), "include <stdio.h>\n", 18) == 0 | |
205 | ) | |
206 | exit(0); | |
207 | exit(1); | |
208 | } | |
209 | EOP | |
210 | val="$undef" | |
211 | if $cc $ccflags $ldflags -o try try.c $libs >/dev/null 2>&1; then | |
212 | if ./try; then | |
213 | echo "Your stdio acts pretty std." | |
214 | val="$define" | |
215 | else | |
216 | echo "Your stdio isn't very std." | |
217 | fi | |
218 | else | |
219 | echo "Your stdio doesn't appear very std." | |
220 | fi | |
611f4b83 | 221 | $rm_try |
d8875586 MBT |
222 | set d_stdstdio |
223 | eval $setvar | |
224 | ||
225 | @if STDIO_PTR_LVALUE || d_stdio_ptr_lval | |
226 | : Can _ptr be used as an lvalue? | |
227 | ?X: Only makes sense if we have a known stdio implementation. | |
228 | case "$d_stdstdio$ptr_lval" in | |
229 | $define$define) val=$define ;; | |
230 | *) val=$undef ;; | |
231 | esac | |
232 | set d_stdio_ptr_lval | |
233 | eval $setvar | |
234 | ||
235 | @end | |
236 | @if STDIO_CNT_LVALUE || d_stdio_cnt_lval | |
237 | : Can _cnt be used as an lvalue? | |
238 | ?X: Only makes sense if we have a known stdio implementation. | |
239 | case "$d_stdstdio$cnt_lval" in | |
240 | $define$define) val=$define ;; | |
241 | *) val=$undef ;; | |
242 | esac | |
243 | set d_stdio_cnt_lval | |
244 | eval $setvar | |
245 | ||
246 | @end | |
247 | @if FILE_filbuf | |
248 | : How to access the stdio _filbuf or __filbuf function. | |
249 | : If this fails, check how the getc macro in stdio.h works. | |
250 | case "${d_stdio_ptr_lval}${d_stdio_cnt_lval}" in | |
251 | ${define}${define}) | |
252 | : Try hint value, if any, then _filbuf, __filbuf, _fill, then punt. | |
253 | : _fill is for OS/2. | |
254 | xxx='notok' | |
255 | for filbuf in $stdio_filbuf '_filbuf(fp)' '__filbuf(fp) ' '_fill(fp)' ; do | |
256 | $cat >try.c <<EOP | |
257 | #include <stdio.h> | |
258 | #define FILE_ptr(fp) $stdio_ptr | |
259 | #define FILE_cnt(fp) $stdio_cnt | |
260 | #define FILE_filbuf(fp) $filbuf | |
261 | int main() { | |
262 | FILE *fp = fopen("try.c", "r"); | |
263 | int c; | |
264 | c = getc(fp); | |
265 | c = FILE_filbuf(fp); /* Just looking for linker errors.*/ | |
266 | exit(0); | |
267 | } | |
268 | EOP | |
269 | if $cc $ccflags $ldflags -o try try.c $libs >/dev/null 2>&1 && ./try; then | |
270 | echo "Your stdio appears to use $filbuf" | |
271 | stdio_filbuf="$filbuf" | |
272 | xxx='ok' | |
273 | break | |
274 | else | |
275 | echo "Hmm. $filbuf doesn't seem to work." | |
276 | fi | |
611f4b83 | 277 | $rm_try |
d8875586 MBT |
278 | done |
279 | case "$xxx" in | |
280 | notok) echo "I can't figure out how to access _filbuf" | |
281 | echo "I'll just have to work around it." | |
282 | d_stdio_ptr_lval="$undef" | |
283 | d_stdio_cnt_lval="$undef" | |
284 | ;; | |
285 | esac | |
286 | ;; | |
287 | esac | |
288 | @end | |
289 | @if d_stdiobase || USE_STDIO_BASE || FILE_base || FILE_bufsiz | |
290 | : see if _base is also standard | |
291 | val="$undef" | |
292 | case "$d_stdstdio" in | |
293 | $define) | |
294 | $cat >try.c <<EOP | |
295 | #include <stdio.h> | |
296 | #define FILE_base(fp) $stdio_base | |
297 | #define FILE_bufsiz(fp) $stdio_bufsiz | |
298 | int main() { | |
299 | FILE *fp = fopen("try.c", "r"); | |
300 | char c = getc(fp); | |
301 | if ( | |
302 | 19 <= FILE_bufsiz(fp) && | |
303 | strncmp(FILE_base(fp), "#include <stdio.h>\n", 19) == 0 | |
304 | ) | |
305 | exit(0); | |
306 | exit(1); | |
307 | } | |
308 | EOP | |
309 | if $cc $ccflags $ldflags -o try try.c $libs > /dev/null 2>&1; then | |
310 | if ./try; then | |
311 | echo "And its _base field acts std." | |
312 | val="$define" | |
313 | else | |
314 | echo "But its _base field isn't std." | |
315 | fi | |
316 | else | |
317 | echo "However, it seems to be lacking the _base field." | |
318 | fi | |
611f4b83 | 319 | $rm_try |
d8875586 MBT |
320 | ;; |
321 | esac | |
322 | set d_stdiobase | |
323 | eval $setvar | |
324 | ||
325 | @end |