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
32if [ $# -lt 1 ] || [ $# -gt 2 ]; then
33	echo "usage: $0 syscallname [funcname]"
34	exit 1
35fi
36
37syscallname="$1"
38if [ $# -eq 1 ]; then
39	funcname="$syscallname"
40else
41	funcname="$2"
42fi
43
44arglist="`printf '#include <sys/syscall.h>' | cpp -C | \
45    grep '^/\* syscall: "'"$syscallname"'" ' | \
46    sed -e 's,^/\* syscall: ,,;s, \*/$,,'`"
47
48eval set -f -- "$arglist"
49
50if [ $# -lt 4 ]; then
51	echo syscall $syscallname not found! 1>&2
52	exit 1
53fi
54
55syscallname=$1
56shift 2			# kill name and "ret:"
57returntype=$1
58shift 2			# kill return type and "args:"
59
60cat << __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
85if [ "`eval echo -n \\$$#`" = "..." ]; then
86	varargs=YES
87	nargs=$(($# - 1))
88else
89	varargs=NO
90	nargs=$#
91fi
92nargswithva=$#
93
94# do ANSI C function header
95echo	"#ifdef __STDC__"
96
97echo -n	"$funcname("
98i=1
99while [ $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))
106done
107if [ $varargs = YES ]; then
108	echo -n "..."
109fi
110echo	")"
111
112# do K&R C function header
113echo	"#else"
114
115echo -n	"$funcname("
116i=1
117while [ $i -le $nargs ]; do
118	echo -n	"arg$i"
119	if [ $i -lt $nargswithva ]; then
120		echo -n	", "
121	fi
122	i=$(($i + 1))
123done
124if [ $varargs = YES ]; then
125	echo -n "va_alist"
126fi
127echo	")"
128i=1
129while [ $i -le $nargs ]; do
130	eval echo -n \""        \$$i"\"
131	echo	" arg$i;"
132	i=$(($i + 1))
133done
134if [ $varargs = YES ]; then
135	echo	"        va_dcl"
136fi
137
138# do function body
139echo	"#endif"
140echo	"{"
141if [ "$returntype" != "void" ]; then
142	echo "        return (($returntype)0);"
143fi
144echo	"}"
145
146exit 0
147