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