makelintstub revision 1.21
11.1Scgd#!/bin/sh -
21.21Srmind# $NetBSD: makelintstub,v 1.21 2008/01/15 03:37:14 rmind 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.14Ssalo#          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.17Schristoscat << _EOF 1>&2
401.17SchristosUsage: $PROG [-n|-p] [-o filename] object ...
411.17Schristos	The CPP environment variable must be set
421.17Schristos	to the path to the C preprocessor.
431.17Schristos_EOF
441.1Scgd	exit 1
451.2Sthorpej}
461.1Scgd
471.2Sthorpejheader()
481.2Sthorpej{
491.1Scgd
501.2Sthorpej	cat <<- __EOF__
511.2Sthorpej	/*
521.2Sthorpej	 * THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT EDIT.
531.2Sthorpej	 */
541.2Sthorpej
551.2Sthorpej	#include <sys/param.h>
561.19Srmind	#include <sys/aio.h>
571.2Sthorpej	#include <sys/time.h>
581.2Sthorpej	#include <sys/mount.h>
591.2Sthorpej	#include <sys/stat.h>
601.3Sfvdl	#include <ufs/ufs/dinode.h>
611.2Sthorpej	#include <ufs/lfs/lfs.h>
621.2Sthorpej	#include <sys/resource.h>
631.2Sthorpej	#include <sys/poll.h>
641.2Sthorpej	#include <sys/uio.h>
651.2Sthorpej	#include <sys/ipc.h>
661.20She	#include <sys/lwpctl.h>
671.19Srmind	#include <sys/mqueue.h>
681.2Sthorpej	#include <sys/msg.h>
691.2Sthorpej	#include <sys/sem.h>
701.2Sthorpej	#include <sys/shm.h>
711.21Srmind	#include <sys/sched.h>
721.2Sthorpej	#include <sys/timex.h>
731.2Sthorpej	#include <sys/socket.h>
741.10Sjdolecek	#include <sys/event.h>
751.16Stsarna	#include <sys/uuid.h>
761.2Sthorpej	#ifdef __STDC__
771.2Sthorpej	#include <stdarg.h>
781.2Sthorpej	#else
791.2Sthorpej	#include <varargs.h>
801.2Sthorpej	#endif
811.2Sthorpej
821.2Sthorpej	__EOF__
831.2Sthorpej}
841.2Sthorpej
851.2Sthorpejsyscall_stub()
861.2Sthorpej{
871.2Sthorpej
881.4Smycroft	syscalldump="$1"
891.2Sthorpej	syscallname="$2"
901.2Sthorpej	funcname="$3"
911.2Sthorpej
921.17Schristos    	arglist="$(
931.4Smycroft    	sed -e 'ta
941.4Smycroft		:a
951.9Sthorpej		s,^/\* syscall: \"'"$syscallname"'\" ,,
961.4Smycroft	        tb
971.4Smycroft		d
981.4Smycroft		:b
991.4Smycroft		s, \*/$,,' $syscalldump
1001.17Schristos	)"
1011.2Sthorpej
1021.2Sthorpej	eval set -f -- "$arglist"
1031.2Sthorpej
1041.4Smycroft	if [ $# -lt 3 ]; then
1051.2Sthorpej		echo syscall $syscallname not found! 1>&2
1061.2Sthorpej		exit 1
1071.2Sthorpej	fi
1081.1Scgd
1091.4Smycroft	shift			# kill "ret:"
1101.4Smycroft	returntype=$1; shift
1111.4Smycroft	shift			# kill "args:"
1121.2Sthorpej
1131.2Sthorpej	cat <<- __EOF__
1141.2Sthorpej	/*ARGSUSED*/
1151.2Sthorpej	$returntype
1161.2Sthorpej	__EOF__
1171.2Sthorpej
1181.2Sthorpej	# do ANSI C function header
1191.5Smycroft	echo	"#ifdef __STDC__"
1201.2Sthorpej
1211.9Sthorpej	echo "$funcname("
1221.17Schristos	first=true; i=1
1231.5Smycroft	for arg; do
1241.17Schristos		if $first; then
1251.17Schristos			first=false
1261.5Smycroft		else
1271.9Sthorpej			echo ", "
1281.2Sthorpej		fi
1291.5Smycroft		case "$arg" in
1301.9Sthorpej		"...") echo "...";;
1311.9Sthorpej		*) echo "$arg arg$i"; i=$(($i + 1));;
1321.5Smycroft		esac
1331.5Smycroft	done
1341.17Schristos	if $first; then
1351.9Sthorpej		echo "void"
1361.9Sthorpej	fi
1371.5Smycroft	echo	")"
1381.1Scgd
1391.5Smycroft	# do K&R C function header
1401.5Smycroft	echo	"#else"
1411.1Scgd
1421.9Sthorpej	echo "$funcname("
1431.17Schristos	first=true; i=1
1441.5Smycroft	for arg; do
1451.17Schristos		if $first; then
1461.17Schristos			first=false
1471.5Smycroft		else
1481.9Sthorpej			echo ", "
1491.2Sthorpej		fi
1501.5Smycroft		case "$arg" in
1511.9Sthorpej		"...") echo "va_alist";;
1521.9Sthorpej		*) echo "arg$i"; i=$(($i + 1));;
1531.5Smycroft		esac
1541.2Sthorpej	done
1551.2Sthorpej	echo	")"
1561.2Sthorpej	i=1
1571.5Smycroft	for arg; do
1581.5Smycroft		case "$arg" in
1591.5Smycroft		"...") echo "	va_dcl";;
1601.5Smycroft		*) echo "	$arg arg$i;"; i=$(($i + 1));;
1611.5Smycroft		esac
1621.2Sthorpej	done
1631.1Scgd
1641.2Sthorpej	# do function body
1651.5Smycroft	echo	"#endif"
1661.5Smycroft
1671.2Sthorpej	echo	"{"
1681.2Sthorpej	if [ "$returntype" != "void" ]; then
1691.2Sthorpej		echo "        return (($returntype)0);"
1701.2Sthorpej	fi
1711.2Sthorpej	echo	"}"
1721.2Sthorpej}
1731.2Sthorpej
1741.2Sthorpejtrailer()
1751.2Sthorpej{
1761.2Sthorpej
1771.2Sthorpej	cat <<- __EOF__
1781.2Sthorpej	/* END */
1791.2Sthorpej	__EOF__
1801.2Sthorpej}
1811.2Sthorpej
1821.2Sthorpej
1831.17Schristospflag=false
1841.17Schristosnflag=false
1851.2Sthorpejoarg=""
1861.2Sthorpejsyscallhdr=/usr/include/sys/syscall.h
1871.4Smycroftsyscalldump=/tmp/makelintstub.$$
1881.17SchristosPROG="$(basename "$0")"
1891.2Sthorpej
1901.17Schristosif [ -z "${CPP}" ]; then
1911.9Sthorpej	usage
1921.9Sthorpejfi
1931.9Sthorpej
1941.17Schristoswhile getopts no:ps: i
1951.17Schristosdo
1961.2Sthorpej	case "$i" in
1971.17Schristos	n)	nflag=true;;
1981.17Schristos	o)	oarg=$OPTARG;;
1991.17Schristos	p)	pflag=true;;
2001.17Schristos	s)	syscallhdr=$OPTARG;;
2011.17Schristos	*)	usage;;
2021.2Sthorpej	esac
2031.1Scgddone
2041.1Scgd
2051.17Schristosshift $(expr $OPTIND - 1)
2061.17Schristos
2071.17Schristosif $pflag && $nflag
2081.17Schristosthen
2091.17Schristos	echo "$PROG: -n flag and -p flag may not be used together" 1>&2
2101.2Sthorpej	usage
2111.2Sthorpejfi
2121.2Sthorpej
2131.17Schristosif [ -n "$oarg" ]; then
2141.2Sthorpej	exec > $oarg
2151.2Sthorpejfi
2161.2Sthorpej
2171.17Schristostrap "rm -f $syscalldump" 0 1 2 3 15
2181.4Smycroft
2191.2Sthorpejheader
2201.17Schristos
2211.17Schristosecho "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump
2221.17Schristos
2231.2Sthorpejfor syscall; do
2241.8Stv	fnname=${syscall%.S}
2251.17Schristos	if $pflag; then
2261.4Smycroft		scname=${fnname#_}
2271.2Sthorpej	else
2281.2Sthorpej		scname=$fnname
2291.1Scgd	fi
2301.4Smycroft	syscall_stub $syscalldump $scname $fnname
2311.2Sthorpej	echo ""
2321.1Scgddone
2331.17Schristos
2341.2Sthorpejtrailer
2351.1Scgd
2361.1Scgdexit 0
237