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