makelintstub revision 1.10
11.1Scgd#!/bin/sh -
21.10Sjdolecek# $NetBSD: makelintstub,v 1.10 2002/10/12 17:41:20 jdolecek Exp $
31.1Scgd#
41.7Scgd# Copyright (c) 1996, 1997 Christopher G. Demetriou
51.7Scgd# All rights reserved.
61.7Scgd# 
71.1Scgd# Redistribution and use in source and binary forms, with or without
81.1Scgd# modification, are permitted provided that the following conditions
91.1Scgd# are met:
101.1Scgd# 1. Redistributions of source code must retain the above copyright
111.1Scgd#    notice, this list of conditions and the following disclaimer.
121.1Scgd# 2. Redistributions in binary form must reproduce the above copyright
131.1Scgd#    notice, this list of conditions and the following disclaimer in the
141.1Scgd#    documentation and/or other materials provided with the distribution.
151.1Scgd# 3. All advertising materials mentioning features or use of this software
161.1Scgd#    must display the following acknowledgement:
171.7Scgd#          This product includes software developed for the
181.7Scgd#          NetBSD Project.  See http://www.netbsd.org/ for
191.7Scgd#          information about NetBSD.
201.1Scgd# 4. The name of the author may not be used to endorse or promote products
211.7Scgd#    derived from this software without specific prior written permission.
221.7Scgd# 
231.1Scgd# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
241.1Scgd# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
251.1Scgd# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
261.1Scgd# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
271.1Scgd# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
281.1Scgd# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
291.1Scgd# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
301.1Scgd# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
311.1Scgd# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
321.1Scgd# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
331.7Scgd# 
341.7Scgd# <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
351.1Scgd
361.2Sthorpejusage()
371.2Sthorpej{
381.2Sthorpej
391.2Sthorpej	echo "usage: $0 [-n|-p] [-o filename] object ..."
401.9Sthorpej	echo "       The CPP environment variable must be set"
411.9Sthorpej	echo "       to the path to the C preprocessor."
421.1Scgd	exit 1
431.2Sthorpej}
441.1Scgd
451.2Sthorpejheader()
461.2Sthorpej{
471.1Scgd
481.2Sthorpej	cat <<- __EOF__
491.2Sthorpej	/*
501.2Sthorpej	 * THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT EDIT.
511.2Sthorpej	 */
521.2Sthorpej
531.2Sthorpej	#include <sys/param.h>
541.2Sthorpej	#include <sys/time.h>
551.2Sthorpej	#include <sys/mount.h>
561.2Sthorpej	#include <sys/stat.h>
571.3Sfvdl	#include <ufs/ufs/dinode.h>
581.2Sthorpej	#include <ufs/lfs/lfs.h>
591.2Sthorpej	#include <sys/resource.h>
601.2Sthorpej	#include <sys/poll.h>
611.2Sthorpej	#include <sys/uio.h>
621.2Sthorpej	#include <sys/ipc.h>
631.2Sthorpej	#include <sys/msg.h>
641.2Sthorpej	#include <sys/sem.h>
651.2Sthorpej	#include <sys/shm.h>
661.2Sthorpej	#include <sys/timex.h>
671.2Sthorpej	#include <sys/socket.h>
681.10Sjdolecek	#ifdef WITH_KQUEUE
691.10Sjdolecek	#include <sys/event.h>
701.10Sjdolecek	#endif
711.2Sthorpej	#ifdef __STDC__
721.2Sthorpej	#include <stdarg.h>
731.2Sthorpej	#else
741.2Sthorpej	#include <varargs.h>
751.2Sthorpej	#endif
761.2Sthorpej
771.2Sthorpej	__EOF__
781.2Sthorpej}
791.2Sthorpej
801.2Sthorpejsyscall_stub()
811.2Sthorpej{
821.2Sthorpej
831.4Smycroft	syscalldump="$1"
841.2Sthorpej	syscallname="$2"
851.2Sthorpej	funcname="$3"
861.2Sthorpej
871.4Smycroft    	arglist="`
881.4Smycroft    	sed -e 'ta
891.4Smycroft		:a
901.9Sthorpej		s,^/\* syscall: \"'"$syscallname"'\" ,,
911.4Smycroft	        tb
921.4Smycroft		d
931.4Smycroft		:b
941.4Smycroft		s, \*/$,,' $syscalldump
951.4Smycroft	`"
961.2Sthorpej
971.2Sthorpej	eval set -f -- "$arglist"
981.2Sthorpej
991.4Smycroft	if [ $# -lt 3 ]; then
1001.2Sthorpej		echo syscall $syscallname not found! 1>&2
1011.2Sthorpej		exit 1
1021.2Sthorpej	fi
1031.1Scgd
1041.4Smycroft	shift			# kill "ret:"
1051.4Smycroft	returntype=$1; shift
1061.4Smycroft	shift			# kill "args:"
1071.2Sthorpej
1081.2Sthorpej	cat <<- __EOF__
1091.2Sthorpej	/*ARGSUSED*/
1101.2Sthorpej	$returntype
1111.2Sthorpej	__EOF__
1121.2Sthorpej
1131.2Sthorpej	# do ANSI C function header
1141.5Smycroft	echo	"#ifdef __STDC__"
1151.2Sthorpej
1161.9Sthorpej	echo "$funcname("
1171.5Smycroft	first=yes; i=1
1181.5Smycroft	for arg; do
1191.5Smycroft		if [ $first = yes ]; then
1201.5Smycroft			first=no
1211.5Smycroft		else
1221.9Sthorpej			echo ", "
1231.2Sthorpej		fi
1241.5Smycroft		case "$arg" in
1251.9Sthorpej		"...") echo "...";;
1261.9Sthorpej		*) echo "$arg arg$i"; i=$(($i + 1));;
1271.5Smycroft		esac
1281.5Smycroft	done
1291.9Sthorpej	if [ $first = yes ]; then
1301.9Sthorpej		echo "void"
1311.9Sthorpej	fi
1321.5Smycroft	echo	")"
1331.1Scgd
1341.5Smycroft	# do K&R C function header
1351.5Smycroft	echo	"#else"
1361.1Scgd
1371.9Sthorpej	echo "$funcname("
1381.5Smycroft	first=yes; i=1
1391.5Smycroft	for arg; do
1401.5Smycroft		if [ $first = yes ]; then
1411.5Smycroft			first=no
1421.5Smycroft		else
1431.9Sthorpej			echo ", "
1441.2Sthorpej		fi
1451.5Smycroft		case "$arg" in
1461.9Sthorpej		"...") echo "va_alist";;
1471.9Sthorpej		*) echo "arg$i"; i=$(($i + 1));;
1481.5Smycroft		esac
1491.2Sthorpej	done
1501.2Sthorpej	echo	")"
1511.2Sthorpej	i=1
1521.5Smycroft	for arg; do
1531.5Smycroft		case "$arg" in
1541.5Smycroft		"...") echo "	va_dcl";;
1551.5Smycroft		*) echo "	$arg arg$i;"; i=$(($i + 1));;
1561.5Smycroft		esac
1571.2Sthorpej	done
1581.1Scgd
1591.2Sthorpej	# do function body
1601.5Smycroft	echo	"#endif"
1611.5Smycroft
1621.2Sthorpej	echo	"{"
1631.2Sthorpej	if [ "$returntype" != "void" ]; then
1641.2Sthorpej		echo "        return (($returntype)0);"
1651.2Sthorpej	fi
1661.2Sthorpej	echo	"}"
1671.2Sthorpej}
1681.2Sthorpej
1691.2Sthorpejtrailer()
1701.2Sthorpej{
1711.2Sthorpej
1721.2Sthorpej	cat <<- __EOF__
1731.2Sthorpej	/* END */
1741.2Sthorpej	__EOF__
1751.2Sthorpej}
1761.2Sthorpej
1771.2Sthorpejset -- `getopt no:ps: $*`
1781.2Sthorpej
1791.2Sthorpejpflag=NO
1801.2Sthorpejnflag=NO
1811.2Sthorpejoarg=""
1821.2Sthorpejsyscallhdr=/usr/include/sys/syscall.h
1831.4Smycroftsyscalldump=/tmp/makelintstub.$$
1841.2Sthorpej
1851.9Sthorpejif test "x${CPP}" = "x"; then
1861.9Sthorpej	usage
1871.9Sthorpejfi
1881.9Sthorpej
1891.2Sthorpejif test $? -ne 0; then
1901.2Sthorpej	usage
1911.2Sthorpejfi
1921.2Sthorpejfor i; do
1931.2Sthorpej	case "$i" in
1941.2Sthorpej	-n)	nflag=YES; shift;;
1951.2Sthorpej	-o)	oarg=$2; shift; shift;;
1961.2Sthorpej	-p)	pflag=YES; shift;;
1971.2Sthorpej	-s)	syscallhdr=$2; shift; shift;;
1981.2Sthorpej	--)	shift; break;;
1991.2Sthorpej	esac
2001.1Scgddone
2011.1Scgd
2021.2Sthorpejif [ $pflag = YES ] && [ $nflag = YES ]; then
2031.2Sthorpej	echo "$0: -n flag and -p flag may not be used together"
2041.2Sthorpej	echo ""
2051.2Sthorpej	usage
2061.2Sthorpejfi
2071.2Sthorpej
2081.2Sthorpejif [ "X$oarg" != "X" ]; then
2091.2Sthorpej	exec > $oarg
2101.2Sthorpejfi
2111.2Sthorpej
2121.4Smycrofttrap "rm -f $syscalldump" 0 1 2 15
2131.4Smycroft
2141.2Sthorpejheader
2151.9Sthorpejprintf '#include "'"$syscallhdr"'"' | ${CPP} -C >$syscalldump
2161.2Sthorpejfor syscall; do
2171.8Stv	fnname=${syscall%.S}
2181.2Sthorpej	if [ $pflag = YES ]; then
2191.4Smycroft		scname=${fnname#_}
2201.2Sthorpej	else
2211.2Sthorpej		scname=$fnname
2221.1Scgd	fi
2231.4Smycroft	syscall_stub $syscalldump $scname $fnname
2241.2Sthorpej	echo ""
2251.1Scgddone
2261.2Sthorpejtrailer
2271.1Scgd
2281.1Scgdexit 0
229