Home | History | Annotate | Line # | Download | only in sys
makelintstub revision 1.21
      1 #!/bin/sh -
      2 # $NetBSD: makelintstub,v 1.21 2008/01/15 03:37:14 rmind 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 cat << _EOF 1>&2
     40 Usage: $PROG [-n|-p] [-o filename] object ...
     41 	The CPP environment variable must be set
     42 	to the path to the C preprocessor.
     43 _EOF
     44 	exit 1
     45 }
     46 
     47 header()
     48 {
     49 
     50 	cat <<- __EOF__
     51 	/*
     52 	 * THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT EDIT.
     53 	 */
     54 
     55 	#include <sys/param.h>
     56 	#include <sys/aio.h>
     57 	#include <sys/time.h>
     58 	#include <sys/mount.h>
     59 	#include <sys/stat.h>
     60 	#include <ufs/ufs/dinode.h>
     61 	#include <ufs/lfs/lfs.h>
     62 	#include <sys/resource.h>
     63 	#include <sys/poll.h>
     64 	#include <sys/uio.h>
     65 	#include <sys/ipc.h>
     66 	#include <sys/lwpctl.h>
     67 	#include <sys/mqueue.h>
     68 	#include <sys/msg.h>
     69 	#include <sys/sem.h>
     70 	#include <sys/shm.h>
     71 	#include <sys/sched.h>
     72 	#include <sys/timex.h>
     73 	#include <sys/socket.h>
     74 	#include <sys/event.h>
     75 	#include <sys/uuid.h>
     76 	#ifdef __STDC__
     77 	#include <stdarg.h>
     78 	#else
     79 	#include <varargs.h>
     80 	#endif
     81 
     82 	__EOF__
     83 }
     84 
     85 syscall_stub()
     86 {
     87 
     88 	syscalldump="$1"
     89 	syscallname="$2"
     90 	funcname="$3"
     91 
     92     	arglist="$(
     93     	sed -e 'ta
     94 		:a
     95 		s,^/\* syscall: \"'"$syscallname"'\" ,,
     96 	        tb
     97 		d
     98 		:b
     99 		s, \*/$,,' $syscalldump
    100 	)"
    101 
    102 	eval set -f -- "$arglist"
    103 
    104 	if [ $# -lt 3 ]; then
    105 		echo syscall $syscallname not found! 1>&2
    106 		exit 1
    107 	fi
    108 
    109 	shift			# kill "ret:"
    110 	returntype=$1; shift
    111 	shift			# kill "args:"
    112 
    113 	cat <<- __EOF__
    114 	/*ARGSUSED*/
    115 	$returntype
    116 	__EOF__
    117 
    118 	# do ANSI C function header
    119 	echo	"#ifdef __STDC__"
    120 
    121 	echo "$funcname("
    122 	first=true; i=1
    123 	for arg; do
    124 		if $first; then
    125 			first=false
    126 		else
    127 			echo ", "
    128 		fi
    129 		case "$arg" in
    130 		"...") echo "...";;
    131 		*) echo "$arg arg$i"; i=$(($i + 1));;
    132 		esac
    133 	done
    134 	if $first; then
    135 		echo "void"
    136 	fi
    137 	echo	")"
    138 
    139 	# do K&R C function header
    140 	echo	"#else"
    141 
    142 	echo "$funcname("
    143 	first=true; i=1
    144 	for arg; do
    145 		if $first; then
    146 			first=false
    147 		else
    148 			echo ", "
    149 		fi
    150 		case "$arg" in
    151 		"...") echo "va_alist";;
    152 		*) echo "arg$i"; i=$(($i + 1));;
    153 		esac
    154 	done
    155 	echo	")"
    156 	i=1
    157 	for arg; do
    158 		case "$arg" in
    159 		"...") echo "	va_dcl";;
    160 		*) echo "	$arg arg$i;"; i=$(($i + 1));;
    161 		esac
    162 	done
    163 
    164 	# do function body
    165 	echo	"#endif"
    166 
    167 	echo	"{"
    168 	if [ "$returntype" != "void" ]; then
    169 		echo "        return (($returntype)0);"
    170 	fi
    171 	echo	"}"
    172 }
    173 
    174 trailer()
    175 {
    176 
    177 	cat <<- __EOF__
    178 	/* END */
    179 	__EOF__
    180 }
    181 
    182 
    183 pflag=false
    184 nflag=false
    185 oarg=""
    186 syscallhdr=/usr/include/sys/syscall.h
    187 syscalldump=/tmp/makelintstub.$$
    188 PROG="$(basename "$0")"
    189 
    190 if [ -z "${CPP}" ]; then
    191 	usage
    192 fi
    193 
    194 while getopts no:ps: i
    195 do
    196 	case "$i" in
    197 	n)	nflag=true;;
    198 	o)	oarg=$OPTARG;;
    199 	p)	pflag=true;;
    200 	s)	syscallhdr=$OPTARG;;
    201 	*)	usage;;
    202 	esac
    203 done
    204 
    205 shift $(expr $OPTIND - 1)
    206 
    207 if $pflag && $nflag
    208 then
    209 	echo "$PROG: -n flag and -p flag may not be used together" 1>&2
    210 	usage
    211 fi
    212 
    213 if [ -n "$oarg" ]; then
    214 	exec > $oarg
    215 fi
    216 
    217 trap "rm -f $syscalldump" 0 1 2 3 15
    218 
    219 header
    220 
    221 echo "#include \"$syscallhdr\"" | ${CPP} -D_LIBC -C > $syscalldump
    222 
    223 for syscall; do
    224 	fnname=${syscall%.S}
    225 	if $pflag; then
    226 		scname=${fnname#_}
    227 	else
    228 		scname=$fnname
    229 	fi
    230 	syscall_stub $syscalldump $scname $fnname
    231 	echo ""
    232 done
    233 
    234 trailer
    235 
    236 exit 0
    237