makelintstub revision 1.2
11.1Scgd#!/bin/sh -
21.2Sthorpej#	$NetBSD: makelintstub,v 1.2 1997/11/05 05:46:18 thorpej 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.2Sthorpej	#include <ufs/lfs/lfs.h>
521.2Sthorpej	#include <sys/resource.h>
531.2Sthorpej	#include <sys/poll.h>
541.2Sthorpej	#include <sys/uio.h>
551.2Sthorpej	#include <sys/ipc.h>
561.2Sthorpej	#include <sys/msg.h>
571.2Sthorpej	#include <sys/sem.h>
581.2Sthorpej	#include <sys/shm.h>
591.2Sthorpej	#include <sys/timex.h>
601.2Sthorpej	#include <sys/socket.h>
611.2Sthorpej	#ifdef __STDC__
621.2Sthorpej	#include <stdarg.h>
631.2Sthorpej	#else
641.2Sthorpej	#include <varargs.h>
651.2Sthorpej	#endif
661.2Sthorpej
671.2Sthorpej	__EOF__
681.2Sthorpej}
691.2Sthorpej
701.2Sthorpejsyscall_stub()
711.2Sthorpej{
721.2Sthorpej
731.2Sthorpej	syscallhdr="$1"
741.2Sthorpej	syscallname="$2"
751.2Sthorpej	funcname="$3"
761.2Sthorpej
771.2Sthorpej	arglist="`printf '#include "'"$syscallhdr"'"' | cpp -C | \
781.2Sthorpej    	grep '^/\* syscall: "'"$syscallname"'" ' | \
791.2Sthorpej    	sed -e 's,^/\* syscall: ,,;s, \*/$,,'`"
801.2Sthorpej
811.2Sthorpej	eval set -f -- "$arglist"
821.2Sthorpej
831.2Sthorpej	if [ $# -lt 4 ]; then
841.2Sthorpej		echo syscall $syscallname not found! 1>&2
851.2Sthorpej		exit 1
861.2Sthorpej	fi
871.1Scgd
881.2Sthorpej	syscallname=$1
891.2Sthorpej	shift 2			# kill name and "ret:"
901.2Sthorpej	returntype=$1
911.2Sthorpej	shift 2			# kill return type and "args:"
921.2Sthorpej
931.2Sthorpej	cat <<- __EOF__
941.2Sthorpej	/*ARGSUSED*/
951.2Sthorpej	$returntype
961.2Sthorpej	__EOF__
971.2Sthorpej
981.2Sthorpej	if [ "`eval echo -n \\$$#`" = "..." ]; then
991.2Sthorpej		varargs=YES
1001.2Sthorpej		nargs=$(($# - 1))
1011.2Sthorpej	else
1021.2Sthorpej		varargs=NO
1031.2Sthorpej		nargs=$#
1041.2Sthorpej	fi
1051.2Sthorpej	nargswithva=$#
1061.1Scgd
1071.2Sthorpej	# do ANSI C function header
1081.2Sthorpej	if [ $varargs = YES ]; then
1091.2Sthorpej		echo	"#ifdef __STDC__"
1101.2Sthorpej
1111.2Sthorpej		echo -n	"$funcname("
1121.2Sthorpej		i=1
1131.2Sthorpej		while [ $i -le $nargs ]; do
1141.2Sthorpej			eval echo -n \""\$$i"\"
1151.2Sthorpej			echo -n	" arg$i"
1161.2Sthorpej			if [ $i -lt $nargswithva ]; then
1171.2Sthorpej				echo -n	", "
1181.2Sthorpej			fi
1191.2Sthorpej			i=$(($i + 1))
1201.2Sthorpej		done
1211.2Sthorpej		if [ $varargs = YES ]; then
1221.2Sthorpej			echo -n "..."
1231.2Sthorpej		fi
1241.2Sthorpej		echo	")"
1251.1Scgd
1261.2Sthorpej		# do K&R C function header
1271.2Sthorpej		echo	"#else"
1281.2Sthorpej	fi
1291.1Scgd
1301.2Sthorpej	echo -n	"$funcname("
1311.2Sthorpej	i=1
1321.2Sthorpej	while [ $i -le $nargs ]; do
1331.2Sthorpej		echo -n	"arg$i"
1341.2Sthorpej		if [ $i -lt $nargswithva ]; then
1351.2Sthorpej			echo -n	", "
1361.2Sthorpej		fi
1371.2Sthorpej		i=$(($i + 1))
1381.2Sthorpej	done
1391.2Sthorpej	if [ $varargs = YES ]; then
1401.2Sthorpej		echo -n "va_alist"
1411.2Sthorpej	fi
1421.2Sthorpej	echo	")"
1431.2Sthorpej	i=1
1441.2Sthorpej	while [ $i -le $nargs ]; do
1451.2Sthorpej		eval echo -n \""        \$$i"\"
1461.2Sthorpej		echo	" arg$i;"
1471.2Sthorpej		i=$(($i + 1))
1481.2Sthorpej	done
1491.2Sthorpej	if [ $varargs = YES ]; then
1501.2Sthorpej		echo	"        va_dcl"
1511.2Sthorpej	fi
1521.1Scgd
1531.2Sthorpej	# do function body
1541.2Sthorpej	if [ $varargs = YES ]; then
1551.2Sthorpej		echo	"#endif"
1561.1Scgd	fi
1571.2Sthorpej	echo	"{"
1581.2Sthorpej	if [ "$returntype" != "void" ]; then
1591.2Sthorpej		echo "        return (($returntype)0);"
1601.2Sthorpej	fi
1611.2Sthorpej	echo	"}"
1621.2Sthorpej}
1631.2Sthorpej
1641.2Sthorpejtrailer()
1651.2Sthorpej{
1661.2Sthorpej
1671.2Sthorpej	cat <<- __EOF__
1681.2Sthorpej	/* END */
1691.2Sthorpej	__EOF__
1701.2Sthorpej}
1711.2Sthorpej
1721.2Sthorpejset -- `getopt no:ps: $*`
1731.2Sthorpej
1741.2Sthorpejpflag=NO
1751.2Sthorpejnflag=NO
1761.2Sthorpejoarg=""
1771.2Sthorpejsyscallhdr=/usr/include/sys/syscall.h
1781.2Sthorpej
1791.2Sthorpejif test $? -ne 0; then
1801.2Sthorpej	usage
1811.2Sthorpejfi
1821.2Sthorpejfor i; do
1831.2Sthorpej	case "$i" in
1841.2Sthorpej	-n)	nflag=YES; shift;;
1851.2Sthorpej	-o)	oarg=$2; shift; shift;;
1861.2Sthorpej	-p)	pflag=YES; shift;;
1871.2Sthorpej	-s)	syscallhdr=$2; shift; shift;;
1881.2Sthorpej	--)	shift; break;;
1891.2Sthorpej	esac
1901.1Scgddone
1911.1Scgd
1921.2Sthorpejif [ $pflag = YES ] && [ $nflag = YES ]; then
1931.2Sthorpej	echo "$0: -n flag and -p flag may not be used together"
1941.2Sthorpej	echo ""
1951.2Sthorpej	usage
1961.2Sthorpejfi
1971.2Sthorpej
1981.2Sthorpejif [ "X$oarg" != "X" ]; then
1991.2Sthorpej	exec > $oarg
2001.2Sthorpejfi
2011.2Sthorpej
2021.2Sthorpejheader
2031.2Sthorpejfor syscall; do
2041.2Sthorpej	fnname=`echo $syscall | sed -e 's,\.o$,,'`
2051.2Sthorpej	if [ $pflag = YES ]; then
2061.2Sthorpej		scname=`echo $fnname | sed -e 's,^_,,'`
2071.2Sthorpej	else
2081.2Sthorpej		scname=$fnname
2091.1Scgd	fi
2101.2Sthorpej	syscall_stub $syscallhdr $scname $fnname
2111.2Sthorpej	echo ""
2121.1Scgddone
2131.2Sthorpejtrailer
2141.1Scgd
2151.1Scgdexit 0
216