makelintstub revision 1.10 1 #!/bin/sh -
2 # $NetBSD: makelintstub,v 1.10 2002/10/12 17:41:20 jdolecek 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 echo "usage: $0 [-n|-p] [-o filename] object ..."
40 echo " The CPP environment variable must be set"
41 echo " to the path to the C preprocessor."
42 exit 1
43 }
44
45 header()
46 {
47
48 cat <<- __EOF__
49 /*
50 * THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT.
51 */
52
53 #include <sys/param.h>
54 #include <sys/time.h>
55 #include <sys/mount.h>
56 #include <sys/stat.h>
57 #include <ufs/ufs/dinode.h>
58 #include <ufs/lfs/lfs.h>
59 #include <sys/resource.h>
60 #include <sys/poll.h>
61 #include <sys/uio.h>
62 #include <sys/ipc.h>
63 #include <sys/msg.h>
64 #include <sys/sem.h>
65 #include <sys/shm.h>
66 #include <sys/timex.h>
67 #include <sys/socket.h>
68 #ifdef WITH_KQUEUE
69 #include <sys/event.h>
70 #endif
71 #ifdef __STDC__
72 #include <stdarg.h>
73 #else
74 #include <varargs.h>
75 #endif
76
77 __EOF__
78 }
79
80 syscall_stub()
81 {
82
83 syscalldump="$1"
84 syscallname="$2"
85 funcname="$3"
86
87 arglist="`
88 sed -e 'ta
89 :a
90 s,^/\* syscall: \"'"$syscallname"'\" ,,
91 tb
92 d
93 :b
94 s, \*/$,,' $syscalldump
95 `"
96
97 eval set -f -- "$arglist"
98
99 if [ $# -lt 3 ]; then
100 echo syscall $syscallname not found! 1>&2
101 exit 1
102 fi
103
104 shift # kill "ret:"
105 returntype=$1; shift
106 shift # kill "args:"
107
108 cat <<- __EOF__
109 /*ARGSUSED*/
110 $returntype
111 __EOF__
112
113 # do ANSI C function header
114 echo "#ifdef __STDC__"
115
116 echo "$funcname("
117 first=yes; i=1
118 for arg; do
119 if [ $first = yes ]; then
120 first=no
121 else
122 echo ", "
123 fi
124 case "$arg" in
125 "...") echo "...";;
126 *) echo "$arg arg$i"; i=$(($i + 1));;
127 esac
128 done
129 if [ $first = yes ]; then
130 echo "void"
131 fi
132 echo ")"
133
134 # do K&R C function header
135 echo "#else"
136
137 echo "$funcname("
138 first=yes; i=1
139 for arg; do
140 if [ $first = yes ]; then
141 first=no
142 else
143 echo ", "
144 fi
145 case "$arg" in
146 "...") echo "va_alist";;
147 *) echo "arg$i"; i=$(($i + 1));;
148 esac
149 done
150 echo ")"
151 i=1
152 for arg; do
153 case "$arg" in
154 "...") echo " va_dcl";;
155 *) echo " $arg arg$i;"; i=$(($i + 1));;
156 esac
157 done
158
159 # do function body
160 echo "#endif"
161
162 echo "{"
163 if [ "$returntype" != "void" ]; then
164 echo " return (($returntype)0);"
165 fi
166 echo "}"
167 }
168
169 trailer()
170 {
171
172 cat <<- __EOF__
173 /* END */
174 __EOF__
175 }
176
177 set -- `getopt no:ps: $*`
178
179 pflag=NO
180 nflag=NO
181 oarg=""
182 syscallhdr=/usr/include/sys/syscall.h
183 syscalldump=/tmp/makelintstub.$$
184
185 if test "x${CPP}" = "x"; then
186 usage
187 fi
188
189 if test $? -ne 0; then
190 usage
191 fi
192 for i; do
193 case "$i" in
194 -n) nflag=YES; shift;;
195 -o) oarg=$2; shift; shift;;
196 -p) pflag=YES; shift;;
197 -s) syscallhdr=$2; shift; shift;;
198 --) shift; break;;
199 esac
200 done
201
202 if [ $pflag = YES ] && [ $nflag = YES ]; then
203 echo "$0: -n flag and -p flag may not be used together"
204 echo ""
205 usage
206 fi
207
208 if [ "X$oarg" != "X" ]; then
209 exec > $oarg
210 fi
211
212 trap "rm -f $syscalldump" 0 1 2 15
213
214 header
215 printf '#include "'"$syscallhdr"'"' | ${CPP} -C >$syscalldump
216 for syscall; do
217 fnname=${syscall%.S}
218 if [ $pflag = YES ]; then
219 scname=${fnname#_}
220 else
221 scname=$fnname
222 fi
223 syscall_stub $syscalldump $scname $fnname
224 echo ""
225 done
226 trailer
227
228 exit 0
229