makelintstub revision 1.3
11.1Scgd#!/bin/sh -
21.3Sfvdl#	$NetBSD: makelintstub,v 1.3 1998/03/01 10:20:06 fvdl Exp $
31.1Scgd#
41.2Sthorpej# Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
51.1Scgd#
61.1Scgd# Redistribution and use in source and binary forms, with or without
71.1Scgd# modification, are permitted provided that the following conditions
81.1Scgd# are met:
91.1Scgd# 1. Redistributions of source code must retain the above copyright
101.1Scgd#    notice, this list of conditions and the following disclaimer.
111.1Scgd# 2. Redistributions in binary form must reproduce the above copyright
121.1Scgd#    notice, this list of conditions and the following disclaimer in the
131.1Scgd#    documentation and/or other materials provided with the distribution.
141.1Scgd# 3. All advertising materials mentioning features or use of this software
151.1Scgd#    must display the following acknowledgement:
161.1Scgd#      This product includes software developed for the NetBSD Project
171.1Scgd#      by Christopher G. Demetriou.
181.1Scgd# 4. The name of the author may not be used to endorse or promote products
191.1Scgd#    derived from this software without specific prior written permission
201.1Scgd#
211.1Scgd# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
221.1Scgd# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
231.1Scgd# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
241.1Scgd# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
251.1Scgd# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
261.1Scgd# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
271.1Scgd# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
281.1Scgd# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291.1Scgd# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
301.1Scgd# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311.1Scgd
321.2Sthorpejusage()
331.2Sthorpej{
341.2Sthorpej
351.2Sthorpej	echo "usage: $0 [-n|-p] [-o filename] object ..."
361.1Scgd	exit 1
371.2Sthorpej}
381.1Scgd
391.2Sthorpejheader()
401.2Sthorpej{
411.1Scgd
421.2Sthorpej	cat <<- __EOF__
431.2Sthorpej	/*
441.2Sthorpej	 * THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT EDIT.
451.2Sthorpej	 */
461.2Sthorpej
471.2Sthorpej	#include <sys/param.h>
481.2Sthorpej	#include <sys/time.h>
491.2Sthorpej	#include <sys/mount.h>
501.2Sthorpej	#include <sys/stat.h>
511.3Sfvdl	#include <ufs/ufs/dinode.h>
521.2Sthorpej	#include <ufs/lfs/lfs.h>
531.2Sthorpej	#include <sys/resource.h>
541.2Sthorpej	#include <sys/poll.h>
551.2Sthorpej	#include <sys/uio.h>
561.2Sthorpej	#include <sys/ipc.h>
571.2Sthorpej	#include <sys/msg.h>
581.2Sthorpej	#include <sys/sem.h>
591.2Sthorpej	#include <sys/shm.h>
601.2Sthorpej	#include <sys/timex.h>
611.2Sthorpej	#include <sys/socket.h>
621.2Sthorpej	#ifdef __STDC__
631.2Sthorpej	#include <stdarg.h>
641.2Sthorpej	#else
651.2Sthorpej	#include <varargs.h>
661.2Sthorpej	#endif
671.2Sthorpej
681.2Sthorpej	__EOF__
691.2Sthorpej}
701.2Sthorpej
711.2Sthorpejsyscall_stub()
721.2Sthorpej{
731.2Sthorpej
741.2Sthorpej	syscallhdr="$1"
751.2Sthorpej	syscallname="$2"
761.2Sthorpej	funcname="$3"
771.2Sthorpej
781.2Sthorpej	arglist="`printf '#include "'"$syscallhdr"'"' | cpp -C | \
791.2Sthorpej    	grep '^/\* syscall: "'"$syscallname"'" ' | \
801.2Sthorpej    	sed -e 's,^/\* syscall: ,,;s, \*/$,,'`"
811.2Sthorpej
821.2Sthorpej	eval set -f -- "$arglist"
831.2Sthorpej
841.2Sthorpej	if [ $# -lt 4 ]; then
851.2Sthorpej		echo syscall $syscallname not found! 1>&2
861.2Sthorpej		exit 1
871.2Sthorpej	fi
881.1Scgd
891.2Sthorpej	syscallname=$1
901.2Sthorpej	shift 2			# kill name and "ret:"
911.2Sthorpej	returntype=$1
921.2Sthorpej	shift 2			# kill return type and "args:"
931.2Sthorpej
941.2Sthorpej	cat <<- __EOF__
951.2Sthorpej	/*ARGSUSED*/
961.2Sthorpej	$returntype
971.2Sthorpej	__EOF__
981.2Sthorpej
991.2Sthorpej	if [ "`eval echo -n \\$$#`" = "..." ]; then
1001.2Sthorpej		varargs=YES
1011.2Sthorpej		nargs=$(($# - 1))
1021.2Sthorpej	else
1031.2Sthorpej		varargs=NO
1041.2Sthorpej		nargs=$#
1051.2Sthorpej	fi
1061.2Sthorpej	nargswithva=$#
1071.1Scgd
1081.2Sthorpej	# do ANSI C function header
1091.2Sthorpej	if [ $varargs = YES ]; then
1101.2Sthorpej		echo	"#ifdef __STDC__"
1111.2Sthorpej
1121.2Sthorpej		echo -n	"$funcname("
1131.2Sthorpej		i=1
1141.2Sthorpej		while [ $i -le $nargs ]; do
1151.2Sthorpej			eval echo -n \""\$$i"\"
1161.2Sthorpej			echo -n	" arg$i"
1171.2Sthorpej			if [ $i -lt $nargswithva ]; then
1181.2Sthorpej				echo -n	", "
1191.2Sthorpej			fi
1201.2Sthorpej			i=$(($i + 1))
1211.2Sthorpej		done
1221.2Sthorpej		if [ $varargs = YES ]; then
1231.2Sthorpej			echo -n "..."
1241.2Sthorpej		fi
1251.2Sthorpej		echo	")"
1261.1Scgd
1271.2Sthorpej		# do K&R C function header
1281.2Sthorpej		echo	"#else"
1291.2Sthorpej	fi
1301.1Scgd
1311.2Sthorpej	echo -n	"$funcname("
1321.2Sthorpej	i=1
1331.2Sthorpej	while [ $i -le $nargs ]; do
1341.2Sthorpej		echo -n	"arg$i"
1351.2Sthorpej		if [ $i -lt $nargswithva ]; then
1361.2Sthorpej			echo -n	", "
1371.2Sthorpej		fi
1381.2Sthorpej		i=$(($i + 1))
1391.2Sthorpej	done
1401.2Sthorpej	if [ $varargs = YES ]; then
1411.2Sthorpej		echo -n "va_alist"
1421.2Sthorpej	fi
1431.2Sthorpej	echo	")"
1441.2Sthorpej	i=1
1451.2Sthorpej	while [ $i -le $nargs ]; do
1461.2Sthorpej		eval echo -n \""        \$$i"\"
1471.2Sthorpej		echo	" arg$i;"
1481.2Sthorpej		i=$(($i + 1))
1491.2Sthorpej	done
1501.2Sthorpej	if [ $varargs = YES ]; then
1511.2Sthorpej		echo	"        va_dcl"
1521.2Sthorpej	fi
1531.1Scgd
1541.2Sthorpej	# do function body
1551.2Sthorpej	if [ $varargs = YES ]; then
1561.2Sthorpej		echo	"#endif"
1571.1Scgd	fi
1581.2Sthorpej	echo	"{"
1591.2Sthorpej	if [ "$returntype" != "void" ]; then
1601.2Sthorpej		echo "        return (($returntype)0);"
1611.2Sthorpej	fi
1621.2Sthorpej	echo	"}"
1631.2Sthorpej}
1641.2Sthorpej
1651.2Sthorpejtrailer()
1661.2Sthorpej{
1671.2Sthorpej
1681.2Sthorpej	cat <<- __EOF__
1691.2Sthorpej	/* END */
1701.2Sthorpej	__EOF__
1711.2Sthorpej}
1721.2Sthorpej
1731.2Sthorpejset -- `getopt no:ps: $*`
1741.2Sthorpej
1751.2Sthorpejpflag=NO
1761.2Sthorpejnflag=NO
1771.2Sthorpejoarg=""
1781.2Sthorpejsyscallhdr=/usr/include/sys/syscall.h
1791.2Sthorpej
1801.2Sthorpejif test $? -ne 0; then
1811.2Sthorpej	usage
1821.2Sthorpejfi
1831.2Sthorpejfor i; do
1841.2Sthorpej	case "$i" in
1851.2Sthorpej	-n)	nflag=YES; shift;;
1861.2Sthorpej	-o)	oarg=$2; shift; shift;;
1871.2Sthorpej	-p)	pflag=YES; shift;;
1881.2Sthorpej	-s)	syscallhdr=$2; shift; shift;;
1891.2Sthorpej	--)	shift; break;;
1901.2Sthorpej	esac
1911.1Scgddone
1921.1Scgd
1931.2Sthorpejif [ $pflag = YES ] && [ $nflag = YES ]; then
1941.2Sthorpej	echo "$0: -n flag and -p flag may not be used together"
1951.2Sthorpej	echo ""
1961.2Sthorpej	usage
1971.2Sthorpejfi
1981.2Sthorpej
1991.2Sthorpejif [ "X$oarg" != "X" ]; then
2001.2Sthorpej	exec > $oarg
2011.2Sthorpejfi
2021.2Sthorpej
2031.2Sthorpejheader
2041.2Sthorpejfor syscall; do
2051.2Sthorpej	fnname=`echo $syscall | sed -e 's,\.o$,,'`
2061.2Sthorpej	if [ $pflag = YES ]; then
2071.2Sthorpej		scname=`echo $fnname | sed -e 's,^_,,'`
2081.2Sthorpej	else
2091.2Sthorpej		scname=$fnname
2101.1Scgd	fi
2111.2Sthorpej	syscall_stub $syscallhdr $scname $fnname
2121.2Sthorpej	echo ""
2131.1Scgddone
2141.2Sthorpejtrailer
2151.1Scgd
2161.1Scgdexit 0
217