Home | History | Annotate | Line # | Download | only in sys
makelintstub revision 1.1
      1  1.1  cgd #!/bin/sh -
      2  1.1  cgd #	$NetBSD: makelintstub,v 1.1 1996/12/22 11:38:34 cgd Exp $
      3  1.1  cgd #
      4  1.1  cgd # Copyright (c) 1996 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.1  cgd if [ $# -lt 1 ] || [ $# -gt 2 ]; then
     33  1.1  cgd 	echo "usage: $0 syscallname [funcname]"
     34  1.1  cgd 	exit 1
     35  1.1  cgd fi
     36  1.1  cgd 
     37  1.1  cgd syscallname="$1"
     38  1.1  cgd if [ $# -eq 1 ]; then
     39  1.1  cgd 	funcname="$syscallname"
     40  1.1  cgd else
     41  1.1  cgd 	funcname="$2"
     42  1.1  cgd fi
     43  1.1  cgd 
     44  1.1  cgd arglist="`printf '#include <sys/syscall.h>' | cpp -C | \
     45  1.1  cgd     grep '^/\* syscall: "'"$syscallname"'" ' | \
     46  1.1  cgd     sed -e 's,^/\* syscall: ,,;s, \*/$,,'`"
     47  1.1  cgd 
     48  1.1  cgd eval set -f -- "$arglist"
     49  1.1  cgd 
     50  1.1  cgd if [ $# -lt 4 ]; then
     51  1.1  cgd 	echo syscall $syscallname not found! 1>&2
     52  1.1  cgd 	exit 1
     53  1.1  cgd fi
     54  1.1  cgd 
     55  1.1  cgd syscallname=$1
     56  1.1  cgd shift 2			# kill name and "ret:"
     57  1.1  cgd returntype=$1
     58  1.1  cgd shift 2			# kill return type and "args:"
     59  1.1  cgd 
     60  1.1  cgd cat << __EOF__
     61  1.1  cgd #include <sys/param.h>
     62  1.1  cgd #include <sys/time.h>
     63  1.1  cgd #include <sys/mount.h>
     64  1.1  cgd #include <sys/stat.h>
     65  1.1  cgd #include <ufs/lfs/lfs.h>
     66  1.1  cgd #include <sys/resource.h>
     67  1.1  cgd #include <sys/poll.h>
     68  1.1  cgd #include <sys/uio.h>
     69  1.1  cgd #include <sys/ipc.h>
     70  1.1  cgd #include <sys/msg.h>
     71  1.1  cgd #include <sys/sem.h>
     72  1.1  cgd #include <sys/shm.h>
     73  1.1  cgd #include <sys/timex.h>
     74  1.1  cgd #include <sys/socket.h>
     75  1.1  cgd #ifdef __STDC__
     76  1.1  cgd #include <stdarg.h>
     77  1.1  cgd #else
     78  1.1  cgd #include <varargs.h>
     79  1.1  cgd #endif
     80  1.1  cgd 
     81  1.1  cgd /*ARGSUSED*/
     82  1.1  cgd $returntype
     83  1.1  cgd __EOF__
     84  1.1  cgd 
     85  1.1  cgd if [ "`eval echo -n \\$$#`" = "..." ]; then
     86  1.1  cgd 	varargs=YES
     87  1.1  cgd 	nargs=$(($# - 1))
     88  1.1  cgd else
     89  1.1  cgd 	varargs=NO
     90  1.1  cgd 	nargs=$#
     91  1.1  cgd fi
     92  1.1  cgd nargswithva=$#
     93  1.1  cgd 
     94  1.1  cgd # do ANSI C function header
     95  1.1  cgd echo	"#ifdef __STDC__"
     96  1.1  cgd 
     97  1.1  cgd echo -n	"$funcname("
     98  1.1  cgd i=1
     99  1.1  cgd while [ $i -le $nargs ]; do
    100  1.1  cgd 	eval echo -n \""\$$i"\"
    101  1.1  cgd 	echo -n	" arg$i"
    102  1.1  cgd 	if [ $i -lt $nargswithva ]; then
    103  1.1  cgd 		echo -n	", "
    104  1.1  cgd 	fi
    105  1.1  cgd 	i=$(($i + 1))
    106  1.1  cgd done
    107  1.1  cgd if [ $varargs = YES ]; then
    108  1.1  cgd 	echo -n "..."
    109  1.1  cgd fi
    110  1.1  cgd echo	")"
    111  1.1  cgd 
    112  1.1  cgd # do K&R C function header
    113  1.1  cgd echo	"#else"
    114  1.1  cgd 
    115  1.1  cgd echo -n	"$funcname("
    116  1.1  cgd i=1
    117  1.1  cgd while [ $i -le $nargs ]; do
    118  1.1  cgd 	echo -n	"arg$i"
    119  1.1  cgd 	if [ $i -lt $nargswithva ]; then
    120  1.1  cgd 		echo -n	", "
    121  1.1  cgd 	fi
    122  1.1  cgd 	i=$(($i + 1))
    123  1.1  cgd done
    124  1.1  cgd if [ $varargs = YES ]; then
    125  1.1  cgd 	echo -n "va_alist"
    126  1.1  cgd fi
    127  1.1  cgd echo	")"
    128  1.1  cgd i=1
    129  1.1  cgd while [ $i -le $nargs ]; do
    130  1.1  cgd 	eval echo -n \""        \$$i"\"
    131  1.1  cgd 	echo	" arg$i;"
    132  1.1  cgd 	i=$(($i + 1))
    133  1.1  cgd done
    134  1.1  cgd if [ $varargs = YES ]; then
    135  1.1  cgd 	echo	"        va_dcl"
    136  1.1  cgd fi
    137  1.1  cgd 
    138  1.1  cgd # do function body
    139  1.1  cgd echo	"#endif"
    140  1.1  cgd echo	"{"
    141  1.1  cgd if [ "$returntype" != "void" ]; then
    142  1.1  cgd 	echo "        return (($returntype)0);"
    143  1.1  cgd fi
    144  1.1  cgd echo	"}"
    145  1.1  cgd 
    146  1.1  cgd exit 0
    147