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