makelintstub revision 1.1 1 #!/bin/sh -
2 # $NetBSD: makelintstub,v 1.1 1996/12/22 11:38:34 cgd Exp $
3 #
4 # Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. All advertising materials mentioning features or use of this software
15 # must display the following acknowledgement:
16 # This product includes software developed for the NetBSD Project
17 # by Christopher G. Demetriou.
18 # 4. The name of the author may not be used to endorse or promote products
19 # derived from this software without specific prior written permission
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
33 echo "usage: $0 syscallname [funcname]"
34 exit 1
35 fi
36
37 syscallname="$1"
38 if [ $# -eq 1 ]; then
39 funcname="$syscallname"
40 else
41 funcname="$2"
42 fi
43
44 arglist="`printf '#include <sys/syscall.h>' | cpp -C | \
45 grep '^/\* syscall: "'"$syscallname"'" ' | \
46 sed -e 's,^/\* syscall: ,,;s, \*/$,,'`"
47
48 eval set -f -- "$arglist"
49
50 if [ $# -lt 4 ]; then
51 echo syscall $syscallname not found! 1>&2
52 exit 1
53 fi
54
55 syscallname=$1
56 shift 2 # kill name and "ret:"
57 returntype=$1
58 shift 2 # kill return type and "args:"
59
60 cat << __EOF__
61 #include <sys/param.h>
62 #include <sys/time.h>
63 #include <sys/mount.h>
64 #include <sys/stat.h>
65 #include <ufs/lfs/lfs.h>
66 #include <sys/resource.h>
67 #include <sys/poll.h>
68 #include <sys/uio.h>
69 #include <sys/ipc.h>
70 #include <sys/msg.h>
71 #include <sys/sem.h>
72 #include <sys/shm.h>
73 #include <sys/timex.h>
74 #include <sys/socket.h>
75 #ifdef __STDC__
76 #include <stdarg.h>
77 #else
78 #include <varargs.h>
79 #endif
80
81 /*ARGSUSED*/
82 $returntype
83 __EOF__
84
85 if [ "`eval echo -n \\$$#`" = "..." ]; then
86 varargs=YES
87 nargs=$(($# - 1))
88 else
89 varargs=NO
90 nargs=$#
91 fi
92 nargswithva=$#
93
94 # do ANSI C function header
95 echo "#ifdef __STDC__"
96
97 echo -n "$funcname("
98 i=1
99 while [ $i -le $nargs ]; do
100 eval echo -n \""\$$i"\"
101 echo -n " arg$i"
102 if [ $i -lt $nargswithva ]; then
103 echo -n ", "
104 fi
105 i=$(($i + 1))
106 done
107 if [ $varargs = YES ]; then
108 echo -n "..."
109 fi
110 echo ")"
111
112 # do K&R C function header
113 echo "#else"
114
115 echo -n "$funcname("
116 i=1
117 while [ $i -le $nargs ]; do
118 echo -n "arg$i"
119 if [ $i -lt $nargswithva ]; then
120 echo -n ", "
121 fi
122 i=$(($i + 1))
123 done
124 if [ $varargs = YES ]; then
125 echo -n "va_alist"
126 fi
127 echo ")"
128 i=1
129 while [ $i -le $nargs ]; do
130 eval echo -n \"" \$$i"\"
131 echo " arg$i;"
132 i=$(($i + 1))
133 done
134 if [ $varargs = YES ]; then
135 echo " va_dcl"
136 fi
137
138 # do function body
139 echo "#endif"
140 echo "{"
141 if [ "$returntype" != "void" ]; then
142 echo " return (($returntype)0);"
143 fi
144 echo "}"
145
146 exit 0
147