Home | History | Annotate | Line # | Download | only in sys
makelintstub revision 1.12
      1 #!/bin/sh -
      2 # $NetBSD: makelintstub,v 1.12 2002/11/11 00:54:57 thorpej Exp $
      3 #
      4 # Copyright (c) 1996, 1997 Christopher G. Demetriou
      5 # All rights reserved.
      6 # 
      7 # Redistribution and use in source and binary forms, with or without
      8 # modification, are permitted provided that the following conditions
      9 # are met:
     10 # 1. Redistributions of source code must retain the above copyright
     11 #    notice, this list of conditions and the following disclaimer.
     12 # 2. Redistributions in binary form must reproduce the above copyright
     13 #    notice, this list of conditions and the following disclaimer in the
     14 #    documentation and/or other materials provided with the distribution.
     15 # 3. All advertising materials mentioning features or use of this software
     16 #    must display the following acknowledgement:
     17 #          This product includes software developed for the
     18 #          NetBSD Project.  See http://www.netbsd.org/ for
     19 #          information about NetBSD.
     20 # 4. The name of the author may not be used to endorse or promote products
     21 #    derived from this software without specific prior written permission.
     22 # 
     23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33 # 
     34 # <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
     35 
     36 usage()
     37 {
     38 
     39 	echo "usage: $0 [-n|-p] [-o filename] object ..."
     40 	echo "       The CPP environment variable must be set"
     41 	echo "       to the path to the C preprocessor."
     42 	exit 1
     43 }
     44 
     45 header()
     46 {
     47 
     48 	cat <<- __EOF__
     49 	/*
     50 	 * THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT EDIT.
     51 	 */
     52 
     53 	#include <sys/param.h>
     54 	#include <sys/time.h>
     55 	#include <sys/mount.h>
     56 	#include <sys/stat.h>
     57 	#include <ufs/ufs/dinode.h>
     58 	#include <ufs/lfs/lfs.h>
     59 	#include <sys/resource.h>
     60 	#include <sys/poll.h>
     61 	#include <sys/uio.h>
     62 	#include <sys/ipc.h>
     63 	#include <sys/msg.h>
     64 	#include <sys/sem.h>
     65 	#include <sys/shm.h>
     66 	#include <sys/timex.h>
     67 	#include <sys/socket.h>
     68 	#include <sys/event.h>
     69 	#ifdef __STDC__
     70 	#include <stdarg.h>
     71 	#else
     72 	#include <varargs.h>
     73 	#endif
     74 
     75 	__EOF__
     76 }
     77 
     78 syscall_stub()
     79 {
     80 
     81 	syscalldump="$1"
     82 	syscallname="$2"
     83 	funcname="$3"
     84 
     85     	arglist="`
     86     	sed -e 'ta
     87 		:a
     88 		s,^/\* syscall: \"'"$syscallname"'\" ,,
     89 	        tb
     90 		d
     91 		:b
     92 		s, \*/$,,' $syscalldump
     93 	`"
     94 
     95 	eval set -f -- "$arglist"
     96 
     97 	if [ $# -lt 3 ]; then
     98 		echo syscall $syscallname not found! 1>&2
     99 		exit 1
    100 	fi
    101 
    102 	shift			# kill "ret:"
    103 	returntype=$1; shift
    104 	shift			# kill "args:"
    105 
    106 	cat <<- __EOF__
    107 	/*ARGSUSED*/
    108 	$returntype
    109 	__EOF__
    110 
    111 	# do ANSI C function header
    112 	echo	"#ifdef __STDC__"
    113 
    114 	echo "$funcname("
    115 	first=yes; i=1
    116 	for arg; do
    117 		if [ $first = yes ]; then
    118 			first=no
    119 		else
    120 			echo ", "
    121 		fi
    122 		case "$arg" in
    123 		"...") echo "...";;
    124 		*) echo "$arg arg$i"; i=$(($i + 1));;
    125 		esac
    126 	done
    127 	if [ $first = yes ]; then
    128 		echo "void"
    129 	fi
    130 	echo	")"
    131 
    132 	# do K&R C function header
    133 	echo	"#else"
    134 
    135 	echo "$funcname("
    136 	first=yes; i=1
    137 	for arg; do
    138 		if [ $first = yes ]; then
    139 			first=no
    140 		else
    141 			echo ", "
    142 		fi
    143 		case "$arg" in
    144 		"...") echo "va_alist";;
    145 		*) echo "arg$i"; i=$(($i + 1));;
    146 		esac
    147 	done
    148 	echo	")"
    149 	i=1
    150 	for arg; do
    151 		case "$arg" in
    152 		"...") echo "	va_dcl";;
    153 		*) echo "	$arg arg$i;"; i=$(($i + 1));;
    154 		esac
    155 	done
    156 
    157 	# do function body
    158 	echo	"#endif"
    159 
    160 	echo	"{"
    161 	if [ "$returntype" != "void" ]; then
    162 		echo "        return (($returntype)0);"
    163 	fi
    164 	echo	"}"
    165 }
    166 
    167 trailer()
    168 {
    169 
    170 	cat <<- __EOF__
    171 	/* END */
    172 	__EOF__
    173 }
    174 
    175 set -- `getopt no:ps: $*`
    176 
    177 pflag=NO
    178 nflag=NO
    179 oarg=""
    180 syscallhdr=/usr/include/sys/syscall.h
    181 syscalldump=/tmp/makelintstub.$$
    182 
    183 if test "x${CPP}" = "x"; then
    184 	usage
    185 fi
    186 
    187 if test $? -ne 0; then
    188 	usage
    189 fi
    190 for i; do
    191 	case "$i" in
    192 	-n)	nflag=YES; shift;;
    193 	-o)	oarg=$2; shift; shift;;
    194 	-p)	pflag=YES; shift;;
    195 	-s)	syscallhdr=$2; shift; shift;;
    196 	--)	shift; break;;
    197 	esac
    198 done
    199 
    200 if [ $pflag = YES ] && [ $nflag = YES ]; then
    201 	echo "$0: -n flag and -p flag may not be used together"
    202 	echo ""
    203 	usage
    204 fi
    205 
    206 if [ "X$oarg" != "X" ]; then
    207 	exec > $oarg
    208 fi
    209 
    210 trap "rm -f $syscalldump" 0 1 2 15
    211 
    212 header
    213 echo "#include \"$syscallhdr\"" | ${CPP} -C >$syscalldump
    214 for syscall; do
    215 	fnname=${syscall%.S}
    216 	if [ $pflag = YES ]; then
    217 		scname=${fnname#_}
    218 	else
    219 		scname=$fnname
    220 	fi
    221 	syscall_stub $syscalldump $scname $fnname
    222 	echo ""
    223 done
    224 trailer
    225 
    226 exit 0
    227