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