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