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