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