makelintstub revision 1.18 1 #!/bin/sh -
2 # $NetBSD: makelintstub,v 1.18 2007/02/09 22:08:48 ad 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/time.h>
57 #include <sys/mount.h>
58 #include <sys/stat.h>
59 #include <ufs/ufs/dinode.h>
60 #include <ufs/lfs/lfs.h>
61 #include <sys/resource.h>
62 #include <sys/poll.h>
63 #include <sys/uio.h>
64 #include <sys/ipc.h>
65 #include <sys/msg.h>
66 #include <sys/sem.h>
67 #include <sys/shm.h>
68 #include <sys/timex.h>
69 #include <sys/socket.h>
70 #include <sys/event.h>
71 #include <sys/uuid.h>
72 #ifdef __STDC__
73 #include <stdarg.h>
74 #else
75 #include <varargs.h>
76 #endif
77
78 __EOF__
79 }
80
81 syscall_stub()
82 {
83
84 syscalldump="$1"
85 syscallname="$2"
86 funcname="$3"
87
88 arglist="$(
89 sed -e 'ta
90 :a
91 s,^/\* syscall: \"'"$syscallname"'\" ,,
92 tb
93 d
94 :b
95 s, \*/$,,' $syscalldump
96 )"
97
98 eval set -f -- "$arglist"
99
100 if [ $# -lt 3 ]; then
101 echo syscall $syscallname not found! 1>&2
102 exit 1
103 fi
104
105 shift # kill "ret:"
106 returntype=$1; shift
107 shift # kill "args:"
108
109 cat <<- __EOF__
110 /*ARGSUSED*/
111 $returntype
112 __EOF__
113
114 # do ANSI C function header
115 echo "#ifdef __STDC__"
116
117 echo "$funcname("
118 first=true; i=1
119 for arg; do
120 if $first; then
121 first=false
122 else
123 echo ", "
124 fi
125 case "$arg" in
126 "...") echo "...";;
127 *) echo "$arg arg$i"; i=$(($i + 1));;
128 esac
129 done
130 if $first; then
131 echo "void"
132 fi
133 echo ")"
134
135 # do K&R C function header
136 echo "#else"
137
138 echo "$funcname("
139 first=true; i=1
140 for arg; do
141 if $first; then
142 first=false
143 else
144 echo ", "
145 fi
146 case "$arg" in
147 "...") echo "va_alist";;
148 *) echo "arg$i"; i=$(($i + 1));;
149 esac
150 done
151 echo ")"
152 i=1
153 for arg; do
154 case "$arg" in
155 "...") echo " va_dcl";;
156 *) echo " $arg arg$i;"; i=$(($i + 1));;
157 esac
158 done
159
160 # do function body
161 echo "#endif"
162
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
179 pflag=false
180 nflag=false
181 oarg=""
182 syscallhdr=/usr/include/sys/syscall.h
183 syscalldump=/tmp/makelintstub.$$
184 PROG="$(basename "$0")"
185
186 if [ -z "${CPP}" ]; then
187 usage
188 fi
189
190 while getopts no:ps: i
191 do
192 case "$i" in
193 n) nflag=true;;
194 o) oarg=$OPTARG;;
195 p) pflag=true;;
196 s) syscallhdr=$OPTARG;;
197 *) usage;;
198 esac
199 done
200
201 shift $(expr $OPTIND - 1)
202
203 if $pflag && $nflag
204 then
205 echo "$PROG: -n flag and -p flag may not be used together" 1>&2
206 usage
207 fi
208
209 if [ -n "$oarg" ]; then
210 exec > $oarg
211 fi
212
213 trap "rm -f $syscalldump" 0 1 2 3 15
214
215 header
216
217 echo "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump
218
219 for syscall; do
220 fnname=${syscall%.S}
221 if $pflag; then
222 scname=${fnname#_}
223 else
224 scname=$fnname
225 fi
226 syscall_stub $syscalldump $scname $fnname
227 echo ""
228 done
229
230 trailer
231
232 exit 0
233