makelintstub revision 1.4
11.1Scgd#!/bin/sh -
21.4Smycroft#	$NetBSD: makelintstub,v 1.4 1998/07/03 17:50:10 mycroft 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.4Smycroft	syscalldump="$1"
751.2Sthorpej	syscallname="$2"
761.2Sthorpej	funcname="$3"
771.2Sthorpej
781.4Smycroft    	arglist="`
791.4Smycroft    	sed -e 'ta
801.4Smycroft		:a
811.4Smycroft		s,^/\* syscall: "'"$syscallname"'" ,,
821.4Smycroft	        tb
831.4Smycroft		d
841.4Smycroft		:b
851.4Smycroft		s, \*/$,,' $syscalldump
861.4Smycroft	`"
871.2Sthorpej
881.2Sthorpej	eval set -f -- "$arglist"
891.2Sthorpej
901.4Smycroft	if [ $# -lt 3 ]; then
911.2Sthorpej		echo syscall $syscallname not found! 1>&2
921.2Sthorpej		exit 1
931.2Sthorpej	fi
941.1Scgd
951.4Smycroft	shift			# kill "ret:"
961.4Smycroft	returntype=$1; shift
971.4Smycroft	shift			# kill "args:"
981.2Sthorpej
991.2Sthorpej	cat <<- __EOF__
1001.2Sthorpej	/*ARGSUSED*/
1011.2Sthorpej	$returntype
1021.2Sthorpej	__EOF__
1031.2Sthorpej
1041.2Sthorpej	if [ "`eval echo -n \\$$#`" = "..." ]; then
1051.2Sthorpej		varargs=YES
1061.2Sthorpej		nargs=$(($# - 1))
1071.2Sthorpej	else
1081.2Sthorpej		varargs=NO
1091.2Sthorpej		nargs=$#
1101.2Sthorpej	fi
1111.2Sthorpej	nargswithva=$#
1121.1Scgd
1131.2Sthorpej	# do ANSI C function header
1141.2Sthorpej	if [ $varargs = YES ]; then
1151.2Sthorpej		echo	"#ifdef __STDC__"
1161.2Sthorpej
1171.2Sthorpej		echo -n	"$funcname("
1181.2Sthorpej		i=1
1191.2Sthorpej		while [ $i -le $nargs ]; do
1201.2Sthorpej			eval echo -n \""\$$i"\"
1211.2Sthorpej			echo -n	" arg$i"
1221.2Sthorpej			if [ $i -lt $nargswithva ]; then
1231.2Sthorpej				echo -n	", "
1241.2Sthorpej			fi
1251.2Sthorpej			i=$(($i + 1))
1261.2Sthorpej		done
1271.2Sthorpej		if [ $varargs = YES ]; then
1281.2Sthorpej			echo -n "..."
1291.2Sthorpej		fi
1301.2Sthorpej		echo	")"
1311.1Scgd
1321.2Sthorpej		# do K&R C function header
1331.2Sthorpej		echo	"#else"
1341.2Sthorpej	fi
1351.1Scgd
1361.2Sthorpej	echo -n	"$funcname("
1371.2Sthorpej	i=1
1381.2Sthorpej	while [ $i -le $nargs ]; do
1391.2Sthorpej		echo -n	"arg$i"
1401.2Sthorpej		if [ $i -lt $nargswithva ]; then
1411.2Sthorpej			echo -n	", "
1421.2Sthorpej		fi
1431.2Sthorpej		i=$(($i + 1))
1441.2Sthorpej	done
1451.2Sthorpej	if [ $varargs = YES ]; then
1461.2Sthorpej		echo -n "va_alist"
1471.2Sthorpej	fi
1481.2Sthorpej	echo	")"
1491.2Sthorpej	i=1
1501.2Sthorpej	while [ $i -le $nargs ]; do
1511.2Sthorpej		eval echo -n \""        \$$i"\"
1521.2Sthorpej		echo	" arg$i;"
1531.2Sthorpej		i=$(($i + 1))
1541.2Sthorpej	done
1551.2Sthorpej	if [ $varargs = YES ]; then
1561.2Sthorpej		echo	"        va_dcl"
1571.2Sthorpej	fi
1581.1Scgd
1591.2Sthorpej	# do function body
1601.2Sthorpej	if [ $varargs = YES ]; then
1611.2Sthorpej		echo	"#endif"
1621.1Scgd	fi
1631.2Sthorpej	echo	"{"
1641.2Sthorpej	if [ "$returntype" != "void" ]; then
1651.2Sthorpej		echo "        return (($returntype)0);"
1661.2Sthorpej	fi
1671.2Sthorpej	echo	"}"
1681.2Sthorpej}
1691.2Sthorpej
1701.2Sthorpejtrailer()
1711.2Sthorpej{
1721.2Sthorpej
1731.2Sthorpej	cat <<- __EOF__
1741.2Sthorpej	/* END */
1751.2Sthorpej	__EOF__
1761.2Sthorpej}
1771.2Sthorpej
1781.2Sthorpejset -- `getopt no:ps: $*`
1791.2Sthorpej
1801.2Sthorpejpflag=NO
1811.2Sthorpejnflag=NO
1821.2Sthorpejoarg=""
1831.2Sthorpejsyscallhdr=/usr/include/sys/syscall.h
1841.4Smycroftsyscalldump=/tmp/makelintstub.$$
1851.2Sthorpej
1861.2Sthorpejif test $? -ne 0; then
1871.2Sthorpej	usage
1881.2Sthorpejfi
1891.2Sthorpejfor i; do
1901.2Sthorpej	case "$i" in
1911.2Sthorpej	-n)	nflag=YES; shift;;
1921.2Sthorpej	-o)	oarg=$2; shift; shift;;
1931.2Sthorpej	-p)	pflag=YES; shift;;
1941.2Sthorpej	-s)	syscallhdr=$2; shift; shift;;
1951.2Sthorpej	--)	shift; break;;
1961.2Sthorpej	esac
1971.1Scgddone
1981.1Scgd
1991.2Sthorpejif [ $pflag = YES ] && [ $nflag = YES ]; then
2001.2Sthorpej	echo "$0: -n flag and -p flag may not be used together"
2011.2Sthorpej	echo ""
2021.2Sthorpej	usage
2031.2Sthorpejfi
2041.2Sthorpej
2051.2Sthorpejif [ "X$oarg" != "X" ]; then
2061.2Sthorpej	exec > $oarg
2071.2Sthorpejfi
2081.2Sthorpej
2091.4Smycrofttrap "rm -f $syscalldump" 0 1 2 15
2101.4Smycroft
2111.2Sthorpejheader
2121.4Smycroftprintf '#include "'"$syscallhdr"'"' | cpp -C >$syscalldump
2131.2Sthorpejfor syscall; do
2141.4Smycroft	fnname=${syscall%.o}
2151.2Sthorpej	if [ $pflag = YES ]; then
2161.4Smycroft		scname=${fnname#_}
2171.2Sthorpej	else
2181.2Sthorpej		scname=$fnname
2191.1Scgd	fi
2201.4Smycroft	syscall_stub $syscalldump $scname $fnname
2211.2Sthorpej	echo ""
2221.1Scgddone
2231.2Sthorpejtrailer
2241.1Scgd
2251.1Scgdexit 0
226