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