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