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