Home | History | Annotate | Line # | Download | only in sys
makelintstub revision 1.13
      1 #!/bin/sh -
      2 # $NetBSD: makelintstub,v 1.13 2003/01/18 11:33:07 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 <sys/sa.h>
     58 	#include <ufs/ufs/dinode.h>
     59 	#include <ufs/lfs/lfs.h>
     60 	#include <sys/resource.h>
     61 	#include <sys/poll.h>
     62 	#include <sys/uio.h>
     63 	#include <sys/ipc.h>
     64 	#include <sys/msg.h>
     65 	#include <sys/sem.h>
     66 	#include <sys/shm.h>
     67 	#include <sys/timex.h>
     68 	#include <sys/socket.h>
     69 	#include <sys/event.h>
     70 	#ifdef __STDC__
     71 	#include <stdarg.h>
     72 	#else
     73 	#include <varargs.h>
     74 	#endif
     75 
     76 	__EOF__
     77 }
     78 
     79 syscall_stub()
     80 {
     81 
     82 	syscalldump="$1"
     83 	syscallname="$2"
     84 	funcname="$3"
     85 
     86     	arglist="`
     87     	sed -e 'ta
     88 		:a
     89 		s,^/\* syscall: \"'"$syscallname"'\" ,,
     90 	        tb
     91 		d
     92 		:b
     93 		s, \*/$,,' $syscalldump
     94 	`"
     95 
     96 	eval set -f -- "$arglist"
     97 
     98 	if [ $# -lt 3 ]; then
     99 		echo syscall $syscallname not found! 1>&2
    100 		exit 1
    101 	fi
    102 
    103 	shift			# kill "ret:"
    104 	returntype=$1; shift
    105 	shift			# kill "args:"
    106 
    107 	cat <<- __EOF__
    108 	/*ARGSUSED*/
    109 	$returntype
    110 	__EOF__
    111 
    112 	# do ANSI C function header
    113 	echo	"#ifdef __STDC__"
    114 
    115 	echo "$funcname("
    116 	first=yes; i=1
    117 	for arg; do
    118 		if [ $first = yes ]; then
    119 			first=no
    120 		else
    121 			echo ", "
    122 		fi
    123 		case "$arg" in
    124 		"...") echo "...";;
    125 		*) echo "$arg arg$i"; i=$(($i + 1));;
    126 		esac
    127 	done
    128 	if [ $first = yes ]; then
    129 		echo "void"
    130 	fi
    131 	echo	")"
    132 
    133 	# do K&R C function header
    134 	echo	"#else"
    135 
    136 	echo "$funcname("
    137 	first=yes; i=1
    138 	for arg; do
    139 		if [ $first = yes ]; then
    140 			first=no
    141 		else
    142 			echo ", "
    143 		fi
    144 		case "$arg" in
    145 		"...") echo "va_alist";;
    146 		*) echo "arg$i"; i=$(($i + 1));;
    147 		esac
    148 	done
    149 	echo	")"
    150 	i=1
    151 	for arg; do
    152 		case "$arg" in
    153 		"...") echo "	va_dcl";;
    154 		*) echo "	$arg arg$i;"; i=$(($i + 1));;
    155 		esac
    156 	done
    157 
    158 	# do function body
    159 	echo	"#endif"
    160 
    161 	echo	"{"
    162 	if [ "$returntype" != "void" ]; then
    163 		echo "        return (($returntype)0);"
    164 	fi
    165 	echo	"}"
    166 }
    167 
    168 trailer()
    169 {
    170 
    171 	cat <<- __EOF__
    172 	/* END */
    173 	__EOF__
    174 }
    175 
    176 set -- `getopt no:ps: $*`
    177 
    178 pflag=NO
    179 nflag=NO
    180 oarg=""
    181 syscallhdr=/usr/include/sys/syscall.h
    182 syscalldump=/tmp/makelintstub.$$
    183 
    184 if test "x${CPP}" = "x"; then
    185 	usage
    186 fi
    187 
    188 if test $? -ne 0; then
    189 	usage
    190 fi
    191 for i; do
    192 	case "$i" in
    193 	-n)	nflag=YES; shift;;
    194 	-o)	oarg=$2; shift; shift;;
    195 	-p)	pflag=YES; shift;;
    196 	-s)	syscallhdr=$2; shift; shift;;
    197 	--)	shift; break;;
    198 	esac
    199 done
    200 
    201 if [ $pflag = YES ] && [ $nflag = YES ]; then
    202 	echo "$0: -n flag and -p flag may not be used together"
    203 	echo ""
    204 	usage
    205 fi
    206 
    207 if [ "X$oarg" != "X" ]; then
    208 	exec > $oarg
    209 fi
    210 
    211 trap "rm -f $syscalldump" 0 1 2 15
    212 
    213 header
    214 echo "#include \"$syscallhdr\"" | ${CPP} -C >$syscalldump
    215 for syscall; do
    216 	fnname=${syscall%.S}
    217 	if [ $pflag = YES ]; then
    218 		scname=${fnname#_}
    219 	else
    220 		scname=$fnname
    221 	fi
    222 	syscall_stub $syscalldump $scname $fnname
    223 	echo ""
    224 done
    225 trailer
    226 
    227 exit 0
    228