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