makelintstub revision 1.5
11.1Scgd#!/bin/sh -
21.4Smycroft#	$NetBSD: makelintstub,v 1.5 1998/07/03 18:09:25 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	# do ANSI C function header
1051.5Smycroft	echo	"#ifdef __STDC__"
1061.2Sthorpej
1071.5Smycroft	echo -n	"$funcname("
1081.5Smycroft	first=yes; i=1
1091.5Smycroft	for arg; do
1101.5Smycroft		if [ $first = yes ]; then
1111.5Smycroft			first=no
1121.5Smycroft		else
1131.5Smycroft			echo -n	", "
1141.2Sthorpej		fi
1151.5Smycroft		case "$arg" in
1161.5Smycroft		"...") echo -n "...";;
1171.5Smycroft		*) echo -n "$arg arg$i"; i=$(($i + 1));;
1181.5Smycroft		esac
1191.5Smycroft	done
1201.5Smycroft	echo	")"
1211.1Scgd
1221.5Smycroft	# do K&R C function header
1231.5Smycroft	echo	"#else"
1241.1Scgd
1251.2Sthorpej	echo -n	"$funcname("
1261.5Smycroft	first=yes; i=1
1271.5Smycroft	for arg; do
1281.5Smycroft		if [ $first = yes ]; then
1291.5Smycroft			first=no
1301.5Smycroft		else
1311.2Sthorpej			echo -n	", "
1321.2Sthorpej		fi
1331.5Smycroft		case "$arg" in
1341.5Smycroft		"...") echo -n "va_alist";;
1351.5Smycroft		*) echo -n "arg$i"; i=$(($i + 1));;
1361.5Smycroft		esac
1371.2Sthorpej	done
1381.2Sthorpej	echo	")"
1391.2Sthorpej	i=1
1401.5Smycroft	for arg; do
1411.5Smycroft		case "$arg" in
1421.5Smycroft		"...") echo "	va_dcl";;
1431.5Smycroft		*) echo "	$arg arg$i;"; i=$(($i + 1));;
1441.5Smycroft		esac
1451.2Sthorpej	done
1461.1Scgd
1471.2Sthorpej	# do function body
1481.5Smycroft	echo	"#endif"
1491.5Smycroft
1501.2Sthorpej	echo	"{"
1511.2Sthorpej	if [ "$returntype" != "void" ]; then
1521.2Sthorpej		echo "        return (($returntype)0);"
1531.2Sthorpej	fi
1541.2Sthorpej	echo	"}"
1551.2Sthorpej}
1561.2Sthorpej
1571.2Sthorpejtrailer()
1581.2Sthorpej{
1591.2Sthorpej
1601.2Sthorpej	cat <<- __EOF__
1611.2Sthorpej	/* END */
1621.2Sthorpej	__EOF__
1631.2Sthorpej}
1641.2Sthorpej
1651.2Sthorpejset -- `getopt no:ps: $*`
1661.2Sthorpej
1671.2Sthorpejpflag=NO
1681.2Sthorpejnflag=NO
1691.2Sthorpejoarg=""
1701.2Sthorpejsyscallhdr=/usr/include/sys/syscall.h
1711.4Smycroftsyscalldump=/tmp/makelintstub.$$
1721.2Sthorpej
1731.2Sthorpejif test $? -ne 0; then
1741.2Sthorpej	usage
1751.2Sthorpejfi
1761.2Sthorpejfor i; do
1771.2Sthorpej	case "$i" in
1781.2Sthorpej	-n)	nflag=YES; shift;;
1791.2Sthorpej	-o)	oarg=$2; shift; shift;;
1801.2Sthorpej	-p)	pflag=YES; shift;;
1811.2Sthorpej	-s)	syscallhdr=$2; shift; shift;;
1821.2Sthorpej	--)	shift; break;;
1831.2Sthorpej	esac
1841.1Scgddone
1851.1Scgd
1861.2Sthorpejif [ $pflag = YES ] && [ $nflag = YES ]; then
1871.2Sthorpej	echo "$0: -n flag and -p flag may not be used together"
1881.2Sthorpej	echo ""
1891.2Sthorpej	usage
1901.2Sthorpejfi
1911.2Sthorpej
1921.2Sthorpejif [ "X$oarg" != "X" ]; then
1931.2Sthorpej	exec > $oarg
1941.2Sthorpejfi
1951.2Sthorpej
1961.4Smycrofttrap "rm -f $syscalldump" 0 1 2 15
1971.4Smycroft
1981.2Sthorpejheader
1991.4Smycroftprintf '#include "'"$syscallhdr"'"' | cpp -C >$syscalldump
2001.2Sthorpejfor syscall; do
2011.4Smycroft	fnname=${syscall%.o}
2021.2Sthorpej	if [ $pflag = YES ]; then
2031.4Smycroft		scname=${fnname#_}
2041.2Sthorpej	else
2051.2Sthorpej		scname=$fnname
2061.1Scgd	fi
2071.4Smycroft	syscall_stub $syscalldump $scname $fnname
2081.2Sthorpej	echo ""
2091.1Scgddone
2101.2Sthorpejtrailer
2111.1Scgd
2121.1Scgdexit 0
213