Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: Findhdr.U,v 3.0.1.2 1994/10/29 15:53:08 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
65a32477 MBT |
4 | ?RCS: |
5 | ?RCS: You may redistribute only under the terms of the Artistic License, | |
959f3c4c JH |
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 | |
65a32477 | 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
959f3c4c JH |
9 | ?RCS: of the source tree for dist 3.0. |
10 | ?RCS: | |
11 | ?RCS: Original Author: Thomas Neumann <tom@smart.bo.open.de> | |
12 | ?RCS: | |
13 | ?RCS: $Log: Findhdr.U,v $ | |
14 | ?RCS: Revision 3.0.1.2 1994/10/29 15:53:08 ram | |
15 | ?RCS: patch36: added ?F: line for metalint file checking | |
16 | ?RCS: | |
17 | ?RCS: Revision 3.0.1.1 1994/05/06 14:03:56 ram | |
18 | ?RCS: patch23: cppminus must be after other cppflags, not before | |
19 | ?RCS: | |
20 | ?RCS: Revision 3.0 1993/08/18 12:04:54 ram | |
21 | ?RCS: Baseline for dist 3.0 netwide release. | |
22 | ?RCS: | |
23 | ?X: | |
24 | ?X: This unit produces a findhdr script which is used to locate the header | |
25 | ?X: files in $usrinc or other stranger places using cpp capabilities. The | |
26 | ?X: script is given an include file base name, like 'stdio.h' or 'sys/file.h' | |
27 | ?X: and it returns the full path of the include file and a zero status or an | |
28 | ?X: empty string with an error status if the file could not be located. | |
29 | ?X: | |
3af75476 | 30 | ?MAKE:Findhdr: grep test tr rm incpth awk cat startsh \ |
e8970d08 | 31 | cppstdin cppminus +cppflags osname |
959f3c4c | 32 | ?MAKE: -pick add $@ %< |
3af75476 | 33 | ?LINT:extern cppfilter |
959f3c4c JH |
34 | ?LINT:define fieldn |
35 | ?S:fieldn: | |
36 | ?S: This variable is used internally by Configure. It contains the position | |
37 | ?S: of the included file name in cpp output. That is to say, when cpp | |
38 | ?S: pre-processes a #include <file> line, it replaces it by a # line which | |
39 | ?S: contains the original position in the input file and the full name of | |
40 | ?S: included file, between "quotes". | |
41 | ?S:. | |
42 | ?V:fieldn | |
43 | ?F:./findhdr !fieldn | |
3af75476 | 44 | ?T:cline pos wanted name awkprg usrincdir status testaccess |
959f3c4c JH |
45 | : determine filename position in cpp output |
46 | echo " " | |
47 | echo "Computing filename position in cpp output for #include directives..." >&4 | |
4795084e JH |
48 | case "$osname" in |
49 | vos) testaccess=-e ;; | |
50 | *) testaccess=-r ;; | |
51 | esac | |
959f3c4c JH |
52 | echo '#include <stdio.h>' > foo.c |
53 | $cat >fieldn <<EOF | |
54 | $startsh | |
55 | $cppstdin $cppflags $cppminus <foo.c 2>/dev/null | \ | |
56 | $grep '^[ ]*#.*stdio\.h' | \ | |
57 | while read cline; do | |
58 | pos=1 | |
59 | set \$cline | |
60 | while $test \$# -gt 0; do | |
4795084e | 61 | if $test $testaccess \`echo \$1 | $tr -d '"'\`; then |
959f3c4c JH |
62 | echo "\$pos" |
63 | exit 0 | |
64 | fi | |
65 | shift | |
66 | pos=\`expr \$pos + 1\` | |
67 | done | |
68 | done | |
69 | EOF | |
70 | chmod +x fieldn | |
71 | fieldn=`./fieldn` | |
72 | $rm -f foo.c fieldn | |
73 | case $fieldn in | |
74 | '') pos='???';; | |
75 | 1) pos=first;; | |
76 | 2) pos=second;; | |
77 | 3) pos=third;; | |
78 | *) pos="${fieldn}th";; | |
79 | esac | |
80 | echo "Your cpp writes the filename in the $pos field of the line." | |
81 | ||
82 | ?X: To locate a header file, we cannot simply check for $usrinc/file.h, since | |
83 | ?X: some machine have the headers in weird places and our only hope is that | |
84 | ?X: the C pre-processor will know how to find those headers. Thank you NexT! | |
85 | : locate header file | |
86 | $cat >findhdr <<EOF | |
87 | $startsh | |
88 | wanted=\$1 | |
89 | name='' | |
3af75476 | 90 | for usrincdir in $incpth |
959f3c4c JH |
91 | do |
92 | if test -f \$usrincdir/\$wanted; then | |
93 | echo "\$usrincdir/\$wanted" | |
94 | exit 0 | |
95 | fi | |
96 | done | |
97 | awkprg='{ print \$$fieldn }' | |
98 | echo "#include <\$wanted>" > foo\$\$.c | |
99 | $cppstdin $cppminus $cppflags < foo\$\$.c 2>/dev/null | \ | |
e8970d08 | 100 | $cppfilter $grep "^[ ]*#.*\$wanted" | \ |
959f3c4c JH |
101 | while read cline; do |
102 | name=\`echo \$cline | $awk "\$awkprg" | $tr -d '"'\` | |
103 | case "\$name" in | |
104 | *[/\\\\]\$wanted) echo "\$name"; exit 1;; | |
105 | *[\\\\/]\$wanted) echo "\$name"; exit 1;; | |
106 | *) exit 2;; | |
107 | esac; | |
108 | done; | |
109 | # | |
110 | # status = 0: grep returned 0 lines, case statement not executed | |
111 | # status = 1: headerfile found | |
112 | # status = 2: while loop executed, no headerfile found | |
113 | # | |
114 | status=\$? | |
115 | $rm -f foo\$\$.c; | |
116 | if test \$status -eq 1; then | |
117 | exit 0; | |
118 | fi | |
119 | exit 1 | |
120 | EOF | |
121 | chmod +x findhdr | |
122 |