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