makelintstub revision 1.19 1 #!/bin/sh -
2 # $NetBSD: makelintstub,v 1.19 2007/10/09 18:18:33 rmind Exp $
3 #
4 # Copyright (c) 1996, 1997 Christopher G. Demetriou
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. All advertising materials mentioning features or use of this software
16 # must display the following acknowledgement:
17 # This product includes software developed for the
18 # NetBSD Project. See http://www.NetBSD.org/ for
19 # information about NetBSD.
20 # 4. The name of the author may not be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #
34 # <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
35
36 usage()
37 {
38
39 cat << _EOF 1>&2
40 Usage: $PROG [-n|-p] [-o filename] object ...
41 The CPP environment variable must be set
42 to the path to the C preprocessor.
43 _EOF
44 exit 1
45 }
46
47 header()
48 {
49
50 cat <<- __EOF__
51 /*
52 * THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT.
53 */
54
55 #include <sys/param.h>
56 #include <sys/aio.h>
57 #include <sys/time.h>
58 #include <sys/mount.h>
59 #include <sys/stat.h>
60 #include <ufs/ufs/dinode.h>
61 #include <ufs/lfs/lfs.h>
62 #include <sys/resource.h>
63 #include <sys/poll.h>
64 #include <sys/uio.h>
65 #include <sys/ipc.h>
66 #include <sys/mqueue.h>
67 #include <sys/msg.h>
68 #include <sys/sem.h>
69 #include <sys/shm.h>
70 #include <sys/timex.h>
71 #include <sys/socket.h>
72 #include <sys/event.h>
73 #include <sys/uuid.h>
74 #ifdef __STDC__
75 #include <stdarg.h>
76 #else
77 #include <varargs.h>
78 #endif
79
80 __EOF__
81 }
82
83 syscall_stub()
84 {
85
86 syscalldump="$1"
87 syscallname="$2"
88 funcname="$3"
89
90 arglist="$(
91 sed -e 'ta
92 :a
93 s,^/\* syscall: \"'"$syscallname"'\" ,,
94 tb
95 d
96 :b
97 s, \*/$,,' $syscalldump
98 )"
99
100 eval set -f -- "$arglist"
101
102 if [ $# -lt 3 ]; then
103 echo syscall $syscallname not found! 1>&2
104 exit 1
105 fi
106
107 shift # kill "ret:"
108 returntype=$1; shift
109 shift # kill "args:"
110
111 cat <<- __EOF__
112 /*ARGSUSED*/
113 $returntype
114 __EOF__
115
116 # do ANSI C function header
117 echo "#ifdef __STDC__"
118
119 echo "$funcname("
120 first=true; i=1
121 for arg; do
122 if $first; then
123 first=false
124 else
125 echo ", "
126 fi
127 case "$arg" in
128 "...") echo "...";;
129 *) echo "$arg arg$i"; i=$(($i + 1));;
130 esac
131 done
132 if $first; then
133 echo "void"
134 fi
135 echo ")"
136
137 # do K&R C function header
138 echo "#else"
139
140 echo "$funcname("
141 first=true; i=1
142 for arg; do
143 if $first; then
144 first=false
145 else
146 echo ", "
147 fi
148 case "$arg" in
149 "...") echo "va_alist";;
150 *) echo "arg$i"; i=$(($i + 1));;
151 esac
152 done
153 echo ")"
154 i=1
155 for arg; do
156 case "$arg" in
157 "...") echo " va_dcl";;
158 *) echo " $arg arg$i;"; i=$(($i + 1));;
159 esac
160 done
161
162 # do function body
163 echo "#endif"
164
165 echo "{"
166 if [ "$returntype" != "void" ]; then
167 echo " return (($returntype)0);"
168 fi
169 echo "}"
170 }
171
172 trailer()
173 {
174
175 cat <<- __EOF__
176 /* END */
177 __EOF__
178 }
179
180
181 pflag=false
182 nflag=false
183 oarg=""
184 syscallhdr=/usr/include/sys/syscall.h
185 syscalldump=/tmp/makelintstub.$$
186 PROG="$(basename "$0")"
187
188 if [ -z "${CPP}" ]; then
189 usage
190 fi
191
192 while getopts no:ps: i
193 do
194 case "$i" in
195 n) nflag=true;;
196 o) oarg=$OPTARG;;
197 p) pflag=true;;
198 s) syscallhdr=$OPTARG;;
199 *) usage;;
200 esac
201 done
202
203 shift $(expr $OPTIND - 1)
204
205 if $pflag && $nflag
206 then
207 echo "$PROG: -n flag and -p flag may not be used together" 1>&2
208 usage
209 fi
210
211 if [ -n "$oarg" ]; then
212 exec > $oarg
213 fi
214
215 trap "rm -f $syscalldump" 0 1 2 3 15
216
217 header
218
219 echo "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump
220
221 for syscall; do
222 fnname=${syscall%.S}
223 if $pflag; then
224 scname=${fnname#_}
225 else
226 scname=$fnname
227 fi
228 syscall_stub $syscalldump $scname $fnname
229 echo ""
230 done
231
232 trailer
233
234 exit 0
235